From f909a2151bea3d55801edc77f5858e0ec7399895 Mon Sep 17 00:00:00 2001 From: Aditya Date: Mon, 22 Jun 2020 19:14:14 +0530 Subject: [PATCH 01/13] src/gui/editors/SongEditor.cpp --- src/gui/editors/SongEditor.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index a8602880565..ab04a98a87b 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -55,7 +55,7 @@ positionLine::positionLine( QWidget * parent ) : QWidget( parent ) { - setFixedWidth( 1 ); + setFixedWidth( 8 ); setAttribute( Qt::WA_NoSystemBackground, true ); } @@ -65,7 +65,15 @@ positionLine::positionLine( QWidget * parent ) : void positionLine::paintEvent( QPaintEvent * pe ) { QPainter p( this ); - p.fillRect( rect(), QColor( 255, 255, 255, 153 ) ); + + // Create the gradient trail behind the line + QLinearGradient gradient(rect().bottomLeft(), rect().bottomRight()); + gradient.setColorAt(0, QColor (255, 255, 255, 0) ); + gradient.setColorAt(0.875, QColor (255, 255, 255, 60) ); + gradient.setColorAt(1, QColor (255, 255, 255, 153) ); + + // Fill line + p.fillRect( rect(), gradient ); } const QVector SongEditor::m_zoomLevels = @@ -808,7 +816,7 @@ void SongEditor::updatePosition( const MidiTime & t ) if( x >= trackOpWidth + widgetWidth -1 ) { m_positionLine->show(); - m_positionLine->move( x, m_timeLine->height() ); + m_positionLine->move( x-7, m_timeLine->height() ); } else { From c5dc75da5d1a425a7d74658129b999816db86918 Mon Sep 17 00:00:00 2001 From: Aditya Date: Tue, 23 Jun 2020 14:00:34 +0530 Subject: [PATCH 02/13] Gradient can be toggled and color can be changed. --- data/themes/classic/style.css | 5 +++++ data/themes/default/style.css | 5 +++++ include/SongEditor.h | 15 ++++++++++++++ src/gui/editors/SongEditor.cpp | 38 +++++++++++++++++++++++++++------- 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/data/themes/classic/style.css b/data/themes/classic/style.css index cf609066a81..a19547989bf 100644 --- a/data/themes/classic/style.css +++ b/data/themes/classic/style.css @@ -118,6 +118,11 @@ QMenu::indicator:selected { background-color: #747474; } +positionLine { + qproperty-tailGradient: false; + qproperty-lineColor: rgba(255, 255, 255, 153); +} + PianoRoll { background-color: rgb(0, 0, 0); qproperty-backgroundShade: rgba( 255, 255, 255, 10 ); diff --git a/data/themes/default/style.css b/data/themes/default/style.css index feb85a612b0..4c698a9e239 100644 --- a/data/themes/default/style.css +++ b/data/themes/default/style.css @@ -150,6 +150,11 @@ QMenu::indicator:selected { background-color: #101213; } +positionLine { + qproperty-tailGradient: true; + qproperty-lineColor: rgb(255, 255, 255); +} + PianoRoll { background-color: #141616; qproperty-backgroundShade: rgba(255, 255, 255, 10); diff --git a/include/SongEditor.h b/include/SongEditor.h index 9621bcc23d8..a668d2f3651 100644 --- a/include/SongEditor.h +++ b/include/SongEditor.h @@ -28,6 +28,7 @@ #define SONG_EDITOR_H #include +#include #include "ActionGroup.h" #include "Editor.h" @@ -45,13 +46,27 @@ class Song; class TextFloat; class TimeLineWidget; +Q_DECLARE_METATYPE(QLinearGradient) + class positionLine : public QWidget { + Q_OBJECT + Q_PROPERTY( bool tailGradient READ tailGradient WRITE setTailGradient ) + Q_PROPERTY( QColor lineColor READ lineColor WRITE setLineColor ) public: positionLine( QWidget * parent ); + + // qproperty access functions + bool tailGradient() const; + void setTailGradient( const bool & g ); + QColor lineColor() const; + void setLineColor( const QColor & c ); private: void paintEvent( QPaintEvent * pe ) override; + + bool m_tailGradient; + QColor m_lineColor; } ; diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index ab04a98a87b..dc97f8c1777 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -53,24 +53,36 @@ #include "Track.h" positionLine::positionLine( QWidget * parent ) : - QWidget( parent ) + QWidget( parent ), + m_tailGradient ( false ), + m_lineColor (0, 0, 0, 0) { setFixedWidth( 8 ); setAttribute( Qt::WA_NoSystemBackground, true ); } - - - void positionLine::paintEvent( QPaintEvent * pe ) { QPainter p( this ); // Create the gradient trail behind the line QLinearGradient gradient(rect().bottomLeft(), rect().bottomRight()); - gradient.setColorAt(0, QColor (255, 255, 255, 0) ); - gradient.setColorAt(0.875, QColor (255, 255, 255, 60) ); - gradient.setColorAt(1, QColor (255, 255, 255, 153) ); + + gradient.setColorAt(0, + QColor (m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 0) ); + gradient.setColorAt(1, + QColor (m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 153) ); + + if (m_tailGradient) + { + gradient.setColorAt(0.875, + QColor (m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 60) ); + } + else + { + gradient.setColorAt(0.875, + QColor (m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 0) ); + } // Fill line p.fillRect( rect(), gradient ); @@ -1139,3 +1151,15 @@ void SongEditorWindow::keyReleaseEvent( QKeyEvent *ke ) } } } + +bool positionLine::tailGradient() const +{ return m_tailGradient; } + +void positionLine::setTailGradient( const bool & g ) +{ m_tailGradient = g; } + +QColor positionLine::lineColor() const +{ return m_lineColor; } + +void positionLine::setLineColor( const QColor & c ) +{ m_lineColor = c; } From d724335b02667af9cd47e207c59a0e19ee31406b Mon Sep 17 00:00:00 2001 From: Aditya Date: Tue, 23 Jun 2020 14:32:49 +0530 Subject: [PATCH 03/13] Made playback line (and tail) transparent to mouse clicks --- data/themes/classic/style.css | 2 +- src/gui/editors/SongEditor.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/data/themes/classic/style.css b/data/themes/classic/style.css index a19547989bf..dceb426dfd8 100644 --- a/data/themes/classic/style.css +++ b/data/themes/classic/style.css @@ -120,7 +120,7 @@ QMenu::indicator:selected { positionLine { qproperty-tailGradient: false; - qproperty-lineColor: rgba(255, 255, 255, 153); + qproperty-lineColor: rgb(255, 255, 255); } PianoRoll { diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index dc97f8c1777..ffe20e2005e 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -59,6 +59,7 @@ positionLine::positionLine( QWidget * parent ) : { setFixedWidth( 8 ); setAttribute( Qt::WA_NoSystemBackground, true ); + setAttribute( Qt::WA_TransparentForMouseEvents ); } void positionLine::paintEvent( QPaintEvent * pe ) From 94d865b27b175ea5109d4fecc3f45b86d3a299f5 Mon Sep 17 00:00:00 2001 From: Aditya Date: Wed, 24 Jun 2020 16:17:20 +0530 Subject: [PATCH 04/13] Gradient disappears when paused/stopped; tail length depends on zoom --- include/SongEditor.h | 19 +++++- src/gui/editors/SongEditor.cpp | 118 +++++++++++++++++++++++---------- 2 files changed, 102 insertions(+), 35 deletions(-) diff --git a/include/SongEditor.h b/include/SongEditor.h index a668d2f3651..571bbd73fe3 100644 --- a/include/SongEditor.h +++ b/include/SongEditor.h @@ -54,7 +54,12 @@ class positionLine : public QWidget Q_PROPERTY( bool tailGradient READ tailGradient WRITE setTailGradient ) Q_PROPERTY( QColor lineColor READ lineColor WRITE setLineColor ) public: - positionLine( QWidget * parent ); + positionLine( QWidget * parent, ComboBoxModel*, Song* ); + + int width (); + void go (int, int); + void zoomUpdate (); + void playStateChanged (); // qproperty access functions bool tailGradient() const; @@ -65,8 +70,18 @@ class positionLine : public QWidget private: void paintEvent( QPaintEvent * pe ) override; + int m_width; + int m_x, m_y; // NOTE: m_x is the playback position, not the position where the tail starts + bool m_tailGradient; QColor m_lineColor; + + // to accomodate the change in size by zoom + ComboBoxModel* currentZoom; + static const QVector m_zoomLevels; + + // to remove gradient when the line is not moving + Song * p_song; } ; @@ -129,6 +144,8 @@ private slots: void updateScrollBar(int len); void zoomingChanged(); + + void playbackStateChanged(); private: void keyPressEvent( QKeyEvent * ke ) override; diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index ffe20e2005e..9c55f934318 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -52,12 +52,21 @@ #include "PianoRoll.h" #include "Track.h" -positionLine::positionLine( QWidget * parent ) : +const QVector positionLine::m_zoomLevels = + { 0.125f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f, 8.0f, 16.0f }; + +positionLine::positionLine( QWidget * parent, ComboBoxModel* zoom, Song* song ) : QWidget( parent ), m_tailGradient ( false ), m_lineColor (0, 0, 0, 0) { - setFixedWidth( 8 ); + m_x = 0; + m_y = 0; + m_width = 8; + currentZoom = zoom; + p_song = song; + resize( m_width, height() ); + setAttribute( Qt::WA_NoSystemBackground, true ); setAttribute( Qt::WA_TransparentForMouseEvents ); } @@ -66,32 +75,78 @@ void positionLine::paintEvent( QPaintEvent * pe ) { QPainter p( this ); - // Create the gradient trail behind the line - QLinearGradient gradient(rect().bottomLeft(), rect().bottomRight()); + // Resize based on the zoom value + m_width = 8.0f * m_zoomLevels[ currentZoom->value() ]; + resize( m_width, height() ); - gradient.setColorAt(0, - QColor (m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 0) ); - gradient.setColorAt(1, - QColor (m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 153) ); - - if (m_tailGradient) - { - gradient.setColorAt(0.875, - QColor (m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 60) ); + // If width is 1, we don't need a gradient + if (m_width == 1) + { + p.fillRect ( rect(), + QColor (m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 153) ); } - else - { - gradient.setColorAt(0.875, + + // If width > 1, we need the gradient + else + { + // Create the gradient trail behind the line + QLinearGradient gradient(rect().bottomLeft(), rect().bottomRight()); + + // If gradient is enabled and we're playing, enable gradient + if (p_song->isPlaying() && m_tailGradient) + gradient.setColorAt((double)( ( width() - 1.0f )/width() ), + QColor (m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 60) ); + else + gradient.setColorAt((double)( ( width() - 1.0f )/width() ), + QColor (m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 0) ); + + // Fill in the remaining parts + gradient.setColorAt(0, QColor (m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 0) ); + gradient.setColorAt(1, + QColor (m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 153) ); + + // Fill line + p.fillRect( rect(), gradient ); } - - // Fill line - p.fillRect( rect(), gradient ); } const QVector SongEditor::m_zoomLevels = { 0.125f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f, 8.0f, 16.0f }; +int positionLine::width( void ) +{ + m_width = 8.0f * m_zoomLevels[ currentZoom->value() ]; + return m_width; +} + +void positionLine::go( int x, int y ) +{ + move(x, y); + m_x = x + width() - 1; + m_y = y; +} + +void positionLine::zoomUpdate() +{ move ( m_x - width() + 1, m_y ); } + +// Essentially causes a redraw so that gradient does not persist +void positionLine::playStateChanged() +{ repaint(); } + +// QProperty handles +bool positionLine::tailGradient() const +{ return m_tailGradient; } + +void positionLine::setTailGradient( const bool & g ) +{ m_tailGradient = g; } + +QColor positionLine::lineColor() const +{ return m_lineColor; } + +void positionLine::setLineColor( const QColor & c ) +{ m_lineColor = c; } + SongEditor::SongEditor( Song * song ) : TrackContainerView( song ), @@ -129,8 +184,10 @@ SongEditor::SongEditor( Song * song ) : this, SLOT( selectRegionFromPixels( int, int ) ) ); connect( m_timeLine, SIGNAL( selectionFinished() ), this, SLOT( stopRubberBand() ) ); + connect( m_song, SIGNAL( playbackStateChanged() ), + this, SLOT( playbackStateChanged() ) ); - m_positionLine = new positionLine( this ); + m_positionLine = new positionLine( this, m_zoomingModel, m_song ); static_cast( layout() )->insertWidget( 1, m_timeLine ); @@ -829,7 +886,7 @@ void SongEditor::updatePosition( const MidiTime & t ) if( x >= trackOpWidth + widgetWidth -1 ) { m_positionLine->show(); - m_positionLine->move( x-7, m_timeLine->height() ); + m_positionLine->go( x-( m_positionLine->width() - 1 ), m_timeLine->height() ); } else { @@ -858,9 +915,14 @@ void SongEditor::zoomingChanged() setPixelsPerBar( pixelsPerBar() ); realignTracks(); updateRubberband(); + + m_positionLine->zoomUpdate(); } - +void SongEditor::playbackStateChanged() +{ + m_positionLine->playStateChanged(); +} void SongEditor::selectAllTcos( bool select ) @@ -1152,15 +1214,3 @@ void SongEditorWindow::keyReleaseEvent( QKeyEvent *ke ) } } } - -bool positionLine::tailGradient() const -{ return m_tailGradient; } - -void positionLine::setTailGradient( const bool & g ) -{ m_tailGradient = g; } - -QColor positionLine::lineColor() const -{ return m_lineColor; } - -void positionLine::setLineColor( const QColor & c ) -{ m_lineColor = c; } From 1fa643d322746b77a207321f2128887cb483fc4f Mon Sep 17 00:00:00 2001 From: Aditya Date: Thu, 25 Jun 2020 11:48:06 +0530 Subject: [PATCH 05/13] Fixes bug where gradient appears when a pattern is played; style corrections --- include/SongEditor.h | 22 +++++++++---------- src/gui/editors/SongEditor.cpp | 39 +++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/include/SongEditor.h b/include/SongEditor.h index 571bbd73fe3..9379537ea91 100644 --- a/include/SongEditor.h +++ b/include/SongEditor.h @@ -51,21 +51,21 @@ Q_DECLARE_METATYPE(QLinearGradient) class positionLine : public QWidget { Q_OBJECT - Q_PROPERTY( bool tailGradient READ tailGradient WRITE setTailGradient ) - Q_PROPERTY( QColor lineColor READ lineColor WRITE setLineColor ) + Q_PROPERTY ( bool tailGradient READ tailGradient WRITE setTailGradient ) + Q_PROPERTY ( QColor lineColor READ lineColor WRITE setLineColor ) public: - positionLine( QWidget * parent, ComboBoxModel*, Song* ); + positionLine ( QWidget * parent, ComboBoxModel * zoom, Song * song ); int width (); - void go (int, int); + void go ( int x, int y ); // NOTE: Check SongEditor.cpp for usage void zoomUpdate (); void playStateChanged (); // qproperty access functions - bool tailGradient() const; - void setTailGradient( const bool & g ); - QColor lineColor() const; - void setLineColor( const QColor & c ); + bool tailGradient () const; + void setTailGradient ( const bool & g ); + QColor lineColor () const; + void setLineColor ( const QColor & c ); private: void paintEvent( QPaintEvent * pe ) override; @@ -77,13 +77,13 @@ class positionLine : public QWidget QColor m_lineColor; // to accomodate the change in size by zoom - ComboBoxModel* currentZoom; + ComboBoxModel * currentZoom; static const QVector m_zoomLevels; // to remove gradient when the line is not moving - Song * p_song; + Song * p_song; // NOTE: p here stands for pointer -} ; +}; class SongEditor : public TrackContainerView diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index 9c55f934318..1fb3249282d 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -55,7 +55,7 @@ const QVector positionLine::m_zoomLevels = { 0.125f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f, 8.0f, 16.0f }; -positionLine::positionLine( QWidget * parent, ComboBoxModel* zoom, Song* song ) : +positionLine::positionLine( QWidget * parent, ComboBoxModel * zoom, Song * song ) : QWidget( parent ), m_tailGradient ( false ), m_lineColor (0, 0, 0, 0) @@ -82,55 +82,59 @@ void positionLine::paintEvent( QPaintEvent * pe ) // If width is 1, we don't need a gradient if (m_width == 1) { - p.fillRect ( rect(), - QColor (m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 153) ); + p.fillRect( rect(), + QColor( m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 153) ); } // If width > 1, we need the gradient else { // Create the gradient trail behind the line - QLinearGradient gradient(rect().bottomLeft(), rect().bottomRight()); + QLinearGradient gradient( rect().bottomLeft(), rect().bottomRight() ); - // If gradient is enabled and we're playing, enable gradient - if (p_song->isPlaying() && m_tailGradient) + // If gradient is enabled, we're in focus and we're playing, enable gradient + if (p_song->isPlaying() && m_tailGradient && + p_song->playMode() == Song::Mode_PlaySong) + { gradient.setColorAt((double)( ( width() - 1.0f )/width() ), - QColor (m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 60) ); + QColor( m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 60) ); + } else + { gradient.setColorAt((double)( ( width() - 1.0f )/width() ), - QColor (m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 0) ); + QColor( m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 0) ); + } // Fill in the remaining parts gradient.setColorAt(0, - QColor (m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 0) ); + QColor( m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 0) ); gradient.setColorAt(1, - QColor (m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 153) ); + QColor( m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 153) ); // Fill line p.fillRect( rect(), gradient ); } } -const QVector SongEditor::m_zoomLevels = - { 0.125f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f, 8.0f, 16.0f }; - int positionLine::width( void ) { m_width = 8.0f * m_zoomLevels[ currentZoom->value() ]; return m_width; } +// synonymous to move(), but use this instead of move() so position line can log changes in its m_x & m_y void positionLine::go( int x, int y ) { - move(x, y); + move( x, y ); m_x = x + width() - 1; m_y = y; } +// update width if zoom changes void positionLine::zoomUpdate() { move ( m_x - width() + 1, m_y ); } -// Essentially causes a redraw so that gradient does not persist +// Essentially repaints so that gradient does not persist when stopped (this is a bug fix) void positionLine::playStateChanged() { repaint(); } @@ -148,6 +152,11 @@ void positionLine::setLineColor( const QColor & c ) { m_lineColor = c; } + + +const QVector SongEditor::m_zoomLevels = + { 0.125f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f, 8.0f, 16.0f }; + SongEditor::SongEditor( Song * song ) : TrackContainerView( song ), m_song( song ), From 9a7a1e102bdcffb629e3dd47fe0f7d57171e7f82 Mon Sep 17 00:00:00 2001 From: Aditya Date: Fri, 26 Jun 2020 10:58:02 +0530 Subject: [PATCH 06/13] Cleaned up code --- include/SongEditor.h | 21 ++---------- src/gui/editors/SongEditor.cpp | 61 +++++++++------------------------- 2 files changed, 18 insertions(+), 64 deletions(-) diff --git a/include/SongEditor.h b/include/SongEditor.h index 9379537ea91..1abd49b8023 100644 --- a/include/SongEditor.h +++ b/include/SongEditor.h @@ -46,20 +46,13 @@ class Song; class TextFloat; class TimeLineWidget; -Q_DECLARE_METATYPE(QLinearGradient) - class positionLine : public QWidget { Q_OBJECT Q_PROPERTY ( bool tailGradient READ tailGradient WRITE setTailGradient ) Q_PROPERTY ( QColor lineColor READ lineColor WRITE setLineColor ) public: - positionLine ( QWidget * parent, ComboBoxModel * zoom, Song * song ); - - int width (); - void go ( int x, int y ); // NOTE: Check SongEditor.cpp for usage - void zoomUpdate (); - void playStateChanged (); + positionLine ( QWidget* parent, ComboBoxModel* zoom ); // qproperty access functions bool tailGradient () const; @@ -68,20 +61,14 @@ class positionLine : public QWidget void setLineColor ( const QColor & c ); private: - void paintEvent( QPaintEvent * pe ) override; - - int m_width; - int m_x, m_y; // NOTE: m_x is the playback position, not the position where the tail starts + void paintEvent( QPaintEvent* pe ) override; bool m_tailGradient; QColor m_lineColor; // to accomodate the change in size by zoom - ComboBoxModel * currentZoom; + ComboBoxModel* m_currentZoom; static const QVector m_zoomLevels; - - // to remove gradient when the line is not moving - Song * p_song; // NOTE: p here stands for pointer }; @@ -144,8 +131,6 @@ private slots: void updateScrollBar(int len); void zoomingChanged(); - - void playbackStateChanged(); private: void keyPressEvent( QKeyEvent * ke ) override; diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index 1fb3249282d..8ce5a7b403f 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -55,32 +55,27 @@ const QVector positionLine::m_zoomLevels = { 0.125f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f, 8.0f, 16.0f }; -positionLine::positionLine( QWidget * parent, ComboBoxModel * zoom, Song * song ) : +positionLine::positionLine( QWidget* parent, ComboBoxModel* zoom) : QWidget( parent ), m_tailGradient ( false ), m_lineColor (0, 0, 0, 0) { - m_x = 0; - m_y = 0; - m_width = 8; - currentZoom = zoom; - p_song = song; - resize( m_width, height() ); + m_currentZoom = zoom; + resize( 8, height() ); setAttribute( Qt::WA_NoSystemBackground, true ); setAttribute( Qt::WA_TransparentForMouseEvents ); } -void positionLine::paintEvent( QPaintEvent * pe ) +void positionLine::paintEvent( QPaintEvent* pe ) { QPainter p( this ); // Resize based on the zoom value - m_width = 8.0f * m_zoomLevels[ currentZoom->value() ]; - resize( m_width, height() ); + resize( 8.0f * m_zoomLevels[ m_currentZoom->value() ], height() ); // If width is 1, we don't need a gradient - if (m_width == 1) + if (width() == 1) { p.fillRect( rect(), QColor( m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 153) ); @@ -93,8 +88,8 @@ void positionLine::paintEvent( QPaintEvent * pe ) QLinearGradient gradient( rect().bottomLeft(), rect().bottomRight() ); // If gradient is enabled, we're in focus and we're playing, enable gradient - if (p_song->isPlaying() && m_tailGradient && - p_song->playMode() == Song::Mode_PlaySong) + if (Engine::getSong()->isPlaying() && m_tailGradient && + Engine::getSong()->playMode() == Song::Mode_PlaySong) { gradient.setColorAt((double)( ( width() - 1.0f )/width() ), QColor( m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 60) ); @@ -116,28 +111,6 @@ void positionLine::paintEvent( QPaintEvent * pe ) } } -int positionLine::width( void ) -{ - m_width = 8.0f * m_zoomLevels[ currentZoom->value() ]; - return m_width; -} - -// synonymous to move(), but use this instead of move() so position line can log changes in its m_x & m_y -void positionLine::go( int x, int y ) -{ - move( x, y ); - m_x = x + width() - 1; - m_y = y; -} - -// update width if zoom changes -void positionLine::zoomUpdate() -{ move ( m_x - width() + 1, m_y ); } - -// Essentially repaints so that gradient does not persist when stopped (this is a bug fix) -void positionLine::playStateChanged() -{ repaint(); } - // QProperty handles bool positionLine::tailGradient() const { return m_tailGradient; } @@ -193,11 +166,12 @@ SongEditor::SongEditor( Song * song ) : this, SLOT( selectRegionFromPixels( int, int ) ) ); connect( m_timeLine, SIGNAL( selectionFinished() ), this, SLOT( stopRubberBand() ) ); - connect( m_song, SIGNAL( playbackStateChanged() ), - this, SLOT( playbackStateChanged() ) ); - m_positionLine = new positionLine( this, m_zoomingModel, m_song ); + m_positionLine = new positionLine( this, m_zoomingModel ); static_cast( layout() )->insertWidget( 1, m_timeLine ); + + connect( m_song, SIGNAL( playbackStateChanged() ), + m_positionLine, SLOT( update() ) ); // add some essential widgets to global tool-bar @@ -337,6 +311,8 @@ SongEditor::SongEditor( Song * song ) : m_zoomingModel->findText( "100%" ) ); connect( m_zoomingModel, SIGNAL( dataChanged() ), this, SLOT( zoomingChanged() ) ); + connect( m_zoomingModel, SIGNAL( dataChanged() ), + m_positionLine, SLOT( update() ) ); //Set up snapping model, 2^i for ( int i = 3; i >= -4; i-- ) @@ -895,7 +871,7 @@ void SongEditor::updatePosition( const MidiTime & t ) if( x >= trackOpWidth + widgetWidth -1 ) { m_positionLine->show(); - m_positionLine->go( x-( m_positionLine->width() - 1 ), m_timeLine->height() ); + m_positionLine->move( x-( m_positionLine->width() - 1 ), m_timeLine->height() ); } else { @@ -924,13 +900,6 @@ void SongEditor::zoomingChanged() setPixelsPerBar( pixelsPerBar() ); realignTracks(); updateRubberband(); - - m_positionLine->zoomUpdate(); -} - -void SongEditor::playbackStateChanged() -{ - m_positionLine->playStateChanged(); } From db3ee772a2db8c5fb972b27ce58a94c152573251 Mon Sep 17 00:00:00 2001 From: Aditya Date: Fri, 26 Jun 2020 11:01:27 +0530 Subject: [PATCH 07/13] Rename m_zoomLevels to s_zoomLevels --- include/SongEditor.h | 2 +- src/gui/editors/SongEditor.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/SongEditor.h b/include/SongEditor.h index 1abd49b8023..9b030e8acfd 100644 --- a/include/SongEditor.h +++ b/include/SongEditor.h @@ -68,7 +68,7 @@ class positionLine : public QWidget // to accomodate the change in size by zoom ComboBoxModel* m_currentZoom; - static const QVector m_zoomLevels; + static const QVector s_zoomLevels; }; diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index 8ce5a7b403f..edb535b2557 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -52,7 +52,7 @@ #include "PianoRoll.h" #include "Track.h" -const QVector positionLine::m_zoomLevels = +const QVector positionLine::s_zoomLevels = { 0.125f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f, 8.0f, 16.0f }; positionLine::positionLine( QWidget* parent, ComboBoxModel* zoom) : @@ -72,7 +72,7 @@ void positionLine::paintEvent( QPaintEvent* pe ) QPainter p( this ); // Resize based on the zoom value - resize( 8.0f * m_zoomLevels[ m_currentZoom->value() ], height() ); + resize( 8.0f * s_zoomLevels[ m_currentZoom->value() ], height() ); // If width is 1, we don't need a gradient if (width() == 1) From 7bc8a7775cdf38f3eb89412d2e37e2541875cd7d Mon Sep 17 00:00:00 2001 From: Aditya Date: Sat, 27 Jun 2020 20:05:19 +0530 Subject: [PATCH 08/13] Finalising code --- include/SongEditor.h | 8 ++++---- src/gui/editors/SongEditor.cpp | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/SongEditor.h b/include/SongEditor.h index 9b030e8acfd..7353dc74bcd 100644 --- a/include/SongEditor.h +++ b/include/SongEditor.h @@ -49,21 +49,21 @@ class TimeLineWidget; class positionLine : public QWidget { Q_OBJECT - Q_PROPERTY ( bool tailGradient READ tailGradient WRITE setTailGradient ) + Q_PROPERTY ( bool tailGradient READ hasTailGradient WRITE setHasTailGradient ) Q_PROPERTY ( QColor lineColor READ lineColor WRITE setLineColor ) public: positionLine ( QWidget* parent, ComboBoxModel* zoom ); // qproperty access functions - bool tailGradient () const; - void setTailGradient ( const bool & g ); + bool hasTailGradient () const; + void setHasTailGradient ( const bool g ); QColor lineColor () const; void setLineColor ( const QColor & c ); private: void paintEvent( QPaintEvent* pe ) override; - bool m_tailGradient; + bool m_hasTailGradient; QColor m_lineColor; // to accomodate the change in size by zoom diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index edb535b2557..14b223c9911 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -57,7 +57,7 @@ const QVector positionLine::s_zoomLevels = positionLine::positionLine( QWidget* parent, ComboBoxModel* zoom) : QWidget( parent ), - m_tailGradient ( false ), + m_hasTailGradient ( false ), m_lineColor (0, 0, 0, 0) { m_currentZoom = zoom; @@ -88,15 +88,15 @@ void positionLine::paintEvent( QPaintEvent* pe ) QLinearGradient gradient( rect().bottomLeft(), rect().bottomRight() ); // If gradient is enabled, we're in focus and we're playing, enable gradient - if (Engine::getSong()->isPlaying() && m_tailGradient && + if (Engine::getSong()->isPlaying() && m_hasTailGradient && Engine::getSong()->playMode() == Song::Mode_PlaySong) { - gradient.setColorAt((double)( ( width() - 1.0f )/width() ), + gradient.setColorAt(( ( width() - 1.0f )/width() ), QColor( m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 60) ); } else { - gradient.setColorAt((double)( ( width() - 1.0f )/width() ), + gradient.setColorAt(( ( width() - 1.0f )/width() ), QColor( m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 0) ); } @@ -112,11 +112,11 @@ void positionLine::paintEvent( QPaintEvent* pe ) } // QProperty handles -bool positionLine::tailGradient() const -{ return m_tailGradient; } +bool positionLine::hasTailGradient() const +{ return m_hasTailGradient; } -void positionLine::setTailGradient( const bool & g ) -{ m_tailGradient = g; } +void positionLine::setHasTailGradient( const bool g ) +{ m_hasTailGradient = g; } QColor positionLine::lineColor() const { return m_lineColor; } From a34f48fd7ec227320def28618a1c9f190e15478e Mon Sep 17 00:00:00 2001 From: Aditya Date: Wed, 1 Jul 2020 09:48:43 +0530 Subject: [PATCH 09/13] Make positionLine class independent of parent zooming model --- include/SongEditor.h | 12 +++++++----- src/gui/editors/SongEditor.cpp | 29 ++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/include/SongEditor.h b/include/SongEditor.h index 7353dc74bcd..c4c25d7d0c9 100644 --- a/include/SongEditor.h +++ b/include/SongEditor.h @@ -52,7 +52,7 @@ class positionLine : public QWidget Q_PROPERTY ( bool tailGradient READ hasTailGradient WRITE setHasTailGradient ) Q_PROPERTY ( QColor lineColor READ lineColor WRITE setLineColor ) public: - positionLine ( QWidget* parent, ComboBoxModel* zoom ); + positionLine ( QWidget* parent ); // qproperty access functions bool hasTailGradient () const; @@ -60,15 +60,14 @@ class positionLine : public QWidget QColor lineColor () const; void setLineColor ( const QColor & c ); +public slots: + void zoomChange (double zoom); + private: void paintEvent( QPaintEvent* pe ) override; bool m_hasTailGradient; QColor m_lineColor; - - // to accomodate the change in size by zoom - ComboBoxModel* m_currentZoom; - static const QVector s_zoomLevels; }; @@ -181,6 +180,9 @@ private slots: bool m_selectRegion; friend class SongEditorWindow; + +signals: + void zoomingValueChanged( double ); } ; diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index 14b223c9911..7c6e7be6915 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -52,15 +52,11 @@ #include "PianoRoll.h" #include "Track.h" -const QVector positionLine::s_zoomLevels = - { 0.125f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f, 8.0f, 16.0f }; - -positionLine::positionLine( QWidget* parent, ComboBoxModel* zoom) : +positionLine::positionLine( QWidget* parent ) : QWidget( parent ), m_hasTailGradient ( false ), m_lineColor (0, 0, 0, 0) { - m_currentZoom = zoom; resize( 8, height() ); setAttribute( Qt::WA_NoSystemBackground, true ); @@ -72,7 +68,7 @@ void positionLine::paintEvent( QPaintEvent* pe ) QPainter p( this ); // Resize based on the zoom value - resize( 8.0f * s_zoomLevels[ m_currentZoom->value() ], height() ); + //resize( 8.0f * s_zoomLevels[ m_currentZoom->value() ], height() ); // If width is 1, we don't need a gradient if (width() == 1) @@ -91,12 +87,12 @@ void positionLine::paintEvent( QPaintEvent* pe ) if (Engine::getSong()->isPlaying() && m_hasTailGradient && Engine::getSong()->playMode() == Song::Mode_PlaySong) { - gradient.setColorAt(( ( width() - 1.0f )/width() ), + gradient.setColorAt(( ( width() - 1.0 )/width() ), QColor( m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 60) ); } else { - gradient.setColorAt(( ( width() - 1.0f )/width() ), + gradient.setColorAt(( ( width() - 1.0 )/width() ), QColor( m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 0) ); } @@ -124,6 +120,17 @@ QColor positionLine::lineColor() const void positionLine::setLineColor( const QColor & c ) { m_lineColor = c; } +// NOTE: the move() implementation fixes a bug where the position line would appear +// in an unexpected location when positioned at the start of the track +void positionLine::zoomChange( double zoom ) +{ + move( x() + width() - 1, y() ); + resize( 8.0 * zoom, height() ); + move( x() - width() + 1, y() ); + + update(); +} + @@ -167,11 +174,13 @@ SongEditor::SongEditor( Song * song ) : connect( m_timeLine, SIGNAL( selectionFinished() ), this, SLOT( stopRubberBand() ) ); - m_positionLine = new positionLine( this, m_zoomingModel ); + m_positionLine = new positionLine( this ); static_cast( layout() )->insertWidget( 1, m_timeLine ); connect( m_song, SIGNAL( playbackStateChanged() ), m_positionLine, SLOT( update() ) ); + connect( this, SIGNAL( zoomingValueChanged( double ) ), + m_positionLine, SLOT( zoomChange( double ) ) ); // add some essential widgets to global tool-bar @@ -900,6 +909,8 @@ void SongEditor::zoomingChanged() setPixelsPerBar( pixelsPerBar() ); realignTracks(); updateRubberband(); + + emit zoomingValueChanged( m_zoomLevels[m_zoomingModel->value()] ); } From e6a179313472adb9ec98b7bf50b441a501f1598c Mon Sep 17 00:00:00 2001 From: Aditya Date: Wed, 1 Jul 2020 15:29:11 +0530 Subject: [PATCH 10/13] Edit a bug fix to make it more efficient --- src/gui/editors/SongEditor.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index 7c6e7be6915..02d71abafab 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -124,9 +124,10 @@ void positionLine::setLineColor( const QColor & c ) // in an unexpected location when positioned at the start of the track void positionLine::zoomChange( double zoom ) { - move( x() + width() - 1, y() ); + int m_x = x() + width() - 1; + resize( 8.0 * zoom, height() ); - move( x() - width() + 1, y() ); + move( m_x - width() + 1, y() ); update(); } From 6fa3fa71fe257a73dc21f81239e31e9053aae8c4 Mon Sep 17 00:00:00 2001 From: Aditya Date: Thu, 2 Jul 2020 07:17:55 +0530 Subject: [PATCH 11/13] Rename m_x and finalise positionLine code --- src/gui/editors/SongEditor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index 02d71abafab..7949ab5bfea 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -124,10 +124,10 @@ void positionLine::setLineColor( const QColor & c ) // in an unexpected location when positioned at the start of the track void positionLine::zoomChange( double zoom ) { - int m_x = x() + width() - 1; + int X = x() + width() - 1; resize( 8.0 * zoom, height() ); - move( m_x - width() + 1, y() ); + move( X - width() + 1, y() ); update(); } From c18baa96eb7a03680f70c96f85b8df80fc1aa9ca Mon Sep 17 00:00:00 2001 From: Aditya Date: Thu, 2 Jul 2020 07:18:48 +0530 Subject: [PATCH 12/13] Rename m_x and finalise positionLine changes --- src/gui/editors/SongEditor.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index 7949ab5bfea..1e6884f9273 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -67,9 +67,6 @@ void positionLine::paintEvent( QPaintEvent* pe ) { QPainter p( this ); - // Resize based on the zoom value - //resize( 8.0f * s_zoomLevels[ m_currentZoom->value() ], height() ); - // If width is 1, we don't need a gradient if (width() == 1) { From da2727d9286560c252dccbcf39d5622d61b77946 Mon Sep 17 00:00:00 2001 From: adi Date: Thu, 2 Jul 2020 15:58:00 +0530 Subject: [PATCH 13/13] Rename X to playHeadPos --- src/gui/editors/SongEditor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index 1e6884f9273..a7f67c743f8 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -121,10 +121,10 @@ void positionLine::setLineColor( const QColor & c ) // in an unexpected location when positioned at the start of the track void positionLine::zoomChange( double zoom ) { - int X = x() + width() - 1; + int playHeadPos = x() + width() - 1; resize( 8.0 * zoom, height() ); - move( X - width() + 1, y() ); + move( playHeadPos - width() + 1, y() ); update(); }