From 830386fb1fdf86e193d2e8d55d800a6826f8a958 Mon Sep 17 00:00:00 2001 From: mhduiy Date: Fri, 20 Dec 2024 23:47:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E4=BD=BF=E7=94=A8OpenGL=E6=B8=B2=E6=9F=93=E7=9A=84=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../settingPageTools/othersettingshandler.cpp | 20 +++++++++++++-- .../settingPageTools/othersettingshandler.h | 6 +++++ src/cpp/settingPageTools/settingPageTools.cpp | 2 -- src/cpp/utils/globalsetting.cpp | 3 +++ src/main.cpp | 22 +++++++++++----- src/qml/pages/SettingPage.qml | 25 ++++++++----------- 6 files changed, 54 insertions(+), 24 deletions(-) diff --git a/src/cpp/settingPageTools/othersettingshandler.cpp b/src/cpp/settingPageTools/othersettingshandler.cpp index 401ae8c..db1f60b 100644 --- a/src/cpp/settingPageTools/othersettingshandler.cpp +++ b/src/cpp/settingPageTools/othersettingshandler.cpp @@ -7,11 +7,16 @@ OtherSettingsHandler::OtherSettingsHandler(QObject *parent) { m_triggerTimer->setInterval(300); m_triggerTimer->setSingleShot(true); + connect(m_triggerTimer, &QTimer::timeout, this, &OtherSettingsHandler::syncConfig); + GlobalSetting::instance()->checkConfig("other", "wrapperOpacity", 0.3); double configWrapperOpacity = GlobalSetting::instance()->readConfig("other", "wrapperOpacity").toDouble(); - setWrapperOpacity(configWrapperOpacity); - connect(m_triggerTimer, &QTimer::timeout, this, &OtherSettingsHandler::syncConfig); + GlobalSetting::instance()->checkConfig("other", "useOpenGL", QVariant::fromValue(false)); + bool useOpenGL = GlobalSetting::instance()->readConfig("other", "useOpenGL").toBool(); + + setWrapperOpacity(configWrapperOpacity); + setUseOpenGL(useOpenGL); } void OtherSettingsHandler::setWrapperOpacity(double value) @@ -23,7 +28,18 @@ void OtherSettingsHandler::setWrapperOpacity(double value) } } +void OtherSettingsHandler::setUseOpenGL(bool value) +{ + qWarning() << "========="; + if (m_useOpenGL != value) { + m_useOpenGL = value; + Q_EMIT useOpenGLChanged(value); + m_triggerTimer->start(); + } +} + void OtherSettingsHandler::syncConfig() { GlobalSetting::instance()->writeConfig("other", "wrapperOpacity", m_wrapperOpacity); + GlobalSetting::instance()->writeConfig("other", "useOpenGL", m_useOpenGL); } diff --git a/src/cpp/settingPageTools/othersettingshandler.h b/src/cpp/settingPageTools/othersettingshandler.h index 0378a78..583e202 100644 --- a/src/cpp/settingPageTools/othersettingshandler.h +++ b/src/cpp/settingPageTools/othersettingshandler.h @@ -9,17 +9,23 @@ class OtherSettingsHandler : public QObject Q_OBJECT SINGLETON(OtherSettingsHandler) Q_PROPERTY(double wrapperOpacity READ wrapperOpacity WRITE setWrapperOpacity NOTIFY wrapperOpacityChanged) + Q_PROPERTY(bool useOpenGL READ useOpenGL WRITE setUseOpenGL NOTIFY useOpenGLChanged) public: double wrapperOpacity() const { return m_wrapperOpacity; } void setWrapperOpacity(double value); + bool useOpenGL() const { return m_useOpenGL; } + void setUseOpenGL(bool value); + signals: void wrapperOpacityChanged(double value); + void useOpenGLChanged(bool value); private slots: void syncConfig(); private: double m_wrapperOpacity; + bool m_useOpenGL; QTimer *m_triggerTimer; }; diff --git a/src/cpp/settingPageTools/settingPageTools.cpp b/src/cpp/settingPageTools/settingPageTools.cpp index 755eb68..a5d251f 100644 --- a/src/cpp/settingPageTools/settingPageTools.cpp +++ b/src/cpp/settingPageTools/settingPageTools.cpp @@ -98,7 +98,6 @@ void WallPaperModel::setCurrentIndex(int index) m_currentIndex = index; emit currentItemChanged(url); emit currentIndexChanged(index); - qWarning() << "****" << url; WallpaperHelper::instance()->setWallPaper(url); GlobalSetting::instance()->writeConfig("wallpaper", "url", url); GlobalSetting::instance()->writeConfig("wallpaper", "index", QString::number(index)); @@ -171,7 +170,6 @@ void SettingPageTools::onRequestRefreshWallpaperList() QJsonObject imageObj = it.toObject(); QString fileNameUrl = imageObj["url"].toString(); QUrl url = QUrl(fileNameUrl); - qWarning() << url << url.toLocalFile(); if (!QFile::exists(url.toLocalFile())) { continue; } diff --git a/src/cpp/utils/globalsetting.cpp b/src/cpp/utils/globalsetting.cpp index 3836057..acb442e 100644 --- a/src/cpp/utils/globalsetting.cpp +++ b/src/cpp/utils/globalsetting.cpp @@ -20,6 +20,7 @@ GlobalSetting::GlobalSetting(QObject *parent) : QObject(parent) { dir.mkpath(cacheDir); } + qDebug() << "config file:" << cacheDir + "/config.ini"; settings = new QSettings(cacheDir + "/config.ini", QSettings::IniFormat); } @@ -37,8 +38,10 @@ bool GlobalSetting::checkConfig(const QString &title, const QString &key, const settings->beginGroup(title); if (!settings->contains(key)) { settings->setValue(key, defaultValue); + settings->endGroup(); return false; } + settings->endGroup(); return true; } diff --git a/src/main.cpp b/src/main.cpp index 1eaa434..2340eee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,6 +18,7 @@ #include "cpp/settingPageTools/settingPageTools.h" #include "cpp/utils/notificationcontroller.h" #include "cpp/components/fpsitem.h" +#include "cpp/utils/globalsetting.h" bool checkADB() { QProcess process; @@ -41,6 +42,15 @@ bool checkADB() { return false; } +bool forceOpenGL() +{ + QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL); + QSurfaceFormat format; + format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); + format.setSwapInterval(0); + QSurfaceFormat::setDefaultFormat(format); +} + int main(int argc, char *argv[]) { QApplication app(argc, argv); @@ -99,12 +109,12 @@ int main(int argc, char *argv[]) qmlRegisterType( "FpsItem", 1, 0, "FpsItem"); - QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL); - - QSurfaceFormat format; - format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); - format.setSwapInterval(0); - QSurfaceFormat::setDefaultFormat(format); + GlobalSetting::instance()->checkConfig("other", "useOpenGL", QVariant::fromValue(false)); + bool useOpenGL = GlobalSetting::instance()->readConfig("other", "useOpenGL").toBool(); + if (useOpenGL) { + qInfo() << "force use OpenGL"; + forceOpenGL(); + } QQmlApplicationEngine engine; const QUrl url("qrc:/qml/Main.qml"); diff --git a/src/qml/pages/SettingPage.qml b/src/qml/pages/SettingPage.qml index dd1b6c6..37cdbd4 100644 --- a/src/qml/pages/SettingPage.qml +++ b/src/qml/pages/SettingPage.qml @@ -187,25 +187,22 @@ ItemPage { } SettingItem { - title: "夜间模式" - description: "将所有控件设置为深色主题" + title: "OpenGL渲染模式" + description: "强制使用OpenGL渲染,如果设备镜像功能不可用,可尝试开启此开关,重启应用生效" controlItem: MSwitchButton { - + status: OtherSettingsHandler.useOpenGL + onStatusChanged: { + console.warn("=======", status) + OtherSettingsHandler.useOpenGL = status + } } } - Repeater { - model: 16 - SettingItem { - title: "夜间模式" - description: "将所有控件设置为深色主题" - controlItem: MLoadIndicator { - id: loadIndicator - Component.onCompleted: { - loadIndicator.start() - } + SettingItem { + title: "夜间模式" + description: "将所有控件设置为深色主题, 此功能开发中..." + controlItem: MSwitchButton { - } } } }