aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/qcustomplot.cpp
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2016-02-08 12:13:52 -0800
committerGerald Combs <gerald@wireshark.org>2016-02-08 23:26:28 +0000
commit0af5ef3fce9f6eb72d4d45b4424a4f219f7cb976 (patch)
treecea0774928dba0f57dc0817f84895d3cb3edf5f5 /ui/qt/qcustomplot.cpp
parent0ae6a19f7dbd560c6f6a06a6470472eea0c24fda (diff)
QCP: Fix retina label calculations.
The retina fixes in gb10bad1 and gb3f3d66 were incomplete and caused rendering problems in our axis labels. Handle the device pixel ratio in a couple of more places so that our axis rects are correctly sized. Add a switch (WS_ENABLE_DP_RATIO) to make it easy to turn scaling on and off. Change-Id: I633d94d633e0743be2a607c9a4cbb3409e9eed62 Ping-Bug: 11710 Reviewed-on: https://code.wireshark.org/review/13834 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'ui/qt/qcustomplot.cpp')
-rw-r--r--ui/qt/qcustomplot.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/ui/qt/qcustomplot.cpp b/ui/qt/qcustomplot.cpp
index e850b02633..d8525b45b1 100644
--- a/ui/qt/qcustomplot.cpp
+++ b/ui/qt/qcustomplot.cpp
@@ -27,7 +27,9 @@
#include "qcustomplot.h"
-
+// Set to nonzero to use device pixel scaling. Uncommenting the debug rects
+// at the bottom of QCPAxisPainterPrivate::draw can be helpful for testing.
+#define WS_ENABLE_DP_RATIO 1
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////// QCPPainter
@@ -6317,10 +6319,10 @@ int QCPAxisPainterPrivate::size() const
QSize tickLabelsSize(0, 0);
if (!tickLabels.isEmpty())
{
- for (int i=0; i<tickLabels.size(); ++i)
- getMaxTickLabelSize(tickLabelFont, tickLabels.at(i), &tickLabelsSize);
- result += QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width();
- result += tickLabelPadding;
+ for (int i=0; i<tickLabels.size(); ++i)
+ getMaxTickLabelSize(tickLabelFont, tickLabels.at(i), &tickLabelsSize);
+ result += QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width();
+ result += tickLabelPadding;
}
}
@@ -6405,7 +6407,7 @@ void QCPAxisPainterPrivate::placeTickLabel(QCPPainter *painter, double position,
CachedLabel *newCachedLabel = new CachedLabel;
TickLabelData labelData = getTickLabelData(painter->font(), text);
newCachedLabel->offset = getTickLabelDrawOffset(labelData)+labelData.rotatedTotalBounds.topLeft();
-#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
+#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) && WS_ENABLE_DP_RATIO
QSize clSize = labelData.rotatedTotalBounds.size();
clSize *= painter->device()->devicePixelRatio();
newCachedLabel->pixmap = QPixmap(clSize);
@@ -6438,6 +6440,9 @@ void QCPAxisPainterPrivate::placeTickLabel(QCPPainter *painter, double position,
}
painter->drawPixmap(labelAnchor+cachedLabel->offset, cachedLabel->pixmap);
finalSize = cachedLabel->pixmap.size();
+#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) && WS_ENABLE_DP_RATIO
+ finalSize /= cachedLabel->pixmap.devicePixelRatio();
+#endif
} else // label caching disabled, draw text directly on surface:
{
TickLabelData labelData = getTickLabelData(painter->font(), text);
@@ -6691,6 +6696,9 @@ void QCPAxisPainterPrivate::getMaxTickLabelSize(const QFont &font, const QString
{
const CachedLabel *cachedLabel = mLabelCache.object(text);
finalSize = cachedLabel->pixmap.size();
+#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) && WS_ENABLE_DP_RATIO
+ finalSize /= cachedLabel->pixmap.devicePixelRatio();
+#endif
} else // label caching disabled or no label with this text cached:
{
TickLabelData labelData = getTickLabelData(font, text);
@@ -9082,7 +9090,7 @@ QCustomPlot::QCustomPlot(QWidget *parent) :
currentLocale.setNumberOptions(QLocale::OmitGroupSeparator);
setLocale(currentLocale);
-#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
+#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) && WS_ENABLE_DP_RATIO
QSize pbSize = mPaintBuffer.size();
pbSize *= devicePixelRatio();
mPaintBuffer = QPixmap(pbSize);
@@ -10708,7 +10716,7 @@ void QCustomPlot::paintEvent(QPaintEvent *event)
void QCustomPlot::resizeEvent(QResizeEvent *event)
{
// resize and repaint the buffer:
-#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
+#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) && WS_ENABLE_DP_RATIO
QSize pbSize = event->size();
pbSize *= devicePixelRatio();
mPaintBuffer = QPixmap(pbSize);