From 439b3a24c7a9f872a0be315126b422a783d29e75 Mon Sep 17 00:00:00 2001 From: adi Date: Sun, 19 Jul 2020 14:30:49 +0530 Subject: [PATCH 01/18] Enable mixer color-coding --- include/FxLine.h | 24 ++++++++++ include/FxMixer.h | 5 ++ src/core/FxMixer.cpp | 10 +++- src/gui/widgets/FxLine.cpp | 98 +++++++++++++++++++++++++++++++++++++- 4 files changed, 135 insertions(+), 2 deletions(-) diff --git a/include/FxLine.h b/include/FxLine.h index c16dcd5f598..3a479d7d325 100644 --- a/include/FxLine.h +++ b/include/FxLine.h @@ -80,6 +80,27 @@ class FxLine : public QWidget static const int FxLineHeight; bool eventFilter (QObject *dist, QEvent *event) override; + + /*unsigned int color() + { + return m_color.rgb(); + } + void setColor( unsigned int c ) + { + m_color.setRgb( c ); + } + + bool hasColor() + { + return m_hasColor; + } + void setHasColor( bool b ) + { + m_hasColor = b; + }*/ + + /*void saveSettings( QDomElement & _this ); + void loadSettings( const QDomElement & _this );*/ private: void drawFxLine( QPainter* p, const FxLine *fxLine, bool isActive, bool sendToThis, bool receiveFromThis ); @@ -101,6 +122,9 @@ class FxLine : public QWidget public slots: void renameChannel(); + void resetColor(); + void changeColor(); + void randomColor(); private slots: void renameFinished(); diff --git a/include/FxMixer.h b/include/FxMixer.h index 68b69d9bc88..69ba62e005c 100644 --- a/include/FxMixer.h +++ b/include/FxMixer.h @@ -32,6 +32,8 @@ #include +#include + class FxRoute; typedef QVector FxRouteVector; @@ -69,6 +71,9 @@ class FxChannel : public ThreadableJob bool requiresProcessing() const override { return true; } void unmuteForSolo(); + + QColor m_color; + bool m_hasColor; std::atomic_int m_dependenciesMet; diff --git a/src/core/FxMixer.cpp b/src/core/FxMixer.cpp index 4a68c3f3b05..989ca2e61e5 100644 --- a/src/core/FxMixer.cpp +++ b/src/core/FxMixer.cpp @@ -73,7 +73,8 @@ FxChannel::FxChannel( int idx, Model * _parent ) : m_lock(), m_channelIndex( idx ), m_queued( false ), - m_dependenciesMet(0) + m_dependenciesMet(0), + m_hasColor( false ) { BufferManager::clear( m_buffer, Engine::mixer()->framesPerPeriod() ); } @@ -741,6 +742,8 @@ void FxMixer::saveSettings( QDomDocument & _doc, QDomElement & _this ) ch->m_soloModel.saveSettings( _doc, fxch, "soloed" ); fxch.setAttribute( "num", i ); fxch.setAttribute( "name", ch->m_name ); + fxch.setAttribute( "hascolor", ch->m_hasColor ); + fxch.setAttribute( "mixercolor", ch->m_color.rgb() ); // add the channel sends for( int si = 0; si < ch->m_sends.size(); ++si ) @@ -786,6 +789,11 @@ void FxMixer::loadSettings( const QDomElement & _this ) m_fxChannels[num]->m_muteModel.loadSettings( fxch, "muted" ); m_fxChannels[num]->m_soloModel.loadSettings( fxch, "soloed" ); m_fxChannels[num]->m_name = fxch.attribute( "name" ); + if( fxch.hasAttribute( "hascolor" ) ) + { + m_fxChannels[num]->m_hasColor = fxch.attribute( "hascolor" ).toInt(); + m_fxChannels[num]->m_color.setRgb( fxch.attribute( "mixercolor" ).toUInt() ); + } m_fxChannels[num]->m_fxChain.restoreState( fxch.firstChildElement( m_fxChannels[num]->m_fxChain.nodeName() ) ); diff --git a/src/gui/widgets/FxLine.cpp b/src/gui/widgets/FxLine.cpp index 3314301fd77..1a1590dc124 100644 --- a/src/gui/widgets/FxLine.cpp +++ b/src/gui/widgets/FxLine.cpp @@ -25,6 +25,10 @@ #include "FxLine.h" +#include +#include + +#include #include #include "CaptionMenu.h" @@ -120,6 +124,10 @@ FxLine::FxLine( QWidget * _parent, FxMixerView * _mv, int _channelIndex ) : proxyWidget->setPos( 8, 145 ); connect( m_renameLineEdit, SIGNAL( editingFinished() ), this, SLOT( renameFinished() ) ); + + connect( &Engine::fxMixer()->effectChannel( m_channelIndex )->m_muteModel, SIGNAL( dataChanged() ), this, SLOT( update() ) ); + + srand( time( 0 ) ); } @@ -148,6 +156,7 @@ void FxLine::setChannelIndex( int index ) void FxLine::drawFxLine( QPainter* p, const FxLine *fxLine, bool isActive, bool sendToThis, bool receiveFromThis ) { QString name = Engine::fxMixer()->effectChannel( m_channelIndex )->m_name; + bool muted = Engine::fxMixer()->effectChannel( m_channelIndex )->m_muteModel.value(); QString elidedName = elideName( name ); if( !m_inRename && m_renameLineEdit->text() != elidedName ) { @@ -157,7 +166,13 @@ void FxLine::drawFxLine( QPainter* p, const FxLine *fxLine, bool isActive, bool int width = fxLine->rect().width(); int height = fxLine->rect().height(); - p->fillRect( fxLine->rect(), isActive ? fxLine->backgroundActive() : p->background() ); + QColor color = muted ? ( isActive ? fxLine->backgroundActive().color() : p->background().color() ) + : ( Engine::fxMixer()->effectChannel( m_channelIndex )->m_hasColor ? ( isActive ? Engine::fxMixer()->effectChannel( m_channelIndex )->m_color.darker( 120 ) + : Engine::fxMixer()->effectChannel( m_channelIndex )->m_color.darker( 150 ) ) + : ( isActive ? fxLine->backgroundActive().color() + : p->background().color() ) ); + + p->fillRect( fxLine->rect(), color ); // inner border p->setPen( isActive ? fxLine->strokeInnerActive() : fxLine->strokeInnerInactive() ); @@ -238,6 +253,11 @@ void FxLine::contextMenuEvent( QContextMenuEvent * ) contextMenu->addSeparator(); } contextMenu->addAction( embed::getIconPixmap( "cancel" ), tr( "Remove &unused channels" ), this, SLOT( removeUnusedChannels() ) ); + + contextMenu->addSeparator(); + contextMenu->addAction( embed::getIconPixmap( "colorize" ), tr( "Set channel color" ), this, SLOT( changeColor() ) ); + contextMenu->addAction( embed::getIconPixmap( "colorize" ), tr( "Remove channel color" ), this, SLOT( resetColor() ) ); + contextMenu->addAction( embed::getIconPixmap( "colorize" ), tr( "Pick random channel color" ), this, SLOT( randomColor() ) ); contextMenu->exec( QCursor::pos() ); delete contextMenu; } @@ -395,3 +415,79 @@ void FxLine::setStrokeInnerInactive( const QColor & c ) { m_strokeInnerInactive = c; } + + +/*void FxLine::saveSettings( QDomElement & _this ) +{ + QString mixercolor = "mixercolor" + QString::number( m_channelIndex ); + QString hascolor = "hascolor" + QString::number( m_channelIndex ); + + _this.setAttribute( mixercolor, m_color.rgb() ); + _this.setAttribute( hascolor, m_hasColor ); +} + +void FxLine::loadSettings( const QDomElement & _this ) +{ + QString mixercolor = "mixercolor" + QString::number( m_channelIndex ); + QString hascolor = "hascolor" + QString::number( m_channelIndex ); + + if( _this.hasAttribute( hascolor ) ) + { + m_hasColor = _this.attribute( hascolor ).toUInt() == 1 ? true : false; + m_color.setRgb( _this.attribute( mixercolor ).toUInt() ); + } +}*/ + +void FxLine::changeColor() +{ + QColorDialog colorDialog( Engine::fxMixer()->effectChannel( m_channelIndex )->m_color ); + QColor buffer( 0, 0, 0 ); + + for( int i = 0; i < 48; i += 6 ) + { + for( int j = 0; j < 6; j++ ) + { + buffer.setHsl( qMax( 0, 44 * ( i / 6 ) - 1 ), 150 - 20 * j, 140 - 10 * j ); + colorDialog.setStandardColor( i + j, buffer ); + } + + } + + QColor new_color = colorDialog.getColor( Engine::fxMixer()->effectChannel( m_channelIndex )->m_color ); + if( ! new_color.isValid() ) + { return; } + + Engine::fxMixer()->effectChannel( m_channelIndex )->m_color = new_color; + Engine::fxMixer()->effectChannel( m_channelIndex )->m_hasColor = true; + + update(); +} + +void FxLine::resetColor() +{ + Engine::fxMixer()->effectChannel( m_channelIndex )->m_hasColor = false; + update(); +} + +void FxLine::randomColor() +{ + int index = rand() % 48; + QColor buffer( 0, 0, 0 ); + + for( int i = 0; i < 48; i += 6 ) + { + for( int j = 0; j < 6; j++ ) + { + if( i + j + 1 == index ) + { + buffer.setHsl( qMax( 0, 44 * ( i / 6 ) - 1 ), 150 - 20 * j, 140 - 10 * j ); + break; + } + } + + } + + Engine::fxMixer()->effectChannel( m_channelIndex )->m_color = buffer; + Engine::fxMixer()->effectChannel( m_channelIndex )->m_hasColor = true; + update(); +} From 7c15d348f099d8065f936c933a1ebaec34e8f478 Mon Sep 17 00:00:00 2001 From: adi Date: Sun, 19 Jul 2020 14:32:29 +0530 Subject: [PATCH 02/18] Cleanup --- include/FxLine.h | 21 --------------------- src/gui/widgets/FxLine.cpp | 22 ---------------------- 2 files changed, 43 deletions(-) diff --git a/include/FxLine.h b/include/FxLine.h index 3a479d7d325..a3f71576446 100644 --- a/include/FxLine.h +++ b/include/FxLine.h @@ -80,27 +80,6 @@ class FxLine : public QWidget static const int FxLineHeight; bool eventFilter (QObject *dist, QEvent *event) override; - - /*unsigned int color() - { - return m_color.rgb(); - } - void setColor( unsigned int c ) - { - m_color.setRgb( c ); - } - - bool hasColor() - { - return m_hasColor; - } - void setHasColor( bool b ) - { - m_hasColor = b; - }*/ - - /*void saveSettings( QDomElement & _this ); - void loadSettings( const QDomElement & _this );*/ private: void drawFxLine( QPainter* p, const FxLine *fxLine, bool isActive, bool sendToThis, bool receiveFromThis ); diff --git a/src/gui/widgets/FxLine.cpp b/src/gui/widgets/FxLine.cpp index 1a1590dc124..ba64706d226 100644 --- a/src/gui/widgets/FxLine.cpp +++ b/src/gui/widgets/FxLine.cpp @@ -416,28 +416,6 @@ void FxLine::setStrokeInnerInactive( const QColor & c ) m_strokeInnerInactive = c; } - -/*void FxLine::saveSettings( QDomElement & _this ) -{ - QString mixercolor = "mixercolor" + QString::number( m_channelIndex ); - QString hascolor = "hascolor" + QString::number( m_channelIndex ); - - _this.setAttribute( mixercolor, m_color.rgb() ); - _this.setAttribute( hascolor, m_hasColor ); -} - -void FxLine::loadSettings( const QDomElement & _this ) -{ - QString mixercolor = "mixercolor" + QString::number( m_channelIndex ); - QString hascolor = "hascolor" + QString::number( m_channelIndex ); - - if( _this.hasAttribute( hascolor ) ) - { - m_hasColor = _this.attribute( hascolor ).toUInt() == 1 ? true : false; - m_color.setRgb( _this.attribute( mixercolor ).toUInt() ); - } -}*/ - void FxLine::changeColor() { QColorDialog colorDialog( Engine::fxMixer()->effectChannel( m_channelIndex )->m_color ); From 8352362c86167062172a05664753ef2fe15728e5 Mon Sep 17 00:00:00 2001 From: adi Date: Sun, 19 Jul 2020 14:34:25 +0530 Subject: [PATCH 03/18] Fix warnings --- src/core/FxMixer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/FxMixer.cpp b/src/core/FxMixer.cpp index 989ca2e61e5..c13cfa6bae9 100644 --- a/src/core/FxMixer.cpp +++ b/src/core/FxMixer.cpp @@ -73,8 +73,8 @@ FxChannel::FxChannel( int idx, Model * _parent ) : m_lock(), m_channelIndex( idx ), m_queued( false ), - m_dependenciesMet(0), - m_hasColor( false ) + m_hasColor( false ), + m_dependenciesMet(0) { BufferManager::clear( m_buffer, Engine::mixer()->framesPerPeriod() ); } From 5c898e84b223deeda8622e293bfd28f68ec922a3 Mon Sep 17 00:00:00 2001 From: adi Date: Mon, 27 Jul 2020 10:52:00 +0530 Subject: [PATCH 04/18] Improvements --- include/FxLine.h | 2 ++ src/gui/widgets/FxLine.cpp | 66 ++++++++++++++++---------------------- 2 files changed, 30 insertions(+), 38 deletions(-) diff --git a/include/FxLine.h b/include/FxLine.h index a3f71576446..9d3a6e18005 100644 --- a/include/FxLine.h +++ b/include/FxLine.h @@ -26,6 +26,7 @@ #ifndef FX_LINE_H #define FX_LINE_H +#include #include #include #include @@ -98,6 +99,7 @@ class FxLine : public QWidget bool m_inRename; QLineEdit * m_renameLineEdit; QGraphicsView * m_view; + QColorDialog m_dialog; public slots: void renameChannel(); diff --git a/src/gui/widgets/FxLine.cpp b/src/gui/widgets/FxLine.cpp index ba64706d226..169f5edb3a9 100644 --- a/src/gui/widgets/FxLine.cpp +++ b/src/gui/widgets/FxLine.cpp @@ -28,7 +28,6 @@ #include #include -#include #include #include "CaptionMenu.h" @@ -69,7 +68,8 @@ FxLine::FxLine( QWidget * _parent, FxMixerView * _mv, int _channelIndex ) : m_strokeOuterInactive( 0, 0, 0 ), m_strokeInnerActive( 0, 0, 0 ), m_strokeInnerInactive( 0, 0, 0 ), - m_inRename( false ) + m_inRename( false ), + m_dialog( QColor( 0, 0, 0 ) ) { if( !s_sendBgArrow ) { @@ -128,6 +128,18 @@ FxLine::FxLine( QWidget * _parent, FxMixerView * _mv, int _channelIndex ) : connect( &Engine::fxMixer()->effectChannel( m_channelIndex )->m_muteModel, SIGNAL( dataChanged() ), this, SLOT( update() ) ); srand( time( 0 ) ); + + QColor buffer; + for( int i = 0; i < 48; i += 6 ) + { + for( int j = 0; j < 6; j++ ) + { + buffer.setHsl( qMax( 0, 44 * ( i / 6 ) - 1 ), 150 - 20 * j, 140 - 10 * j ); + m_dialog.setStandardColor( i + j, buffer ); + } + + } + } @@ -155,9 +167,11 @@ void FxLine::setChannelIndex( int index ) void FxLine::drawFxLine( QPainter* p, const FxLine *fxLine, bool isActive, bool sendToThis, bool receiveFromThis ) { - QString name = Engine::fxMixer()->effectChannel( m_channelIndex )->m_name; - bool muted = Engine::fxMixer()->effectChannel( m_channelIndex )->m_muteModel.value(); + auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); + bool muted = channel->m_muteModel.value(); + QString name = channel->m_name; QString elidedName = elideName( name ); + if( !m_inRename && m_renameLineEdit->text() != elidedName ) { m_renameLineEdit->setText( elidedName ); @@ -167,8 +181,8 @@ void FxLine::drawFxLine( QPainter* p, const FxLine *fxLine, bool isActive, bool int height = fxLine->rect().height(); QColor color = muted ? ( isActive ? fxLine->backgroundActive().color() : p->background().color() ) - : ( Engine::fxMixer()->effectChannel( m_channelIndex )->m_hasColor ? ( isActive ? Engine::fxMixer()->effectChannel( m_channelIndex )->m_color.darker( 120 ) - : Engine::fxMixer()->effectChannel( m_channelIndex )->m_color.darker( 150 ) ) + : ( channel->m_hasColor ? ( isActive ? channel->m_color.darker( 120 ) + : channel->m_color.darker( 150 ) ) : ( isActive ? fxLine->backgroundActive().color() : p->background().color() ) ); @@ -418,25 +432,14 @@ void FxLine::setStrokeInnerInactive( const QColor & c ) void FxLine::changeColor() { - QColorDialog colorDialog( Engine::fxMixer()->effectChannel( m_channelIndex )->m_color ); - QColor buffer( 0, 0, 0 ); - - for( int i = 0; i < 48; i += 6 ) - { - for( int j = 0; j < 6; j++ ) - { - buffer.setHsl( qMax( 0, 44 * ( i / 6 ) - 1 ), 150 - 20 * j, 140 - 10 * j ); - colorDialog.setStandardColor( i + j, buffer ); - } - - } + auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); - QColor new_color = colorDialog.getColor( Engine::fxMixer()->effectChannel( m_channelIndex )->m_color ); + QColor new_color = m_dialog.getColor( channel->m_color ); if( ! new_color.isValid() ) { return; } - Engine::fxMixer()->effectChannel( m_channelIndex )->m_color = new_color; - Engine::fxMixer()->effectChannel( m_channelIndex )->m_hasColor = true; + channel->m_color = new_color; + channel->m_hasColor = true; update(); } @@ -449,23 +452,10 @@ void FxLine::resetColor() void FxLine::randomColor() { - int index = rand() % 48; - QColor buffer( 0, 0, 0 ); + auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); + + channel->m_color = m_dialog.standardColor( rand() % 48 ); + channel->m_hasColor = true; - for( int i = 0; i < 48; i += 6 ) - { - for( int j = 0; j < 6; j++ ) - { - if( i + j + 1 == index ) - { - buffer.setHsl( qMax( 0, 44 * ( i / 6 ) - 1 ), 150 - 20 * j, 140 - 10 * j ); - break; - } - } - - } - - Engine::fxMixer()->effectChannel( m_channelIndex )->m_color = buffer; - Engine::fxMixer()->effectChannel( m_channelIndex )->m_hasColor = true; update(); } From 646658bdb69c6af2b9ddd943eadd04332124b5eb Mon Sep 17 00:00:00 2001 From: adi Date: Sat, 1 Aug 2020 16:35:58 +0530 Subject: [PATCH 05/18] Improvements --- include/FxLine.h | 2 ++ src/gui/widgets/FxLine.cpp | 38 +++++++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/include/FxLine.h b/include/FxLine.h index 9d3a6e18005..7852766c770 100644 --- a/include/FxLine.h +++ b/include/FxLine.h @@ -85,6 +85,8 @@ class FxLine : public QWidget private: void drawFxLine( QPainter* p, const FxLine *fxLine, bool isActive, bool sendToThis, bool receiveFromThis ); QString elideName( const QString & name ); + QColor mutedColor( QPainter* p, const FxLine *fxLine, bool isActive ); + QColor unmutedColor( QPainter* p, const FxLine *fxLine, bool isActive ); FxMixerView * m_mv; LcdWidget* m_lcd; diff --git a/src/gui/widgets/FxLine.cpp b/src/gui/widgets/FxLine.cpp index 169f5edb3a9..446bb8218ff 100644 --- a/src/gui/widgets/FxLine.cpp +++ b/src/gui/widgets/FxLine.cpp @@ -130,12 +130,12 @@ FxLine::FxLine( QWidget * _parent, FxMixerView * _mv, int _channelIndex ) : srand( time( 0 ) ); QColor buffer; - for( int i = 0; i < 48; i += 6 ) + for( int x = 0; x < 8; x++ ) { - for( int j = 0; j < 6; j++ ) + for( int y = 0; y < 6; y++ ) { - buffer.setHsl( qMax( 0, 44 * ( i / 6 ) - 1 ), 150 - 20 * j, 140 - 10 * j ); - m_dialog.setStandardColor( i + j, buffer ); + buffer.setHsl( qMax( 0, 44 * x - 1 ), 150 - 20 * y, 140 - 10 * y ); + m_dialog.setStandardColor( 6 * x + y, buffer ); } } @@ -165,6 +165,30 @@ void FxLine::setChannelIndex( int index ) +QColor FxLine::mutedColor( QPainter* p, const FxLine *fxLine, bool isActive ) +{ + return isActive ? fxLine->backgroundActive().color() : p->background().color(); +} + + + + +QColor FxLine::unmutedColor( QPainter* p, const FxLine *fxLine, bool isActive ) +{ + auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); + + if( channel->m_hasColor ) + { + return isActive ? channel->m_color.darker( 120 ) : channel->m_color.darker( 150 ); + } + else + { + return isActive ? fxLine->backgroundActive().color() : p->background().color(); + } +} + + + void FxLine::drawFxLine( QPainter* p, const FxLine *fxLine, bool isActive, bool sendToThis, bool receiveFromThis ) { auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); @@ -180,11 +204,7 @@ void FxLine::drawFxLine( QPainter* p, const FxLine *fxLine, bool isActive, bool int width = fxLine->rect().width(); int height = fxLine->rect().height(); - QColor color = muted ? ( isActive ? fxLine->backgroundActive().color() : p->background().color() ) - : ( channel->m_hasColor ? ( isActive ? channel->m_color.darker( 120 ) - : channel->m_color.darker( 150 ) ) - : ( isActive ? fxLine->backgroundActive().color() - : p->background().color() ) ); + QColor color = muted ? mutedColor( p, fxLine, isActive ) : unmutedColor( p, fxLine, isActive ); p->fillRect( fxLine->rect(), color ); From f5659718ee048997b28c974819d32efd5f761bff Mon Sep 17 00:00:00 2001 From: adi Date: Sat, 1 Aug 2020 17:29:07 +0530 Subject: [PATCH 06/18] Use ColorChooser instead of QColorDialog --- include/ColorChooser.h | 21 ++++++- include/FxLine.h | 2 +- src/gui/CMakeLists.txt | 1 + src/gui/dialogs/ColorChooser.cpp | 96 ++++++++++++++++++++++++++++++++ src/gui/widgets/FxLine.cpp | 18 +----- 5 files changed, 121 insertions(+), 17 deletions(-) create mode 100644 src/gui/dialogs/ColorChooser.cpp diff --git a/include/ColorChooser.h b/include/ColorChooser.h index fe5b7a22a4e..911a43e0716 100644 --- a/include/ColorChooser.h +++ b/include/ColorChooser.h @@ -21,15 +21,26 @@ * */ -#include #include +#include +#include #include +#include class ColorChooser: public QColorDialog { public: ColorChooser(const QColor &initial, QWidget *parent): QColorDialog(initial, parent) {}; ColorChooser(QWidget *parent): QColorDialog(parent) {}; + + enum class CCPalette {Default, Track, Mixer}; + + //! Set global palette via array, checking bounds + void setPalette (const QVector); + //! Set global paletter via enum + void setPalette (const CCPalette); + //! Set palette via enum, return self pointer for chaining + ColorChooser* setPaletteAndPoint (const CCPalette); protected: // Forward key events to the parent to prevent stuck notes when the dialog gets focus @@ -38,4 +49,12 @@ class ColorChooser: public QColorDialog QKeyEvent ke(*event); QApplication::sendEvent(parentWidget(), &ke); } + +private: + //! Generate a default-ish QColorDialog palette into an array + QVector defaultPalette(); + //! Copy the current QColorDialog palette into an array + QVector currentPalette(); + //! Generate a nice palette, with adjustable value + QVector nicePalette (const int); }; diff --git a/include/FxLine.h b/include/FxLine.h index 7852766c770..5fd653b6a2b 100644 --- a/include/FxLine.h +++ b/include/FxLine.h @@ -31,6 +31,7 @@ #include #include +#include "ColorChooser.h" #include "Knob.h" #include "LcdWidget.h" #include "SendButtonIndicator.h" @@ -101,7 +102,6 @@ class FxLine : public QWidget bool m_inRename; QLineEdit * m_renameLineEdit; QGraphicsView * m_view; - QColorDialog m_dialog; public slots: void renameChannel(); diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 81e588c6659..f38e1675332 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -37,6 +37,7 @@ SET(LMMS_SRCS gui/dialogs/FileDialog.cpp gui/dialogs/VersionedSaveDialog.cpp + gui/dialogs/ColorChooser.cpp gui/editors/AutomationEditor.cpp gui/editors/BBEditor.cpp diff --git a/src/gui/dialogs/ColorChooser.cpp b/src/gui/dialogs/ColorChooser.cpp new file mode 100644 index 00000000000..a6802ce4024 --- /dev/null +++ b/src/gui/dialogs/ColorChooser.cpp @@ -0,0 +1,96 @@ +/* ColorChooser.cpp - definition of ColorChooser class. + * + * Copyright (c) 2020 russiankumar + * + * This file is part of LMMS - https://lmms.io + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +#include + + + +void ColorChooser::setPalette (const QVector colors) +{ + const int max = qMin (colors.size(), 48); + for (int i = 0; i < max; i++) + { + ColorChooser::setStandardColor (i, colors[i]); + } +} + + +void ColorChooser::setPalette (const CCPalette palette) +{ + switch (palette) + { + case CCPalette::Default: setPalette (defaultPalette()); break; + case CCPalette::Mixer: setPalette (nicePalette(140)); break; + case CCPalette::Track: setPalette (nicePalette(150)); break; + } +} + + +ColorChooser* ColorChooser::setPaletteAndPoint (const CCPalette palette) +{ + setPalette (palette); + return this; +} + + + + +QVector ColorChooser::currentPalette() +{ + QVector result; + for (int i = 0; i < 48; i++) + { + result.push_back (QColorDialog::standardColor(i)); + } + return result; +} + + +QVector ColorChooser::defaultPalette() +{ + QVector result; + result.resize(48); + for (int x = 0; x < 8; x++) + { + for (int y = 0; y < 6; y++) + { + result[6 * x + y].setHsl (qMax(0, 44 * x - 1), 300 - 40 * y, 300 - 40 * y); + } + } + return result; +} + + +QVector ColorChooser::nicePalette (const int base) +{ + QVector result; + result.resize(48); + for (int x = 0; x < 8; x++) + { + for (int y = 0; y < 6; y++) + { + result[6 * x + y].setHsl (qMax(0, 44 * x - 1), 150 - 20 * y, base - 10 * y); + } + } + return result; +} diff --git a/src/gui/widgets/FxLine.cpp b/src/gui/widgets/FxLine.cpp index 446bb8218ff..75a9847253b 100644 --- a/src/gui/widgets/FxLine.cpp +++ b/src/gui/widgets/FxLine.cpp @@ -68,8 +68,7 @@ FxLine::FxLine( QWidget * _parent, FxMixerView * _mv, int _channelIndex ) : m_strokeOuterInactive( 0, 0, 0 ), m_strokeInnerActive( 0, 0, 0 ), m_strokeInnerInactive( 0, 0, 0 ), - m_inRename( false ), - m_dialog( QColor( 0, 0, 0 ) ) + m_inRename( false ) { if( !s_sendBgArrow ) { @@ -129,17 +128,6 @@ FxLine::FxLine( QWidget * _parent, FxMixerView * _mv, int _channelIndex ) : srand( time( 0 ) ); - QColor buffer; - for( int x = 0; x < 8; x++ ) - { - for( int y = 0; y < 6; y++ ) - { - buffer.setHsl( qMax( 0, 44 * x - 1 ), 150 - 20 * y, 140 - 10 * y ); - m_dialog.setStandardColor( 6 * x + y, buffer ); - } - - } - } @@ -454,7 +442,7 @@ void FxLine::changeColor() { auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); - QColor new_color = m_dialog.getColor( channel->m_color ); + auto new_color = ColorChooser( this ).setPaletteAndPoint( ColorChooser::CCPalette::Mixer )->getColor( channel->m_color ); if( ! new_color.isValid() ) { return; } @@ -474,7 +462,7 @@ void FxLine::randomColor() { auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); - channel->m_color = m_dialog.standardColor( rand() % 48 ); + channel->m_color = ColorChooser( this ).setPaletteAndPoint( ColorChooser::CCPalette::Mixer )->standardColor( rand() % 48 ); channel->m_hasColor = true; update(); From c9dab2606fb07cb5227ee9758928bf946050b18f Mon Sep 17 00:00:00 2001 From: adi Date: Sat, 1 Aug 2020 17:33:27 +0530 Subject: [PATCH 07/18] Fix default palette being out of range --- src/gui/dialogs/ColorChooser.cpp | 2 +- src/gui/widgets/FxLine.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/dialogs/ColorChooser.cpp b/src/gui/dialogs/ColorChooser.cpp index a6802ce4024..b92cdddd28a 100644 --- a/src/gui/dialogs/ColorChooser.cpp +++ b/src/gui/dialogs/ColorChooser.cpp @@ -74,7 +74,7 @@ QVector ColorChooser::defaultPalette() { for (int y = 0; y < 6; y++) { - result[6 * x + y].setHsl (qMax(0, 44 * x - 1), 300 - 40 * y, 300 - 40 * y); + result[6 * x + y].setHsl (qMax(0, 44 * x - 1), 200 - 30 * y, 200 - 30 * y); } } return result; diff --git a/src/gui/widgets/FxLine.cpp b/src/gui/widgets/FxLine.cpp index 75a9847253b..0232e9f31f2 100644 --- a/src/gui/widgets/FxLine.cpp +++ b/src/gui/widgets/FxLine.cpp @@ -442,7 +442,7 @@ void FxLine::changeColor() { auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); - auto new_color = ColorChooser( this ).setPaletteAndPoint( ColorChooser::CCPalette::Mixer )->getColor( channel->m_color ); + auto new_color = ColorChooser( this ).setPaletteAndPoint( ColorChooser::CCPalette::Default )->getColor( channel->m_color ); if( ! new_color.isValid() ) { return; } From 75a115795be52daac748d8d53d6c01362400a24d Mon Sep 17 00:00:00 2001 From: adi Date: Sat, 1 Aug 2020 17:35:39 +0530 Subject: [PATCH 08/18] Remove a redundant function --- include/ColorChooser.h | 4 +--- src/gui/dialogs/ColorChooser.cpp | 17 +---------------- src/gui/widgets/FxLine.cpp | 2 +- 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/include/ColorChooser.h b/include/ColorChooser.h index 911a43e0716..232bdc98fdb 100644 --- a/include/ColorChooser.h +++ b/include/ColorChooser.h @@ -51,10 +51,8 @@ class ColorChooser: public QColorDialog } private: - //! Generate a default-ish QColorDialog palette into an array - QVector defaultPalette(); //! Copy the current QColorDialog palette into an array - QVector currentPalette(); + QVector defaultPalette(); //! Generate a nice palette, with adjustable value QVector nicePalette (const int); }; diff --git a/src/gui/dialogs/ColorChooser.cpp b/src/gui/dialogs/ColorChooser.cpp index b92cdddd28a..c5aa0f1fb27 100644 --- a/src/gui/dialogs/ColorChooser.cpp +++ b/src/gui/dialogs/ColorChooser.cpp @@ -55,7 +55,7 @@ ColorChooser* ColorChooser::setPaletteAndPoint (const CCPalette palette) -QVector ColorChooser::currentPalette() +QVector ColorChooser::defaultPalette() { QVector result; for (int i = 0; i < 48; i++) @@ -66,21 +66,6 @@ QVector ColorChooser::currentPalette() } -QVector ColorChooser::defaultPalette() -{ - QVector result; - result.resize(48); - for (int x = 0; x < 8; x++) - { - for (int y = 0; y < 6; y++) - { - result[6 * x + y].setHsl (qMax(0, 44 * x - 1), 200 - 30 * y, 200 - 30 * y); - } - } - return result; -} - - QVector ColorChooser::nicePalette (const int base) { QVector result; diff --git a/src/gui/widgets/FxLine.cpp b/src/gui/widgets/FxLine.cpp index 0232e9f31f2..75a9847253b 100644 --- a/src/gui/widgets/FxLine.cpp +++ b/src/gui/widgets/FxLine.cpp @@ -442,7 +442,7 @@ void FxLine::changeColor() { auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); - auto new_color = ColorChooser( this ).setPaletteAndPoint( ColorChooser::CCPalette::Default )->getColor( channel->m_color ); + auto new_color = ColorChooser( this ).setPaletteAndPoint( ColorChooser::CCPalette::Mixer )->getColor( channel->m_color ); if( ! new_color.isValid() ) { return; } From 2b2882ccbfe9ab67173b38677391b95b591d01aa Mon Sep 17 00:00:00 2001 From: adi Date: Sun, 2 Aug 2020 13:30:45 +0530 Subject: [PATCH 09/18] Rename and make stuff efficient --- include/ColorChooser.h | 2 +- src/gui/dialogs/ColorChooser.cpp | 9 ++++----- src/gui/widgets/FxLine.cpp | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/ColorChooser.h b/include/ColorChooser.h index 232bdc98fdb..8f824965ddb 100644 --- a/include/ColorChooser.h +++ b/include/ColorChooser.h @@ -40,7 +40,7 @@ class ColorChooser: public QColorDialog //! Set global paletter via enum void setPalette (const CCPalette); //! Set palette via enum, return self pointer for chaining - ColorChooser* setPaletteAndPoint (const CCPalette); + ColorChooser* withPalette (const CCPalette); protected: // Forward key events to the parent to prevent stuck notes when the dialog gets focus diff --git a/src/gui/dialogs/ColorChooser.cpp b/src/gui/dialogs/ColorChooser.cpp index c5aa0f1fb27..5364fbe147e 100644 --- a/src/gui/dialogs/ColorChooser.cpp +++ b/src/gui/dialogs/ColorChooser.cpp @@ -46,7 +46,7 @@ void ColorChooser::setPalette (const CCPalette palette) } -ColorChooser* ColorChooser::setPaletteAndPoint (const CCPalette palette) +ColorChooser* ColorChooser::withPalette (const CCPalette palette) { setPalette (palette); return this; @@ -57,10 +57,10 @@ ColorChooser* ColorChooser::setPaletteAndPoint (const CCPalette palette) QVector ColorChooser::defaultPalette() { - QVector result; + QVector result (48); for (int i = 0; i < 48; i++) { - result.push_back (QColorDialog::standardColor(i)); + result[i] = (QColorDialog::standardColor(i)); } return result; } @@ -68,8 +68,7 @@ QVector ColorChooser::defaultPalette() QVector ColorChooser::nicePalette (const int base) { - QVector result; - result.resize(48); + QVector result (48); for (int x = 0; x < 8; x++) { for (int y = 0; y < 6; y++) diff --git a/src/gui/widgets/FxLine.cpp b/src/gui/widgets/FxLine.cpp index 75a9847253b..e5b2900536b 100644 --- a/src/gui/widgets/FxLine.cpp +++ b/src/gui/widgets/FxLine.cpp @@ -442,7 +442,7 @@ void FxLine::changeColor() { auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); - auto new_color = ColorChooser( this ).setPaletteAndPoint( ColorChooser::CCPalette::Mixer )->getColor( channel->m_color ); + auto new_color = ColorChooser( this ).withPalette( ColorChooser::CCPalette::Mixer )->getColor( channel->m_color ); if( ! new_color.isValid() ) { return; } @@ -462,7 +462,7 @@ void FxLine::randomColor() { auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); - channel->m_color = ColorChooser( this ).setPaletteAndPoint( ColorChooser::CCPalette::Mixer )->standardColor( rand() % 48 ); + channel->m_color = ColorChooser( this ).withPalette( ColorChooser::CCPalette::Mixer )->standardColor( rand() % 48 ); channel->m_hasColor = true; update(); From 1e97b5520cea7dd10d3f826307373b6e19554d2f Mon Sep 17 00:00:00 2001 From: adi Date: Sun, 2 Aug 2020 13:35:57 +0530 Subject: [PATCH 10/18] Comment on the code --- include/ColorChooser.h | 2 +- src/gui/dialogs/ColorChooser.cpp | 5 +++++ src/gui/widgets/FxLine.cpp | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/ColorChooser.h b/include/ColorChooser.h index 8f824965ddb..91013ec7a33 100644 --- a/include/ColorChooser.h +++ b/include/ColorChooser.h @@ -43,7 +43,7 @@ class ColorChooser: public QColorDialog ColorChooser* withPalette (const CCPalette); protected: - // Forward key events to the parent to prevent stuck notes when the dialog gets focus + //! Forward key events to the parent to prevent stuck notes when the dialog gets focus void keyReleaseEvent(QKeyEvent *event) override { QKeyEvent ke(*event); diff --git a/src/gui/dialogs/ColorChooser.cpp b/src/gui/dialogs/ColorChooser.cpp index 5364fbe147e..fcdb025249b 100644 --- a/src/gui/dialogs/ColorChooser.cpp +++ b/src/gui/dialogs/ColorChooser.cpp @@ -25,6 +25,7 @@ +//! Set global palette via array, checking bounds void ColorChooser::setPalette (const QVector colors) { const int max = qMin (colors.size(), 48); @@ -35,6 +36,7 @@ void ColorChooser::setPalette (const QVector colors) } +//! Set global paletter via enum void ColorChooser::setPalette (const CCPalette palette) { switch (palette) @@ -46,6 +48,7 @@ void ColorChooser::setPalette (const CCPalette palette) } +//! Set palette via enum, return self pointer for chaining ColorChooser* ColorChooser::withPalette (const CCPalette palette) { setPalette (palette); @@ -55,6 +58,7 @@ ColorChooser* ColorChooser::withPalette (const CCPalette palette) +//! Copy the current QColorDialog palette into an array QVector ColorChooser::defaultPalette() { QVector result (48); @@ -66,6 +70,7 @@ QVector ColorChooser::defaultPalette() } +//! Generate a nice palette, with adjustable value QVector ColorChooser::nicePalette (const int base) { QVector result (48); diff --git a/src/gui/widgets/FxLine.cpp b/src/gui/widgets/FxLine.cpp index e5b2900536b..36665cadf1b 100644 --- a/src/gui/widgets/FxLine.cpp +++ b/src/gui/widgets/FxLine.cpp @@ -153,6 +153,7 @@ void FxLine::setChannelIndex( int index ) +// Return what color the mixer should be if it is muted QColor FxLine::mutedColor( QPainter* p, const FxLine *fxLine, bool isActive ) { return isActive ? fxLine->backgroundActive().color() : p->background().color(); @@ -161,6 +162,7 @@ QColor FxLine::mutedColor( QPainter* p, const FxLine *fxLine, bool isActive ) +// Return what color the mixer should be if it is not muted QColor FxLine::unmutedColor( QPainter* p, const FxLine *fxLine, bool isActive ) { auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); @@ -438,6 +440,8 @@ void FxLine::setStrokeInnerInactive( const QColor & c ) m_strokeInnerInactive = c; } + +// Ask user for a color, and set it as the mixer line color void FxLine::changeColor() { auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); @@ -452,12 +456,16 @@ void FxLine::changeColor() update(); } + +// Disable the usage of color on this mixer line void FxLine::resetColor() { Engine::fxMixer()->effectChannel( m_channelIndex )->m_hasColor = false; update(); } + +// Pick a random color from the mixer palette and set it as our color void FxLine::randomColor() { auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); From 274dee57cf487333ed293d28b30448984165034d Mon Sep 17 00:00:00 2001 From: adi Date: Mon, 3 Aug 2020 09:10:41 +0530 Subject: [PATCH 11/18] Make things more efficient --- include/ColorChooser.h | 11 +++++--- include/FxLine.h | 2 -- src/core/FxMixer.cpp | 9 +++---- src/gui/dialogs/ColorChooser.cpp | 23 ++++++++++++---- src/gui/widgets/FxLine.cpp | 45 +++++++++----------------------- 5 files changed, 42 insertions(+), 48 deletions(-) diff --git a/include/ColorChooser.h b/include/ColorChooser.h index 91013ec7a33..ecc09dea6b3 100644 --- a/include/ColorChooser.h +++ b/include/ColorChooser.h @@ -33,14 +33,19 @@ class ColorChooser: public QColorDialog ColorChooser(const QColor &initial, QWidget *parent): QColorDialog(initial, parent) {}; ColorChooser(QWidget *parent): QColorDialog(parent) {}; - enum class CCPalette {Default, Track, Mixer}; + //! For getting a color without having to initialise a color dialog + ColorChooser() {}; + + enum class Palette {Default, Track, Mixer}; //! Set global palette via array, checking bounds void setPalette (const QVector); //! Set global paletter via enum - void setPalette (const CCPalette); + void setPalette (const Palette); //! Set palette via enum, return self pointer for chaining - ColorChooser* withPalette (const CCPalette); + ColorChooser* withPalette (const Palette); + //! Return a certain palette + QVector getPalette (const Palette); protected: //! Forward key events to the parent to prevent stuck notes when the dialog gets focus diff --git a/include/FxLine.h b/include/FxLine.h index 5fd653b6a2b..e9ee248b811 100644 --- a/include/FxLine.h +++ b/include/FxLine.h @@ -86,8 +86,6 @@ class FxLine : public QWidget private: void drawFxLine( QPainter* p, const FxLine *fxLine, bool isActive, bool sendToThis, bool receiveFromThis ); QString elideName( const QString & name ); - QColor mutedColor( QPainter* p, const FxLine *fxLine, bool isActive ); - QColor unmutedColor( QPainter* p, const FxLine *fxLine, bool isActive ); FxMixerView * m_mv; LcdWidget* m_lcd; diff --git a/src/core/FxMixer.cpp b/src/core/FxMixer.cpp index c13cfa6bae9..3306ef27fcc 100644 --- a/src/core/FxMixer.cpp +++ b/src/core/FxMixer.cpp @@ -742,8 +742,7 @@ void FxMixer::saveSettings( QDomDocument & _doc, QDomElement & _this ) ch->m_soloModel.saveSettings( _doc, fxch, "soloed" ); fxch.setAttribute( "num", i ); fxch.setAttribute( "name", ch->m_name ); - fxch.setAttribute( "hascolor", ch->m_hasColor ); - fxch.setAttribute( "mixercolor", ch->m_color.rgb() ); + if( ch->m_hasColor ) fxch.setAttribute( "color", ch->m_color.rgb() ); // add the channel sends for( int si = 0; si < ch->m_sends.size(); ++si ) @@ -789,10 +788,10 @@ void FxMixer::loadSettings( const QDomElement & _this ) m_fxChannels[num]->m_muteModel.loadSettings( fxch, "muted" ); m_fxChannels[num]->m_soloModel.loadSettings( fxch, "soloed" ); m_fxChannels[num]->m_name = fxch.attribute( "name" ); - if( fxch.hasAttribute( "hascolor" ) ) + if( fxch.hasAttribute( "color" ) ) { - m_fxChannels[num]->m_hasColor = fxch.attribute( "hascolor" ).toInt(); - m_fxChannels[num]->m_color.setRgb( fxch.attribute( "mixercolor" ).toUInt() ); + m_fxChannels[num]->m_hasColor = true; + m_fxChannels[num]->m_color.setRgb( fxch.attribute( "color" ).toUInt() ); } m_fxChannels[num]->m_fxChain.restoreState( fxch.firstChildElement( diff --git a/src/gui/dialogs/ColorChooser.cpp b/src/gui/dialogs/ColorChooser.cpp index fcdb025249b..3462c319872 100644 --- a/src/gui/dialogs/ColorChooser.cpp +++ b/src/gui/dialogs/ColorChooser.cpp @@ -25,6 +25,7 @@ + //! Set global palette via array, checking bounds void ColorChooser::setPalette (const QVector colors) { @@ -37,25 +38,37 @@ void ColorChooser::setPalette (const QVector colors) //! Set global paletter via enum -void ColorChooser::setPalette (const CCPalette palette) +void ColorChooser::setPalette (const Palette palette) { switch (palette) { - case CCPalette::Default: setPalette (defaultPalette()); break; - case CCPalette::Mixer: setPalette (nicePalette(140)); break; - case CCPalette::Track: setPalette (nicePalette(150)); break; + case Palette::Default: setPalette (defaultPalette()); break; + case Palette::Mixer: setPalette (nicePalette(140)); break; + case Palette::Track: setPalette (nicePalette(150)); break; } } //! Set palette via enum, return self pointer for chaining -ColorChooser* ColorChooser::withPalette (const CCPalette palette) +ColorChooser* ColorChooser::withPalette (const Palette palette) { setPalette (palette); return this; } +//! Return a certain palette +QVector ColorChooser::getPalette (const Palette palette) +{ + switch (palette) + { + case Palette::Default: return defaultPalette(); + case Palette::Mixer: return nicePalette(140); + case Palette::Track: return nicePalette(150); + } +} + + //! Copy the current QColorDialog palette into an array diff --git a/src/gui/widgets/FxLine.cpp b/src/gui/widgets/FxLine.cpp index 36665cadf1b..268006cdfe1 100644 --- a/src/gui/widgets/FxLine.cpp +++ b/src/gui/widgets/FxLine.cpp @@ -152,33 +152,6 @@ void FxLine::setChannelIndex( int index ) - -// Return what color the mixer should be if it is muted -QColor FxLine::mutedColor( QPainter* p, const FxLine *fxLine, bool isActive ) -{ - return isActive ? fxLine->backgroundActive().color() : p->background().color(); -} - - - - -// Return what color the mixer should be if it is not muted -QColor FxLine::unmutedColor( QPainter* p, const FxLine *fxLine, bool isActive ) -{ - auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); - - if( channel->m_hasColor ) - { - return isActive ? channel->m_color.darker( 120 ) : channel->m_color.darker( 150 ); - } - else - { - return isActive ? fxLine->backgroundActive().color() : p->background().color(); - } -} - - - void FxLine::drawFxLine( QPainter* p, const FxLine *fxLine, bool isActive, bool sendToThis, bool receiveFromThis ) { auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); @@ -193,10 +166,16 @@ void FxLine::drawFxLine( QPainter* p, const FxLine *fxLine, bool isActive, bool int width = fxLine->rect().width(); int height = fxLine->rect().height(); - - QColor color = muted ? mutedColor( p, fxLine, isActive ) : unmutedColor( p, fxLine, isActive ); - - p->fillRect( fxLine->rect(), color ); + + if( channel->m_hasColor && !muted ) + { + p->fillRect( fxLine->rect(), channel->m_color.darker( isActive ? 120 : 150 ) ); + } + else + { + p->fillRect( fxLine->rect(), + isActive ? fxLine->backgroundActive().color() : p->background().color() ); + } // inner border p->setPen( isActive ? fxLine->strokeInnerActive() : fxLine->strokeInnerInactive() ); @@ -446,7 +425,7 @@ void FxLine::changeColor() { auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); - auto new_color = ColorChooser( this ).withPalette( ColorChooser::CCPalette::Mixer )->getColor( channel->m_color ); + auto new_color = ColorChooser( this ).withPalette( ColorChooser::Palette::Mixer )->getColor( channel->m_color ); if( ! new_color.isValid() ) { return; } @@ -470,7 +449,7 @@ void FxLine::randomColor() { auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); - channel->m_color = ColorChooser( this ).withPalette( ColorChooser::CCPalette::Mixer )->standardColor( rand() % 48 ); + channel->m_color = ColorChooser().getPalette( ColorChooser::Palette::Mixer )[ rand() % 48 ]; channel->m_hasColor = true; update(); From 5ef3d3516e3a062401b592cab40cdeac60b4ac69 Mon Sep 17 00:00:00 2001 From: adi Date: Mon, 3 Aug 2020 09:15:07 +0530 Subject: [PATCH 12/18] Fix breaking builds --- src/gui/dialogs/ColorChooser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/dialogs/ColorChooser.cpp b/src/gui/dialogs/ColorChooser.cpp index 3462c319872..49fb80f14c9 100644 --- a/src/gui/dialogs/ColorChooser.cpp +++ b/src/gui/dialogs/ColorChooser.cpp @@ -62,9 +62,9 @@ QVector ColorChooser::getPalette (const Palette palette) { switch (palette) { - case Palette::Default: return defaultPalette(); case Palette::Mixer: return nicePalette(140); case Palette::Track: return nicePalette(150); + default: return defaultPalette(); } } From 32bf5bac8cbc2aa194240d1492f3f11649a88b13 Mon Sep 17 00:00:00 2001 From: adi Date: Wed, 5 Aug 2020 09:18:01 +0530 Subject: [PATCH 13/18] Improvements --- include/ColorChooser.h | 2 +- src/core/FxMixer.cpp | 4 ++-- src/gui/dialogs/ColorChooser.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/ColorChooser.h b/include/ColorChooser.h index ecc09dea6b3..dfc46760ee0 100644 --- a/include/ColorChooser.h +++ b/include/ColorChooser.h @@ -59,5 +59,5 @@ class ColorChooser: public QColorDialog //! Copy the current QColorDialog palette into an array QVector defaultPalette(); //! Generate a nice palette, with adjustable value - QVector nicePalette (const int); + QVector nicePalette (int); }; diff --git a/src/core/FxMixer.cpp b/src/core/FxMixer.cpp index 3306ef27fcc..7ddcbea623a 100644 --- a/src/core/FxMixer.cpp +++ b/src/core/FxMixer.cpp @@ -742,7 +742,7 @@ void FxMixer::saveSettings( QDomDocument & _doc, QDomElement & _this ) ch->m_soloModel.saveSettings( _doc, fxch, "soloed" ); fxch.setAttribute( "num", i ); fxch.setAttribute( "name", ch->m_name ); - if( ch->m_hasColor ) fxch.setAttribute( "color", ch->m_color.rgb() ); + if( ch->m_hasColor ) fxch.setAttribute( "color", ch->m_color.name() ); // add the channel sends for( int si = 0; si < ch->m_sends.size(); ++si ) @@ -791,7 +791,7 @@ void FxMixer::loadSettings( const QDomElement & _this ) if( fxch.hasAttribute( "color" ) ) { m_fxChannels[num]->m_hasColor = true; - m_fxChannels[num]->m_color.setRgb( fxch.attribute( "color" ).toUInt() ); + m_fxChannels[num]->m_color.setNamedColor( fxch.attribute( "color" ) ); } m_fxChannels[num]->m_fxChain.restoreState( fxch.firstChildElement( diff --git a/src/gui/dialogs/ColorChooser.cpp b/src/gui/dialogs/ColorChooser.cpp index 49fb80f14c9..99e85f33f6c 100644 --- a/src/gui/dialogs/ColorChooser.cpp +++ b/src/gui/dialogs/ColorChooser.cpp @@ -84,7 +84,7 @@ QVector ColorChooser::defaultPalette() //! Generate a nice palette, with adjustable value -QVector ColorChooser::nicePalette (const int base) +QVector ColorChooser::nicePalette (int base) { QVector result (48); for (int x = 0; x < 8; x++) From b6357fbfa0aa6fbcf9e942697fd35632f33957a0 Mon Sep 17 00:00:00 2001 From: adi Date: Fri, 7 Aug 2020 11:12:28 +0530 Subject: [PATCH 14/18] Improvements pt. 2 --- include/ColorChooser.h | 8 ++++---- src/gui/dialogs/ColorChooser.cpp | 13 ++++--------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/include/ColorChooser.h b/include/ColorChooser.h index dfc46760ee0..4597662eeb3 100644 --- a/include/ColorChooser.h +++ b/include/ColorChooser.h @@ -39,13 +39,13 @@ class ColorChooser: public QColorDialog enum class Palette {Default, Track, Mixer}; //! Set global palette via array, checking bounds - void setPalette (const QVector); + void setPalette (QVector); //! Set global paletter via enum - void setPalette (const Palette); + void setPalette (Palette); //! Set palette via enum, return self pointer for chaining - ColorChooser* withPalette (const Palette); + ColorChooser* withPalette (Palette); //! Return a certain palette - QVector getPalette (const Palette); + QVector getPalette (Palette); protected: //! Forward key events to the parent to prevent stuck notes when the dialog gets focus diff --git a/src/gui/dialogs/ColorChooser.cpp b/src/gui/dialogs/ColorChooser.cpp index 99e85f33f6c..459b2487159 100644 --- a/src/gui/dialogs/ColorChooser.cpp +++ b/src/gui/dialogs/ColorChooser.cpp @@ -27,7 +27,7 @@ //! Set global palette via array, checking bounds -void ColorChooser::setPalette (const QVector colors) +void ColorChooser::setPalette (QVector colors) { const int max = qMin (colors.size(), 48); for (int i = 0; i < max; i++) @@ -38,14 +38,9 @@ void ColorChooser::setPalette (const QVector colors) //! Set global paletter via enum -void ColorChooser::setPalette (const Palette palette) +void ColorChooser::setPalette (Palette palette) { - switch (palette) - { - case Palette::Default: setPalette (defaultPalette()); break; - case Palette::Mixer: setPalette (nicePalette(140)); break; - case Palette::Track: setPalette (nicePalette(150)); break; - } + setPalette (getPalette (palette)); } @@ -58,7 +53,7 @@ ColorChooser* ColorChooser::withPalette (const Palette palette) //! Return a certain palette -QVector ColorChooser::getPalette (const Palette palette) +QVector ColorChooser::getPalette (Palette palette) { switch (palette) { From 563fe1b6ff861cc2210340905b02649e46d670db Mon Sep 17 00:00:00 2001 From: adi Date: Sat, 8 Aug 2020 09:41:02 +0530 Subject: [PATCH 15/18] Improvements pt. 3 --- include/FxMixer.h | 2 ++ src/gui/dialogs/ColorChooser.cpp | 2 +- src/gui/widgets/FxLine.cpp | 4 +--- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/FxMixer.h b/include/FxMixer.h index 69ba62e005c..de406301ff1 100644 --- a/include/FxMixer.h +++ b/include/FxMixer.h @@ -72,6 +72,8 @@ class FxChannel : public ThreadableJob bool requiresProcessing() const override { return true; } void unmuteForSolo(); + + // TODO C++17 and above: use std::optional insteads QColor m_color; bool m_hasColor; diff --git a/src/gui/dialogs/ColorChooser.cpp b/src/gui/dialogs/ColorChooser.cpp index 459b2487159..b25aa97be6c 100644 --- a/src/gui/dialogs/ColorChooser.cpp +++ b/src/gui/dialogs/ColorChooser.cpp @@ -45,7 +45,7 @@ void ColorChooser::setPalette (Palette palette) //! Set palette via enum, return self pointer for chaining -ColorChooser* ColorChooser::withPalette (const Palette palette) +ColorChooser* ColorChooser::withPalette (Palette palette) { setPalette (palette); return this; diff --git a/src/gui/widgets/FxLine.cpp b/src/gui/widgets/FxLine.cpp index 268006cdfe1..c45c028d248 100644 --- a/src/gui/widgets/FxLine.cpp +++ b/src/gui/widgets/FxLine.cpp @@ -126,8 +126,6 @@ FxLine::FxLine( QWidget * _parent, FxMixerView * _mv, int _channelIndex ) : connect( &Engine::fxMixer()->effectChannel( m_channelIndex )->m_muteModel, SIGNAL( dataChanged() ), this, SLOT( update() ) ); - srand( time( 0 ) ); - } @@ -242,7 +240,7 @@ void FxLine::mouseDoubleClickEvent( QMouseEvent * ) void FxLine::contextMenuEvent( QContextMenuEvent * ) { QPointer contextMenu = new CaptionMenu( Engine::fxMixer()->effectChannel( m_channelIndex )->m_name, this ); - if( m_channelIndex != 0 ) // no move-options in master + if( m_channelIndex != 0 ) // no move-options in master { contextMenu->addAction( tr( "Move &left" ), this, SLOT( moveChannelLeft() ) ); contextMenu->addAction( tr( "Move &right" ), this, SLOT( moveChannelRight() ) ); From 22fc382d645995a3755af05df2caa5830ef4c322 Mon Sep 17 00:00:00 2001 From: adi Date: Sun, 9 Aug 2020 10:36:05 +0530 Subject: [PATCH 16/18] Improvements pt. 4 --- src/gui/widgets/FxLine.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gui/widgets/FxLine.cpp b/src/gui/widgets/FxLine.cpp index c45c028d248..a8859ba93db 100644 --- a/src/gui/widgets/FxLine.cpp +++ b/src/gui/widgets/FxLine.cpp @@ -26,7 +26,6 @@ #include "FxLine.h" #include -#include #include From 9e5142a229efa23ec252ecf987fe91a1afdc81aa Mon Sep 17 00:00:00 2001 From: adi Date: Mon, 10 Aug 2020 11:54:43 +0530 Subject: [PATCH 17/18] Improvements pt. 5 --- include/ColorChooser.h | 6 +++--- src/gui/widgets/FxLine.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/ColorChooser.h b/include/ColorChooser.h index 4597662eeb3..f339d815d91 100644 --- a/include/ColorChooser.h +++ b/include/ColorChooser.h @@ -45,7 +45,7 @@ class ColorChooser: public QColorDialog //! Set palette via enum, return self pointer for chaining ColorChooser* withPalette (Palette); //! Return a certain palette - QVector getPalette (Palette); + static QVector getPalette (Palette); protected: //! Forward key events to the parent to prevent stuck notes when the dialog gets focus @@ -57,7 +57,7 @@ class ColorChooser: public QColorDialog private: //! Copy the current QColorDialog palette into an array - QVector defaultPalette(); + static QVector defaultPalette(); //! Generate a nice palette, with adjustable value - QVector nicePalette (int); + static QVector nicePalette (int); }; diff --git a/src/gui/widgets/FxLine.cpp b/src/gui/widgets/FxLine.cpp index a8859ba93db..926db34170d 100644 --- a/src/gui/widgets/FxLine.cpp +++ b/src/gui/widgets/FxLine.cpp @@ -446,7 +446,7 @@ void FxLine::randomColor() { auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); - channel->m_color = ColorChooser().getPalette( ColorChooser::Palette::Mixer )[ rand() % 48 ]; + channel->m_color = ColorChooser::getPalette( ColorChooser::Palette::Mixer )[ rand() % 48 ]; channel->m_hasColor = true; update(); From 705a820c234f5b6417fa22e375ee530db1dbca71 Mon Sep 17 00:00:00 2001 From: Kumar Date: Tue, 11 Aug 2020 12:44:14 +0530 Subject: [PATCH 18/18] Apply suggestions from code review Co-authored-by: Hyunjin Song --- include/ColorChooser.h | 4 ---- include/FxMixer.h | 4 ++-- src/gui/widgets/FxLine.cpp | 8 -------- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/include/ColorChooser.h b/include/ColorChooser.h index f339d815d91..ac2a1b62d4a 100644 --- a/include/ColorChooser.h +++ b/include/ColorChooser.h @@ -32,12 +32,9 @@ class ColorChooser: public QColorDialog public: ColorChooser(const QColor &initial, QWidget *parent): QColorDialog(initial, parent) {}; ColorChooser(QWidget *parent): QColorDialog(parent) {}; - //! For getting a color without having to initialise a color dialog ColorChooser() {}; - enum class Palette {Default, Track, Mixer}; - //! Set global palette via array, checking bounds void setPalette (QVector); //! Set global paletter via enum @@ -54,7 +51,6 @@ class ColorChooser: public QColorDialog QKeyEvent ke(*event); QApplication::sendEvent(parentWidget(), &ke); } - private: //! Copy the current QColorDialog palette into an array static QVector defaultPalette(); diff --git a/include/FxMixer.h b/include/FxMixer.h index de406301ff1..920d4e27bc3 100644 --- a/include/FxMixer.h +++ b/include/FxMixer.h @@ -71,8 +71,8 @@ class FxChannel : public ThreadableJob bool requiresProcessing() const override { return true; } void unmuteForSolo(); - - + + // TODO C++17 and above: use std::optional insteads QColor m_color; bool m_hasColor; diff --git a/src/gui/widgets/FxLine.cpp b/src/gui/widgets/FxLine.cpp index 926db34170d..476d8773b2b 100644 --- a/src/gui/widgets/FxLine.cpp +++ b/src/gui/widgets/FxLine.cpp @@ -122,7 +122,6 @@ FxLine::FxLine( QWidget * _parent, FxMixerView * _mv, int _channelIndex ) : proxyWidget->setPos( 8, 145 ); connect( m_renameLineEdit, SIGNAL( editingFinished() ), this, SLOT( renameFinished() ) ); - connect( &Engine::fxMixer()->effectChannel( m_channelIndex )->m_muteModel, SIGNAL( dataChanged() ), this, SLOT( update() ) ); } @@ -155,7 +154,6 @@ void FxLine::drawFxLine( QPainter* p, const FxLine *fxLine, bool isActive, bool bool muted = channel->m_muteModel.value(); QString name = channel->m_name; QString elidedName = elideName( name ); - if( !m_inRename && m_renameLineEdit->text() != elidedName ) { m_renameLineEdit->setText( elidedName ); @@ -253,7 +251,6 @@ void FxLine::contextMenuEvent( QContextMenuEvent * ) contextMenu->addSeparator(); } contextMenu->addAction( embed::getIconPixmap( "cancel" ), tr( "Remove &unused channels" ), this, SLOT( removeUnusedChannels() ) ); - contextMenu->addSeparator(); contextMenu->addAction( embed::getIconPixmap( "colorize" ), tr( "Set channel color" ), this, SLOT( changeColor() ) ); contextMenu->addAction( embed::getIconPixmap( "colorize" ), tr( "Remove channel color" ), this, SLOT( resetColor() ) ); @@ -421,14 +418,11 @@ void FxLine::setStrokeInnerInactive( const QColor & c ) void FxLine::changeColor() { auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); - auto new_color = ColorChooser( this ).withPalette( ColorChooser::Palette::Mixer )->getColor( channel->m_color ); if( ! new_color.isValid() ) { return; } - channel->m_color = new_color; channel->m_hasColor = true; - update(); } @@ -445,9 +439,7 @@ void FxLine::resetColor() void FxLine::randomColor() { auto channel = Engine::fxMixer()->effectChannel( m_channelIndex ); - channel->m_color = ColorChooser::getPalette( ColorChooser::Palette::Mixer )[ rand() % 48 ]; channel->m_hasColor = true; - update(); }