diff --git a/data/projects/demos/Greippi - Krem Kaakkuja (Second Flight Remix).mmpz b/data/projects/demos/Greippi - Krem Kaakkuja (Second Flight Remix).mmpz index 9ea29b34d3f..d08ca6e04c1 100644 Binary files a/data/projects/demos/Greippi - Krem Kaakkuja (Second Flight Remix).mmpz and b/data/projects/demos/Greippi - Krem Kaakkuja (Second Flight Remix).mmpz differ diff --git a/include/AutomationPatternView.h b/include/AutomationPatternView.h index 3f019483a10..a6529b5d4a1 100644 --- a/include/AutomationPatternView.h +++ b/include/AutomationPatternView.h @@ -27,10 +27,11 @@ #include +#include "AutomationPattern.h" +#include "Song.h" +#include "SongEditor.h" #include "Track.h" -class AutomationPattern; - class AutomationPatternView : public TrackContentObjectView { diff --git a/include/BBTrack.h b/include/BBTrack.h index 70195f28de6..36a10884547 100644 --- a/include/BBTrack.h +++ b/include/BBTrack.h @@ -50,33 +50,11 @@ class BBTCO : public TrackContentObject 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 @@ class BBTCOView : public TrackContentObjectView 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 @@ class LMMS_EXPORT BBTrack : public Track 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 @@ class LMMS_EXPORT BBTrack : public Track typedef QMap infoMap; static infoMap s_infoMap; - static QColor * s_lastTCOColor; - friend class BBTrackView; } ; diff --git a/include/Track.h b/include/Track.h index 9362a838019..f646c66b28b 100644 --- a/include/Track.h +++ b/include/Track.h @@ -133,6 +133,25 @@ class LMMS_EXPORT TrackContentObject : public Model, public JournallingObject { 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 @@ class LMMS_EXPORT TrackContentObject : public Model, public JournallingObject MidiTime startTimeOffset() const; void setStartTimeOffset( const MidiTime &startTimeOffset ); + + void updateColor(); public slots: void copy(); @@ -165,6 +186,7 @@ public slots: void lengthChanged(); void positionChanged(); void destroyedTCO(); + void trackColorChanged(); private: @@ -188,6 +210,9 @@ public slots: bool m_selectViewOnCreate; + QColor m_color; + bool m_useCustomClipColor; + friend class TrackContentObjectView; } ; @@ -263,12 +288,17 @@ class TrackContentObjectView : public selectableObject, public ModelView // some metadata to be written to the clipboard. static void remove( QVector tcovs ); static void toggleMute( QVector tcovs ); + + QColor getColorForDisplay( QColor ); public slots: virtual bool close(); void cut(); 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 slots: signals: void trackRemovalScheduled( TrackView * t ); + void colorChanged( QColor & c ); + void colorParented(); + void colorReset(); } ; @@ -635,7 +672,16 @@ class LMMS_EXPORT Track : public Model, public JournallingObject { 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 @@ public slots: tcoVector m_trackContentObjects; QMutex m_processingLock; + + QColor m_color; + bool m_hasColor; friend class TrackView; diff --git a/src/core/AutomationPattern.cpp b/src/core/AutomationPattern.cpp index 2fd1cea125f..8886d7ea5e6 100644 --- a/src/core/AutomationPattern.cpp +++ b/src/core/AutomationPattern.cpp @@ -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 ) diff --git a/src/core/Track.cpp b/src/core/Track.cpp index c7f6d62b0b5..83d1a0c8a20 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -38,8 +38,10 @@ #include "Track.h" #include +#include #include +#include #include #include #include @@ -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() ) { @@ -247,7 +252,27 @@ 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(); +} @@ -312,6 +337,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(); @@ -535,6 +562,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. * @@ -1174,6 +1227,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() ); @@ -1412,6 +1472,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; +} + + + // =========================================================================== @@ -2121,6 +2226,10 @@ TrackOperationsWidget::TrackOperationsWidget( TrackView * parent ) : m_trackView->trackContainerView(), SLOT( deleteTrackView( TrackView * ) ), Qt::QueuedConnection ); + + connect( m_trackView->getTrack()->getMutedModel(), SIGNAL( dataChanged() ), + this, SLOT( update() ) ); + } @@ -2183,7 +2292,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 ) { @@ -2238,7 +2355,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 @@ -2279,6 +2430,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() ) ); } @@ -2334,7 +2496,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; @@ -2479,7 +2643,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 @@ -2532,6 +2701,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(); @@ -2909,7 +3084,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() @@ -2980,6 +3172,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(); diff --git a/src/gui/AutomationPatternView.cpp b/src/gui/AutomationPatternView.cpp index 6daba567b0f..1c9ac03a418 100644 --- a/src/gui/AutomationPatternView.cpp +++ b/src/gui/AutomationPatternView.cpp @@ -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 ); diff --git a/src/tracks/BBTrack.cpp b/src/tracks/BBTrack.cpp index ec6b4042004..4f0ba38e2df 100644 --- a/src/tracks/BBTrack.cpp +++ b/src/tracks/BBTrack.cpp @@ -23,7 +23,6 @@ */ #include "BBTrack.h" -#include #include #include @@ -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" ) ) - { - setColor( QColor( element.attribute( "color" ).toUInt() ) ); - } - if( element.hasAttribute( "usestyle" ) ) + // for colors saved in 1.3-onwards + if( element.hasAttribute( "color" ) && !element.hasAttribute( "usestyle" ) ) { - if( element.attribute( "usestyle" ).toUInt() == 1 ) - { - m_useStyleColor = true; - } - else - { - m_useStyleColor = false; - } + useCustomClipColor( true ); + setColor( element.attribute( "color" ) ); } + + // 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( _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 selected = - gui->songEditor()->m_editor->selectedObjects(); - for( QVector::iterator it = - selected.begin(); - it != selected.end(); ++it ) - { - BBTCOView * bb_tcov = dynamic_cast( *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; } diff --git a/src/tracks/Pattern.cpp b/src/tracks/Pattern.cpp index e5de8b83b68..69d575813b6 100644 --- a/src/tracks/Pattern.cpp +++ b/src/tracks/Pattern.cpp @@ -30,11 +30,13 @@ #include #include #include +#include #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( _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) diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index 80d41adea7f..6515be3e42a 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -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