Fixed an issue where the magnifier did not account for hiDPI on retina screens (#2187)

This commit is contained in:
borgmanJeremy
2021-12-24 14:36:39 -06:00
committed by GitHub
parent aaf6eebe97
commit da5d71c23c

View File

@@ -200,11 +200,26 @@ void ColorGrabWidget::updateWidget()
float zoom = m_extraZoomActive ? ZOOM2 : ZOOM1;
// Set window size and move its center to the mouse cursor
QRect rect(0, 0, width, width);
auto realCursorPos = cursorPos();
auto adjustedCursorPos = realCursorPos;
#if defined(Q_OS_MACOS)
QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen();
if (currentScreen) {
adjustedCursorPos =
QPoint((realCursorPos.x() - currentScreen->geometry().x()) *
currentScreen->devicePixelRatio(),
(realCursorPos.y() - currentScreen->geometry().y()) *
currentScreen->devicePixelRatio());
}
#endif
rect.moveCenter(cursorPos());
setGeometry(rect);
// Store a pixmap containing the zoomed-in section around the cursor
QRect sourceRect(0, 0, width / zoom, width / zoom);
sourceRect.moveCenter(rect.center());
sourceRect.moveCenter(adjustedCursorPos);
m_previewImage = m_pixmap->copy(sourceRect).toImage();
// Repaint
update();