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:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user