mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-20 13:46:06 +00:00
Take pixel ratio into account for graph cache. (#1405)
* Take pixel ratio into account for graph cache.
This commit is contained in:
parent
8cffd7e07d
commit
103decedd6
@ -311,7 +311,8 @@ SOURCES += \
|
||||
common/BasicBlockHighlighter.cpp \
|
||||
dialogs/LinkTypeDialog.cpp \
|
||||
common/UpdateWorker.cpp \
|
||||
widgets/MemoryDockWidget.cpp
|
||||
widgets/MemoryDockWidget.cpp \
|
||||
common/HighDpiPixmap.cpp
|
||||
|
||||
HEADERS += \
|
||||
core/Cutter.h \
|
||||
@ -428,7 +429,8 @@ HEADERS += \
|
||||
common/BasicBlockHighlighter.h \
|
||||
common/UpdateWorker.h \
|
||||
dialogs/LinkTypeDialog.h \
|
||||
widgets/MemoryDockWidget.h
|
||||
widgets/MemoryDockWidget.h \
|
||||
common/HighDpiPixmap.h
|
||||
|
||||
FORMS += \
|
||||
dialogs/AboutDialog.ui \
|
||||
|
@ -29,6 +29,7 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc
|
||||
setApplicationVersion(CUTTER_VERSION_FULL);
|
||||
setWindowIcon(QIcon(":/img/cutter.svg"));
|
||||
setAttribute(Qt::AA_DontShowIconsInMenus);
|
||||
setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
setLayoutDirection(Qt::LeftToRight);
|
||||
|
||||
// WARN!!! Put initialization code below this line. Code above this line is mandatory to be run First
|
||||
|
23
src/common/HighDpiPixmap.cpp
Normal file
23
src/common/HighDpiPixmap.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "common/HighDpiPixmap.h"
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QScreen>
|
||||
|
||||
static qreal GetDevicePixelRatio(qreal devicePixelRatio)
|
||||
{
|
||||
if (devicePixelRatio > 0) {
|
||||
return devicePixelRatio;
|
||||
}
|
||||
qreal ratio = 1;
|
||||
for (auto screen : QGuiApplication::screens()) {
|
||||
ratio = std::max(ratio, screen->devicePixelRatio());
|
||||
}
|
||||
return ratio;
|
||||
}
|
||||
|
||||
HighDpiPixmap::HighDpiPixmap(int width, int height, qreal devicePixelRatio)
|
||||
: QPixmap(int(width * GetDevicePixelRatio(devicePixelRatio)),
|
||||
int(height * GetDevicePixelRatio(devicePixelRatio)))
|
||||
{
|
||||
setDevicePixelRatio(GetDevicePixelRatio(devicePixelRatio));
|
||||
}
|
11
src/common/HighDpiPixmap.h
Normal file
11
src/common/HighDpiPixmap.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef HIGHDPIPIXMAP_H
|
||||
#define HIGHDPIPIXMAP_H
|
||||
|
||||
#include <QPixmap>
|
||||
class HighDpiPixmap : public QPixmap
|
||||
{
|
||||
public:
|
||||
HighDpiPixmap(int width, int height, qreal devicePixelRatio = -1);
|
||||
};
|
||||
|
||||
#endif // HIGHDPIPIXMAP_H
|
@ -4,6 +4,7 @@
|
||||
#include "dialogs/AboutDialog.h"
|
||||
#include "ui_NewfileDialog.h"
|
||||
#include "common/Helpers.h"
|
||||
#include "common/HighDpiPixmap.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QtGui>
|
||||
@ -33,7 +34,7 @@ static QIcon getIconFor(const QString &str, int pos)
|
||||
int w = 64;
|
||||
int h = 64;
|
||||
|
||||
QPixmap pixmap(w, h);
|
||||
HighDpiPixmap pixmap(w, h);
|
||||
pixmap.fill(Qt::transparent);
|
||||
|
||||
QPainter pixPaint(&pixmap);
|
||||
|
@ -381,11 +381,13 @@ QPolygonF GraphView::recalculatePolygon(QPolygonF polygon)
|
||||
void GraphView::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
if (useCache) {
|
||||
qreal dpr = devicePixelRatioF();
|
||||
if (useCache && qFuzzyCompare(dpr, pixmap.devicePixelRatioF())) {
|
||||
drawGraph();
|
||||
return;
|
||||
}
|
||||
pixmap = QPixmap(viewport()->width(), viewport()->height());
|
||||
pixmap = QPixmap(int(viewport()->width() * dpr), int(viewport()->height() * dpr));
|
||||
pixmap.setDevicePixelRatio(dpr);
|
||||
QPainter p(&pixmap);
|
||||
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
@ -393,9 +395,8 @@ void GraphView::paintEvent(QPaintEvent *event)
|
||||
int render_width = viewport()->width();
|
||||
int render_height = viewport()->height();
|
||||
|
||||
QRect viewportRect(viewport()->rect().topLeft(), viewport()->rect().bottomRight() - QPoint(1, 1));
|
||||
p.setBrush(backgroundColor);
|
||||
p.drawRect(viewportRect);
|
||||
p.drawRect(viewport()->rect());
|
||||
p.setBrush(Qt::black);
|
||||
|
||||
p.scale(current_scale, current_scale);
|
||||
@ -448,7 +449,8 @@ void GraphView::paintEvent(QPaintEvent *event)
|
||||
void GraphView::drawGraph()
|
||||
{
|
||||
QRectF target(0.0, 0.0, viewport()->width(), viewport()->height());
|
||||
QRectF source(0.0, 0.0, viewport()->width(), viewport()->height());
|
||||
QRectF source(0.0, 0.0, viewport()->width() * pixmap.devicePixelRatioF(),
|
||||
viewport()->height() * pixmap.devicePixelRatioF());
|
||||
QPainter p(viewport());
|
||||
p.drawPixmap(target, pixmap, source);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user