mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #3111
initramfs (1): fix(screenshot): incorrect screenshot capture resolution under HiDPI
This commit is contained in:
commit
ef2394dc21
|
@ -50,6 +50,13 @@ ScreenshotGrabber::ScreenshotGrabber(QObject* parent)
|
||||||
window->setFrameShape(QFrame::NoFrame);
|
window->setFrameShape(QFrame::NoFrame);
|
||||||
window->installEventFilter(this);
|
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();
|
setupScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,6 +148,11 @@ void ScreenshotGrabber::setupScene()
|
||||||
|
|
||||||
this->screenGrabDisplay = scene->addPixmap(this->screenGrab);
|
this->screenGrabDisplay = scene->addPixmap(this->screenGrab);
|
||||||
this->helperTooltip = scene->addText(QString());
|
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);
|
scene->addItem(this->overlay);
|
||||||
this->chooserRect = new ScreenGrabberChooserRectItem(scene);
|
this->chooserRect = new ScreenGrabberChooserRectItem(scene);
|
||||||
scene->addItem(this->helperToolbox);
|
scene->addItem(this->helperToolbox);
|
||||||
|
@ -188,8 +200,10 @@ void ScreenshotGrabber::adjustTooltipPosition()
|
||||||
const QRectF ttRect = this->helperToolbox->childrenBoundingRect();
|
const QRectF ttRect = this->helperToolbox->childrenBoundingRect();
|
||||||
int x = abs(recGL.x()) + rec.x() + ((rec.width() - ttRect.width()) / 2);
|
int x = abs(recGL.x()) + rec.x() + ((rec.width() - ttRect.width()) / 2);
|
||||||
int y = abs(recGL.y()) + rec.y();
|
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()
|
void ScreenshotGrabber::reject()
|
||||||
|
@ -203,11 +217,13 @@ QPixmap ScreenshotGrabber::grabScreen()
|
||||||
{
|
{
|
||||||
QScreen* screen = QGuiApplication::primaryScreen();
|
QScreen* screen = QGuiApplication::primaryScreen();
|
||||||
QRect rec = screen->virtualGeometry();
|
QRect rec = screen->virtualGeometry();
|
||||||
|
|
||||||
|
// Multiply by devicePixelRatio to get actual desktop size
|
||||||
return screen->grabWindow(QApplication::desktop()->winId(),
|
return screen->grabWindow(QApplication::desktop()->winId(),
|
||||||
rec.x(),
|
rec.x() * pixRatio,
|
||||||
rec.y(),
|
rec.y() * pixRatio,
|
||||||
rec.width(),
|
rec.width() * pixRatio,
|
||||||
rec.height());
|
rec.height() * pixRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenshotGrabber::hideVisibleWindows()
|
void ScreenshotGrabber::hideVisibleWindows()
|
||||||
|
|
|
@ -85,6 +85,8 @@ private:
|
||||||
ToolBoxGraphicsItem* helperToolbox;
|
ToolBoxGraphicsItem* helperToolbox;
|
||||||
QGraphicsTextItem* helperTooltip;
|
QGraphicsTextItem* helperTooltip;
|
||||||
|
|
||||||
|
qreal pixRatio = 1.0;
|
||||||
|
|
||||||
bool mQToxVisible;
|
bool mQToxVisible;
|
||||||
QVector< QPointer<QWidget> > mHiddenWindows;
|
QVector< QPointer<QWidget> > mHiddenWindows;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user