Mercurial > hg > svgui
changeset 1402:b0eeec95ab5b
Handle integer pixel scaling as well
author | Chris Cannam |
---|---|
date | Thu, 15 Nov 2018 14:18:26 +0000 |
parents | 28075cc658c9 |
children | 10e768adaee5 |
files | layer/LayerGeometryProvider.h layer/TimeValueLayer.cpp view/Pane.cpp view/View.cpp view/View.h view/ViewProxy.h |
diffstat | 6 files changed, 27 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/LayerGeometryProvider.h Thu Nov 15 14:04:32 2018 +0000 +++ b/layer/LayerGeometryProvider.h Thu Nov 15 14:18:26 2018 +0000 @@ -180,6 +180,7 @@ virtual void updatePaintRect(QRect r) = 0; virtual double scaleSize(double size) const = 0; + virtual int scalePixelSize(int size) const = 0; virtual double scalePenWidth(double width) const = 0; virtual QPen scalePen(QPen pen) const = 0;
--- a/layer/TimeValueLayer.cpp Thu Nov 15 14:04:32 2018 +0000 +++ b/layer/TimeValueLayer.cpp Thu Nov 15 14:18:26 2018 +0000 @@ -565,7 +565,7 @@ } if (!usePoints.empty()) { - int fuzz = v->scaleSize(2); + double fuzz = v->scaleSize(2); int px = v->getXForFrame(usePoints.begin()->frame); if ((px > x && px - x > fuzz) || (px < x && x - px > fuzz + 3)) {
--- a/view/Pane.cpp Thu Nov 15 14:04:32 2018 +0000 +++ b/view/Pane.cpp Thu Nov 15 14:18:26 2018 +0000 @@ -1173,7 +1173,7 @@ if (!m_manager) return Selection(); - sv_frame_t testFrame = getFrameForX(x - scaleSize(5)); + sv_frame_t testFrame = getFrameForX(x - scalePixelSize(5)); if (testFrame < 0) { testFrame = getFrameForX(x); if (testFrame < 0) return Selection(); @@ -1185,14 +1185,14 @@ int lx = getXForFrame(selection.getStartFrame()); int rx = getXForFrame(selection.getEndFrame()); - int fuzz = scaleSize(2); + int fuzz = scalePixelSize(2); if (x < lx - fuzz || x > rx + fuzz) return Selection(); int width = rx - lx; - fuzz = scaleSize(3); + fuzz = scalePixelSize(3); if (width < 12) fuzz = width / 4; - if (fuzz < scaleSize(1)) { - fuzz = scaleSize(1); + if (fuzz < scalePixelSize(1)) { + fuzz = scalePixelSize(1); } if (x < lx + fuzz) closeToLeftEdge = true;
--- a/view/View.cpp Thu Nov 15 14:04:32 2018 +0000 +++ b/view/View.cpp Thu Nov 15 14:18:26 2018 +0000 @@ -238,7 +238,7 @@ } } - int y = scaleSize(15) + paint.fontMetrics().ascent(); + int y = scalePixelSize(15) + paint.fontMetrics().ascent(); for (std::map<int, Layer *>::const_iterator i = sortedLayers.begin(); i != sortedLayers.end(); ++i) { @@ -674,7 +674,7 @@ QPushButton *cancel = new QPushButton(this); cancel->setIcon(IconLoader().load("cancel")); cancel->setFlat(true); - int scaled20 = scaleSize(20); + int scaled20 = scalePixelSize(20); cancel->setFixedSize(QSize(scaled20, scaled20)); connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked())); @@ -1620,6 +1620,15 @@ return size * ratio; } +int +View::scalePixelSize(int size) const +{ + double d = scaleSize(size); + int i = int(d + 0.5); + if (size != 0 && i == 0) i = 1; + return i; +} + double View::scalePenWidth(double width) const { @@ -1792,7 +1801,7 @@ timer->start(); } - int scaled20 = scaleSize(20); + int scaled20 = scalePixelSize(20); cancel->move(0, ph - pb->height()/2 - scaled20/2); cancel->show();
--- a/view/View.h Thu Nov 15 14:04:32 2018 +0000 +++ b/view/View.h Thu Nov 15 14:18:26 2018 +0000 @@ -377,6 +377,7 @@ int getPaintHeight() const { return getPaintRect().height(); } double scaleSize(double size) const; + int scalePixelSize(int size) const; double scalePenWidth(double width) const; QPen scalePen(QPen pen) const;
--- a/view/ViewProxy.h Thu Nov 15 14:04:32 2018 +0000 +++ b/view/ViewProxy.h Thu Nov 15 14:18:26 2018 +0000 @@ -156,6 +156,13 @@ } /** + * Integer version of scaleSize. + */ + virtual int scalePixelSize(int size) const { + return m_view->scalePixelSize(size * m_scaleFactor); + } + + /** * Scale up pen width for a hi-dpi display without pixel doubling. * This is like scaleSize except that it also scales the * zero-width case.