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

计算显示位置时未考虑缩放因素,重构代码中未考虑这里 Log: 修复开启缩放后,任务栏显示一场问题 Bug: https://pms.uniontech.com/zentao/bug-view-41620.html Change-Id: I03026852f261c78bb0d2e8a6f650c9b8f3805c16 Reviewed-on: http://gerrit.uniontech.com/c/dde-dock/+/1379 Reviewed-by: <mailman@uniontech.com> Reviewed-by: niecheng <niecheng@uniontech.com> Reviewed-by: fanpengcheng <fanpengcheng@uniontech.com> Tested-by: <mailman@uniontech.com>
87 lines
2.6 KiB
C++
87 lines
2.6 KiB
C++
/*
|
|
* 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
|
|
#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;
|
|
}
|
|
|
|
// 判断坐标是否位于屏幕边缘
|
|
//!!! 注意:这里传入的QPoint是未计算缩放的
|
|
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;
|
|
}
|
|
|
|
//!!! 注意:这里传入的QPoint是未计算缩放的
|
|
inline QScreen * screenAtByScaled(const QPoint &point) {
|
|
for (QScreen *screen : qApp->screens()) {
|
|
const QRect r { screen->geometry() };
|
|
QRect rect { r.topLeft(), r.size() * screen->devicePixelRatio() };
|
|
if (rect.contains(point)) {
|
|
return screen;
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
#endif // UTILS
|