From 0dbbba56da52fb1752b5a2f16d23c4d0ceb0377d Mon Sep 17 00:00:00 2001 From: zhuzihcu Date: Thu, 25 May 2023 17:00:48 +0800 Subject: [PATCH 1/3] update --- example/qml/TestWindow.qml | 4 + example/qml/component/CodeExpander.qml | 169 +++++++++--------- example/src/AppInfo.cpp | 29 ++- example/src/AppInfo.h | 4 + example/src/main.cpp | 23 +-- src/FluApp.cpp | 2 - src/FluApp.h | 1 + src/imports/FluentUI/Controls/FluDivider.qml | 5 - src/imports/FluentUI/Controls/FluIcon.qml | 5 + .../FluentUI/Controls/FluIconButton.qml | 10 +- 10 files changed, 136 insertions(+), 116 deletions(-) diff --git a/example/qml/TestWindow.qml b/example/qml/TestWindow.qml index b8d65357..f75f284a 100644 --- a/example/qml/TestWindow.qml +++ b/example/qml/TestWindow.qml @@ -18,6 +18,10 @@ FluWindow { launchMode: FluWindow.SingleTask visible: true + Component.onCompleted: { +// FluApp.init(window) + } + FluNavigationView2{ id:nav_view anchors.fill: parent diff --git a/example/qml/component/CodeExpander.qml b/example/qml/component/CodeExpander.qml index 3f673a68..fd98792c 100644 --- a/example/qml/component/CodeExpander.qml +++ b/example/qml/component/CodeExpander.qml @@ -24,6 +24,11 @@ FluExpander{ color:FluTheme.dark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(247/255,247/255,247/255,1) border.color: FluTheme.dark ? Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(226/255,229/255,234/255,1) border.width: 1 + Behavior on color{ + ColorAnimation { + duration: 300 + } + } } } @@ -42,91 +47,91 @@ FluExpander{ } function htmlEncode(e){ - var i,s; - for(i in s={ - "&":/&/g,//""//":/"/g,"'":/'/g, - "<":/":/>/g,"
":/\n/g, - " ":/ /g," ":/\t/g - })e=e.replace(s[i],i); - return e; + var i,s; + for(i in s={ + "&":/&/g,//""//":/"/g,"'":/'/g, + "<":/":/>/g,"
":/\n/g, + " ":/ /g," ":/\t/g + })e=e.replace(s[i],i); + return e; } function highlightQmlCode(code) { - // 定义 QML 关键字列表 - var qmlKeywords = [ - "FluTextButton", - "FluAppBar", - "FluAutoSuggestBox", - "FluBadge", - "FluButton", - "FluCalendarPicker", - "FluCalendarView", - "FluCarousel", - "FluCheckBox", - "FluColorPicker", - "FluColorView", - "FluComboBox", - "FluContentDialog", - "FluContentPage", - "FluDatePicker", - "FluDivider", - "FluDropDownButton", - "FluExpander", - "FluFilledButton", - "FluFlipView", - "FluFocusRectangle", - "FluIcon", - "FluIconButton", - "FluInfoBar", - "FluItem", - "FluMediaPlayer", - "FluMenu", - "FluMenuItem", - "FluMultilineTextBox", - "FluNavigationView", - "FluObject", - "FluPaneItem", - "FluPaneItemExpander", - "FluPaneItemHeader", - "FluPaneItemSeparator", - "FluPivot", - "FluPivotItem", - "FluProgressBar", - "FluProgressRing", - "FluRadioButton", - "FluRectangle", - "FluScrollablePage", - "FluScrollBar", - "FluShadow", - "FluSlider", - "FluTabView", - "FluText", - "FluTextArea", - "FluTextBox", - "FluTextBoxBackground", - "FluTextBoxMenu", - "FluTextButton", - "FluTextFiled", - "FluTimePicker", - "FluToggleSwitch", - "FluTooltip", - "FluTreeView", - "FluWindow", - "FluWindowResize", - "FluToggleButton", - "FluTableView", - "FluColors", - "FluTheme", - "FluStatusView", - "FluRatingControl", - "FluPasswordBox", - "FluBreadcrumbBar", - "FluCopyableText", - "FluAcrylic" - ]; - code = code.replace(/\n/g, "
"); - code = code.replace(/ /g, " "); - return code.replace(RegExp("\\b(" + qmlKeywords.join("|") + ")\\b", "g"), "$1"); + // 定义 QML 关键字列表 + var qmlKeywords = [ + "FluTextButton", + "FluAppBar", + "FluAutoSuggestBox", + "FluBadge", + "FluButton", + "FluCalendarPicker", + "FluCalendarView", + "FluCarousel", + "FluCheckBox", + "FluColorPicker", + "FluColorView", + "FluComboBox", + "FluContentDialog", + "FluContentPage", + "FluDatePicker", + "FluDivider", + "FluDropDownButton", + "FluExpander", + "FluFilledButton", + "FluFlipView", + "FluFocusRectangle", + "FluIcon", + "FluIconButton", + "FluInfoBar", + "FluItem", + "FluMediaPlayer", + "FluMenu", + "FluMenuItem", + "FluMultilineTextBox", + "FluNavigationView", + "FluObject", + "FluPaneItem", + "FluPaneItemExpander", + "FluPaneItemHeader", + "FluPaneItemSeparator", + "FluPivot", + "FluPivotItem", + "FluProgressBar", + "FluProgressRing", + "FluRadioButton", + "FluRectangle", + "FluScrollablePage", + "FluScrollBar", + "FluShadow", + "FluSlider", + "FluTabView", + "FluText", + "FluTextArea", + "FluTextBox", + "FluTextBoxBackground", + "FluTextBoxMenu", + "FluTextButton", + "FluTextFiled", + "FluTimePicker", + "FluToggleSwitch", + "FluTooltip", + "FluTreeView", + "FluWindow", + "FluWindowResize", + "FluToggleButton", + "FluTableView", + "FluColors", + "FluTheme", + "FluStatusView", + "FluRatingControl", + "FluPasswordBox", + "FluBreadcrumbBar", + "FluCopyableText", + "FluAcrylic" + ]; + code = code.replace(/\n/g, "
"); + code = code.replace(/ /g, " "); + return code.replace(RegExp("\\b(" + qmlKeywords.join("|") + ")\\b", "g"), "$1"); } diff --git a/example/src/AppInfo.cpp b/example/src/AppInfo.cpp index 91a2d08f..734ae203 100644 --- a/example/src/AppInfo.cpp +++ b/example/src/AppInfo.cpp @@ -1,7 +1,9 @@ #include "AppInfo.h" + +#include +#include #include "lang/En.h" #include "lang/Zh.h" -#include #define STR(x) #x #define VER_JOIN(a,b,c,d) STR(a.b.c.d) @@ -15,6 +17,16 @@ AppInfo::AppInfo(QObject *parent) lang(new En()); } +void AppInfo::init(QQmlApplicationEngine *engine){ + QQmlContext * context = engine->rootContext(); + Lang* lang = this->lang(); + context->setContextProperty("lang",lang); + QObject::connect(this,&AppInfo::langChanged,this,[=]{ + context->setContextProperty("lang",this->lang()); + }); + context->setContextProperty("appInfo",this); +} + void AppInfo::changeLang(const QString& locale){ if(_lang){ _lang->deleteLater(); @@ -27,3 +39,18 @@ void AppInfo::changeLang(const QString& locale){ lang(new En()); } } + +bool AppInfo::isOwnerProcess(IPC *ipc){ + QString activeWindowEvent = "activeWindow"; + if(!ipc->isCurrentOwner()){ + ipc->postEvent(activeWindowEvent,QString().toUtf8(),0); + return false; + } + if(ipc->isAttached()){ + ipc->registerEventHandler(activeWindowEvent,[=](const QByteArray&){ + Q_EMIT this->activeWindow(); + return true; + }); + } + return true; +} diff --git a/example/src/AppInfo.h b/example/src/AppInfo.h index 828152b0..8e3fb9d1 100644 --- a/example/src/AppInfo.h +++ b/example/src/AppInfo.h @@ -2,6 +2,8 @@ #define APPINFO_H #include +#include +#include "tool/IPC.h" #include "lang/Lang.h" #include "stdafx.h" @@ -12,6 +14,8 @@ class AppInfo : public QObject Q_PROPERTY_AUTO(Lang*,lang) public: explicit AppInfo(QObject *parent = nullptr); + void init(QQmlApplicationEngine *engine); + bool isOwnerProcess(IPC *ipc); Q_INVOKABLE void changeLang(const QString& locale); Q_SIGNAL void activeWindow(); }; diff --git a/example/src/main.cpp b/example/src/main.cpp index d923b320..e3f1d2cf 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -6,13 +6,11 @@ #include #include #include -#include "lang/Lang.h" #include "AppInfo.h" -#include "tool/IPC.h" FRAMELESSHELPER_USE_NAMESPACE - int main(int argc, char *argv[]) +int main(int argc, char *argv[]) { //将样式设置为Basic,不然会导致组件显示异常 qputenv("QT_QUICK_CONTROLS_STYLE","Basic"); @@ -31,28 +29,13 @@ FRAMELESSHELPER_USE_NAMESPACE #endif AppInfo* appInfo = new AppInfo(); IPC ipc(0); - QString activeWindowEvent = "activeWindow"; - if(!ipc.isCurrentOwner()){ - ipc.postEvent(activeWindowEvent,QString().toUtf8(),0); - delete appInfo; + if(!appInfo->isOwnerProcess(&ipc)){ return 0; } - if(ipc.isAttached()){ - ipc.registerEventHandler(activeWindowEvent,[&appInfo](const QByteArray&){ - Q_EMIT appInfo->activeWindow(); - return true; - }); - } app.setQuitOnLastWindowClosed(false); QQmlApplicationEngine engine; FramelessHelper::Quick::registerTypes(&engine); - QQmlContext * context = engine.rootContext(); - Lang* lang = appInfo->lang(); - context->setContextProperty("lang",lang); - QObject::connect(appInfo,&AppInfo::langChanged,&app,[context,appInfo]{ - context->setContextProperty("lang",appInfo->lang()); - }); - context->setContextProperty("appInfo",appInfo); + appInfo->init(&engine); const QUrl url(QStringLiteral("qrc:/example/qml/App.qml")); // const QUrl url(QStringLiteral("qrc:/example/qml/TestWindow.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, diff --git a/src/FluApp.cpp b/src/FluApp.cpp index 5e4e0676..eb6966ed 100644 --- a/src/FluApp.cpp +++ b/src/FluApp.cpp @@ -23,11 +23,9 @@ FluApp *FluApp::getInstance() FluApp::FluApp(QObject *parent) : QObject{parent} { - QFontDatabase::addApplicationFont(":/FluentUI/Font/Segoe_Fluent_Icons.ttf"); } FluApp::~FluApp(){ - } void FluApp::init(QQuickWindow *window){ diff --git a/src/FluApp.h b/src/FluApp.h index ecdbcbfa..d116455f 100644 --- a/src/FluApp.h +++ b/src/FluApp.h @@ -27,6 +27,7 @@ class FluApp : public QObject */ Q_PROPERTY_AUTO(QJsonObject,routes); + QML_FOREIGN(FluApp) QML_NAMED_ELEMENT(FluApp) QML_SINGLETON private: diff --git a/src/imports/FluentUI/Controls/FluDivider.qml b/src/imports/FluentUI/Controls/FluDivider.qml index 3efaa46b..b41ef1c0 100644 --- a/src/imports/FluentUI/Controls/FluDivider.qml +++ b/src/imports/FluentUI/Controls/FluDivider.qml @@ -4,9 +4,4 @@ import FluentUI Rectangle { color: FluTheme.dark ? Window.active ? Qt.rgba(55/255,55/255,55/255,1):Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(226/255,230/255,234/255,1) - Behavior on color{ - ColorAnimation { - duration: 300 - } - } } diff --git a/src/imports/FluentUI/Controls/FluIcon.qml b/src/imports/FluentUI/Controls/FluIcon.qml index 156990aa..cade7301 100644 --- a/src/imports/FluentUI/Controls/FluIcon.qml +++ b/src/imports/FluentUI/Controls/FluIcon.qml @@ -13,4 +13,9 @@ Text { verticalAlignment: Text.AlignVCenter color: iconColor text: (String.fromCharCode(iconSource).toString(16)) + + FontLoader{ + source: "../Font/Segoe_Fluent_Icons.ttf" + } + } diff --git a/src/imports/FluentUI/Controls/FluIconButton.qml b/src/imports/FluentUI/Controls/FluIconButton.qml index cdd28aed..05231efc 100644 --- a/src/imports/FluentUI/Controls/FluIconButton.qml +++ b/src/imports/FluentUI/Controls/FluIconButton.qml @@ -51,17 +51,15 @@ Button { } } contentItem: Item{ - Text { + FluIcon { id:text_icon - font.family: "Segoe Fluent Icons" font.pixelSize: iconSize - width: iconSize - height: iconSize + iconSize: control.iconSize horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter anchors.centerIn: parent - color:control.iconColor - text: (String.fromCharCode(iconSource).toString(16)); + iconColor: control.iconColor + iconSource: control.iconSource; } FluTooltip{ id:tool_tip From 3007f8f3df106c268c5bd38b5be462ce148f5575 Mon Sep 17 00:00:00 2001 From: Mentalflow <312902918@qq.com> Date: Thu, 25 May 2023 21:49:16 +0800 Subject: [PATCH 2/3] Add FluPopup for universally use. --- .../FluentUI/Controls/FluContentDialog.qml | 49 ++----------------- src/imports/FluentUI/Controls/FluPopup.qml | 46 +++++++++++++++++ 2 files changed, 50 insertions(+), 45 deletions(-) create mode 100644 src/imports/FluentUI/Controls/FluPopup.qml diff --git a/src/imports/FluentUI/Controls/FluContentDialog.qml b/src/imports/FluentUI/Controls/FluContentDialog.qml index 75823d33..171a973e 100644 --- a/src/imports/FluentUI/Controls/FluContentDialog.qml +++ b/src/imports/FluentUI/Controls/FluContentDialog.qml @@ -4,15 +4,13 @@ import QtQuick.Controls import QtQuick.Window import FluentUI -Popup { +FluPopup { id: popup property string title: "Title" property string message: "Message" property string neutralText: "Neutral" property string negativeText: "Negative" property string positiveText: "Positive" - property alias blurSource: blur.sourceItem - property bool blurBackground: true signal neutralClicked signal negativeClicked signal positiveClicked @@ -27,53 +25,14 @@ Popup { return 400 return Math.min(Window.window.width,400) } - modal:true - anchors.centerIn: Overlay.overlay - closePolicy: Popup.CloseOnEscape - background:Item{} - enter: Transition { - reversible: true - NumberAnimation { - properties: "opacity,scale" - from:0 - to:1 - duration: 167 - easing.type: Easing.BezierSpline - easing.bezierCurve: [ 0, 0, 0, 1 ] - } - } - exit:Transition { - NumberAnimation { - properties: "opacity,scale" - from:1 - to:0 - duration: 167 - easing.type: Easing.BezierSpline - easing.bezierCurve: [ 1, 0, 0, 0 ] - } - } - contentItem: - Rectangle { + + Rectangle { id:layout_content anchors.fill: parent implicitWidth:minWidth implicitHeight: text_title.height + text_message.height + layout_actions.height color: 'transparent' radius:5 - FluAcrylic{ - id:blur - anchors{ - top:parent.top - left: parent.left - right: parent.right - bottom: layout_actions.bottom - } - height: parent.height - color: FluTheme.dark ? Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(249/255,249/255,249/255,1) - rectX: popup.x - rectY: popup.y - acrylicOpacity:blurBackground ? 0.8 : 1 - } FluText{ id:text_title font: FluTextStyle.TitleLarge @@ -107,7 +66,7 @@ Popup { id:layout_actions height: 68 radius: 5 - color: FluTheme.dark ? Qt.rgba(32/255,32/255,32/255, blurBackground ? blur.acrylicOpacity - 0.4 : 1) : Qt.rgba(243/255,243/255,243/255,blurBackground ? blur.acrylicOpacity - 0.4 : 1) + color: FluTheme.dark ? Qt.rgba(32/255,32/255,32/255, blurBackground ? blurOpacity - 0.4 : 1) : Qt.rgba(243/255,243/255,243/255,blurBackground ? blurOpacity - 0.4 : 1) anchors{ top:text_message.bottom left: parent.left diff --git a/src/imports/FluentUI/Controls/FluPopup.qml b/src/imports/FluentUI/Controls/FluPopup.qml new file mode 100644 index 00000000..b58f0efa --- /dev/null +++ b/src/imports/FluentUI/Controls/FluPopup.qml @@ -0,0 +1,46 @@ +import QtQuick +import QtQuick.Layouts +import QtQuick.Controls +import QtQuick.Window +import FluentUI + +Popup { + id: popup + padding: 0 + modal:true + anchors.centerIn: Overlay.overlay + closePolicy: Popup.CloseOnEscape + property alias blurSource: blur.sourceItem + property bool blurBackground: true + property alias blurOpacity: blur.acrylicOpacity + + enter: Transition { + reversible: true + NumberAnimation { + properties: "opacity,scale" + from:0 + to:1 + duration: 167 + easing.type: Easing.BezierSpline + easing.bezierCurve: [ 0, 0, 0, 1 ] + } + } + exit:Transition { + NumberAnimation { + properties: "opacity,scale" + from:1 + to:0 + duration: 167 + easing.type: Easing.BezierSpline + easing.bezierCurve: [ 1, 0, 0, 0 ] + } + } + + background: FluAcrylic{ + id:blur + color: FluTheme.dark ? Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(249/255,249/255,249/255,1) + rectX: popup.x + rectY: popup.y + acrylicOpacity:blurBackground ? 0.8 : 1 + } +} From e3abd96b8ea5cddf509cfa9eda1af61c97e68aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Fri, 26 May 2023 07:36:39 +0800 Subject: [PATCH 3/3] update --- src/imports/FluentUI/Controls/FluTextBoxBackground.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/imports/FluentUI/Controls/FluTextBoxBackground.qml b/src/imports/FluentUI/Controls/FluTextBoxBackground.qml index 41fd95da..032f9117 100644 --- a/src/imports/FluentUI/Controls/FluTextBoxBackground.qml +++ b/src/imports/FluentUI/Controls/FluTextBoxBackground.qml @@ -48,7 +48,7 @@ Rectangle{ } Behavior on height{ NumberAnimation{ - duration: 167 + duration: 83 easing.type: Easing.BezierSpline easing.bezierCurve: [ 1, 0, 0, 0 ] }