Changed bar lines to follow snap size (#7034)

* Added lines in between bars
* Changed bar lines to follow snap size
* Changed default zoom and quantization value
* Added constants for line widths
* Added QSS configuration for new grid line colors
* Tied line widths to QSS properties
* Changed default quantization to 1/4
* Removed clear() from destructor model
* Removed destructor in ComboBoxModel.h
* Changed member set/get functions to pass by value
* Updated signal connection with newer syntax
This commit is contained in:
BoredGuy1
2024-05-20 03:37:18 -07:00
committed by GitHub
parent d60fd0d022
commit a527427abf
8 changed files with 192 additions and 50 deletions

View File

@@ -352,14 +352,24 @@ lmms--gui--TrackView > QWidget {
/* autoscroll, loop, stop behaviour toggle buttons */
/* track background colors */
/* track background config */
lmms--gui--TrackContentWidget {
qproperty-darkerColor: qlineargradient(x1:0, y1:0, x2:0, y2:1,
stop:0 rgb( 50, 50, 50 ), stop:0.33 rgb( 20, 20, 20 ), stop:1 rgb( 15, 15, 15 ) );
qproperty-lighterColor: qlineargradient(x1:0, y1:0, x2:0, y2:1,
stop:0 rgb( 50, 50, 50 ), stop:0.33 rgb( 40, 40, 40 ), stop:1 rgb( 30, 30, 30 ) );
qproperty-gridColor: rgba( 0, 0, 0, 160 );
qproperty-embossColor: rgba( 140, 140, 140, 64 );
/* colors */
qproperty-darkerColor: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgb(50, 50, 50), stop:0.33 rgb(20, 20, 20), stop:1 rgb(15, 15, 15));
qproperty-lighterColor: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgb(50, 50, 50), stop:0.33 rgb(40, 40, 40), stop:1 rgb(30, 30, 30));
qproperty-coarseGridColor: rgba(0, 0, 0, 160);
qproperty-fineGridColor: rgba(0, 0, 0, 80);
qproperty-horizontalColor: rgba(0, 0, 0, 160);
qproperty-embossColor: rgba(140, 140, 140, 64);
/* line widths */
qproperty-coarseGridWidth: 2;
qproperty-fineGridWidth: 1;
qproperty-horizontalWidth: 1;
qproperty-embossWidth: 0;
/* positive offset shifts emboss to the right */
qproperty-embossOffset: 0;
}

View File

@@ -388,12 +388,24 @@ lmms--gui--TrackView > QWidget {
/* autoscroll, loop, stop behaviour toggle buttons */
/* track background colors */
/* track background config */
lmms--gui--TrackContentWidget {
/* colors */
qproperty-darkerColor: #0C0E0F;
qproperty-lighterColor: #14151A;
qproperty-gridColor: #262B30;
qproperty-embossColor: rgba( 0, 0, 0, 0 );
qproperty-coarseGridColor: #3C444C;
qproperty-fineGridColor: #262B30;
qproperty-horizontalColor: #3C444C;
qproperty-embossColor: rgba(0, 0, 0, 0);
/* line widths */
qproperty-coarseGridWidth: 2;
qproperty-fineGridWidth: 1;
qproperty-horizontalWidth: 1;
qproperty-embossWidth: 0;
/* positive offset shifts emboss to the right */
qproperty-embossOffset: 0;
}

View File

@@ -47,11 +47,6 @@ public:
{
}
~ComboBoxModel() override
{
clear();
}
void addItem( QString item, std::unique_ptr<PixmapLoader> loader = nullptr );
void replaceItem(std::size_t index, QString item, std::unique_ptr<PixmapLoader> loader = nullptr);

View File

@@ -164,6 +164,7 @@ private:
signals:
void pixelsPerBarChanged(float);
void proportionalSnapChanged();
} ;

View File

@@ -166,7 +166,7 @@ public slots:
protected:
static const int DEFAULT_PIXELS_PER_BAR = 16;
static const int DEFAULT_PIXELS_PER_BAR = 128;
void resizeEvent( QResizeEvent * ) override;

View File

@@ -49,18 +49,24 @@ class TrackContentWidget : public QWidget, public JournallingObject
Q_OBJECT
// qproperties for track background gradients
Q_PROPERTY( QBrush darkerColor READ darkerColor WRITE setDarkerColor )
Q_PROPERTY( QBrush lighterColor READ lighterColor WRITE setLighterColor )
Q_PROPERTY( QBrush gridColor READ gridColor WRITE setGridColor )
Q_PROPERTY( QBrush embossColor READ embossColor WRITE setEmbossColor )
Q_PROPERTY(QBrush darkerColor READ darkerColor WRITE setDarkerColor)
Q_PROPERTY(QBrush lighterColor READ lighterColor WRITE setLighterColor)
Q_PROPERTY(QBrush coarseGridColor READ coarseGridColor WRITE setCoarseGridColor)
Q_PROPERTY(QBrush fineGridColor READ fineGridColor WRITE setFineGridColor)
Q_PROPERTY(QBrush horizontalColor READ horizontalColor WRITE setHorizontalColor)
Q_PROPERTY(QBrush embossColor READ embossColor WRITE setEmbossColor)
Q_PROPERTY(int coarseGridWidth READ coarseGridWidth WRITE setCoarseGridWidth)
Q_PROPERTY(int fineGridWidth READ fineGridWidth WRITE setFineGridWidth)
Q_PROPERTY(int horizontalWidth READ horizontalWidth WRITE setHorizontalWidth)
Q_PROPERTY(int embossWidth READ embossWidth WRITE setEmbossWidth)
Q_PROPERTY(int embossOffset READ embossOffset WRITE setEmbossOffset)
public:
TrackContentWidget( TrackView * parent );
~TrackContentWidget() override = default;
/*! \brief Updates the background tile pixmap. */
void updateBackground();
void addClipView( ClipView * clipv );
void removeClipView( ClipView * clipv );
void removeClipView( int clipNum )
@@ -82,17 +88,37 @@ public:
QBrush darkerColor() const;
QBrush lighterColor() const;
QBrush gridColor() const;
QBrush coarseGridColor() const;
QBrush fineGridColor() const;
QBrush horizontalColor() const;
QBrush embossColor() const;
void setDarkerColor( const QBrush & c );
void setLighterColor( const QBrush & c );
void setGridColor( const QBrush & c );
void setEmbossColor( const QBrush & c);
int coarseGridWidth() const;
int fineGridWidth() const;
int horizontalWidth() const;
int embossWidth() const;
int embossOffset() const;
void setDarkerColor(const QBrush & c);
void setLighterColor(const QBrush & c);
void setCoarseGridColor(const QBrush & c);
void setFineGridColor(const QBrush & c);
void setHorizontalColor(const QBrush & c);
void setEmbossColor(const QBrush & c);
void setCoarseGridWidth(int c);
void setFineGridWidth(int c);
void setHorizontalWidth(int c);
void setEmbossWidth(int c);
void setEmbossOffset(int c);
public slots:
void update();
void changePosition( const lmms::TimePos & newPos = TimePos( -1 ) );
/*! \brief Updates the background tile pixmap. */
void updateBackground();
protected:
enum class ContextMenuAction
@@ -140,8 +166,17 @@ private:
// qproperty fields
QBrush m_darkerColor;
QBrush m_lighterColor;
QBrush m_gridColor;
QBrush m_coarseGridColor;
QBrush m_fineGridColor;
QBrush m_horizontalColor;
QBrush m_embossColor;
int m_coarseGridWidth;
int m_fineGridWidth;
int m_horizontalWidth;
int m_embossWidth;
int m_embossOffset;
} ;

View File

@@ -63,7 +63,7 @@ namespace lmms::gui
namespace
{
constexpr int MIN_PIXELS_PER_BAR = 2;
constexpr int MIN_PIXELS_PER_BAR = 4;
constexpr int MAX_PIXELS_PER_BAR = 400;
constexpr int ZOOM_STEPS = 200;
@@ -263,7 +263,7 @@ SongEditor::SongEditor( Song * song ) :
m_snappingModel->addItem(QString("1/%1 Bar").arg(1 / bars));
}
}
m_snappingModel->setInitValue( m_snappingModel->findText( "1 Bar" ) );
m_snappingModel->setInitValue( m_snappingModel->findText( "1/4 Bar" ) );
setFocusPolicy( Qt::StrongFocus );
setFocus();
@@ -447,6 +447,8 @@ void SongEditor::toggleProportionalSnap()
{
m_proportionalSnap = !m_proportionalSnap;
m_timeLine->setSnapSize(getSnapSize());
emit proportionalSnapChanged();
}

View File

@@ -43,14 +43,15 @@
#include "ClipView.h"
#include "TrackView.h"
namespace lmms::gui
{
/*! Alternate between a darker and a lighter background color every 4 bars
*/
const int BARS_PER_GROUP = 4;
/* Lines between bars will disappear if zoomed too far out (i.e
if there are less than 4 pixels between lines)*/
const int MIN_PIXELS_BETWEEN_LINES = 4;
/*! \brief Create a new trackContentWidget
*
@@ -65,7 +66,9 @@ TrackContentWidget::TrackContentWidget( TrackView * parent ) :
m_trackView( parent ),
m_darkerColor( Qt::SolidPattern ),
m_lighterColor( Qt::SolidPattern ),
m_gridColor( Qt::SolidPattern ),
m_coarseGridColor( Qt::SolidPattern ),
m_fineGridColor( Qt::SolidPattern ),
m_horizontalColor( Qt::SolidPattern ),
m_embossColor( Qt::SolidPattern )
{
setAcceptDrops( true );
@@ -74,6 +77,14 @@ TrackContentWidget::TrackContentWidget( TrackView * parent ) :
SIGNAL( positionChanged( const lmms::TimePos& ) ),
this, SLOT( changePosition( const lmms::TimePos& ) ) );
// Update background if snap size changes
connect(getGUI()->songEditor()->m_editor->snappingModel(), &Model::dataChanged,
this, &TrackContentWidget::updateBackground);
// Also update background if proportional snap is enabled/disabled
connect(getGUI()->songEditor()->m_editor, &SongEditor::proportionalSnapChanged,
this, &TrackContentWidget::updateBackground);
setStyle( QApplication::style() );
updateBackground();
@@ -82,16 +93,30 @@ TrackContentWidget::TrackContentWidget( TrackView * parent ) :
void TrackContentWidget::updateBackground()
{
{
// use snapSize to determine number of lines to draw
float snapSize = getGUI()->songEditor()->m_editor->getSnapSize();
const TrackContainerView * tcv = m_trackView->trackContainerView();
// Assume even-pixels-per-bar. Makes sense, should be like this anyways
int ppb = static_cast<int>( tcv->pixelsPerBar() );
// Coarse grid appears every bar (less frequently if quantization > 1 bar)
float coarseGridResolution = (snapSize >= 1) ? snapSize : 1;
// Fine grid appears within bars
float fineGridResolution = snapSize;
// Increase fine grid resolution (size between lines) if it results in less than
// 4 pixels between each line to avoid cluttering
float pixelsBetweenLines = ppb * snapSize;
if (pixelsBetweenLines < MIN_PIXELS_BETWEEN_LINES) {
// Scale fineGridResolution so that there are enough pixels between lines
// scaleFactor should be a power of 2
int scaleFactor = 1 << static_cast<int>( std::ceil( std::log2( MIN_PIXELS_BETWEEN_LINES / pixelsBetweenLines ) ) );
fineGridResolution *= scaleFactor;
}
int w = ppb * BARS_PER_GROUP;
int h = height();
m_background = QPixmap( w * 2, height() );
@@ -101,22 +126,29 @@ void TrackContentWidget::updateBackground()
pmp.fillRect( w, 0, w , h, lighterColor() );
// draw lines
// vertical lines
pmp.setPen( QPen( gridColor(), 1 ) );
for( float x = 0; x < w * 2; x += ppb )
// draw fine grid
pmp.setPen( QPen( fineGridColor(), fineGridWidth() ) );
for (float x = 0; x < w * 2; x += ppb * fineGridResolution)
{
pmp.drawLine( QLineF( x, 0.0, x, h ) );
}
pmp.setPen( QPen( embossColor(), 1 ) );
for( float x = 1.0; x < w * 2; x += ppb )
// draw coarse grid
pmp.setPen( QPen( coarseGridColor(), coarseGridWidth() ) );
for (float x = 0; x < w * 2; x += ppb * coarseGridResolution)
{
pmp.drawLine( QLineF( x, 0.0, x, h ) );
}
// horizontal line
pmp.setPen( QPen( gridColor(), 1 ) );
pmp.drawLine( 0, h-1, w*2, h-1 );
pmp.setPen( QPen( embossColor(), embossWidth() ) );
for (float x = (coarseGridWidth() + embossOffset()); x < w * 2; x += ppb * coarseGridResolution)
{
pmp.drawLine( QLineF( x, 0.0, x, h ) );
}
// draw horizontal line
pmp.setPen( QPen( horizontalColor(), horizontalWidth() ) );
pmp.drawLine(0, h - (horizontalWidth() + 1) / 2, w * 2, h - (horizontalWidth() + 1) / 2);
pmp.end();
@@ -690,13 +722,41 @@ QBrush TrackContentWidget::lighterColor() const
{ return m_lighterColor; }
//! \brief CSS theming qproperty access method
QBrush TrackContentWidget::gridColor() const
{ return m_gridColor; }
QBrush TrackContentWidget::coarseGridColor() const
{ return m_coarseGridColor; }
//! \brief CSS theming qproperty access method
QBrush TrackContentWidget::fineGridColor() const
{ return m_fineGridColor; }
//! \brief CSS theming qproperty access method
QBrush TrackContentWidget::horizontalColor() const
{ return m_horizontalColor; }
//! \brief CSS theming qproperty access method
QBrush TrackContentWidget::embossColor() const
{ return m_embossColor; }
//! \brief CSS theming qproperty access method
int TrackContentWidget::coarseGridWidth() const
{ return m_coarseGridWidth; }
//! \brief CSS theming qproperty access method
int TrackContentWidget::fineGridWidth() const
{ return m_fineGridWidth; }
//! \brief CSS theming qproperty access method
int TrackContentWidget::horizontalWidth() const
{ return m_horizontalWidth; }
//! \brief CSS theming qproperty access method
int TrackContentWidget::embossWidth() const
{ return m_embossWidth; }
//! \brief CSS theming qproperty access method
int TrackContentWidget::embossOffset() const
{ return m_embossOffset; }
//! \brief CSS theming qproperty access method
void TrackContentWidget::setDarkerColor( const QBrush & c )
{ m_darkerColor = c; }
@@ -706,12 +766,39 @@ void TrackContentWidget::setLighterColor( const QBrush & c )
{ m_lighterColor = c; }
//! \brief CSS theming qproperty access method
void TrackContentWidget::setGridColor( const QBrush & c )
{ m_gridColor = c; }
void TrackContentWidget::setCoarseGridColor( const QBrush & c )
{ m_coarseGridColor = c; }
//! \brief CSS theming qproperty access method
void TrackContentWidget::setFineGridColor( const QBrush & c )
{ m_fineGridColor = c; }
//! \brief CSS theming qproperty access method
void TrackContentWidget::setHorizontalColor( const QBrush & c )
{ m_horizontalColor = c; }
//! \brief CSS theming qproperty access method
void TrackContentWidget::setEmbossColor( const QBrush & c )
{ m_embossColor = c; }
//! \brief CSS theming qproperty access method
void TrackContentWidget::setCoarseGridWidth(int c)
{ m_coarseGridWidth = c; }
//! \brief CSS theming qproperty access method
void TrackContentWidget::setFineGridWidth(int c)
{ m_fineGridWidth = c; }
//! \brief CSS theming qproperty access method
void TrackContentWidget::setHorizontalWidth(int c)
{ m_horizontalWidth = c; }
//! \brief CSS theming qproperty access method
void TrackContentWidget::setEmbossWidth(int c)
{ m_embossWidth = c; }
//! \brief CSS theming qproperty access method
void TrackContentWidget::setEmbossOffset(int c)
{ m_embossOffset = c; }
} // namespace lmms::gui