Skip to content
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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

enp2s0
Copy link
Contributor

@enp2s0 enp2s0 commented Jul 19, 2023

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.

Screenshot from 2023-07-19 11-37-03
Screenshot from 2023-07-19 11-36-48

Currently supports various zoom levels between 100% and 1600%.

@enp2s0
Copy link
Contributor Author

enp2s0 commented Jul 19, 2023

This is currently WIP/needs testing, not ready for merge yet.

@enp2s0
Copy link
Contributor Author

enp2s0 commented Jul 19, 2023

did a bit of testing and loaded a few of my projects up and everything seems to be in order. Ready for testing/merge

Copy link
Contributor

@Veratil Veratil left a 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.

@DomClark DomClark self-requested a review July 19, 2023 23:31
Copy link
Member

@messmerd messmerd left a 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);
Copy link
Member

@messmerd messmerd Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines +255 to +256
connect(m_zoomingXModel, SIGNAL(dataChanged()), this, SLOT(zoomingChanged()));
connect(m_zoomingXModel, SIGNAL(dataChanged()), m_positionLine, SLOT(update()));
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static const int DEFAULT_TRACK_HEIGHT = 32;
static constexpr int DEFAULT_TRACK_HEIGHT = 32;

Copy link
Member

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.

Comment on lines +151 to +152
static const QVector<float> m_zoomXLevels;
static const QVector<float> m_zoomYLevels;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines +61 to +66
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 };

Copy link
Member

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()));
Copy link
Member

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

Comment on lines +1009 to +1011
auto zoomx_lbl = new QLabel(m_toolBar);
zoomx_lbl->setPixmap(embed::getIconPixmap("zoom_x"));
auto zoomy_lbl = new QLabel(m_toolBar);
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for(const auto& zoomLevel : m_zoomYLevels)
for (const auto& zoomLevel : m_zoomYLevels)

style

Comment on lines +372 to +376
// 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);
}
Copy link
Member

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.

Comment on lines +286 to +288
int height = lround(m_trackHeightScale * DEFAULT_TRACK_HEIGHT);
trackView->setFixedHeight(height);
trackView->getTrack()->setHeight(height);
Copy link
Member

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.

@DomClark
Copy link
Member

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)
Copy link
Member

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?

Comment on lines +64 to +65
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 };
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants