-
Notifications
You must be signed in to change notification settings - Fork 69
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
ISSUE-50: Add zoom in/out shortcuts #315
Conversation
Great to see this being worked on! Feel free to let me know when I should take a look over the changes, or if you have any questions about how to approach things |
312027b
to
9bcb7e0
Compare
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.
Hey @cameronwhite thanks for the heads up! : )
I think I have the basic idea in place. I've done probably the most basic approach for achieving these zoom in/out shortcuts (which do seems relatively small as a change). I haven't added wheel zoom though.
Overall, I don't really enjoy enlarging the already significant powertabeditor
class. I guess the zoom logic deserves a dedicated class, especially if the wheel zoom is added. On the other hand I didn't what to overengeneer this simple functionality.
I'd be happy to hear your thoughts on the current changes. I've added a couple of questions
source/app/powertabeditor.cpp
Outdated
|
||
void PowerTabEditor::zoomOutScore() | ||
{ | ||
const int ZOOM_CHANGE_COEFITIENT = 25; |
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 don't have a good idea where this constant should live :/ I don't want to pollute the substantial powertabeditor
class.
This constant is related to the "Zoom in shortcuts", something that we don't have a dedicated place for...
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 think I'd probably put that inside the ViewOptions
class, maybe with just an increaseZoom / decreaseZoom method? If the predefined zoom levels (currently stored in playbackwidget.ui
for populating the combobox widget) were instead stored in ViewOptions
, the increase / decrease methods could also step through the predefined zoom levels rather than a fixed percentage
source/app/viewoptions.cpp
Outdated
@@ -17,6 +17,14 @@ | |||
|
|||
#include "viewoptions.h" | |||
|
|||
static constexpr double MIN_ZOOM = 25; | |||
static constexpr double MAX_ZOOM = 300; |
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 feel these should live in a more general place so that the playback widget could also appreciate them. Any suggestions?
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 think these could be fine as static constants on the ViewOptions
class, and then the UI widgets can refer to those constants as needed.
I agree on not adding further bloat to the main |
/// Increases to the next possible zoom level. | ||
bool increaseZoom(); | ||
/// Increases to the previous possible zoom level. | ||
bool decreaseZoom(); |
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 decided to make them Booleans in case we decide to add an "error" sound upon hitting a bound
source/app/viewoptions.h
Outdated
public: | ||
static constexpr double MIN_ZOOM = 25; | ||
static constexpr double MAX_ZOOM = 300; | ||
static constexpr std::array<unsigned short, 14> ZOOM_LEVELS = { 25, 50, 70, 80, 90, 100, 110, 125, 150, 175, 200, 225, 250, 300 }; |
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.
Wanted these to be scoped. Wasn't sure whether to use namespace or the class though
@cameronwhite I moved as much logic to ViewOptions as I could, but the One side note - how about adding setting for the default "zoom level"? That would save me a few actions when opening a document. I suppose there are others having a similar feeling for this behaviour |
That looks good! Having the zoom constants in class scope is fine Adding a preference to remember the last zoom level sounds reasonable! |
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.
Hey @cameronwhite, here's a suggestion on the saving the zoom level as a setting. Overall, I'm keeping the last "set" zoom level (LastZoomLevel) and apply it to all newly opened documents (either preexisting or fresh new).
Another way would be to have it configurable in the preferences.
{ | ||
myDocumentList.emplace_back(new Document()); | ||
myCurrentIndex = static_cast<int>(myDocumentList.size()) - 1; | ||
|
||
auto settings = settings_manager.getReadHandle(); | ||
myDocumentList.back()->getViewOptions().setZoom(settings->get(Settings::LastZoomLevel)); |
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'm not so sure about applying the setting here - for a "default" document we should be ok. On the other hand, at some point in the future we might find it useful to serialise the zoom level with a file...
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.
At this point, at least, I'm thinking it probably won't be likely that we want to save the zoom level with a file, since that's specific to a user's machine / monitor?
More likely might be saving per-document zoom settings locally, but I think the current behaviour is good for now.
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.
Yep, I misused the idea of serialising. I was thinking precisely for a per-document zoom setting locally
@@ -140,6 +140,7 @@ void ScoreArea::renderDocument(const Document &document) | |||
} | |||
|
|||
myScene.addItem(myCaretPainter); | |||
refreshZoom(); |
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.
We want the document's zoom applied. Most likely there's a better way to integrate it in the rendering itself (in the Caret). I'd prefer to avoid breaking something with this oftenly used functionality.
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.
Is this needed because the document might now have a zoom level other than 100% after it's first created / rendered?
I think that's fine to call here - it just sets the overall transform for the scene, so it could probably even be done at the start of this method.
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.
Yep, the document didn't got rescaled with the initial value. I'll give it a try moving it to the 🔝
public: | ||
ViewOptions(); | ||
|
||
const std::optional<int> &getFilter() const { return myFilter; } | ||
void setFilter(int filter) { myFilter = filter; } | ||
void clearFilter() { myFilter.reset(); } | ||
|
||
double getZoom() const { return myZoom; } | ||
void setZoom(double percent) { myZoom = percent; } | ||
int getZoom() const { return myZoom; } |
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.
@cameronwhite was there a particular reason for the zoom to be a double? I believe a short
would suit it better. What do you think? (I know I've changed it to int
here. A simple way to avoid a settings converter)
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 don't think I had any particular reason for double - changing to int
would be fine!
I usually avoid lower capacity types like short
unless there's a real need for it.
@cameronwhite what do you think about the predefined behaviour of |
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.
Saving the zoom level by default makes the most sense IMO, versus adding a new configurable preference.
For QKeySequence I'd directly specify your own shortcuts, then, if it isn't the expected behaviour (we have ifdef
's in a few places for macOS-specific variants of other shortcuts)
{ | ||
myDocumentList.emplace_back(new Document()); | ||
myCurrentIndex = static_cast<int>(myDocumentList.size()) - 1; | ||
|
||
auto settings = settings_manager.getReadHandle(); | ||
myDocumentList.back()->getViewOptions().setZoom(settings->get(Settings::LastZoomLevel)); |
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.
At this point, at least, I'm thinking it probably won't be likely that we want to save the zoom level with a file, since that's specific to a user's machine / monitor?
More likely might be saving per-document zoom settings locally, but I think the current behaviour is good for now.
@@ -140,6 +140,7 @@ void ScoreArea::renderDocument(const Document &document) | |||
} | |||
|
|||
myScene.addItem(myCaretPainter); | |||
refreshZoom(); |
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.
Is this needed because the document might now have a zoom level other than 100% after it's first created / rendered?
I think that's fine to call here - it just sets the overall transform for the scene, so it could probably even be done at the start of this method.
public: | ||
ViewOptions(); | ||
|
||
const std::optional<int> &getFilter() const { return myFilter; } | ||
void setFilter(int filter) { myFilter = filter; } | ||
void clearFilter() { myFilter.reset(); } | ||
|
||
double getZoom() const { return myZoom; } | ||
void setZoom(double percent) { myZoom = percent; } | ||
int getZoom() const { return myZoom; } |
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 don't think I had any particular reason for double - changing to int
would be fine!
I usually avoid lower capacity types like short
unless there's a real need for it.
I've merged this in and fixed up the last couple suggestions from the code review |
Description of Change(s)
Introduces keyboard shortcuts for zooming in/out the score. It mainly reuses the existing zoom change mechanics. The default shortcuts are as follows:
MacOS
Cmd+=
Cmd+-
Widndows
Ctrl+=
Ctrl+-
Fixes Issue(s)
TODO