mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
#include <QPixmap>
|
|
#include <QImageReader>
|
|
#include <QApplication>
|
|
#include <QScreen>
|
|
|
|
namespace Utils {
|
|
inline QPixmap renderSVG(const QString &path, const QSize &size, const qreal devicePixelRatio) {
|
|
QImageReader reader;
|
|
QPixmap pixmap;
|
|
reader.setFileName(path);
|
|
if (reader.canRead()) {
|
|
reader.setScaledSize(size * devicePixelRatio);
|
|
pixmap = QPixmap::fromImage(reader.read());
|
|
pixmap.setDevicePixelRatio(devicePixelRatio);
|
|
}
|
|
else {
|
|
pixmap.load(path);
|
|
}
|
|
|
|
return pixmap;
|
|
}
|
|
|
|
inline 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;
|
|
}
|
|
|
|
inline QScreen * screenAtByScaled(const QPoint &point) {
|
|
for (QScreen *screen : qApp->screens()) {
|
|
if (screen->geometry().contains(point)) {
|
|
return screen;
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
}
|