Refactor PianoRoll (#5253)

* Rework PianoRoll paintEvent + some extras
* Split out PositionLine class to own file
* Refactor PianoRoll Q_PROPERTYs
* Reduce code by using Q_PROPERTY's MEMBER function and removing getter/setter functions
  After looking at the getters and setters, they did nothing different than what direct
  access would allow. Nothing outside of PianoRoll used the public functions as well.
  Considering these factors we can reduce the number of functions by 2x the number of
  Q_PROPERTIES, and go with direct access instead.
* Remove need for keyboard pixmaps
  With the recent change to allow zooming vertically, aligning pixmaps is a PITA. Since
  we have themes which can take brushes and colors, it would be simpler to take a solid
  color or a gradient with some extra style properties to resize the keys and text colors.
  While it will slightly be a downgrade from pixmaps since they can be anything really,
  this will allow us to customize the piano roll further moving forward.
* Added the ability to update margins for TimeLineWidget and StepRecorderWidget
  These take a X coordinate, which was hardcoded to WHITE_KEY_WIDTH, and never looked
  back. Now we can adjust on the fly if we need to. Currently this just allows us to
  shift the left margin to the style-defined white key width.
* Fix phantom pixmaps when PianoRoll not focused
* Update PositionLine class changes related to #5543
This commit is contained in:
Kevin Zander
2020-08-09 18:01:35 -05:00
committed by GitHub
parent 7a9b33627d
commit ef961e53de
13 changed files with 757 additions and 793 deletions

View File

@@ -81,6 +81,7 @@ SET(LMMS_SRCS
gui/widgets/NStateButton.cpp
gui/widgets/Oscilloscope.cpp
gui/widgets/PixmapButton.cpp
gui/widgets/PositionLine.cpp
gui/widgets/ProjectNotes.cpp
gui/widgets/RenameDialog.cpp
gui/widgets/Rubberband.cpp

View File

@@ -109,6 +109,14 @@ TimeLineWidget::~TimeLineWidget()
void TimeLineWidget::setXOffset(const int x)
{
m_xOffset = x;
if (s_posMarkerPixmap != nullptr) { m_xOffset -= s_posMarkerPixmap->width() / 2; }
}
void TimeLineWidget::addToolButtons( QToolBar * _tool_bar )
{

File diff suppressed because it is too large Load Diff

View File

@@ -52,86 +52,6 @@
#include "PianoRoll.h"
#include "Track.h"
positionLine::positionLine( QWidget* parent ) :
QWidget( parent ),
m_hasTailGradient ( false ),
m_lineColor (0, 0, 0, 0)
{
resize( 8, height() );
setAttribute( Qt::WA_NoSystemBackground, true );
setAttribute( Qt::WA_TransparentForMouseEvents );
}
void positionLine::paintEvent( QPaintEvent* pe )
{
QPainter p( this );
// If width is 1, we don't need a gradient
if (width() == 1)
{
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() );
// If gradient is enabled, we're in focus and we're playing, enable gradient
if (Engine::getSong()->isPlaying() && m_hasTailGradient &&
Engine::getSong()->playMode() == Song::Mode_PlaySong)
{
gradient.setColorAt(( ( width() - 1.0 )/width() ),
QColor( m_lineColor.red(), m_lineColor.green(), m_lineColor.blue(), 60) );
}
else
{
gradient.setColorAt(( ( width() - 1.0 )/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 );
}
}
// QProperty handles
bool positionLine::hasTailGradient() const
{ return m_hasTailGradient; }
void positionLine::setHasTailGradient( const bool g )
{ m_hasTailGradient = g; }
QColor positionLine::lineColor() const
{ return m_lineColor; }
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 )
{
int playHeadPos = x() + width() - 1;
resize( 8.0 * zoom, height() );
move( playHeadPos - width() + 1, y() );
update();
}
const QVector<double> SongEditor::m_zoomLevels =
{ 0.125f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f, 8.0f, 16.0f };
@@ -172,7 +92,7 @@ SongEditor::SongEditor( Song * song ) :
connect( m_timeLine, SIGNAL( selectionFinished() ),
this, SLOT( stopRubberBand() ) );
m_positionLine = new positionLine( this );
m_positionLine = new PositionLine(this);
static_cast<QVBoxLayout *>( layout() )->insertWidget( 1, m_timeLine );
connect( m_song, SIGNAL( playbackStateChanged() ),

View File

@@ -0,0 +1,98 @@
/*
* PositionLine.cpp
*
* Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* 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 "PositionLine.h"
#include <QPainter>
#include "GuiApplication.h"
#include "Song.h"
PositionLine::PositionLine(QWidget* parent) :
QWidget(parent),
m_hasTailGradient(false),
m_lineColor(0, 0, 0, 0)
{
resize(8, height());
setAttribute(Qt::WA_NoSystemBackground, true);
setAttribute(Qt::WA_TransparentForMouseEvents);
}
void PositionLine::paintEvent(QPaintEvent* pe)
{
QPainter p(this);
QColor c = QColor(m_lineColor);
// If width is 1, we don't need a gradient
if (width() == 1)
{
c.setAlpha(153);
p.fillRect(rect(), c);
}
// If width > 1, we need the gradient
else
{
// Create the gradient trail behind the line
QLinearGradient gradient(rect().bottomLeft(), rect().bottomRight());
qreal w = (width() - 1.0) / width();
// If gradient is enabled, we're in focus and we're playing, enable gradient
if (m_hasTailGradient &&
Engine::getSong()->isPlaying() &&
(Engine::getSong()->playMode() == Song::Mode_PlaySong ||
Engine::getSong()->playMode() == Song::Mode_PlayPattern))
{
c.setAlpha(60);
gradient.setColorAt(w, c);
}
else
{
c.setAlpha(0);
gradient.setColorAt(w, c);
}
// Fill in the remaining parts
c.setAlpha(0);
gradient.setColorAt(0, c);
c.setAlpha(153);
gradient.setColorAt(1, c);
// Fill line
p.fillRect(rect(), gradient);
}
}
// 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)
{
int playHeadPos = x() + width() - 1;
resize(8.0 * zoom, height());
move(playHeadPos - width() + 1, y());
update();
}

View File

@@ -58,6 +58,19 @@ void StepRecorderWidget::setCurrentPosition(MidiTime currentPosition)
m_currentPosition = currentPosition;
}
void StepRecorderWidget::setMargins(const QMargins &qm)
{
m_left = qm.left();
m_right = qm.right();
m_top = qm.top();
m_bottom = qm.bottom();
}
QMargins StepRecorderWidget::margins()
{
return QMargins(m_left, m_top, m_right, m_bottom);
}
void StepRecorderWidget::setBottomMargin(const int marginBottom)
{
m_marginBottom = marginBottom;