Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(video): fix scaling issues under HiDPI displays with desktop video
Browse files Browse the repository at this point in the history
This commit fixes missing scaling factors with desktop video to allow
desktop video under HiDPI scaling to work as intended. Also removes a
few obsolete lines of scaling that that was required for older Qt
versions.
  • Loading branch information
initramfs committed Aug 16, 2016
1 parent 79c249b commit ef157ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
8 changes: 7 additions & 1 deletion src/video/cameradevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,13 @@ QVector<VideoMode> CameraDevice::getScreenModes()
QRect rect = s->geometry();
QPoint p = rect.topLeft();

VideoMode mode(rect.width(), rect.height(), p.x(), p.y());
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
qreal pixRatio = s->devicePixelRatio();
#else
qreal pixRatio = 1.0;
#endif

VideoMode mode(rect.width() * pixRatio, rect.height() * pixRatio, p.x() * pixRatio, p.y() * pixRatio);
result.push_back(mode);
});

Expand Down
15 changes: 5 additions & 10 deletions src/widget/tool/screenshotgrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ ScreenshotGrabber::ScreenshotGrabber()
pixRatio = QApplication::primaryScreen()->devicePixelRatio();
#endif

// Scale window down by devicePixelRatio to show full screen region
window->scale(1 / pixRatio, 1 / pixRatio);

setupScene();
}

Expand Down Expand Up @@ -131,6 +128,9 @@ void ScreenshotGrabber::acceptRegion()
if (rect.width() < 1 || rect.height() < 1)
return;

// Scale the accepted region from DIPs to actual pixels
rect.setRect(rect.x() * pixRatio, rect.y() * pixRatio, rect.width() * pixRatio, rect.height() * pixRatio);

emit regionChosen(rect);
qDebug() << "Screenshot accepted, chosen region" << rect;
QPixmap pixmap = this->screenGrab.copy(rect);
Expand All @@ -152,10 +152,6 @@ 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);
Expand Down Expand Up @@ -203,9 +199,8 @@ void ScreenshotGrabber::adjustTooltipPosition()
int x = qAbs(recGL.x()) + rec.x() + ((rec.width() - ttRect.width()) / 2);
int y = qAbs(recGL.y()) + rec.y();

// Multiply by devicePixelRatio to get centered positions under scaling
helperToolbox->setX(x * pixRatio);
helperToolbox->setY(y * pixRatio);
helperToolbox->setX(x);
helperToolbox->setY(y);
}

void ScreenshotGrabber::reject()
Expand Down

0 comments on commit ef157ca

Please sign in to comment.