2020-08-05 19:46:15 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 ~ 2028 Uniontech Technology Co., Ltd.
|
|
|
|
*
|
|
|
|
* Author: fanpengcheng <fanpengcheng@uniontech.com>
|
|
|
|
*
|
|
|
|
* Maintainer: fanpengcheng <fanpengcheng@uniontech.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#ifndef UTILS
|
|
|
|
#define UTILS
|
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;
|
|
|
|
}
|
|
|
|
}
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
|
|
#endif // UTILS
|