From f616a2da6a0916b72538d3d1d808ab0398cd1faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Wed, 27 Mar 2024 14:13:36 +0800 Subject: [PATCH] update --- example/example_en_US.ts | 86 +++++++------- example/example_zh_CN.ts | 86 +++++++------- example/qml/page/T_Settings.qml | 9 -- example/qml/window/MainWindow.qml | 3 - example/res/template/src/App.qml.in | 4 +- src/FluEventBus.cpp | 23 ---- src/FluEventBus.h | 41 ------- src/FluFramelessHelper.cpp | 105 ++++++++---------- src/FluFramelessHelper.h | 8 +- src/FluentUI.cpp | 7 +- .../imports/FluentUI/Controls/FluEvent.qml | 15 +++ .../imports/FluentUI/Controls/FluEventBus.qml | 24 ++++ src/Qt5/imports/FluentUI/Controls/qmldir | 1 + src/Qt5/imports/FluentUI/plugins.qmltypes | 99 ++++++++++++----- src/Qt5/imports/FluentUI/qmldir | 2 + src/Qt5/imports/fluentui.qrc | 2 + .../imports/FluentUI/Controls/FluEvent.qml | 15 +++ .../imports/FluentUI/Controls/FluEventBus.qml | 24 ++++ src/Qt6/imports/FluentUI/Controls/qmldir | 1 + 19 files changed, 299 insertions(+), 256 deletions(-) delete mode 100644 src/FluEventBus.cpp delete mode 100644 src/FluEventBus.h create mode 100644 src/Qt5/imports/FluentUI/Controls/FluEvent.qml create mode 100644 src/Qt5/imports/FluentUI/Controls/FluEventBus.qml create mode 100644 src/Qt6/imports/FluentUI/Controls/FluEvent.qml create mode 100644 src/Qt6/imports/FluentUI/Controls/FluEventBus.qml diff --git a/example/example_en_US.ts b/example/example_en_US.ts index bd858af1..e39ea575 100644 --- a/example/example_en_US.ts +++ b/example/example_en_US.ts @@ -535,104 +535,104 @@ MainWindow - + Dark Mode - - + + Quit - + Are you sure you want to exit the program? - + Minimize - + Friendly Reminder - + FluentUI is hidden from the tray, click on the tray to activate the window again - - + + Cancel - + Open in Separate Window - + Click Time - + Search - + Finish - + Next - + Previous - + Here you can switch to night mode. - + Hide Easter eggs - + Try a few more clicks!! - + Upgrade Tips - + FluentUI is currently up to date - + -- The current app version - + Now go and download the new version? @@ -641,17 +641,17 @@ Updated content: - + OK - + The current version is already the latest - + The network is abnormal @@ -1741,92 +1741,92 @@ My only desire is to be permitted to drive out the traitors and restore the Han. - + Current Version - + Check for Updates - + Use System AppBar - + Fits AppBar Windows - + Friendly Reminder - + This action requires a restart of the program to take effect, is it restarted? - + Cancel - + OK - + Dark Mode - + System - + Light - + Dark - + Navigation View Display Mode - + Open - + Compact - + Minimal - + Auto - + Language diff --git a/example/example_zh_CN.ts b/example/example_zh_CN.ts index d2ba204a..763c76b4 100644 --- a/example/example_zh_CN.ts +++ b/example/example_zh_CN.ts @@ -535,104 +535,104 @@ MainWindow - + Dark Mode 夜间模式 - - + + Quit 退出 - + Are you sure you want to exit the program? 您确定要退出程序吗 - + Minimize 最小化 - + Friendly Reminder 友情提示 - + FluentUI is hidden from the tray, click on the tray to activate the window again FluentUI 在托盘中处于隐藏状态,单击托盘以再次激活窗口 - - + + Cancel 取消 - + Open in Separate Window 在独立窗口中打开 - + Click Time 点击次数 - + Search 搜索 - + Finish 完成 - + Next 下一步 - + Previous 上一步 - + Here you can switch to night mode. 在这里,您可以切换到夜间模式。 - + Hide Easter eggs 隐藏彩蛋 - + Try a few more clicks!! 再试几下!! - + Upgrade Tips 升级提示 - + FluentUI is currently up to date FluentUI 目前最新版本 - + -- The current app version -- 当前应用版本 - + Now go and download the new version? @@ -645,17 +645,17 @@ Updated content: - + OK 确定 - + The current version is already the latest 当前版本已经是最新版本 - + The network is abnormal 网络异常 @@ -1790,92 +1790,92 @@ My only desire is to be permitted to drive out the traitors and restore the Han. 设置 - + Current Version 当前版本 - + Check for Updates 检查更新 - + Use System AppBar 使用系统应用栏 - + Fits AppBar Windows 沉浸式应用栏 - + Friendly Reminder 友情提示 - + This action requires a restart of the program to take effect, is it restarted? 此操作需要重启程序才能生效,是否重新启动? - + Cancel 取消 - + OK 确定 - + Dark Mode 夜间模式 - + System 跟随系统 - + Light 浅色 - + Dark 深色 - + Navigation View Display Mode 导航视图 - + Open 开放 - + Compact 紧凑 - + Minimal 极简 - + Auto 自动 - + Language 语言 diff --git a/example/qml/page/T_Settings.qml b/example/qml/page/T_Settings.qml index a36fd0e1..87837b9d 100644 --- a/example/qml/page/T_Settings.qml +++ b/example/qml/page/T_Settings.qml @@ -11,21 +11,12 @@ FluScrollablePage{ title: qsTr("Settings") FluEvent{ - id:event_checkupdate_finish name: "checkUpdateFinish" onTriggered: { btn_checkupdate.loading = false } } - Component.onCompleted: { - FluEventBus.registerEvent(event_checkupdate_finish) - } - - Component.onDestruction: { - FluEventBus.unRegisterEvent(event_checkupdate_finish) - } - FluArea{ Layout.fillWidth: true Layout.topMargin: 20 diff --git a/example/qml/window/MainWindow.qml b/example/qml/window/MainWindow.qml index 7cee4815..90e6840a 100644 --- a/example/qml/window/MainWindow.qml +++ b/example/qml/window/MainWindow.qml @@ -29,7 +29,6 @@ FluWindow { } FluEvent{ - id:event_checkupdate name: "checkUpdate" onTriggered: { checkUpdate(false) @@ -50,11 +49,9 @@ FluWindow { Component.onCompleted: { checkUpdate(true) - FluEventBus.registerEvent(event_checkupdate) } Component.onDestruction: { - FluEventBus.unRegisterEvent(event_checkupdate) FluRouter.exit() } diff --git a/example/res/template/src/App.qml.in b/example/res/template/src/App.qml.in index a79eba28..0dabb565 100644 --- a/example/res/template/src/App.qml.in +++ b/example/res/template/src/App.qml.in @@ -4,12 +4,12 @@ import QtQuick.Controls 2.15 import QtQuick.Layouts 1.15 import FluentUI 1.0 -Item { +FluLauncher { id: app Component.onCompleted: { FluApp.init(app) FluApp.windowIcon = "qrc:/logo.ico" - FluApp.routes = { + FluRouter.routes = { "/":"qrc:/main.qml", } FluRouter.navigate("/") diff --git a/src/FluEventBus.cpp b/src/FluEventBus.cpp deleted file mode 100644 index e9472110..00000000 --- a/src/FluEventBus.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "FluEventBus.h" - -FluEvent::FluEvent(QObject *parent):QObject{parent}{ -} - -FluEventBus::FluEventBus(QObject *parent):QObject{parent}{ -} - -void FluEventBus::registerEvent(FluEvent* event){ - _eventData.append(event); -} - -void FluEventBus::unRegisterEvent(FluEvent* event){ - _eventData.removeOne(event); -} - -void FluEventBus::post(const QString& name,const QMap& data){ - foreach (auto event, _eventData) { - if(event->name()==name){ - Q_EMIT event->triggered(data); - } - } -} diff --git a/src/FluEventBus.h b/src/FluEventBus.h deleted file mode 100644 index badddf90..00000000 --- a/src/FluEventBus.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef FLUEVENTBUS_H -#define FLUEVENTBUS_H - -#include -#include -#include "stdafx.h" -#include "singleton.h" - -/** - * @brief The FluEvent class - */ -class FluEvent : public QObject{ - Q_OBJECT - Q_PROPERTY_AUTO(QString,name); - QML_NAMED_ELEMENT(FluEvent) -public: - explicit FluEvent(QObject *parent = nullptr); - Q_SIGNAL void triggered(QMap data); -}; - -/** - * @brief The FluEventBus class - */ -class FluEventBus : public QObject -{ - Q_OBJECT - QML_NAMED_ELEMENT(FluEventBus) - QML_SINGLETON -private: - explicit FluEventBus(QObject *parent = nullptr); -public: - SINGLETON(FluEventBus) - static FluEventBus *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();} - Q_INVOKABLE void registerEvent(FluEvent* event); - Q_INVOKABLE void unRegisterEvent(FluEvent* event); - Q_INVOKABLE void post(const QString& name,const QMap& params = {}); -private: - QList _eventData; -}; - -#endif // FLUEVENTBUS_H diff --git a/src/FluFramelessHelper.cpp b/src/FluFramelessHelper.cpp index 14d3ac0f..f31a3e13 100644 --- a/src/FluFramelessHelper.cpp +++ b/src/FluFramelessHelper.cpp @@ -39,12 +39,12 @@ static inline bool isCompositionEnabled(){ FramelessEventFilter::FramelessEventFilter(FluFramelessHelper* helper){ _helper = helper; - _current = _helper->window->winId(); + _current = _helper->window_->winId(); } bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, QT_NATIVE_EVENT_RESULT_TYPE *result){ #ifdef Q_OS_WIN - if ((eventType != qtNativeEventType()) || !message || _helper.isNull() || _helper->window.isNull()) { + if ((eventType != qtNativeEventType()) || !message || _helper.isNull() || _helper->window_.isNull()) { return false; } const auto msg = static_cast(message); @@ -174,8 +174,8 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * minmaxInfo->ptMaxSize.x = 0; minmaxInfo->ptMaxSize.y = 0; #else - auto pixelRatio = _helper->window->devicePixelRatio(); - auto geometry = _helper->window->screen()->availableGeometry(); + auto pixelRatio = _helper->window_->devicePixelRatio(); + auto geometry = _helper->window_->screen()->availableGeometry(); RECT rect; SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0); minmaxInfo->ptMaxPosition.x = rect.left - offsetXY.x(); @@ -192,15 +192,15 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * const bool altPressed = ((wParam == VK_MENU) || (::GetKeyState(VK_MENU) < 0)); const bool spacePressed = ((wParam == VK_SPACE) || (::GetKeyState(VK_SPACE) < 0)); if (altPressed && spacePressed) { - auto pos = _helper->window->position(); + auto pos = _helper->window_->position(); _helper->showSystemMenu(QPoint(pos.x(),pos.y()+_helper->getAppBarHeight())); } }else if(uMsg == WM_SYSCOMMAND){ if(wParam == SC_MINIMIZE){ - if(_helper->window->transientParent()){ - _helper->window->transientParent()->showMinimized(); + if(_helper->window_->transientParent()){ + _helper->window_->transientParent()->showMinimized(); }else{ - _helper->window->showMinimized(); + _helper->window_->showMinimized(); } return true; } @@ -211,8 +211,8 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * return false; } -FluFramelessHelper::FluFramelessHelper(QObject *parent) - : QObject{parent} +FluFramelessHelper::FluFramelessHelper(QQuickItem *parent) + : QQuickItem{parent} { } @@ -222,36 +222,36 @@ void FluFramelessHelper::classBegin(){ void FluFramelessHelper::_updateCursor(int edges){ switch (edges) { case 0: - window->setCursor(Qt::ArrowCursor); + window_->setCursor(Qt::ArrowCursor); break; case Qt::LeftEdge: case Qt::RightEdge: - window->setCursor(Qt::SizeHorCursor); + window_->setCursor(Qt::SizeHorCursor); break; case Qt::TopEdge: case Qt::BottomEdge: - window->setCursor(Qt::SizeVerCursor); + window_->setCursor(Qt::SizeVerCursor); break; case Qt::LeftEdge | Qt::TopEdge: case Qt::RightEdge | Qt::BottomEdge: - window->setCursor(Qt::SizeFDiagCursor); + window_->setCursor(Qt::SizeFDiagCursor); break; case Qt::RightEdge | Qt::TopEdge: case Qt::LeftEdge | Qt::BottomEdge: - window->setCursor(Qt::SizeBDiagCursor); + window_->setCursor(Qt::SizeBDiagCursor); break; } } bool FluFramelessHelper::eventFilter(QObject *obj, QEvent *ev){ - if (!window.isNull() && window->flags()) { + if (!window_.isNull() && window_->flags()) { switch (ev->type()) { case QEvent::MouseButtonPress: if(_edges!=0){ QMouseEvent *event = static_cast(ev); if(event->button() == Qt::LeftButton){ _updateCursor(_edges); - window->startSystemResize(Qt::Edges(_edges)); + window_->startSystemResize(Qt::Edges(_edges)); } } break; @@ -272,7 +272,7 @@ bool FluFramelessHelper::eventFilter(QObject *obj, QEvent *ev){ #else event->position().toPoint(); #endif - if(p.x() >= _margins && p.x() <= (window->width() - _margins) && p.y() >= _margins && p.y() <= (window->height() - _margins)){ + if(p.x() >= _margins && p.x() <= (window_->width() - _margins) && p.y() >= _margins && p.y() <= (window_->height() - _margins)){ if(_edges != 0){ _edges = 0; _updateCursor(_edges); @@ -283,13 +283,13 @@ bool FluFramelessHelper::eventFilter(QObject *obj, QEvent *ev){ if ( p.x() < _margins ) { _edges |= Qt::LeftEdge; } - if ( p.x() > (window->width() - _margins) ) { + if ( p.x() > (window_->width() - _margins) ) { _edges |= Qt::RightEdge; } if ( p.y() < _margins ) { _edges |= Qt::TopEdge; } - if ( p.y() > (window->height() - _margins) ) { + if ( p.y() > (window_->height() - _margins) ) { _edges |= Qt::BottomEdge; } _updateCursor(_edges); @@ -303,38 +303,31 @@ bool FluFramelessHelper::eventFilter(QObject *obj, QEvent *ev){ } void FluFramelessHelper::componentComplete(){ - auto o = parent(); - do { - window = qobject_cast(o); - if (window) { - break; - } - o = o->parent(); - } while (nullptr != o); - if(!window.isNull()){ - _stayTop = QQmlProperty(window,"stayTop"); - _screen = QQmlProperty(window,"screen"); - _fixSize = QQmlProperty(window,"fixSize"); - _realHeight = QQmlProperty(window,"_realHeight"); - _realWidth = QQmlProperty(window,"_realWidth"); - _appBarHeight = QQmlProperty(window,"_appBarHeight"); - _appBar = window->property("appBar"); + this->window_ = window(); + if(!window_.isNull()){ + _stayTop = QQmlProperty(window_,"stayTop"); + _screen = QQmlProperty(window_,"screen"); + _fixSize = QQmlProperty(window_,"fixSize"); + _realHeight = QQmlProperty(window_,"_realHeight"); + _realWidth = QQmlProperty(window_,"_realWidth"); + _appBarHeight = QQmlProperty(window_,"_appBarHeight"); + _appBar = window_->property("appBar"); #ifdef Q_OS_WIN if(!_appBar.isNull()){ _appBar.value()->setProperty("systemMoveEnable",false); } - window->setFlags((window->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint | Qt::FramelessWindowHint); + window_->setFlags((window_->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint | Qt::FramelessWindowHint); #if QT_VERSION < QT_VERSION_CHECK(6,0,0) if(FluTools::getInstance()->isSoftware()){ - window->setFlag(Qt::FramelessWindowHint,false); + window_->setFlag(Qt::FramelessWindowHint,false); } #endif if(resizeable()){ - window->setFlag(Qt::WindowMaximizeButtonHint); + window_->setFlag(Qt::WindowMaximizeButtonHint); } _nativeEvent =new FramelessEventFilter(this); qApp->installNativeEventFilter(_nativeEvent); - HWND hwnd = reinterpret_cast(window->winId()); + HWND hwnd = reinterpret_cast(window_->winId()); DWORD style = ::GetWindowLongPtr(hwnd, GWL_STYLE); if(resizeable()){ ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME); @@ -348,16 +341,16 @@ void FluFramelessHelper::componentComplete(){ } SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); #else - window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window); - window->installEventFilter(this); + window_->setFlags((window_->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window); + window_->installEventFilter(this); #endif int w = _realWidth.read().toInt(); int h = _realHeight.read().toInt()+_appBarHeight.read().toInt(); if(!resizeable()){ - window->setMaximumSize(QSize(w,h)); - window->setMinimumSize(QSize(w,h)); + window_->setMaximumSize(QSize(w,h)); + window_->setMinimumSize(QSize(w,h)); } - window->resize(QSize(w,h)); + window_->resize(QSize(w,h)); _onStayTopChange(); _stayTop.connectNotifySignal(this,SLOT(_onStayTopChange())); _screen.connectNotifySignal(this,SLOT(_onScreenChanged())); @@ -367,7 +360,7 @@ void FluFramelessHelper::componentComplete(){ void FluFramelessHelper::_onScreenChanged(){ #ifdef Q_OS_WIN - HWND hwnd = reinterpret_cast(window->winId()); + HWND hwnd = reinterpret_cast(window_->winId()); ::SetWindowPos(hwnd,0,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOOWNERZORDER); ::RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); #endif @@ -375,7 +368,7 @@ void FluFramelessHelper::_onScreenChanged(){ void FluFramelessHelper::showSystemMenu(QPoint point){ #ifdef Q_OS_WIN - HWND hwnd = reinterpret_cast(window->winId()); + HWND hwnd = reinterpret_cast(window_->winId()); DWORD style = ::GetWindowLongPtr(hwnd,GWL_STYLE); ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_SYSMENU); const HMENU hMenu = ::GetSystemMenu(hwnd, FALSE); @@ -393,7 +386,7 @@ void FluFramelessHelper::showSystemMenu(QPoint point){ ::EnableMenuItem(hMenu,SC_SIZE,MFS_DISABLED); ::EnableMenuItem(hMenu,SC_MAXIMIZE,MFS_DISABLED); } - const int result = ::TrackPopupMenu(hMenu, (TPM_RETURNCMD | (QGuiApplication::isRightToLeft() ? TPM_RIGHTALIGN : TPM_LEFTALIGN)), point.x()*window->devicePixelRatio(), point.y()*window->devicePixelRatio(), 0, hwnd, nullptr); + const int result = ::TrackPopupMenu(hMenu, (TPM_RETURNCMD | (QGuiApplication::isRightToLeft() ? TPM_RIGHTALIGN : TPM_LEFTALIGN)), point.x()*window_->devicePixelRatio(), point.y()*window_->devicePixelRatio(), 0, hwnd, nullptr); if (result != FALSE) { ::PostMessageW(hwnd, WM_SYSCOMMAND, result, 0); } @@ -403,7 +396,7 @@ void FluFramelessHelper::showSystemMenu(QPoint point){ void FluFramelessHelper::showMaximized(){ #ifdef Q_OS_WIN - HWND hwnd = reinterpret_cast(window->winId()); + HWND hwnd = reinterpret_cast(window_->winId()); ::ShowWindow(hwnd,3); #endif } @@ -411,25 +404,25 @@ void FluFramelessHelper::showMaximized(){ void FluFramelessHelper::_onStayTopChange(){ bool isStayTop = _stayTop.read().toBool(); #ifdef Q_OS_WIN - HWND hwnd = reinterpret_cast(window->winId()); + HWND hwnd = reinterpret_cast(window_->winId()); if(isStayTop){ ::SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); }else{ ::SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } #else - window->setFlag(Qt::WindowStaysOnTopHint,isStayTop); + window_->setFlag(Qt::WindowStaysOnTopHint,isStayTop); #endif } FluFramelessHelper::~FluFramelessHelper(){ - if (!window.isNull()) { - window->setFlags(Qt::Window); + if (!window_.isNull()) { + window_->setFlags(Qt::Window); #ifdef Q_OS_WIN qApp->removeNativeEventFilter(_nativeEvent); delete _nativeEvent; #endif - window->removeEventFilter(this); + window_->removeEventFilter(this); } } @@ -488,11 +481,11 @@ bool FluFramelessHelper::resizeable(){ } bool FluFramelessHelper::maximized(){ - return window->visibility() == QWindow::Maximized; + return window_->visibility() == QWindow::Maximized; } bool FluFramelessHelper::fullScreen(){ - return window->visibility() == QWindow::FullScreen; + return window_->visibility() == QWindow::FullScreen; } int FluFramelessHelper::getMargins(){ diff --git a/src/FluFramelessHelper.h b/src/FluFramelessHelper.h index a54cdc26..c39602f0 100644 --- a/src/FluFramelessHelper.h +++ b/src/FluFramelessHelper.h @@ -6,6 +6,7 @@ #include #include #include +#include #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) using QT_NATIVE_EVENT_RESULT_TYPE = qintptr; @@ -33,13 +34,12 @@ public: /** * @brief The FluFramelessHelper class */ -class FluFramelessHelper : public QObject, public QQmlParserStatus +class FluFramelessHelper : public QQuickItem { Q_OBJECT - Q_INTERFACES(QQmlParserStatus) QML_NAMED_ELEMENT(FluFramelessHelper) public: - explicit FluFramelessHelper(QObject *parent = nullptr); + explicit FluFramelessHelper(QQuickItem *parent = nullptr); ~FluFramelessHelper(); void classBegin() override; void componentComplete() override; @@ -62,7 +62,7 @@ private: Q_SLOT void _onStayTopChange(); Q_SLOT void _onScreenChanged(); public: - QPointer window = nullptr; + QPointer window_ = nullptr; private: FramelessEventFilter* _nativeEvent = nullptr; QQmlProperty _stayTop; diff --git a/src/FluentUI.cpp b/src/FluentUI.cpp index 666d9249..6a8b4e02 100644 --- a/src/FluentUI.cpp +++ b/src/FluentUI.cpp @@ -9,7 +9,6 @@ #include "FluTextStyle.h" #include "FluWatermark.h" #include "FluCaptcha.h" -#include "FluEventBus.h" #include "FluTreeModel.h" #include "FluRectangle.h" #include "FluFramelessHelper.h" @@ -24,11 +23,12 @@ void FluentUI::registerTypes(QQmlEngine *engine){ void FluentUI::registerTypes(const char *uri){ #if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0)) Q_INIT_RESOURCE(fluentui); + + //@uri FluentUI qmlRegisterType(uri,major,minor,"FluQrCodeItem"); qmlRegisterType(uri,major,minor,"FluCaptcha"); qmlRegisterType(uri,major,minor,"FluWatermark"); qmlRegisterType(uri,major,minor,"FluAccentColor"); - qmlRegisterType(uri,major,minor,"FluEvent"); qmlRegisterType(uri,major,minor,"FluTreeModel"); qmlRegisterType(uri,major,minor,"FluRectangle"); qmlRegisterType(uri,major,minor,"FluFramelessHelper"); @@ -123,7 +123,9 @@ void FluentUI::registerTypes(const char *uri){ qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluSplitLayout.qml"),uri,major,minor,"FluSplitLayout"); qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluWindowResultLauncher.qml"),uri,major,minor,"FluWindowResultLauncher"); qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluLauncher.qml"),uri,major,minor,"FluLauncher"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluEvent.qml"),uri,major,minor,"FluEvent"); qmlRegisterSingletonType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRouter.qml"),uri,major,minor,"FluRouter"); + qmlRegisterSingletonType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluEventBus.qml"),uri,major,minor,"FluEventBus"); qmlRegisterUncreatableMetaObject(Fluent_Awesome::staticMetaObject, uri,major,minor,"FluentIcons", "Access to enums & flags only"); qmlRegisterUncreatableMetaObject(FluThemeType::staticMetaObject, uri,major,minor,"FluThemeType", "Access to enums & flags only"); @@ -153,5 +155,4 @@ void FluentUI::initializeEngine(QQmlEngine *engine, const char *uri){ engine->rootContext()->setContextProperty("FluTheme",FluTheme::getInstance()); engine->rootContext()->setContextProperty("FluTools",FluTools::getInstance()); engine->rootContext()->setContextProperty("FluTextStyle",FluTextStyle::getInstance()); - engine->rootContext()->setContextProperty("FluEventBus",FluEventBus::getInstance()); } diff --git a/src/Qt5/imports/FluentUI/Controls/FluEvent.qml b/src/Qt5/imports/FluentUI/Controls/FluEvent.qml new file mode 100644 index 00000000..37bfdc13 --- /dev/null +++ b/src/Qt5/imports/FluentUI/Controls/FluEvent.qml @@ -0,0 +1,15 @@ +import QtQuick 2.15 +import QtQuick.Controls 2.15 +import FluentUI 1.0 + +QtObject { + id:control + property string name + signal triggered(var data) + Component.onCompleted: { + FluEventBus.register(control) + } + Component.onDestruction: { + FluEventBus.unregister(control) + } +} diff --git a/src/Qt5/imports/FluentUI/Controls/FluEventBus.qml b/src/Qt5/imports/FluentUI/Controls/FluEventBus.qml new file mode 100644 index 00000000..2ce47053 --- /dev/null +++ b/src/Qt5/imports/FluentUI/Controls/FluEventBus.qml @@ -0,0 +1,24 @@ +pragma Singleton + +import QtQuick 2.15 + +QtObject { + property var events: [] + function register(event){ + events.push(event) + } + function unregister(event){ + var index = events.indexOf(event) + if (index !== -1) { + events.splice(index, 1) + } + } + function post(name,data = {}){ + for(var i =0 ;i< events.length; i++){ + var item = events[i] + if(item.name === name){ + item.triggered(data) + } + } + } +} diff --git a/src/Qt5/imports/FluentUI/Controls/qmldir b/src/Qt5/imports/FluentUI/Controls/qmldir index 672e5b90..a4b6cc13 100644 --- a/src/Qt5/imports/FluentUI/Controls/qmldir +++ b/src/Qt5/imports/FluentUI/Controls/qmldir @@ -1 +1,2 @@ singleton FluRouter 1.0 FluRouter.qml +singleton FluEventBus 1.0 FluEventBus.qml diff --git a/src/Qt5/imports/FluentUI/plugins.qmltypes b/src/Qt5/imports/FluentUI/plugins.qmltypes index 8fcb659b..7155b7b1 100644 --- a/src/Qt5/imports/FluentUI/plugins.qmltypes +++ b/src/Qt5/imports/FluentUI/plugins.qmltypes @@ -64,20 +64,10 @@ Module { } } } - Component { - name: "FluEvent" - prototype: "QObject" - exports: ["FluentUI/FluEvent 1.0"] - exportMetaObjectRevisions: [0] - Property { name: "name"; type: "string" } - Signal { - name: "triggered" - Parameter { name: "data"; type: "QVariantMap" } - } - } Component { name: "FluFramelessHelper" - prototype: "QObject" + defaultProperty: "data" + prototype: "QQuickItem" exports: ["FluentUI/FluFramelessHelper 1.0"] exportMetaObjectRevisions: [0] Signal { name: "loadCompleted" } @@ -2329,23 +2319,27 @@ Module { Property { name: "normalColor"; type: "QColor" } Property { name: "hoverColor"; type: "QColor" } Property { name: "disableColor"; type: "QColor" } + Property { name: "dividerColor"; type: "QColor" } Property { name: "textColor"; type: "QColor" } } Component { - prototype: "QQuickRectangle" + prototype: "QQuickButton" name: "FluentUI/FluCalendarPicker 1.0" exports: ["FluentUI/FluCalendarPicker 1.0"] exportMetaObjectRevisions: [0] isComposite: true defaultProperty: "data" - Property { name: "dividerColor"; type: "QColor" } - Property { name: "hoverColor"; type: "QColor" } - Property { name: "normalColor"; type: "QColor" } - Property { name: "text"; type: "string" } Property { name: "from"; type: "QDateTime" } Property { name: "to"; type: "QDateTime" } Property { name: "current"; type: "QVariant" } Signal { name: "accepted" } + Property { name: "disabled"; type: "bool" } + Property { name: "contentDescription"; type: "string" } + Property { name: "normalColor"; type: "QColor" } + Property { name: "hoverColor"; type: "QColor" } + Property { name: "disableColor"; type: "QColor" } + Property { name: "dividerColor"; type: "QColor" } + Property { name: "textColor"; type: "QColor" } } Component { prototype: "QQuickItem" @@ -2531,15 +2525,12 @@ Module { Property { name: "textColor"; type: "QColor" } } Component { - prototype: "QQuickRectangle" + prototype: "QQuickButton" name: "FluentUI/FluDatePicker 1.0" exports: ["FluentUI/FluDatePicker 1.0"] exportMetaObjectRevisions: [0] isComposite: true defaultProperty: "data" - Property { name: "dividerColor"; type: "QColor" } - Property { name: "hoverColor"; type: "QColor" } - Property { name: "normalColor"; type: "QColor" } Property { name: "showYear"; type: "bool" } Property { name: "current"; type: "QVariant" } Property { name: "yearText"; type: "string" } @@ -2566,6 +2557,13 @@ Module { Parameter { name: "year"; type: "QVariant" } Parameter { name: "month"; type: "QVariant" } } + Property { name: "disabled"; type: "bool" } + Property { name: "contentDescription"; type: "string" } + Property { name: "normalColor"; type: "QColor" } + Property { name: "hoverColor"; type: "QColor" } + Property { name: "disableColor"; type: "QColor" } + Property { name: "dividerColor"; type: "QColor" } + Property { name: "textColor"; type: "QColor" } } Component { prototype: "QQuickItem" @@ -2594,6 +2592,44 @@ Module { Property { name: "window"; type: "QVariant" } Property { name: "contentData"; type: "QObject"; isList: true; isReadonly: true } } + Component { + prototype: "QObject" + name: "FluentUI/FluEvent 1.0" + exports: ["FluentUI/FluEvent 1.0"] + exportMetaObjectRevisions: [0] + isComposite: true + Property { name: "name"; type: "string" } + Signal { + name: "triggered" + Parameter { name: "data"; type: "QVariant" } + } + } + Component { + prototype: "QObject" + name: "FluentUI/FluEventBus 1.0" + exports: ["FluentUI/FluEventBus 1.0"] + exportMetaObjectRevisions: [0] + isComposite: true + isCreatable: false + isSingleton: true + Property { name: "events"; type: "QVariant" } + Method { + name: "register" + type: "QVariant" + Parameter { name: "event"; type: "QVariant" } + } + Method { + name: "unregister" + type: "QVariant" + Parameter { name: "event"; type: "QVariant" } + } + Method { + name: "post" + type: "QVariant" + Parameter { name: "name"; type: "QVariant" } + Parameter { name: "data"; type: "QVariant" } + } + } Component { prototype: "QQuickItem" name: "FluentUI/FluExpander 1.0" @@ -2779,6 +2815,7 @@ Module { Property { name: "normalColor"; type: "QColor" } Property { name: "hoverColor"; type: "QColor" } Property { name: "disableColor"; type: "QColor" } + Property { name: "dividerColor"; type: "QColor" } Property { name: "textColor"; type: "QColor" } } Component { @@ -2857,15 +2894,15 @@ Module { defaultProperty: "data" Property { name: "logo"; type: "QUrl" } Property { name: "title"; type: "string" } - Property { name: "items"; type: "FluObject_QMLTYPE_126"; isPointer: true } - Property { name: "footerItems"; type: "FluObject_QMLTYPE_126"; isPointer: true } + Property { name: "items"; type: "FluObject_QMLTYPE_128"; isPointer: true } + Property { name: "footerItems"; type: "FluObject_QMLTYPE_128"; isPointer: true } Property { name: "displayMode"; type: "int" } Property { name: "autoSuggestBox"; type: "QQmlComponent"; isPointer: true } Property { name: "actionItem"; type: "QQmlComponent"; isPointer: true } Property { name: "topPadding"; type: "int" } Property { name: "pageMode"; type: "int" } - Property { name: "navItemRightMenu"; type: "FluMenu_QMLTYPE_39"; isPointer: true } - Property { name: "navItemExpanderRightMenu"; type: "FluMenu_QMLTYPE_39"; isPointer: true } + Property { name: "navItemRightMenu"; type: "FluMenu_QMLTYPE_34"; isPointer: true } + Property { name: "navItemExpanderRightMenu"; type: "FluMenu_QMLTYPE_34"; isPointer: true } Property { name: "navCompactWidth"; type: "int" } Property { name: "navTopMargin"; type: "int" } Property { name: "cellHeight"; type: "int" } @@ -3575,15 +3612,12 @@ Module { Property { name: "textColor"; type: "QColor" } } Component { - prototype: "QQuickRectangle" + prototype: "QQuickButton" name: "FluentUI/FluTimePicker 1.0" exports: ["FluentUI/FluTimePicker 1.0"] exportMetaObjectRevisions: [0] isComposite: true defaultProperty: "data" - Property { name: "dividerColor"; type: "QColor" } - Property { name: "hoverColor"; type: "QColor" } - Property { name: "normalColor"; type: "QColor" } Property { name: "hourFormat"; type: "int" } Property { name: "isH"; type: "int" } Property { name: "current"; type: "QVariant" } @@ -3600,6 +3634,13 @@ Module { Parameter { name: "start"; type: "QVariant" } Parameter { name: "n"; type: "QVariant" } } + Property { name: "disabled"; type: "bool" } + Property { name: "contentDescription"; type: "string" } + Property { name: "normalColor"; type: "QColor" } + Property { name: "hoverColor"; type: "QColor" } + Property { name: "disableColor"; type: "QColor" } + Property { name: "dividerColor"; type: "QColor" } + Property { name: "textColor"; type: "QColor" } } Component { prototype: "QQuickItem" diff --git a/src/Qt5/imports/FluentUI/qmldir b/src/Qt5/imports/FluentUI/qmldir index 007580f6..15594e2c 100644 --- a/src/Qt5/imports/FluentUI/qmldir +++ b/src/Qt5/imports/FluentUI/qmldir @@ -24,6 +24,8 @@ FluCopyableText 1.0 Controls/FluCopyableText.qml FluDatePicker 1.0 Controls/FluDatePicker.qml FluDivider 1.0 Controls/FluDivider.qml FluDropDownButton 1.0 Controls/FluDropDownButton.qml +FluEvent 1.0 Controls/FluEvent.qml +FluEventBus 1.0 Controls/FluEventBus.qml FluExpander 1.0 Controls/FluExpander.qml FluFilledButton 1.0 Controls/FluFilledButton.qml FluFlipView 1.0 Controls/FluFlipView.qml diff --git a/src/Qt5/imports/fluentui.qrc b/src/Qt5/imports/fluentui.qrc index 500802a4..8cdca59f 100644 --- a/src/Qt5/imports/fluentui.qrc +++ b/src/Qt5/imports/fluentui.qrc @@ -105,5 +105,7 @@ FluentUI/Controls/FluRouter.qml FluentUI/Controls/FluWindowResultLauncher.qml FluentUI/Controls/qmldir + FluentUI/Controls/FluEvent.qml + FluentUI/Controls/FluEventBus.qml diff --git a/src/Qt6/imports/FluentUI/Controls/FluEvent.qml b/src/Qt6/imports/FluentUI/Controls/FluEvent.qml new file mode 100644 index 00000000..89169334 --- /dev/null +++ b/src/Qt6/imports/FluentUI/Controls/FluEvent.qml @@ -0,0 +1,15 @@ +import QtQuick +import QtQuick.Controls +import FluentUI + +QtObject { + id:control + property string name + signal triggered(var data) + Component.onCompleted: { + FluEventBus.register(control) + } + Component.onDestruction: { + FluEventBus.unregister(control) + } +} diff --git a/src/Qt6/imports/FluentUI/Controls/FluEventBus.qml b/src/Qt6/imports/FluentUI/Controls/FluEventBus.qml new file mode 100644 index 00000000..108ecbe7 --- /dev/null +++ b/src/Qt6/imports/FluentUI/Controls/FluEventBus.qml @@ -0,0 +1,24 @@ +pragma Singleton + +import QtQuick + +QtObject { + property var events: [] + function register(event){ + events.push(event) + } + function unregister(event){ + var index = events.indexOf(event) + if (index !== -1) { + events.splice(index, 1) + } + } + function post(name,data = {}){ + for(var i =0 ;i< events.length; i++){ + var item = events[i] + if(item.name === name){ + item.triggered(data) + } + } + } +} diff --git a/src/Qt6/imports/FluentUI/Controls/qmldir b/src/Qt6/imports/FluentUI/Controls/qmldir index 5db69e7f..24e4704e 100644 --- a/src/Qt6/imports/FluentUI/Controls/qmldir +++ b/src/Qt6/imports/FluentUI/Controls/qmldir @@ -1 +1,2 @@ singleton FluRouter FluRouter.qml +singleton FluEventBus FluEventBus.qml