1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(screenshot): incorrect screenshot capture resolution under HiDPI

Resolves the issue where a crop of the full desktop resolution is used
instead of the full resolution when desktop is subjected to DPI-scaling
This commit is contained in:
initramfs 2016-04-08 11:50:32 -04:00
parent 0a2f541945
commit a36248b501
No known key found for this signature in database
GPG Key ID: 78B8BDF87E9EF0AF
2 changed files with 24 additions and 6 deletions

View File

@ -50,6 +50,13 @@ ScreenshotGrabber::ScreenshotGrabber(QObject* parent)
window->setFrameShape(QFrame::NoFrame);
window->installEventFilter(this);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
pixRatio = QApplication::primaryScreen()->devicePixelRatio();
#endif
// Scale window down by devicePixelRatio to show full screen region
window->scale(1 / pixRatio, 1 / pixRatio);
setupScene();
}
@ -141,6 +148,11 @@ void ScreenshotGrabber::setupScene()
this->screenGrabDisplay = scene->addPixmap(this->screenGrab);
this->helperTooltip = scene->addText(QString());
// Scale UI elements up by devicePixelRatio to compensate for window downscaling
this->helperToolbox->setScale(pixRatio);
this->helperTooltip->setScale(pixRatio);
scene->addItem(this->overlay);
this->chooserRect = new ScreenGrabberChooserRectItem(scene);
scene->addItem(this->helperToolbox);
@ -188,8 +200,10 @@ void ScreenshotGrabber::adjustTooltipPosition()
const QRectF ttRect = this->helperToolbox->childrenBoundingRect();
int x = abs(recGL.x()) + rec.x() + ((rec.width() - ttRect.width()) / 2);
int y = abs(recGL.y()) + rec.y();
helperToolbox->setX(x);
helperToolbox->setY(y);
// Multiply by devicePixelRatio to get centered positions under scaling
helperToolbox->setX(x * pixRatio);
helperToolbox->setY(y * pixRatio);
}
void ScreenshotGrabber::reject()
@ -203,11 +217,13 @@ QPixmap ScreenshotGrabber::grabScreen()
{
QScreen* screen = QGuiApplication::primaryScreen();
QRect rec = screen->virtualGeometry();
// Multiply by devicePixelRatio to get actual desktop size
return screen->grabWindow(QApplication::desktop()->winId(),
rec.x(),
rec.y(),
rec.width(),
rec.height());
rec.x() * pixRatio,
rec.y() * pixRatio,
rec.width() * pixRatio,
rec.height() * pixRatio);
}
void ScreenshotGrabber::hideVisibleWindows()

View File

@ -85,6 +85,8 @@ private:
ToolBoxGraphicsItem* helperToolbox;
QGraphicsTextItem* helperTooltip;
qreal pixRatio = 1.0;
bool mQToxVisible;
QVector< QPointer<QWidget> > mHiddenWindows;
};