mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00

插入新屏幕后,新屏幕的缩放是1,切换为复制模式后如果继续使用QApplication::devicePixelRatio会导致 显示错误,统一换成QWidget::devicePixelRatio或QScreen::devicePixelRatio。
46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
#include <QPixmap>
|
|
#include <QImageReader>
|
|
#include <QApplication>
|
|
#include <QScreen>
|
|
|
|
namespace Utils {
|
|
static QPixmap renderSVG(const QString &path, const QSize &size) {
|
|
QImageReader reader;
|
|
QPixmap pixmap;
|
|
reader.setFileName(path);
|
|
if (reader.canRead()) {
|
|
const qreal ratio = qApp->devicePixelRatio();
|
|
reader.setScaledSize(size * ratio);
|
|
pixmap = QPixmap::fromImage(reader.read());
|
|
pixmap.setDevicePixelRatio(ratio);
|
|
}
|
|
else {
|
|
pixmap.load(path);
|
|
}
|
|
|
|
return pixmap;
|
|
}
|
|
|
|
static QScreen * screenAt(const QPoint &point) {
|
|
for (QScreen *screen : qApp->screens()) {
|
|
const QRect r { screen->geometry() };
|
|
const QRect rect { r.topLeft(), r.size() * screen->devicePixelRatio() };
|
|
if (rect.contains(point)) {
|
|
return screen;
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
static QScreen * screenAtByScaled(const QPoint &point) {
|
|
for (QScreen *screen : qApp->screens()) {
|
|
if (screen->geometry().contains(point)) {
|
|
return screen;
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
}
|