Enable track-wide color coding (#5573)

* Enable track-wide color coding

* Add support for automation tracks

* Allow saving & loading track colors

* Allow track color to be reset to default

* Partially migrate common settings to Track.cpp, fix bug

* Completely migrate local TCO color functions to TCO class, fix bug

* Set QColorDialog colors to better colors

* Color the side of the track according to TCO colors

* Disable color gradient when muted

* Change selection color to depend on TCO color

* Fix breaking builds

* Bug fix

* Fix another bug where BB track colors wouldn't load

* Restore changed demo to original state

* Fix BB Editor bug

* Fix breaking builds

* Allow random color picking

* Fix copy-paste bug

* Change how color is painted on a track

* Cleanup, and implement per-pattern colors

* Cleanup comments

* Migrate some functions

* Remove redundant function

* Rename some functions

* Migrate duplicates to superclass

* Use ColorChooser and reorder some includes

* Change how colors are saved

* Fix some formatting

* Fix some code

* Change how clip colors work

* Fix some unexpected behaviors

* Fix note border coloring being green on colored tracks

* Change name of an option

* Remove redundant code

* Fix ghost changes

* Remove colorRgb

* Rename backgroundColor, remove some variables we don't use

* Remove a redundant variable

* Migrate some duplicates to superclass

* Check for nullpointer

* Remove redundant variable

* Update some logic

* Change how muted colors are displayed

* Change how dark muted tracks become

* Place setModified() in appropriate places

* Make getColorForDisplay() function

* Change how colors are organised and saved

* Remove m_useStyleColor

* Remove a comment

* Quick changes

* Change how colors are saved

* Remove redundant stuff

* Remove redundant stuff pt. 2

* Change how colors are copied

* Fixes pt. 3

* Fixes pt. 4

* Change spaces to tabs

* Fix pseudochanges

* Remove s_lastTCOColor

* Fix pseudochanges pt. 2

* Fix breaking builds

* Add files via upload

* Add comments (again)
This commit is contained in:
Kumar
2020-10-20 22:56:22 +05:30
committed by GitHub
parent 8b2902c27a
commit f5d0524b16
10 changed files with 337 additions and 192 deletions

View File

@@ -27,10 +27,11 @@
#include <QStaticText>
#include "AutomationPattern.h"
#include "Song.h"
#include "SongEditor.h"
#include "Track.h"
class AutomationPattern;
class AutomationPatternView : public TrackContentObjectView
{

View File

@@ -50,33 +50,11 @@ public:
return( "bbtco" );
}
unsigned int color() const
{
return( m_color.rgb() );
}
QColor colorObj() const
{
return m_color;
}
void setColor( const QColor & c )
{
m_color = QColor( c );
}
void setUseStyleColor( bool b )
{
m_useStyleColor = b;
}
int bbTrackIndex();
TrackContentObjectView * createView( TrackView * _tv ) override;
private:
QColor m_color;
bool m_useStyleColor;
friend class BBTCOView;
@@ -92,11 +70,6 @@ public:
BBTCOView( TrackContentObject * _tco, TrackView * _tv );
virtual ~BBTCOView() = default;
QColor color() const
{
return( m_bbTCO->m_color );
}
void setColor( QColor _new_color );
public slots:
void update() override;
@@ -105,8 +78,6 @@ protected slots:
void openInBBEditor();
void resetName();
void changeName();
void changeColor();
void resetColor();
protected:
@@ -162,27 +133,6 @@ public:
m_disabledTracks.removeAll( _track );
}
static void setLastTCOColor( const QColor & c )
{
if( ! s_lastTCOColor )
{
s_lastTCOColor = new QColor( c );
}
else
{
*s_lastTCOColor = QColor( c );
}
}
static void clearLastTCOColor()
{
if( s_lastTCOColor )
{
delete s_lastTCOColor;
}
s_lastTCOColor = NULL;
}
protected:
inline QString nodeName() const override
{
@@ -196,8 +146,6 @@ private:
typedef QMap<BBTrack *, int> infoMap;
static infoMap s_infoMap;
static QColor * s_lastTCOColor;
friend class BBTrackView;
} ;

View File

@@ -133,6 +133,25 @@ public:
{
return m_autoResize;
}
QColor color() const
{
return m_color;
}
void setColor( const QColor & c )
{
m_color = c;
}
bool hasColor();
void useCustomClipColor( bool b );
bool usesCustomClipColor()
{
return m_useCustomClipColor;
}
virtual void movePosition( const MidiTime & pos );
virtual void changeLength( const MidiTime & length );
@@ -154,6 +173,8 @@ public:
MidiTime startTimeOffset() const;
void setStartTimeOffset( const MidiTime &startTimeOffset );
void updateColor();
// Will copy the state of a TCO to another TCO
static void copyStateTo( TrackContentObject *src, TrackContentObject *dst );
@@ -166,6 +187,7 @@ signals:
void lengthChanged();
void positionChanged();
void destroyedTCO();
void trackColorChanged();
private:
@@ -189,6 +211,9 @@ private:
bool m_selectViewOnCreate;
QColor m_color;
bool m_useCustomClipColor;
friend class TrackContentObjectView;
} ;
@@ -264,11 +289,16 @@ public:
// some metadata to be written to the clipboard.
static void remove( QVector<TrackContentObjectView *> tcovs );
static void toggleMute( QVector<TrackContentObjectView *> tcovs );
QColor getColorForDisplay( QColor );
public slots:
virtual bool close();
void remove();
void update() override;
void changeClipColor();
void useTrackColor();
protected:
enum ContextMenuAction
@@ -486,6 +516,10 @@ private slots:
void cloneTrack();
void removeTrack();
void updateMenu();
void changeTrackColor();
void randomTrackColor();
void resetTrackColor();
void useTrackColor();
void toggleRecording(bool on);
void recordingOn();
void recordingOff();
@@ -503,6 +537,9 @@ private:
signals:
void trackRemovalScheduled( TrackView * t );
void colorChanged( QColor & c );
void colorParented();
void colorReset();
} ;
@@ -635,7 +672,16 @@ public:
{
return m_processingLock.tryLock();
}
QColor color()
{
return m_color;
}
bool useColor()
{
return m_hasColor;
}
BoolModel* getMutedModel();
public slots:
@@ -647,6 +693,8 @@ public slots:
void toggleSolo();
void trackColorChanged( QColor & c );
void trackColorReset();
private:
TrackContainer* m_trackContainer;
@@ -665,6 +713,9 @@ private:
tcoVector m_trackContentObjects;
QMutex m_processingLock;
QColor m_color;
bool m_hasColor;
friend class TrackView;

View File

@@ -538,6 +538,11 @@ void AutomationPattern::saveSettings( QDomDocument & _doc, QDomElement & _this )
_this.setAttribute( "prog", QString::number( progressionType() ) );
_this.setAttribute( "tens", QString::number( getTension() ) );
_this.setAttribute( "mute", QString::number( isMuted() ) );
if( usesCustomClipColor() )
{
_this.setAttribute( "color", color().name() );
}
for( timeMap::const_iterator it = m_timeMap.begin();
it != m_timeMap.end(); ++it )
@@ -593,6 +598,12 @@ void AutomationPattern::loadSettings( const QDomElement & _this )
m_idsToResolve << element.attribute( "id" ).toInt();
}
}
if( _this.hasAttribute( "color" ) )
{
useCustomClipColor( true );
setColor( _this.attribute( "color" ) );
}
int len = _this.attribute( "len" ).toInt();
if( len <= 0 )

View File

@@ -38,8 +38,10 @@
#include "Track.h"
#include <assert.h>
#include <cstdlib>
#include <QLayout>
#include <QLinearGradient>
#include <QMenu>
#include <QMouseEvent>
#include <QPainter>
@@ -56,6 +58,7 @@
#include "BBTrackContainer.h"
#include "ConfigManager.h"
#include "Clipboard.h"
#include "ColorChooser.h"
#include "embed.h"
#include "Engine.h"
#include "GuiApplication.h"
@@ -104,7 +107,9 @@ TrackContentObject::TrackContentObject( Track * track ) :
m_startPosition(),
m_length(),
m_mutedModel( false, this, tr( "Mute" ) ),
m_selectViewOnCreate( false )
m_selectViewOnCreate( false ),
m_color( 128, 128, 128 ),
m_useCustomClipColor( false )
{
if( getTrack() )
{
@@ -238,8 +243,28 @@ void TrackContentObject::setStartTimeOffset( const MidiTime &startTimeOffset )
m_startTimeOffset = startTimeOffset;
}
// Update TCO color if it follows the track color
void TrackContentObject::updateColor()
{
if( ! m_useCustomClipColor )
{
emit trackColorChanged();
}
}
void TrackContentObject::useCustomClipColor( bool b )
{
m_useCustomClipColor = b;
updateColor();
}
bool TrackContentObject::hasColor()
{
return usesCustomClipColor() || getTrack()->useColor();
}
@@ -303,6 +328,8 @@ TrackContentObjectView::TrackContentObjectView( TrackContentObject * tco,
this, SLOT( updatePosition() ) );
connect( m_tco, SIGNAL( destroyedTCO() ), this, SLOT( close() ) );
setModel( m_tco );
connect( m_tco, SIGNAL( trackColorChanged() ), this, SLOT( update() ) );
connect( m_trackView->getTrackOperationsWidget(), SIGNAL( colorParented() ), this, SLOT( useTrackColor() ) );
m_trackView->getTrackContentWidget()->addTCOView( this );
updateLength();
@@ -512,6 +539,32 @@ void TrackContentObjectView::updatePosition()
void TrackContentObjectView::changeClipColor()
{
// Get a color from the user
QColor new_color = ColorChooser( this ).withPalette( ColorChooser::Palette::Track )->getColor( m_tco->color() );
if( ! new_color.isValid() )
{ return; }
// Use that color
m_tco->setColor( new_color );
m_tco->useCustomClipColor( true );
update();
}
void TrackContentObjectView::useTrackColor()
{
m_tco->useCustomClipColor( false );
update();
}
/*! \brief Change the trackContentObjectView's display when something
* being dragged enters it.
*
@@ -1151,6 +1204,13 @@ void TrackContentObjectView::contextMenuEvent( QContextMenuEvent * cme )
: tr("Mute/unmute selection (<%1> + middle click)")).arg(UI_CTRL_KEY),
[this](){ contextMenuAction( Mute ); } );
contextMenu.addSeparator();
contextMenu.addAction( embed::getIconPixmap( "colorize" ),
tr( "Set clip color" ), this, SLOT( changeClipColor() ) );
contextMenu.addAction( embed::getIconPixmap( "colorize" ),
tr( "Use track color" ), this, SLOT( useTrackColor() ) );
constructContextMenu( &contextMenu );
contextMenu.exec( QCursor::pos() );
@@ -1354,6 +1414,51 @@ MidiTime TrackContentObjectView::draggedTCOPos( QMouseEvent * me )
}
// Return the color that the TCO's background should be
QColor TrackContentObjectView::getColorForDisplay( QColor defaultColor )
{
// Get the pure TCO color
auto tcoColor = m_tco->hasColor()
? m_tco->usesCustomClipColor()
? m_tco->color()
: m_tco->getTrack()->color()
: defaultColor;
// Set variables
QColor c, mutedCustomColor;
bool muted = m_tco->getTrack()->isMuted() || m_tco->isMuted();
mutedCustomColor = tcoColor;
mutedCustomColor.setHsv( mutedCustomColor.hsvHue(), mutedCustomColor.hsvSaturation() / 4, mutedCustomColor.value() );
// Change the pure color by state: selected, muted, colored, normal
if( isSelected() )
{
c = m_tco->hasColor()
? ( muted
? mutedCustomColor.darker( 350 )
: tcoColor.darker( 150 ) )
: selectedColor();
}
else
{
if( muted )
{
c = m_tco->hasColor()
? mutedCustomColor.darker( 250 )
: mutedBackgroundColor();
}
else
{
c = tcoColor;
}
}
// Return color to caller
return c;
}
// ===========================================================================
@@ -2073,6 +2178,10 @@ TrackOperationsWidget::TrackOperationsWidget( TrackView * parent ) :
m_trackView->trackContainerView(),
SLOT( deleteTrackView( TrackView * ) ),
Qt::QueuedConnection );
connect( m_trackView->getTrack()->getMutedModel(), SIGNAL( dataChanged() ),
this, SLOT( update() ) );
}
@@ -2135,7 +2244,15 @@ void TrackOperationsWidget::mousePressEvent( QMouseEvent * me )
void TrackOperationsWidget::paintEvent( QPaintEvent * pe )
{
QPainter p( this );
p.fillRect( rect(), palette().brush(QPalette::Background) );
if( m_trackView->getTrack()->useColor() && ! m_trackView->getTrack()->getMutedModel()->value() )
{
QRect coloredRect( 0, 0, 10, m_trackView->getTrack()->getHeight() );
p.fillRect( coloredRect, m_trackView->getTrack()->color() );
}
if( m_trackView->isMovingTrack() == false )
{
@@ -2190,7 +2307,41 @@ void TrackOperationsWidget::removeTrack()
emit trackRemovalScheduled( m_trackView );
}
void TrackOperationsWidget::changeTrackColor()
{
QColor new_color = ColorChooser( this ).withPalette( ColorChooser::Palette::Track )-> \
getColor( m_trackView->getTrack()->color() );
if( ! new_color.isValid() )
{ return; }
emit colorChanged( new_color );
Engine::getSong()->setModified();
update();
}
void TrackOperationsWidget::resetTrackColor()
{
emit colorReset();
Engine::getSong()->setModified();
update();
}
void TrackOperationsWidget::randomTrackColor()
{
QColor buffer = ColorChooser::getPalette( ColorChooser::Palette::Track )[ rand() % 48 ];
emit colorChanged( buffer );
Engine::getSong()->setModified();
update();
}
void TrackOperationsWidget::useTrackColor()
{
emit colorParented();
Engine::getSong()->setModified();
}
/*! \brief Update the trackOperationsWidget context menu
@@ -2231,6 +2382,17 @@ void TrackOperationsWidget::updateMenu()
toMenu->addAction( tr( "Turn all recording on" ), this, SLOT( recordingOn() ) );
toMenu->addAction( tr( "Turn all recording off" ), this, SLOT( recordingOff() ) );
}
toMenu->addSeparator();
toMenu->addAction( embed::getIconPixmap( "colorize" ),
tr( "Change color" ), this, SLOT( changeTrackColor() ) );
toMenu->addAction( embed::getIconPixmap( "colorize" ),
tr( "Reset color to default" ), this, SLOT( resetTrackColor() ) );
toMenu->addAction( embed::getIconPixmap( "colorize" ),
tr( "Set random color" ), this, SLOT( randomTrackColor() ) );
toMenu->addSeparator();
toMenu->addAction( embed::getIconPixmap( "colorize" ),
tr( "Clear clip colors" ), this, SLOT( useTrackColor() ) );
}
@@ -2286,7 +2448,9 @@ Track::Track( TrackTypes type, TrackContainer * tc ) :
m_soloModel( false, this, tr( "Solo" ) ),
/*!< For controlling track soloing */
m_simpleSerializingMode( false ),
m_trackContentObjects() /*!< The track content objects (segments) */
m_trackContentObjects(), /*!< The track content objects (segments) */
m_color( 0, 0, 0 ),
m_hasColor( false )
{
m_trackContainer->addTrack( this );
m_height = -1;
@@ -2431,7 +2595,12 @@ void Track::saveSettings( QDomDocument & doc, QDomElement & element )
{
element.setAttribute( "trackheight", m_height );
}
if( m_hasColor )
{
element.setAttribute( "color", m_color.name() );
}
QDomElement tsDe = doc.createElement( nodeName() );
// let actual track (InstrumentTrack, bbTrack, sampleTrack etc.) save
// its settings
@@ -2484,6 +2653,12 @@ void Track::loadSettings( const QDomElement & element )
// Older project files that didn't have this attribute will set the value to false (issue 5562)
m_mutedBeforeSolo = QVariant( element.attribute( "mutedBeforeSolo", "0" ) ).toBool();
if( element.hasAttribute( "color" ) )
{
m_color.setNamedColor( element.attribute( "color" ) );
m_hasColor = true;
}
if( m_simpleSerializingMode )
{
QDomNode node = element.firstChild();
@@ -2861,7 +3036,24 @@ void Track::toggleSolo()
}
}
void Track::trackColorChanged( QColor & c )
{
for (int i = 0; i < numOfTCOs(); i++)
{
m_trackContentObjects[i]->updateColor();
}
m_hasColor = true;
m_color = c;
}
void Track::trackColorReset()
{
for (int i = 0; i < numOfTCOs(); i++)
{
m_trackContentObjects[i]->updateColor();
}
m_hasColor = false;
}
BoolModel *Track::getMutedModel()
@@ -2932,6 +3124,13 @@ TrackView::TrackView( Track * track, TrackContainerView * tcv ) :
connect( &m_track->m_soloModel, SIGNAL( dataChanged() ),
m_track, SLOT( toggleSolo() ), Qt::DirectConnection );
connect( &m_trackOperationsWidget, SIGNAL( colorChanged( QColor & ) ),
m_track, SLOT( trackColorChanged( QColor & ) ) );
connect( &m_trackOperationsWidget, SIGNAL( colorReset() ),
m_track, SLOT( trackColorReset() ) );
// create views for already existing TCOs
for( Track::tcoVector::iterator it =
m_track->m_trackContentObjects.begin();

View File

@@ -216,8 +216,6 @@ void AutomationPatternView::constructContextMenu( QMenu * _cm )
this, SLOT( disconnectObject( QAction * ) ) );
_cm->addMenu( m );
}
_cm->addSeparator();
}
@@ -256,13 +254,9 @@ void AutomationPatternView::paintEvent( QPaintEvent * )
QPainter p( &m_paintPixmap );
QLinearGradient lingrad( 0, 0, 0, height() );
QColor c;
QColor c = getColorForDisplay( painter.background().color() );
bool muted = m_pat->getTrack()->isMuted() || m_pat->isMuted();
bool current = gui->automationEditor()->currentPattern() == m_pat;
// state: selected, muted, normal
c = isSelected() ? selectedColor() : ( muted ? mutedBackgroundColor()
: painter.background().color() );
lingrad.setColorAt( 1, c.darker( 300 ) );
lingrad.setColorAt( 0, c );

View File

@@ -23,7 +23,6 @@
*/
#include "BBTrack.h"
#include <QColorDialog>
#include <QMenu>
#include <QPainter>
@@ -32,8 +31,8 @@
#include "embed.h"
#include "Engine.h"
#include "gui_templates.h"
#include "MainWindow.h"
#include "GuiApplication.h"
#include "MainWindow.h"
#include "Mixer.h"
#include "RenameDialog.h"
#include "Song.h"
@@ -47,9 +46,7 @@ BBTrack::infoMap BBTrack::s_infoMap;
BBTCO::BBTCO( Track * _track ) :
TrackContentObject( _track ),
m_color( 128, 128, 128 ),
m_useStyleColor( true )
TrackContentObject( _track )
{
bar_t t = Engine::getBBTrackContainer()->lengthOfBB( bbTrackIndex() );
if( t > 0 )
@@ -74,15 +71,9 @@ void BBTCO::saveSettings( QDomDocument & doc, QDomElement & element )
}
element.setAttribute( "len", length() );
element.setAttribute( "muted", isMuted() );
element.setAttribute( "color", color() );
if( m_useStyleColor )
if( usesCustomClipColor() )
{
element.setAttribute( "usestyle", 1 );
}
else
{
element.setAttribute( "usestyle", 0 );
element.setAttribute( "color", color().name() );
}
}
@@ -101,33 +92,21 @@ void BBTCO::loadSettings( const QDomElement & element )
{
toggleMute();
}
if( element.hasAttribute( "color" ) )
// for colors saved in 1.3-onwards
if( element.hasAttribute( "color" ) && !element.hasAttribute( "usestyle" ) )
{
setColor( QColor( element.attribute( "color" ).toUInt() ) );
useCustomClipColor( true );
setColor( element.attribute( "color" ) );
}
if( element.hasAttribute( "usestyle" ) )
{
if( element.attribute( "usestyle" ).toUInt() == 1 )
{
m_useStyleColor = true;
}
else
{
m_useStyleColor = false;
}
}
// for colors saved before 1.3
else
{
if( m_color.rgb() == qRgb( 128, 182, 175 ) || m_color.rgb() == qRgb( 64, 128, 255 ) ) // old or older default color
{
m_useStyleColor = true;
}
else
{
m_useStyleColor = false;
}
if( element.hasAttribute( "color" ) )
{ setColor( QColor( element.attribute( "color" ).toUInt() ) ); }
// usestyle attribute is no longer used
}
}
@@ -153,7 +132,8 @@ BBTCOView::BBTCOView( TrackContentObject * _tco, TrackView * _tv ) :
m_bbTCO( dynamic_cast<BBTCO *>( _tco ) ),
m_paintPixmap()
{
connect( _tco->getTrack(), SIGNAL( dataChanged() ), this, SLOT( update() ) );
connect( _tco->getTrack(), SIGNAL( dataChanged() ),
this, SLOT( update() ) );
setStyle( QApplication::style() );
}
@@ -173,10 +153,6 @@ void BBTCOView::constructContextMenu( QMenu * _cm )
_cm->addAction( embed::getIconPixmap( "edit_rename" ),
tr( "Change name" ),
this, SLOT( changeName() ) );
_cm->addAction( embed::getIconPixmap( "colorize" ),
tr( "Change color" ), this, SLOT( changeColor() ) );
_cm->addAction( embed::getIconPixmap( "colorize" ),
tr( "Reset color to default" ), this, SLOT( resetColor() ) );
}
@@ -210,13 +186,7 @@ void BBTCOView::paintEvent( QPaintEvent * )
QPainter p( &m_paintPixmap );
QLinearGradient lingrad( 0, 0, 0, height() );
QColor c;
bool muted = m_bbTCO->getTrack()->isMuted() || m_bbTCO->isMuted();
// state: selected, muted, default, user selected
c = isSelected() ? selectedColor() : ( muted ? mutedBackgroundColor()
: ( m_bbTCO->m_useStyleColor ? painter.background().color()
: m_bbTCO->colorObj() ) );
QColor c = getColorForDisplay( painter.background().color() );
lingrad.setColorAt( 0, c.lighter( 130 ) );
lingrad.setColorAt( 1, c.lighter( 70 ) );
@@ -305,63 +275,6 @@ void BBTCOView::changeName()
void BBTCOView::changeColor()
{
QColor new_color = QColorDialog::getColor( m_bbTCO->m_color );
if( ! new_color.isValid() )
{
return;
}
if( isSelected() )
{
QVector<selectableObject *> selected =
gui->songEditor()->m_editor->selectedObjects();
for( QVector<selectableObject *>::iterator it =
selected.begin();
it != selected.end(); ++it )
{
BBTCOView * bb_tcov = dynamic_cast<BBTCOView *>( *it );
if( bb_tcov )
{
bb_tcov->setColor( new_color );
}
}
}
else
{
setColor( new_color );
}
}
/** \brief Makes the BB pattern use the colour defined in the stylesheet */
void BBTCOView::resetColor()
{
if( ! m_bbTCO->m_useStyleColor )
{
m_bbTCO->m_useStyleColor = true;
Engine::getSong()->setModified();
update();
}
BBTrack::clearLastTCOColor();
}
void BBTCOView::setColor( QColor new_color )
{
if( new_color.rgb() != m_bbTCO->color() )
{
m_bbTCO->setColor( new_color );
m_bbTCO->m_useStyleColor = false;
Engine::getSong()->setModified();
update();
}
BBTrack::setLastTCOColor( new_color );
}
void BBTCOView::update()
{
ToolTip::add(this, m_bbTCO->name());
@@ -371,8 +284,6 @@ void BBTCOView::update()
QColor * BBTrack::s_lastTCOColor = NULL;
BBTrack::BBTrack( TrackContainer* tc ) :
Track( Track::BBTrack, tc )
{
@@ -474,11 +385,6 @@ TrackView * BBTrack::createView( TrackContainerView* tcv )
TrackContentObject * BBTrack::createTCO( const MidiTime & _pos )
{
BBTCO * bbtco = new BBTCO( this );
if( s_lastTCOColor )
{
bbtco->setColor( *s_lastTCOColor );
bbtco->setUseStyleColor( false );
}
return bbtco;
}

View File

@@ -30,11 +30,13 @@
#include <QMouseEvent>
#include <QPainter>
#include <QPushButton>
#include <QTimer>
#include "AudioSampleRecorder.h"
#include "BBTrackContainer.h"
#include "DeprecationHelper.h"
#include "embed.h"
#include "gui_templates.h"
#include "GuiApplication.h"
#include "InstrumentTrack.h"
#include "PianoRoll.h"
@@ -356,6 +358,11 @@ void Pattern::saveSettings( QDomDocument & _doc, QDomElement & _this )
{
_this.setAttribute( "type", m_patternType );
_this.setAttribute( "name", name() );
if( usesCustomClipColor() )
{
_this.setAttribute( "color", color().name() );
}
// as the target of copied/dragged pattern is always an existing
// pattern, we must not store actual position, instead we store -1
// which tells loadSettings() not to mess around with position
@@ -387,6 +394,13 @@ void Pattern::loadSettings( const QDomElement & _this )
m_patternType = static_cast<PatternTypes>( _this.attribute( "type"
).toInt() );
setName( _this.attribute( "name" ) );
if( _this.hasAttribute( "color" ) )
{
useCustomClipColor( true );
setColor( _this.attribute( "color" ) );
}
if( _this.attribute( "pos" ).toInt() >= 0 )
{
movePosition( _this.attribute( "pos" ).toInt() );
@@ -853,14 +867,20 @@ void PatternView::paintEvent( QPaintEvent * )
QPainter p( &m_paintPixmap );
QColor c;
bool const muted = m_pat->getTrack()->isMuted() || m_pat->isMuted();
bool current = gui->pianoRoll()->currentPattern() == m_pat;
bool beatPattern = m_pat->m_patternType == Pattern::BeatPattern;
// state: selected, normal, beat pattern, muted
QColor c = isSelected() ? selectedColor() : ( ( !muted && !beatPattern )
? painter.background().color() : ( beatPattern
? BBPatternBackground() : mutedBackgroundColor() ) );
if( beatPattern )
{
// Do not paint BBTCOs how we paint pattern TCOs
c = BBPatternBackground();
}
else
{
c = getColorForDisplay( painter.background().color() );
}
// invert the gradient for the background in the B&B editor
QLinearGradient lingrad( 0, 0, 0, height() );
@@ -973,7 +993,8 @@ void PatternView::paintEvent( QPaintEvent * )
// set colour based on mute status
QColor noteFillColor = muted ? getMutedNoteFillColor() : getNoteFillColor();
QColor noteBorderColor = muted ? getMutedNoteBorderColor() : getNoteBorderColor();
QColor noteBorderColor = muted ? getMutedNoteBorderColor()
: ( m_pat->hasColor() ? c.lighter( 200 ) : getNoteBorderColor() );
bool const drawAsLines = height() < 64;
if (drawAsLines)

View File

@@ -275,7 +275,11 @@ void SampleTCO::saveSettings( QDomDocument & _doc, QDomElement & _this )
_this.setAttribute( "data", m_sampleBuffer->toBase64( s ) );
}
_this.setAttribute ("sample_rate", m_sampleBuffer->sampleRate());
_this.setAttribute( "sample_rate", m_sampleBuffer->sampleRate());
if( usesCustomClipColor() )
{
_this.setAttribute( "color", color().name() );
}
// TODO: start- and end-frame
}
@@ -297,8 +301,14 @@ void SampleTCO::loadSettings( const QDomElement & _this )
setMuted( _this.attribute( "muted" ).toInt() );
setStartTimeOffset( _this.attribute( "off" ).toInt() );
if (_this.hasAttribute("sample_rate")) {
m_sampleBuffer->setSampleRate(_this.attribute("sample_rate").toInt());
if ( _this.hasAttribute( "sample_rate" ) ) {
m_sampleBuffer->setSampleRate( _this.attribute( "sample_rate" ).toInt() );
}
if( _this.hasAttribute( "color" ) )
{
useCustomClipColor( true );
setColor( _this.attribute( "color" ) );
}
}
@@ -397,6 +407,14 @@ void SampleTCOView::contextMenuEvent( QContextMenuEvent * _cme )
/*contextMenu.addAction( embed::getIconPixmap( "record" ),
tr( "Set/clear record" ),
m_tco, SLOT( toggleRecord() ) );*/
contextMenu.addSeparator();
contextMenu.addAction( embed::getIconPixmap( "colorize" ),
tr( "Set clip color" ), this, SLOT( changeClipColor() ) );
contextMenu.addAction( embed::getIconPixmap( "colorize" ),
tr( "Use track color" ), this, SLOT( useTrackColor() ) );
constructContextMenu( &contextMenu );
contextMenu.exec( QCursor::pos() );
@@ -525,13 +543,9 @@ void SampleTCOView::paintEvent( QPaintEvent * pe )
QPainter p( &m_paintPixmap );
QLinearGradient lingrad( 0, 0, 0, height() );
QColor c;
QColor c = getColorForDisplay( painter.background().color() );
bool muted = m_tco->getTrack()->isMuted() || m_tco->isMuted();
// state: selected, muted, normal
c = isSelected() ? selectedColor() : ( muted ? mutedBackgroundColor()
: painter.background().color() );
lingrad.setColorAt( 1, c.darker( 300 ) );
lingrad.setColorAt( 0, c );
@@ -571,12 +585,12 @@ void SampleTCOView::paintEvent( QPaintEvent * pe )
p.setRenderHint( QPainter::Antialiasing, false );
// inner border
p.setPen( c.lighter( 160 ) );
p.setPen( c.lighter( 135 ) );
p.drawRect( 1, 1, rect().right() - TCO_BORDER_WIDTH,
rect().bottom() - TCO_BORDER_WIDTH );
// outer border
p.setPen( c.darker( 300 ) );
p.setPen( c.darker( 200 ) );
p.drawRect( 0, 0, rect().right(), rect().bottom() );
// draw the 'muted' pixmap only if the pattern was manualy muted