-
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
Open
jdpurcell
wants to merge
17
commits into
jurplel:master
Choose a base branch
from
jdpurcell:pr-gv7
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
03ec392
Simplify GraphicsView code
jdpurcell a1129fb
Add zoom level to titlebar in Practical/Verbose modes
jdpurcell 490b598
Option for one-to-one pixel sizing
jdpurcell 2c2799c
Pixel-perfect image fitting
jdpurcell e542bab
Window sizing fixes
jdpurcell 01e55d6
Fix SVG files not filling window due to display scaling
jdpurcell 6aacb3c
Put back some existing behavior
jdpurcell e0239b8
Make zoom level in titlebar update more frequently
jdpurcell 5716a52
Fix rounding issue when using expensive scaling
jdpurcell 7ba4dfa
Uninvert DPI adjustment
jdpurcell 6ed9c9f
Fix tiny borders when display scaling is in use
jdpurcell 24b1843
Merge remote-tracking branch 'upstream/master'
jdpurcell 898af0f
More fixes when fitting image with display scaling
jdpurcell 3c68fb9
Re-invert DPI adjustment
jdpurcell 04e7c6b
Fix rare painting glitch with image rotated 90 degrees
jdpurcell ae8ad70
Fix window not resizing after rotate
jdpurcell d0428d5
Improve look of menu icons in Qt5
jdpurcell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "logicalpixelfitter.h" | ||
#include <QtMath> | ||
|
||
LogicalPixelFitter::LogicalPixelFitter(const qreal logicalScale, const QPoint offset) | ||
: logicalScale(logicalScale), offset(offset) | ||
{ | ||
} | ||
|
||
int LogicalPixelFitter::snapWidth(const qreal value) const | ||
{ | ||
return snap(value + offset.x(), logicalScale) - offset.x(); | ||
} | ||
|
||
int LogicalPixelFitter::snapHeight(const qreal value) const | ||
{ | ||
return snap(value + offset.y(), logicalScale) - offset.y(); | ||
} | ||
|
||
QSize LogicalPixelFitter::snapSize(const QSizeF size) const | ||
{ | ||
return QSize(snapWidth(size.width()), snapHeight(size.height())); | ||
} | ||
|
||
qreal LogicalPixelFitter::unsnapWidth(const int value) const | ||
{ | ||
return unsnap(value + offset.x(), logicalScale) - offset.x(); | ||
} | ||
|
||
qreal LogicalPixelFitter::unsnapHeight(const int value) const | ||
{ | ||
return unsnap(value + offset.y(), logicalScale) - offset.y(); | ||
} | ||
|
||
QSizeF LogicalPixelFitter::unsnapSize(const QSize size) const | ||
{ | ||
return QSizeF(unsnapWidth(size.width()), unsnapHeight(size.height())); | ||
} | ||
|
||
int LogicalPixelFitter::snap(const qreal value, const qreal logicalScale) | ||
{ | ||
const int valueRoundedDown = qFloor(value); | ||
const int valueRoundedUp = valueRoundedDown + 1; | ||
const int physicalPixelsDrawn = qRound(value * logicalScale); | ||
const int physicalPixelsShownIfRoundingUp = qRound(valueRoundedUp * logicalScale); | ||
return physicalPixelsDrawn >= physicalPixelsShownIfRoundingUp ? valueRoundedUp : valueRoundedDown; | ||
} | ||
|
||
qreal LogicalPixelFitter::unsnap(const int value, const qreal logicalScale) | ||
{ | ||
// For a given input value, its physical pixels fall within [value-0.5,value+0.5), so | ||
// calculate the first physical pixel of the next value (rounding up if between pixels), | ||
// and the pixel prior to that is the last one within the current value. | ||
const int maxPhysicalPixelForValue = qCeil((value + 0.5) * logicalScale) - 1; | ||
return maxPhysicalPixelForValue / logicalScale; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef LOGICALPIXELFITTER_H | ||
#define LOGICALPIXELFITTER_H | ||
|
||
#include <QPoint> | ||
#include <QSize> | ||
|
||
class LogicalPixelFitter | ||
{ | ||
public: | ||
LogicalPixelFitter(const qreal logicalScale, const QPoint offset); | ||
|
||
int snapWidth(const qreal value) const; | ||
|
||
int snapHeight(const qreal value) const; | ||
|
||
QSize snapSize(const QSizeF size) const; | ||
|
||
qreal unsnapWidth(const int value) const; | ||
|
||
qreal unsnapHeight(const int value) const; | ||
|
||
QSizeF unsnapSize(const QSize size) const; | ||
|
||
static int snap(const qreal value, const qreal logicalScale); | ||
|
||
static qreal unsnap(const int value, const qreal logicalScale); | ||
|
||
private: | ||
const qreal logicalScale; | ||
const QPoint offset; | ||
}; | ||
|
||
#endif // LOGICALPIXELFITTER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.