From 8f5f656347a10a3f5bc306299bcfb838f1ddd65d Mon Sep 17 00:00:00 2001 From: Yuriy Puchkov Date: Wed, 27 Jan 2021 17:44:23 +0200 Subject: [PATCH] fix - MacOS - Pin on retina (cherry picked from commit 6e6025740d3c512c4f30d48681b42f997104d367) --- src/tools/pin/pintool.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/tools/pin/pintool.cpp b/src/tools/pin/pintool.cpp index 613bd32d..863d523b 100644 --- a/src/tools/pin/pintool.cpp +++ b/src/tools/pin/pintool.cpp @@ -17,6 +17,8 @@ #include "pintool.h" #include "src/tools/pin/pinwidget.h" +#include +#include PinTool::PinTool(QObject* parent) : AbstractActionTool(parent) @@ -49,10 +51,33 @@ QString PinTool::description() const QWidget* PinTool::widget() { + qreal devicePixelRatio = 1; +#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \ + defined(Q_OS_MACX)) + QScreen* currentScreen = QGuiApplication::screenAt(QCursor::pos()); + if (currentScreen) { + devicePixelRatio = currentScreen->devicePixelRatio(); + } +#endif PinWidget* w = new PinWidget(m_pixmap); - const int&& m = w->margin(); + const int m = w->margin() * devicePixelRatio; QRect adjusted_pos = m_geometry + QMargins(m, m, m, m); w->setGeometry(adjusted_pos); +#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \ + defined(Q_OS_MACX)) + if (currentScreen) { + QPoint topLeft = currentScreen->geometry().topLeft(); + adjusted_pos.setX((adjusted_pos.x() - topLeft.x()) / devicePixelRatio + + topLeft.x()); + + adjusted_pos.setY((adjusted_pos.y() - topLeft.y()) / devicePixelRatio + + topLeft.y()); + adjusted_pos.setWidth(adjusted_pos.size().width() / devicePixelRatio); + adjusted_pos.setHeight(adjusted_pos.size().height() / devicePixelRatio); + w->resize(0, 0); + w->move(adjusted_pos.x(), adjusted_pos.y()); + } +#endif return w; }