-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add vertical zoom controls to SongEditor #6776
base: master
Are you sure you want to change the base?
Conversation
This is currently WIP/needs testing, not ready for merge yet. |
did a bit of testing and loaded a few of my projects up and everything seems to be in order. Ready for testing/merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New code style convention fixes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few mostly minor things
@@ -547,19 +558,19 @@ void SongEditor::wheelEvent( QWheelEvent * we ) | |||
{ | |||
z--; | |||
} | |||
z = qBound( 0, z, m_zoomingModel->size() - 1 ); | |||
z = qBound(0, z, m_zoomingXModel->size() - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
z = qBound(0, z, m_zoomingXModel->size() - 1); | |
z = std::clamp(z, 0, m_zoomingXModel->size() - 1); |
We're trying to get away from Qt-specific functions where we can. You may need to include <algorithm> for this.
connect(m_zoomingXModel, SIGNAL(dataChanged()), this, SLOT(zoomingChanged())); | ||
connect(m_zoomingXModel, SIGNAL(dataChanged()), m_positionLine, SLOT(update())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be better to avoid the SIGNAL and SLOT macros and use the newer way of calling connect.
See: https://doc.qt.io/qt-5/signalsandslots.html
@@ -242,16 +247,22 @@ SongEditor::SongEditor( Song * song ) : | |||
|
|||
|
|||
//Set up zooming model | |||
for( float const & zoomLevel : m_zoomLevels ) | |||
for(const auto& zoomLevel : m_zoomXLevels) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for(const auto& zoomLevel : m_zoomXLevels) | |
for (const auto& zoomLevel : m_zoomXLevels) |
style
@@ -167,6 +168,7 @@ public slots: | |||
|
|||
protected: | |||
static const int DEFAULT_PIXELS_PER_BAR = 16; | |||
static const int DEFAULT_TRACK_HEIGHT = 32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static const int DEFAULT_TRACK_HEIGHT = 32; | |
static constexpr int DEFAULT_TRACK_HEIGHT = 32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove this constant entirely - there are already MINIMAL_TRACK_HEIGHT
and DEFAULT_TRACK_HEIGHT
constants defined in include/Track.h
.
static const QVector<float> m_zoomXLevels; | ||
static const QVector<float> m_zoomYLevels; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static const QVector<float> m_zoomXLevels; | |
static const QVector<float> m_zoomYLevels; | |
static constexpr std::array m_zoomXLevels = { 0.125f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f, 8.0f, 16.0f }; | |
static constexpr std::array m_zoomYLevels = { 1.0f, 1.25f, 1.5f, 1.75f, 2.0f, 2.5f, 3.0f, 4.0f, 8.0f, 16.0f }; |
Can use constexpr arrays instead.
const QVector<float> SongEditor::m_zoomXLevels = | ||
{ 0.125f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f, 8.0f, 16.0f }; | ||
|
||
const QVector<float> SongEditor::m_zoomYLevels = | ||
{ 1.0f, 1.25f, 1.5f, 1.75f, 2.0f, 2.5f, 3.0f, 4.0f, 8.0f, 16.0f }; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These can be removed after making them constexpr.
m_zoomingXComboBox->move(580, 4); | ||
m_zoomingXComboBox->setModel(m_editor->m_zoomingXModel); | ||
m_zoomingXComboBox->setToolTip(tr("Horizontal zooming")); | ||
connect(m_editor->zoomingXModel(), SIGNAL(dataChanged()), this, SLOT(updateSnapLabel())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SIGNAL and SLOT macros can be removed here too
auto zoomx_lbl = new QLabel(m_toolBar); | ||
zoomx_lbl->setPixmap(embed::getIconPixmap("zoom_x")); | ||
auto zoomy_lbl = new QLabel(m_toolBar); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zoomx_lbl
and zoomy_lbl
don't follow our naming conventions. Maybe zoomXLabel
and zoomYLabel
could be used.
connect(m_zoomingXModel, SIGNAL(dataChanged()), m_positionLine, SLOT(update())); | ||
|
||
// Set up Y-axis zooming model | ||
for(const auto& zoomLevel : m_zoomYLevels) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for(const auto& zoomLevel : m_zoomYLevels) | |
for (const auto& zoomLevel : m_zoomYLevels) |
style
// clamp the value to prevent it from becoming smaller than the zoom level. | ||
if(new_height < lround(h * DEFAULT_TRACK_HEIGHT)) | ||
{ | ||
new_height = lround(h * DEFAULT_TRACK_HEIGHT); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use std::max
here. Also, why restrict to the zoomed default track height, rather than the absolute minimum track height? Users can still shrink tracks once zoomed in, so this will reset the height of such tracks whenever the user changes the zoom level, which sounds annoying.
int height = lround(m_trackHeightScale * DEFAULT_TRACK_HEIGHT); | ||
trackView->setFixedHeight(height); | ||
trackView->getTrack()->setHeight(height); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will overwrite any custom height when creating the view for a track, which will affect loading tracks from files and cloning tracks.
Thinking more about this, I wonder if it would be better to leave the height stored in the track alone, and instead just scale the view. I think that would be a bit cleaner conceptually, since the zoom level is a property of the track container, rather than of the tracks themselves. It would also avoid any issues with saving and loading track heights. |
@@ -349,6 +356,32 @@ void TrackContainerView::setPixelsPerBar( int ppb ) | |||
} | |||
} | |||
|
|||
void TrackContainerView::setVerticalScale(double h) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely there's a better name than h
for this parameter?
const QVector<float> SongEditor::m_zoomYLevels = | ||
{ 1.0f, 1.25f, 1.5f, 1.75f, 2.0f, 2.5f, 3.0f, 4.0f, 8.0f, 16.0f }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason for these specific values? You may also want to look at #6664, which is changing the horizontal zoom control to a continuous slider.
Song editor tracks could already be resized by shift-dragging them, but this was little known and hard to use. This PR adds a global zoom option that zooms all SongEditor tracks in and out. It also respects existing manual-zoom changes and scales them accordingly.
Currently supports various zoom levels between 100% and 1600%.