mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-09-29 15:12:21 +08:00
fix: 修复 Deepin 系统上显示“开发者模式未开启”的问题
没有区分 Deepin 和 UOS,在 Deepin 上对开发者模式状态文件进行判断,可能造成错误 Log: 添加判断区分 Deepin 和 UOS,仅在 UOS 判断开发者模式状态文件;优化 main 函数长度,将环境变量设置和 config.ini 读写放入 Utils 独立静态函数中调用;修复从托盘打开主界面时透明度动画不流畅的问题;优化关闭窗口动画代码,与打开窗口动画代码合并;修复主窗口关闭时,从托盘打开关于对话框后,调起主窗口会遮挡关于对话框的问题
This commit is contained in:
parent
de2db98324
commit
ab6c3d37d2
@ -1,4 +1,5 @@
|
|||||||
#include "application.h"
|
#include "application.h"
|
||||||
|
#include "mainwindow-dtk.h"
|
||||||
|
|
||||||
#include <DPlatformWindowHandle>
|
#include <DPlatformWindowHandle>
|
||||||
#include <DLog>
|
#include <DLog>
|
||||||
@ -46,7 +47,7 @@ Application::Application(int &argc, char **argv)
|
|||||||
|
|
||||||
void Application::handleAboutAction()
|
void Application::handleAboutAction()
|
||||||
{
|
{
|
||||||
if (aboutDialog()) {
|
if (aboutDialog() && aboutDialog()->parent() == m_mainWindow) {
|
||||||
DApplication::handleAboutAction();
|
DApplication::handleAboutAction();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -81,10 +82,30 @@ void Application::setVersionAndBuildDateTime(const QString &version, const QStri
|
|||||||
setApplicationVersion(DApplication::buildVersion(config.value("build/version").toString() + "-" + "Flamescion" + "-" + config.value("build/time").toString()));
|
setApplicationVersion(DApplication::buildVersion(config.value("build/version").toString() + "-" + "Flamescion" + "-" + config.value("build/time").toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::setMainWindow(MainWindow *window)
|
||||||
|
{
|
||||||
|
m_mainWindow = window;
|
||||||
|
if (aboutDialog() == nullptr || aboutDialog()->parent() != m_mainWindow)
|
||||||
|
{
|
||||||
|
initAboutDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Application::initAboutDialog()
|
void Application::initAboutDialog()
|
||||||
{
|
{
|
||||||
|
if (m_mainWindow == nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aboutDialog())
|
||||||
|
{
|
||||||
|
aboutDialog()->deleteLater();
|
||||||
|
setAboutDialog(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
// 自定义 DAboutDialog
|
// 自定义 DAboutDialog
|
||||||
DAboutDialog *dialog = new DAboutDialog(activeWindow());
|
DAboutDialog *dialog = new DAboutDialog(m_mainWindow);
|
||||||
dialog->setProductName(productName());
|
dialog->setProductName(productName());
|
||||||
dialog->setProductIcon(productIcon());
|
dialog->setProductIcon(productIcon());
|
||||||
dialog->setVersion(translate("DAboutDialog", "Version: %1").arg(applicationVersion()));
|
dialog->setVersion(translate("DAboutDialog", "Version: %1").arg(applicationVersion()));
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
DWIDGET_USE_NAMESPACE
|
DWIDGET_USE_NAMESPACE
|
||||||
|
|
||||||
|
class MainWindow;
|
||||||
class Application : public DApplication
|
class Application : public DApplication
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -16,6 +17,7 @@ public:
|
|||||||
static void checkAppConfigLocation();
|
static void checkAppConfigLocation();
|
||||||
|
|
||||||
void setVersionAndBuildDateTime(const QString &version, const QString &buildDateTime);
|
void setVersionAndBuildDateTime(const QString &version, const QString &buildDateTime);
|
||||||
|
void setMainWindow(MainWindow *window);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initAboutDialog();
|
void initAboutDialog();
|
||||||
@ -23,6 +25,8 @@ private:
|
|||||||
private:
|
private:
|
||||||
QString m_version;
|
QString m_version;
|
||||||
QString m_buildDateTime;
|
QString m_buildDateTime;
|
||||||
|
|
||||||
|
MainWindow *m_mainWindow = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // APPLICATION_H
|
#endif // APPLICATION_H
|
||||||
|
69
src/main.cpp
69
src/main.cpp
@ -1,5 +1,6 @@
|
|||||||
#include "application.h"
|
#include "application.h"
|
||||||
#include "mainwindow-dtk.h"
|
#include "mainwindow-dtk.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
#include <DSysInfo>
|
#include <DSysInfo>
|
||||||
#include <DApplicationSettings>
|
#include <DApplicationSettings>
|
||||||
@ -14,8 +15,6 @@
|
|||||||
DCORE_USE_NAMESPACE
|
DCORE_USE_NAMESPACE
|
||||||
DWIDGET_USE_NAMESPACE
|
DWIDGET_USE_NAMESPACE
|
||||||
|
|
||||||
#define UOSCheckFile "/var/lib/deepin/developer-mode/enabled"
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
// Get build time
|
// Get build time
|
||||||
@ -24,75 +23,16 @@ int main(int argc, char *argv[])
|
|||||||
static const QTime buildTime = QTime::fromString(__TIME__, "hh:mm:ss");
|
static const QTime buildTime = QTime::fromString(__TIME__, "hh:mm:ss");
|
||||||
static const QString buildDateTime = buildDate.toString("yyyy.MM.dd") + "-" + buildTime.toString("hh:mm:ss");
|
static const QString buildDateTime = buildDate.toString("yyyy.MM.dd") + "-" + buildTime.toString("hh:mm:ss");
|
||||||
|
|
||||||
// 设置桌面环境环境变量
|
|
||||||
bool isDeepinOS = true;
|
|
||||||
if (!QString(qgetenv("XDG_CURRENT_DESKTOP")).toLower().startsWith("deepin"))
|
|
||||||
{
|
|
||||||
qputenv("XDG_CURRENT_DESKTOP", "Deepin");
|
|
||||||
isDeepinOS = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isWayland = false;
|
|
||||||
auto e = QProcessEnvironment::systemEnvironment();
|
|
||||||
QString XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE"));
|
|
||||||
QString WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY"));
|
|
||||||
if (XDG_SESSION_TYPE == QLatin1String("wayland") || WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive))
|
|
||||||
{
|
|
||||||
isWayland = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: 提前设置组织名称和应用名称,避免配置文件位置错误
|
// NOTE: 提前设置组织名称和应用名称,避免配置文件位置错误
|
||||||
DApplication::setOrganizationName("spark-union");
|
DApplication::setOrganizationName("spark-union");
|
||||||
DApplication::setApplicationName("spark-store");
|
DApplication::setApplicationName("spark-store");
|
||||||
Application::checkAppConfigLocation(); // 检查 ~/.config/spark-union/spark-store 文件夹是否存在
|
Application::checkAppConfigLocation(); // 检查 ~/.config/spark-union/spark-store 文件夹是否存在
|
||||||
|
|
||||||
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
// 初始化 config.ini 配置文件
|
||||||
config.setValue("build/isWayland", isWayland);
|
Utils::initConfig();
|
||||||
config.setValue("build/isDeepinOS", isDeepinOS);
|
|
||||||
// Check config file, if there is no wayland config, then set it to default, which means use wayland if possible.
|
|
||||||
if (!config.contains("build/useWayland"))
|
|
||||||
{
|
|
||||||
config.setValue("build/useWayland", true);
|
|
||||||
}
|
|
||||||
config.sync(); // 写入更改至 config.ini,并同步最新内容
|
|
||||||
|
|
||||||
bool useWayland = config.value("build/useWayland").toBool();
|
|
||||||
qDebug() << "System Wayland enabled:" << isWayland << ". Spark Wayland enabled:" << useWayland;
|
|
||||||
|
|
||||||
// Set display backend
|
// Set display backend
|
||||||
if (isWayland && useWayland && !(Dtk::Core::DSysInfo::isDDE() || isDeepinOS))
|
Utils::setQPAPlatform();
|
||||||
{
|
|
||||||
qputenv("QT_QPA_PLATFORM", "wayland");
|
|
||||||
}
|
|
||||||
else if (isWayland && useWayland && (Dtk::Core::DSysInfo::isDDE() && isDeepinOS))
|
|
||||||
{
|
|
||||||
qputenv("QT_QPA_PLATFORM", "dwayland");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qputenv("QT_QPA_PLATFORM", "dxcb");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check UOS developer mode.
|
|
||||||
QFile UOSDevelopFile(UOSCheckFile);
|
|
||||||
if (isDeepinOS && UOSDevelopFile.exists() && UOSDevelopFile.open(QFile::ReadOnly | QFile::Text))
|
|
||||||
{
|
|
||||||
config.setValue("UOS/isUOS", true);
|
|
||||||
QString lineData = UOSDevelopFile.readLine();
|
|
||||||
bool devmode = lineData.trimmed().toInt();
|
|
||||||
qDebug() << "UOS Developer Mode Status:" << devmode;
|
|
||||||
config.setValue("UOS/EnableDeveloperMode", devmode);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (config.contains("UOS/isUOS"))
|
|
||||||
{
|
|
||||||
config.remove("UOS/isUOS");
|
|
||||||
config.remove("UOS/EnableDeveloperMode");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
UOSDevelopFile.close();
|
|
||||||
config.sync(); // 写入更改至 config.ini,并同步最新内容
|
|
||||||
|
|
||||||
// 龙芯机器配置,使得 DApplication 能正确加载 QTWEBENGINE
|
// 龙芯机器配置,使得 DApplication 能正确加载 QTWEBENGINE
|
||||||
qputenv("DTK_FORCE_RASTER_WIDGETS", "FALSE");
|
qputenv("DTK_FORCE_RASTER_WIDGETS", "FALSE");
|
||||||
@ -131,6 +71,7 @@ int main(int argc, char *argv[])
|
|||||||
DApplicationSettings settings; // 定义 DApplicationSettings,自动保存主题设置
|
DApplicationSettings settings; // 定义 DApplicationSettings,自动保存主题设置
|
||||||
|
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
|
a.setMainWindow(&w); // 设置应用程序主窗口,用于初始化关于对话框
|
||||||
// 让打开时界面显示在正中
|
// 让打开时界面显示在正中
|
||||||
Dtk::Widget::moveToCenter(&w);
|
Dtk::Widget::moveToCenter(&w);
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ void MainWindow::initTitleBar()
|
|||||||
ly_titlebar->addWidget(backButton);
|
ly_titlebar->addWidget(backButton);
|
||||||
// Check wayland configs
|
// Check wayland configs
|
||||||
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
||||||
if (!config.value("build/isDeepinOS").toBool() && config.value("build/useWayland").toBool())
|
if (!config.value("runtime/isDDE").toBool() && config.value("runtime/useWayland").toBool())
|
||||||
{
|
{
|
||||||
// Wayland 搜索栏居中
|
// Wayland 搜索栏居中
|
||||||
ly_titlebar->addStretch(WaylandSearchCenter);
|
ly_titlebar->addStretch(WaylandSearchCenter);
|
||||||
|
@ -1,9 +1,23 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
|
|
||||||
#include <QDBusInterface>
|
#include <DSysInfo>
|
||||||
|
|
||||||
// Author: chatGPT
|
#include <QDBusInterface>
|
||||||
|
#include <QProcessEnvironment>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
|
#define UOSDeveloperModeFile "/var/lib/deepin/developer-mode/enabled"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author chatGPT
|
||||||
|
* @brief Utils::sendNotification 发送系统通知
|
||||||
|
* @param icon 图标名称
|
||||||
|
* @param title 通知标题
|
||||||
|
* @param body 通知内容
|
||||||
|
*/
|
||||||
void Utils::sendNotification(const QString &icon, const QString &title, const QString &body)
|
void Utils::sendNotification(const QString &icon, const QString &title, const QString &body)
|
||||||
{
|
{
|
||||||
QDBusInterface interface("org.freedesktop.Notifications",
|
QDBusInterface interface("org.freedesktop.Notifications",
|
||||||
@ -22,3 +36,149 @@ void Utils::sendNotification(const QString &icon, const QString &title, const QS
|
|||||||
|
|
||||||
interface.callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
interface.callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Utils::isDDE 判断是否使用 DDE 桌面环境
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
bool Utils::isDDE()
|
||||||
|
{
|
||||||
|
bool isDDE = true;
|
||||||
|
if (!QString::fromUtf8(qgetenv("XDG_CURRENT_DESKTOP")).toLower().startsWith("deepin"))
|
||||||
|
{
|
||||||
|
qputenv("XDG_CURRENT_DESKTOP", "Deepin");
|
||||||
|
isDDE = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isDDE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Utils::isWayland 判断是否使用 wayland 显示协议
|
||||||
|
* @return bool true: 使用 wayland 显示协议 false: 使用 x11 显示协议
|
||||||
|
*/
|
||||||
|
bool Utils::isWayland()
|
||||||
|
{
|
||||||
|
bool isWayland = false;
|
||||||
|
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||||
|
QString XDG_SESSION_TYPE = env.value(QStringLiteral("XDG_SESSION_TYPE"));
|
||||||
|
QString WAYLAND_DISPLAY = env.value(QStringLiteral("WAYLAND_DISPLAY"));
|
||||||
|
if (XDG_SESSION_TYPE == QLatin1String("wayland") || WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
|
isWayland = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isWayland;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Utils::initConfig 初始化 config.ini 配置文件,去除废弃字段
|
||||||
|
*/
|
||||||
|
void Utils::initConfig()
|
||||||
|
{
|
||||||
|
// WARNING: 请在 组织名称 和 应用程序名称 初始化完成后调用
|
||||||
|
bool useWayland = true;
|
||||||
|
|
||||||
|
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
||||||
|
if (config.contains("build/useWayland"))
|
||||||
|
{
|
||||||
|
useWayland = config.value("build/useWayland").toBool();
|
||||||
|
}
|
||||||
|
config.remove("build/isDeepinOS");
|
||||||
|
config.remove("build/isWayland");
|
||||||
|
config.remove("build/useWayland");
|
||||||
|
|
||||||
|
config.setValue("runtime/isDDE", isDDE());
|
||||||
|
config.setValue("runtime/isWayland", isWayland());
|
||||||
|
// Check config file, if there is no wayland config, then set it to default, which means use wayland if possible.
|
||||||
|
if (!config.contains("runtime/useWayland"))
|
||||||
|
{
|
||||||
|
config.setValue("runtime/useWayland", useWayland);
|
||||||
|
}
|
||||||
|
config.sync(); // 写入更改至 config.ini,并同步最新内容
|
||||||
|
|
||||||
|
checkUOSDeveloperMode(); // Check UOS developer mode
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Utils::isUOS 判断是否为 UOS 操作系统
|
||||||
|
* @return bool true: UOS 操作系统 false: 非 UOS 操作系统
|
||||||
|
*/
|
||||||
|
bool Utils::isUOS()
|
||||||
|
{
|
||||||
|
// WARNING: 请在 组织名称 和 应用程序名称 初始化完成后调用
|
||||||
|
bool isUOS = false;
|
||||||
|
|
||||||
|
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
||||||
|
if (Dtk::Core::DSysInfo::productType() == Dtk::Core::DSysInfo::Uos)
|
||||||
|
{
|
||||||
|
isUOS = true;
|
||||||
|
config.setValue("UOS/isUOS", true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isUOS = false;
|
||||||
|
config.remove("UOS");
|
||||||
|
}
|
||||||
|
config.sync(); // 写入更改至 config.ini,并同步最新内容
|
||||||
|
|
||||||
|
return isUOS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Utils::setQPAPlatform Set display backend
|
||||||
|
*/
|
||||||
|
void Utils::setQPAPlatform()
|
||||||
|
{
|
||||||
|
// WARNING: 请在 initConfig() 执行后调用
|
||||||
|
bool isDDE = Utils::isDDE(); // WARNING: 只能执行一次,后续执行时环境变量已经被覆盖,导致判断错误
|
||||||
|
bool isWayland = Utils::isWayland();
|
||||||
|
|
||||||
|
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
||||||
|
bool useWayland = config.value("runtime/useWayland").toBool();
|
||||||
|
|
||||||
|
qDebug() << "System Wayland enabled:" << isWayland << "Spark Wayland enabled:" << useWayland;
|
||||||
|
|
||||||
|
if (isWayland && useWayland && !(Dtk::Core::DSysInfo::isDeepin() || isDDE))
|
||||||
|
{
|
||||||
|
qputenv("QT_QPA_PLATFORM", "wayland");
|
||||||
|
}
|
||||||
|
else if (isWayland && useWayland && (Dtk::Core::DSysInfo::isDeepin() && isDDE))
|
||||||
|
{
|
||||||
|
qputenv("QT_QPA_PLATFORM", "dwayland");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qputenv("QT_QPA_PLATFORM", "dxcb");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Utils::checkUOSDeveloperMode Check UOS developer mode
|
||||||
|
*/
|
||||||
|
void Utils::checkUOSDeveloperMode()
|
||||||
|
{
|
||||||
|
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
||||||
|
|
||||||
|
QFile file(UOSDeveloperModeFile);
|
||||||
|
if (Utils::isUOS() && file.exists() && file.open(QFile::ReadOnly | QFile::Text))
|
||||||
|
{
|
||||||
|
QString lineData = QString::fromUtf8(file.readLine());
|
||||||
|
bool devmode = lineData.trimmed().toInt();
|
||||||
|
qDebug() << "UOS Developer Mode Status:" << devmode;
|
||||||
|
config.setValue("UOS/EnableDeveloperMode", devmode);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* NOTE: Utils::isUOS() 中,判断为非 UOS 时已经从 config 中删除 UOS 组,
|
||||||
|
* 此处若包含该字段则一定是 UOS,直接写入开发者模式开关状态即可
|
||||||
|
*/
|
||||||
|
if (config.contains("UOS/EnableDeveloperMode"))
|
||||||
|
{
|
||||||
|
config.setValue("UOS/EnableDeveloperMode", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
config.sync(); // 写入更改至 config.ini,并同步最新内容
|
||||||
|
}
|
||||||
|
@ -7,6 +7,12 @@ class Utils
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void sendNotification(const QString &icon, const QString &title, const QString &body);
|
static void sendNotification(const QString &icon, const QString &title, const QString &body);
|
||||||
|
static bool isDDE();
|
||||||
|
static bool isWayland();
|
||||||
|
static void initConfig();
|
||||||
|
static bool isUOS();
|
||||||
|
static void setQPAPlatform();
|
||||||
|
static void checkUOSDeveloperMode();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // UTILS_H
|
#endif // UTILS_H
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
#include "widgetanimation.h"
|
#include "widgetanimation.h"
|
||||||
|
#include "widgets/base/basewidgetopacity.h"
|
||||||
WidgetAnimation::WidgetAnimation()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void WidgetAnimation::widgetShake(QWidget *pWidget, int nRange)
|
void WidgetAnimation::widgetShake(QWidget *pWidget, int nRange)
|
||||||
{
|
{
|
||||||
@ -28,27 +25,35 @@ void WidgetAnimation::widgetShake(QWidget *pWidget, int nRange)
|
|||||||
QPropertyAnimation *WidgetAnimation::createWidgetOpacity(QWidget *pWidget, bool isAppear)
|
QPropertyAnimation *WidgetAnimation::createWidgetOpacity(QWidget *pWidget, bool isAppear)
|
||||||
{
|
{
|
||||||
QPropertyAnimation *animation = new QPropertyAnimation(pWidget, "windowOpacity", pWidget);
|
QPropertyAnimation *animation = new QPropertyAnimation(pWidget, "windowOpacity", pWidget);
|
||||||
// 设置动画效果
|
|
||||||
animation->setEasingCurve(QEasingCurve::Linear);
|
|
||||||
// 设置动画时间(单位:毫秒)
|
// 设置动画时间(单位:毫秒)
|
||||||
animation->setDuration(500);
|
animation->setDuration(500);
|
||||||
// 设置动画步长值,以及在该位置时显示的透明度
|
|
||||||
if (isAppear)
|
if (isAppear)
|
||||||
{
|
{
|
||||||
animation->setKeyValueAt(0, 0);
|
// 设置动画效果
|
||||||
// m_animation->setKeyValueAt(0.5, 0);
|
animation->setEasingCurve(QEasingCurve::Linear);
|
||||||
animation->setKeyValueAt(1, 1);
|
// 设置动画步长值,以及在该位置时显示的透明度(即动画关键帧)
|
||||||
|
animation->setKeyValueAt(0.0, 0.0);
|
||||||
|
animation->setKeyValueAt(1.0, 1.0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
animation->setKeyValueAt(0, 1);
|
animation->setEasingCurve(QEasingCurve::OutQuart);
|
||||||
animation->setKeyValueAt(1, 0);
|
animation->setKeyValueAt(0.0, 1.0);
|
||||||
|
animation->setKeyValueAt(1.0, 0.0);
|
||||||
|
|
||||||
|
QObject::connect(animation, &QPropertyAnimation::finished, pWidget, [=]() { pWidget->close(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QObject::connect(animation, &QPropertyAnimation::valueChanged, pWidget, [=]()
|
||||||
|
{
|
||||||
|
pWidget->update(); // NOTE: 保证窗口透明度动画平滑
|
||||||
|
});
|
||||||
|
|
||||||
return animation;
|
return animation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidgetAnimation::widgetOpacity(QWidget *pWidget, bool isAppear)
|
void WidgetAnimation::widgetOpacity(QWidget *pWidget, bool isAppear)
|
||||||
{
|
{
|
||||||
// 开始动画
|
// 启动/关闭动画
|
||||||
createWidgetOpacity(pWidget, isAppear)->start();
|
createWidgetOpacity(pWidget, isAppear)->start(QPropertyAnimation::DeleteWhenStopped);
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
#ifndef WIDGETANIMATION_H
|
#ifndef WIDGETANIMATION_H
|
||||||
#define WIDGETANIMATION_H
|
#define WIDGETANIMATION_H
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
|
|
||||||
class WidgetAnimation
|
class WidgetAnimation
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WidgetAnimation();
|
|
||||||
static void widgetShake(QWidget *pWidget, int nRange);
|
static void widgetShake(QWidget *pWidget, int nRange);
|
||||||
|
|
||||||
static QPropertyAnimation* createWidgetOpacity(QWidget *pWidget, bool isAppear);
|
static QPropertyAnimation* createWidgetOpacity(QWidget *pWidget, bool isAppear);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "basewidgetopacity.h"
|
#include "basewidgetopacity.h"
|
||||||
#include "utils/widgetanimation.h"
|
#include "utils/widgetanimation.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
@ -8,7 +9,6 @@
|
|||||||
|
|
||||||
BaseWidgetOpacity::BaseWidgetOpacity(QWidget *parent) : DBlurEffectWidget(parent)
|
BaseWidgetOpacity::BaseWidgetOpacity(QWidget *parent) : DBlurEffectWidget(parent)
|
||||||
{
|
{
|
||||||
// WidgetAnimation::widgetOpacity(this,true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,7 +19,7 @@ void BaseWidgetOpacity::showEvent(QShowEvent *event)
|
|||||||
{
|
{
|
||||||
// FIXME: wayland 不支持直接设置窗口透明度,需要调用 wayland 相关库(考虑抄控制中心“窗口移动时启用透明特效”代码?)
|
// FIXME: wayland 不支持直接设置窗口透明度,需要调用 wayland 相关库(考虑抄控制中心“窗口移动时启用透明特效”代码?)
|
||||||
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
||||||
bool isWayland = config.value("build/isWayland").toBool();
|
bool isWayland = Utils::isWayland();
|
||||||
if (!isWayland)
|
if (!isWayland)
|
||||||
{
|
{
|
||||||
if (!showWindowAnimation)
|
if (!showWindowAnimation)
|
||||||
@ -32,13 +32,15 @@ void BaseWidgetOpacity::showEvent(QShowEvent *event)
|
|||||||
DBlurEffectWidget::showEvent(event);
|
DBlurEffectWidget::showEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief 窗口关闭事件
|
/**
|
||||||
/// @param event
|
* @brief 窗口关闭事件
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
void BaseWidgetOpacity::closeEvent(QCloseEvent *event)
|
void BaseWidgetOpacity::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
// FIXME: wayland 不支持直接设置窗口透明度,需要调用 wayland 相关库(考虑抄控制中心“窗口移动时启用透明特效”代码?)
|
// FIXME: wayland 不支持直接设置窗口透明度,需要调用 wayland 相关库(考虑抄控制中心“窗口移动时启用透明特效”代码?)
|
||||||
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
||||||
bool isWayland = config.value("build/isWayland").toBool();
|
bool isWayland = Utils::isWayland();
|
||||||
if (isWayland)
|
if (isWayland)
|
||||||
{
|
{
|
||||||
return DBlurEffectWidget::closeEvent(event);
|
return DBlurEffectWidget::closeEvent(event);
|
||||||
@ -47,23 +49,8 @@ void BaseWidgetOpacity::closeEvent(QCloseEvent *event)
|
|||||||
if (!closeWindowAnimation)
|
if (!closeWindowAnimation)
|
||||||
{
|
{
|
||||||
closeWindowAnimation = true;
|
closeWindowAnimation = true;
|
||||||
|
WidgetAnimation::widgetOpacity(this, false);
|
||||||
|
|
||||||
QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity");
|
|
||||||
animation->setEasingCurve(QEasingCurve::OutQuart);
|
|
||||||
animation->setDuration(500);
|
|
||||||
animation->setStartValue(1.0);
|
|
||||||
animation->setEndValue(0.0);
|
|
||||||
|
|
||||||
QObject::connect(animation, &QPropertyAnimation::valueChanged, this, [=](const QVariant &value)
|
|
||||||
{
|
|
||||||
this->update();
|
|
||||||
// setWindowTitle(QString("ヾ(⌒∇⌒*)See You♪ - %1%").arg(int(value.toFloat() * 100)));
|
|
||||||
});
|
|
||||||
|
|
||||||
QObject::connect(animation, &QPropertyAnimation::finished, this, [=]()
|
|
||||||
{ this->close(); });
|
|
||||||
|
|
||||||
animation->start();
|
|
||||||
event->ignore();
|
event->ignore();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user