From 939e04e4cae7ac602b63e5d5fe44107eee56aa57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Sun, 15 Oct 2023 17:24:33 +0800 Subject: [PATCH] update --- example/qml-Qt6/App.qml | 8 ++++++++ example/qml-Qt6/page/T_Settings.qml | 21 +++++++++++++++++++-- example/qml/App.qml | 8 ++++++++ example/qml/page/T_Settings.qml | 21 +++++++++++++++++++-- example/src/helper/SettingsHelper.h | 2 ++ src/FluApp.cpp | 1 + src/FluApp.h | 1 + src/WindowLifecycle.cpp | 7 +++++++ src/WindowLifecycle.h | 1 + 9 files changed, 66 insertions(+), 4 deletions(-) diff --git a/example/qml-Qt6/App.qml b/example/qml-Qt6/App.qml index 71d27b45..8c094086 100644 --- a/example/qml-Qt6/App.qml +++ b/example/qml-Qt6/App.qml @@ -15,6 +15,13 @@ Window { } } + Connections{ + target: FluApp + function onVsyncChanged(){ + SettingsHelper.saveVsync(FluApp.vsync) + } + } + FluHttpInterceptor{ id:interceptor function onIntercept(request){ @@ -33,6 +40,7 @@ Window { Component.onCompleted: { FluApp.init(app) + FluApp.vsync = SettingsHelper.getVsync() FluTheme.darkMode = SettingsHelper.getDarkMode() FluTheme.enableAnimation = true FluApp.routes = { diff --git a/example/qml-Qt6/page/T_Settings.qml b/example/qml-Qt6/page/T_Settings.qml index 0174b410..d38d4d35 100644 --- a/example/qml-Qt6/page/T_Settings.qml +++ b/example/qml-Qt6/page/T_Settings.qml @@ -56,6 +56,23 @@ FluScrollablePage{ } } + FluArea{ + Layout.fillWidth: true + Layout.topMargin: 20 + height: 50 + paddings: 10 + FluCheckBox{ + text:"V-Sync" + checked: FluApp.vsync + anchors.verticalCenter: parent.verticalCenter + onClicked: { + FluApp.vsync = !FluApp.vsync + dialog_restart.open() + } + } + } + + FluArea{ Layout.fillWidth: true Layout.topMargin: 20 @@ -71,13 +88,13 @@ FluScrollablePage{ }else{ SettingsHelper.saveRender("software") } - dialog_render.open() + dialog_restart.open() } } } FluContentDialog{ - id:dialog_render + id:dialog_restart title:"友情提示" message:"此操作需要重启才能生效,是否重新启动?" buttonFlags: FluContentDialogType.NegativeButton | FluContentDialogType.PositiveButton diff --git a/example/qml/App.qml b/example/qml/App.qml index f9d979d9..c4467a12 100644 --- a/example/qml/App.qml +++ b/example/qml/App.qml @@ -15,6 +15,13 @@ Window { } } + Connections{ + target: FluApp + function onVsyncChanged(){ + SettingsHelper.saveVsync(FluApp.vsync) + } + } + FluHttpInterceptor{ id:interceptor function onIntercept(request){ @@ -33,6 +40,7 @@ Window { Component.onCompleted: { FluApp.init(app) + FluApp.vsync = SettingsHelper.getVsync() FluTheme.darkMode = SettingsHelper.getDarkMode() FluTheme.enableAnimation = true FluApp.routes = { diff --git a/example/qml/page/T_Settings.qml b/example/qml/page/T_Settings.qml index f3e8b05f..ec3dae5b 100644 --- a/example/qml/page/T_Settings.qml +++ b/example/qml/page/T_Settings.qml @@ -59,6 +59,23 @@ FluScrollablePage{ } } + FluArea{ + Layout.fillWidth: true + Layout.topMargin: 20 + height: 50 + paddings: 10 + FluCheckBox{ + text:"V-Sync" + checked: FluApp.vsync + anchors.verticalCenter: parent.verticalCenter + onClicked: { + FluApp.vsync = !FluApp.vsync + dialog_restart.open() + } + } + } + + FluArea{ Layout.fillWidth: true Layout.topMargin: 20 @@ -74,13 +91,13 @@ FluScrollablePage{ }else{ SettingsHelper.saveRender("software") } - dialog_render.open() + dialog_restart.open() } } } FluContentDialog{ - id:dialog_render + id:dialog_restart title:"友情提示" message:"此操作需要重启才能生效,是否重新启动?" buttonFlags: FluContentDialogType.NegativeButton | FluContentDialogType.PositiveButton diff --git a/example/src/helper/SettingsHelper.h b/example/src/helper/SettingsHelper.h index 0d15018f..5f426b7f 100644 --- a/example/src/helper/SettingsHelper.h +++ b/example/src/helper/SettingsHelper.h @@ -23,6 +23,8 @@ public: Q_INVOKABLE QString getRender(){return get("render").toString();} Q_INVOKABLE void saveDarkMode(int darkModel){save("darkMode",darkModel);} Q_INVOKABLE int getDarkMode(){return get("darkMode").toInt(0);} + Q_INVOKABLE void saveVsync(bool vsync){save("vsync",vsync);} + Q_INVOKABLE bool getVsync(){return get("vsync").toBool();} private: void save(const QString& key,QVariant val); QVariant get(const QString& key); diff --git a/src/FluApp.cpp b/src/FluApp.cpp index 16b4d140..d0bcf0b1 100644 --- a/src/FluApp.cpp +++ b/src/FluApp.cpp @@ -14,6 +14,7 @@ FRAMELESSHELPER_USE_NAMESPACE FluApp::FluApp(QObject *parent):QObject{parent}{ + vsync(false); httpInterceptor(nullptr); } diff --git a/src/FluApp.h b/src/FluApp.h index ddcaf249..1d85b3fb 100644 --- a/src/FluApp.h +++ b/src/FluApp.h @@ -19,6 +19,7 @@ class FluApp : public QObject { Q_OBJECT + Q_PROPERTY_AUTO(bool,vsync) Q_PROPERTY_AUTO(QString,initialRoute); Q_PROPERTY_AUTO(QJsonObject,routes); Q_PROPERTY_AUTO(FluHttpInterceptor*,httpInterceptor); diff --git a/src/WindowLifecycle.cpp b/src/WindowLifecycle.cpp index 91c1e6f7..790b59d8 100644 --- a/src/WindowLifecycle.cpp +++ b/src/WindowLifecycle.cpp @@ -8,6 +8,7 @@ WindowLifecycle::WindowLifecycle(QObject *parent):QObject{parent}{ void WindowLifecycle::onCompleted(QQuickWindow* window){ this->_window = window; + vsyncEnable(FluApp::getInstance()->vsync()); FluApp::getInstance()->addWindow(this->_window); } @@ -21,6 +22,12 @@ void WindowLifecycle::onDestruction(){ void WindowLifecycle::onVisible(bool visible){ } +void WindowLifecycle::vsyncEnable(bool enable){ + auto froamt = _window->format(); + froamt.setSwapInterval(enable); + _window->setFormat(froamt); +} + QVariant WindowLifecycle::createRegister(QQuickWindow* window,const QString& path){ FluRegister *p = new FluRegister(window); p->from(window); diff --git a/src/WindowLifecycle.h b/src/WindowLifecycle.h index 886ff631..005bb1bb 100644 --- a/src/WindowLifecycle.h +++ b/src/WindowLifecycle.h @@ -22,6 +22,7 @@ public: Q_INVOKABLE void onVisible(bool visible); Q_INVOKABLE void onDestoryOnClose(); Q_INVOKABLE QVariant createRegister(QQuickWindow* window,const QString& path); + void vsyncEnable(bool enable); private: QQuickWindow* _window; };