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>
|
2020-08-19 14:13:35 +08:00
|
|
|
#include <QGSettings>
|
2018-08-23 16:44:39 +08:00
|
|
|
|
|
|
|
namespace Utils {
|
2020-08-19 14:13:35 +08:00
|
|
|
|
2020-09-11 17:55:36 +08:00
|
|
|
#define ICBC_CONF_FILE "/etc/deepin/icbc.conf"
|
2020-08-19 14:13:35 +08:00
|
|
|
|
2021-03-12 13:20:13 +08:00
|
|
|
// 这样命名就是为了强调这是个指针类型
|
|
|
|
inline const QGSettings *SettingsPtr(const QString &module, QObject *parent = nullptr) {
|
|
|
|
return QGSettings::isSchemaInstalled(QString("com.deepin.dde.dock.module." + module).toUtf8())
|
|
|
|
? new QGSettings(QString("com.deepin.dde.dock.module." + module).toUtf8(), QByteArray(), parent) // 自动销毁
|
|
|
|
: nullptr;
|
|
|
|
}
|
|
|
|
|
2020-08-06 14:56:44 +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;
|
2020-08-06 14:56:44 +08:00
|
|
|
}
|
2019-04-23 14:28:09 +08:00
|
|
|
|
2020-08-06 14:56:44 +08:00
|
|
|
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;
|
2019-04-23 14:28:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-06 14:56:44 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
2020-06-21 17:51:23 +08:00
|
|
|
|
2020-08-06 14:56:44 +08:00
|
|
|
//!!! 注意:这里传入的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;
|
|
|
|
}
|
2019-04-23 14:28:09 +08:00
|
|
|
}
|
2020-08-06 14:56:44 +08:00
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
2021-03-12 13:20:13 +08:00
|
|
|
|
2020-09-11 17:55:36 +08:00
|
|
|
inline bool isSettingConfigured(const QString& id, const QString& path, const QString& keyName) {
|
|
|
|
if (!QGSettings::isSchemaInstalled(id.toUtf8())) {
|
|
|
|
return false;
|
2020-08-19 14:13:35 +08:00
|
|
|
}
|
2020-09-11 17:55:36 +08:00
|
|
|
QGSettings setting(id.toUtf8(), path.toUtf8());
|
|
|
|
QVariant v = setting.get(keyName);
|
|
|
|
if (!v.isValid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return v.toBool();
|
2019-04-23 14:28:09 +08:00
|
|
|
}
|
2020-11-06 17:52:08 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 比较两个插件版本号的大小
|
|
|
|
* @param pluginApi1 第一个插件版本号
|
|
|
|
* @param pluginApi2 第二个插件版本号
|
|
|
|
* @return 0:两个版本号相等,1:第一个版本号大,-1:第二个版本号大
|
|
|
|
*/
|
|
|
|
inline int comparePluginApi(const QString &pluginApi1, const QString &pluginApi2) {
|
|
|
|
// 版本号相同
|
|
|
|
if (pluginApi1 == pluginApi2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// 拆分版本号
|
|
|
|
QStringList subPluginApis1 = pluginApi1.split(".", QString::SkipEmptyParts, Qt::CaseSensitive);
|
|
|
|
QStringList subPluginApis2 = pluginApi2.split(".", QString::SkipEmptyParts, Qt::CaseSensitive);
|
|
|
|
for (int i = 0; i < subPluginApis1.size(); ++i) {
|
|
|
|
auto subPluginApi1 = subPluginApis1[i];
|
|
|
|
if (subPluginApis2.size() > i) {
|
|
|
|
auto subPluginApi2 = subPluginApis2[i];
|
|
|
|
|
|
|
|
// 相等判断下一个子版本号
|
|
|
|
if (subPluginApi1 == subPluginApi2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// 转成整形比较
|
|
|
|
if (subPluginApi1.toInt() > subPluginApi2.toInt()) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 循环结束但是没有返回,说明子版本号个数不同,且前面的子版本号都相同
|
|
|
|
// 子版本号多的版本号大
|
|
|
|
if (subPluginApis1.size() > subPluginApis2.size()) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 14:28:09 +08:00
|
|
|
}
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
|
|
#endif // UTILS
|