From 9b5549b8b54e43967e75c3480d98d350ec1e186e Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Thu, 1 Sep 2022 21:37:50 +0200 Subject: [PATCH] JKQTPlotter: generate High-DPI Icons, where necessary/appropriate --- lib/jkqtplotter/gui/jkqtpcomboboxes.cpp | 18 ++++++++++++------ lib/jkqtplotter/jkqtplotter.cpp | 9 +++++++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/jkqtplotter/gui/jkqtpcomboboxes.cpp b/lib/jkqtplotter/gui/jkqtpcomboboxes.cpp index 0f26b860a8..b67dd4f24b 100644 --- a/lib/jkqtplotter/gui/jkqtpcomboboxes.cpp +++ b/lib/jkqtplotter/gui/jkqtpcomboboxes.cpp @@ -102,13 +102,15 @@ void JKQTPSymbolComboBox::setCurrentSymbol(JKQTPGraphSymbols symbol) void JKQTPSymbolComboBox::addSymbol(JKQTPGraphSymbols symbol, const QString &name) { - QPixmap pix(12,12); + const qreal dpr = devicePixelRatioF(); + QPixmap pix(12*dpr,12*dpr); + pix.setDevicePixelRatio(dpr); pix.fill(Qt::transparent); JKQTPEnhancedPainter p; p.begin(&pix); p.setRenderHint(JKQTPEnhancedPainter::Antialiasing); p.setRenderHint(JKQTPEnhancedPainter::TextAntialiasing); - JKQTPPlotSymbol(p, 6,6,symbol,10,1,QColor("blue"), QColor("blue").lighter()); + JKQTPPlotSymbol(p, 6.0*dpr,6.0*dpr,symbol,10.0*dpr,1,QColor("blue"), QColor("blue").lighter()); p.end(); addItem(QIcon(pix), name, JKQTPGraphSymbols2String(symbol)); } @@ -176,15 +178,17 @@ void JKQTPLinePlotStyleComboBox::refill() void JKQTPLinePlotStyleComboBox::addSymbol(JKQTPGraphSymbols symbol, bool line, const QString &name, const QVariant &data) { - QPixmap pix(12,12); + const qreal dpr = devicePixelRatioF(); + QPixmap pix(12*dpr,12*dpr); + pix.setDevicePixelRatio(dpr); pix.fill(Qt::transparent); JKQTPEnhancedPainter p; p.begin(&pix); p.setRenderHint(JKQTPEnhancedPainter::Antialiasing); p.setRenderHint(JKQTPEnhancedPainter::TextAntialiasing); - JKQTPPlotSymbol(p, 6,6,symbol,7,1,QColor("blue"), QColor("blue").lighter()); + JKQTPPlotSymbol(p, 6.0*dpr,6.0*dpr,symbol,7.0*dpr,1,QColor("blue"), QColor("blue").lighter()); p.setPen(QColor("blue")); - if (line) p.drawLine(0,6,12,6); + if (line) p.drawLine(0,6*dpr,12*dpr,6*dpr); p.end(); addItem(QIcon(pix), name, data); } @@ -492,8 +496,10 @@ void JKQTPLinePlotStyleWithSymbolSizeComboBox::refill() void JKQTPLinePlotStyleWithSymbolSizeComboBox::addSymbol(JKQTPGraphSymbols symbol, bool line, double symbolSize, const QString &name, const QVariant &data) { - int pixSize=qMax(16.0, 1.2*symbolSize); + const qreal dpr = devicePixelRatioF(); + int pixSize=qMax(16.0, 1.2*symbolSize)*dpr; QPixmap pix(pixSize, pixSize); + pix.setDevicePixelRatio(dpr); pix.fill(Qt::transparent); JKQTPEnhancedPainter p; p.begin(&pix); diff --git a/lib/jkqtplotter/jkqtplotter.cpp b/lib/jkqtplotter/jkqtplotter.cpp index 769c105228..fd636d5fcf 100644 --- a/lib/jkqtplotter/jkqtplotter.cpp +++ b/lib/jkqtplotter/jkqtplotter.cpp @@ -89,7 +89,9 @@ JKQTPlotter::JKQTPlotter(bool datastore_internal, QWidget* parent, JKQTPDatastor connect(plotter, SIGNAL(beforePlotScalingRecalculate()), this, SLOT(intBeforePlotScalingRecalculate())); connect(plotter, SIGNAL(zoomChangedLocally(double, double, double, double, JKQTBasePlotter*)), this, SLOT(pzoomChangedLocally(double, double, double, double, JKQTBasePlotter*))); - image=QImage(width(), height(), QImage::Format_ARGB32); + const qreal dpr = devicePixelRatioF(); + image=QImage(width()*dpr, height()*dpr, QImage::Format_ARGB32); + image.setDevicePixelRatio(dpr); oldImage=image; // enable mouse-tracking, so mouseMoved-Events can be caught @@ -1116,7 +1118,10 @@ void JKQTPlotter::initContextMenu() QAction* act=new QAction(tit, menVisibleGroup); act->setCheckable(true); act->setChecked(getPlotter()->getGraph(i)->isVisible()); - act->setIcon(QIcon(QPixmap::fromImage(getPlotter()->getGraph(i)->generateKeyMarker(QSize(16,16))))); + const qreal dpr = devicePixelRatioF(); + QPixmap pix=QPixmap::fromImage(getPlotter()->getGraph(i)->generateKeyMarker(QSize(16,16)*dpr)); + pix.setDevicePixelRatio(dpr); + act->setIcon(QIcon(pix)); act->setData(static_cast(i)); connect(act, SIGNAL(toggled(bool)), this, SLOT(reactGraphVisible(bool))); menVisibleGroup->addAction(act);