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 {
|
2020-06-12 09:51:42 +08:00
|
|
|
inline QPixmap renderSVG(const QString &path, const QSize &size, const qreal devicePixelRatio) {
|
2018-08-23 16:44:39 +08:00
|
|
|
QImageReader reader;
|
|
|
|
QPixmap pixmap;
|
|
|
|
reader.setFileName(path);
|
|
|
|
if (reader.canRead()) {
|
2019-04-28 10:10:42 +08:00
|
|
|
reader.setScaledSize(size * devicePixelRatio);
|
2018-08-23 16:44:39 +08:00
|
|
|
pixmap = QPixmap::fromImage(reader.read());
|
2019-04-28 10:10:42 +08:00
|
|
|
pixmap.setDevicePixelRatio(devicePixelRatio);
|
2018-08-23 16:44:39 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
pixmap.load(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pixmap;
|
|
|
|
}
|
2019-04-23 14:28:09 +08:00
|
|
|
|
2020-06-12 09:51:42 +08:00
|
|
|
inline QScreen * screenAt(const QPoint &point) {
|
2019-04-23 14:28:09 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-06-21 17:51:23 +08:00
|
|
|
// 判断坐标是否位于屏幕边缘
|
|
|
|
inline bool onScreenEdge(const QPoint &point) {
|
|
|
|
for (QScreen *screen : qApp->screens()) {
|
|
|
|
const QRect r { screen->geometry() };
|
|
|
|
QRect rect { r.topLeft(), r.size() * screen->devicePixelRatio() };
|
|
|
|
if ( point.y() == screen->geometry().y()+screen->geometry().height()
|
|
|
|
|| point.x() == screen->geometry().x()+screen->geometry().width()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-12 09:51:42 +08:00
|
|
|
inline QScreen * screenAtByScaled(const QPoint &point) {
|
2019-04-23 14:28:09 +08:00
|
|
|
for (QScreen *screen : qApp->screens()) {
|
|
|
|
if (screen->geometry().contains(point)) {
|
|
|
|
return screen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|