-
Notifications
You must be signed in to change notification settings - Fork 123
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
GraphicsView overhaul #699
base: master
Are you sure you want to change the base?
Conversation
Ability to make the zoom level relative to physical screen pixels
Eliminates the need for overscan and ensures that no unnecessary scaling takes place when window matches image size.
Calculated aspect ratio was slightly off in some cases. Also enforce minimum window size in both dimensions.
* Original size can toggle between 100% and zoom-to-fit. * Minimum window size just requires one dimension to be over the minimum.
My latest commit restores part of the "original size" toggle functionality, so that a user can press I also backed out one of my changes to the window sizing; it was trying to ensure that both dimensions are at least the minimum size, which is arguably correct, but ugly because it could leave borders in one dimension. Both changes are controlled by hard-coded options in case you want to play around, otherwise feel to hard-code whatever logic you want and remove the constants. |
// Windows reports the wrong minimum width, so we constrain the image size relative to the dpi to stop weirdness with tiny images | ||
#ifdef Q_OS_WIN | ||
auto minimumImageSize = QSize(qRound(logicalDpiX()*1.5), logicalDpiY()/2); | ||
if (imageSize.boundedTo(minimumImageSize) == imageSize) | ||
imageSize = minimumImageSize; | ||
#endif |
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 was ancient code from before qView had configurable min/max window sizes; I think the minimum window size setting makes this obsolete in a lot of cases, plus Qt/Windows seems to enforce an absolute minimum anyway (I tested on the 5.15.2 build too) so this may have been working around a Qt bug that's since resolved.
Having it inverted is just another potential source of rounding errors.
Qt makes this difficult by not providing access to the native geometry.
Extend logical pixel "rounding" to handle case where menu bar is visible at top of window which influences the calculation.
The last few commits were dealing with a 1 pixel "border" (the image not touching the bottom/right edge, showing a tiny bit of the background) that could appear when display scaling is in use. This is really difficult to because Qt sizes everything in logical pixels; for example when setting the window geometry, it's always in integer logical pixels and thus impossible to set an exact desired physical size (without platform-specific code), and likewise when fetching the geometry, it's always in terms of rounded logical pixels. A few examples:
I did a lot of testing and find it to work well on Windows, macOS, and KDE. I tested at 125%, 150%, 175%, and 200% (w/ macOS only the last once since it doesn't do fractional scaling). I believe it works exactly as intended when viewing images normally, |
The last two commits fixed the remaining 1px border issues and I re-tested everything thoroughly. |
Slightly less ambitious version of the graphicsview-rewrite branch. I actually started with that branch, made some minor fixes, squash merged everything down, removed anything related to constrained positioning, removed anything related to navigation/resize resets zoom, and then broke it back down into more manageable commits. In terms of operation/feel, this should function the same as currently, aside from Original Size which now simply sets the zoom level to 100% instead of functioning like a quasi-toggle / different mode (EDIT: And I can make it function like a toggle again if desired, I just wasn't sure if that was even desired per a past Discord conversation).