2018-08-23 16:44:39 +08:00
|
|
|
#include <QPixmap>
|
|
|
|
#include <QImageReader>
|
|
|
|
#include <QApplication>
|
2019-04-23 14:28:09 +08:00
|
|
|
#include <QScreen>
|
2018-08-23 16:44:39 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2019-04-23 14:28:09 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|