From cbd1b2922f346c2ee0df4da54c1c40b9001df33a Mon Sep 17 00:00:00 2001 From: amass <168062547@qq.com> Date: Sat, 31 Aug 2024 12:32:26 +0800 Subject: [PATCH] add code. --- Fluent/CMakeLists.txt | 6 ++ Fluent/FpsItem.cpp | 21 +++++++ Fluent/FpsItem.h | 18 ++++++ Fluent/qml/Event.qml | 15 +++++ Fluent/qml/EventBus.qml | 24 ++++++++ Fluent/qml/RadioButton.qml | 95 +++++++++++++++++++++++++++++ Fluent/qml/RadioButtons.qml | 90 +++++++++++++++++++++++++++ Fluent/qml/RangeSlider.qml | 117 ++++++++++++++++++++++++++++++++++++ Fluent/qml/Window.qml | 2 +- 9 files changed, 387 insertions(+), 1 deletion(-) create mode 100644 Fluent/FpsItem.cpp create mode 100644 Fluent/FpsItem.h create mode 100644 Fluent/qml/Event.qml create mode 100644 Fluent/qml/EventBus.qml create mode 100644 Fluent/qml/RadioButton.qml create mode 100644 Fluent/qml/RadioButtons.qml create mode 100644 Fluent/qml/RangeSlider.qml diff --git a/Fluent/CMakeLists.txt b/Fluent/CMakeLists.txt index d3daa1e..d2385f6 100644 --- a/Fluent/CMakeLists.txt +++ b/Fluent/CMakeLists.txt @@ -20,6 +20,7 @@ qt6_add_qml_module(Fluent App.h App.cpp CircularReveal.h CircularReveal.cpp Colors.h Colors.cpp + FpsItem.h FpsItem.cpp Frameless.h Frameless.cpp Icons.h Rectangle.h Rectangle.cpp @@ -32,6 +33,8 @@ qt6_add_qml_module(Fluent qml/Button.qml qml/ContentDialog.qml qml/ControlBackground.qml + qml/Event.qml + qml/EventBus.qml qml/FilledButton.qml qml/FocusRectangle.qml qml/Icon.qml @@ -42,6 +45,9 @@ qt6_add_qml_module(Fluent qml/Object.qml qml/Popup.qml qml/ProgressRing.qml + qml/RadioButton.qml + qml/RadioButtons.qml + qml/RangeSlider.qml qml/Router.qml qml/ScrollBar.qml qml/Shadow.qml diff --git a/Fluent/FpsItem.cpp b/Fluent/FpsItem.cpp new file mode 100644 index 0000000..66ebf98 --- /dev/null +++ b/Fluent/FpsItem.cpp @@ -0,0 +1,21 @@ +#include "FpsItem.h" + +#include +#include + +FpsItem::FpsItem() { + m_fps = 0; + auto *timer = new QTimer(this); + connect(timer, &QTimer::timeout, this, [this] { + fps(_frameCount); + _frameCount = 0; + }); + connect(this, &QQuickItem::windowChanged, this, [this] { + if (window()) { + connect( + window(), &QQuickWindow::afterRendering, this, [this] { _frameCount++; }, + Qt::DirectConnection); + } + }); + timer->start(1000); +} diff --git a/Fluent/FpsItem.h b/Fluent/FpsItem.h new file mode 100644 index 0000000..ee363d9 --- /dev/null +++ b/Fluent/FpsItem.h @@ -0,0 +1,18 @@ +#ifndef __FPSITEM_H__ +#define __FPSITEM_H__ + +#include "Utilities.h" +#include + +class FpsItem : public QQuickItem { + Q_OBJECT + QML_ELEMENT + Q_PROPERTY_AUTO(int, fps) +public: + FpsItem(); + +private: + int _frameCount = 0; +}; + +#endif // __FPSITEM_H__ diff --git a/Fluent/qml/Event.qml b/Fluent/qml/Event.qml new file mode 100644 index 0000000..8916933 --- /dev/null +++ b/Fluent/qml/Event.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/Fluent/qml/EventBus.qml b/Fluent/qml/EventBus.qml new file mode 100644 index 0000000..108ecbe --- /dev/null +++ b/Fluent/qml/EventBus.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/Fluent/qml/RadioButton.qml b/Fluent/qml/RadioButton.qml new file mode 100644 index 0000000..449c8e2 --- /dev/null +++ b/Fluent/qml/RadioButton.qml @@ -0,0 +1,95 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Controls.Basic +import QtQuick.Layouts +import FluentUI + +Button { + property string contentDescription: "" + property bool disabled: false + property color borderNormalColor: checked ? FluTheme.primaryColor : FluTheme.dark ? Qt.rgba(161/255,161/255,161/255,1) : Qt.rgba(141/255,141/255,141/255,1) + property color borderDisableColor: FluTheme.dark ? Qt.rgba(82/255,82/255,82/255,1) : Qt.rgba(198/255,198/255,198/255,1) + property color normalColor: FluTheme.dark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(1,1,1,1) + property color hoverColor: checked ? FluTheme.dark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(1,1,1,1) : FluTheme.dark ? Qt.rgba(43/255,43/255,43/255,1) : Qt.rgba(222/255,222/255,222/255,1) + property color disableColor: checked ? FluTheme.dark ? Qt.rgba(159/255,159/255,159/255,1) : Qt.rgba(159/255,159/255,159/255,1) : FluTheme.dark ? Qt.rgba(43/255,43/255,43/255,1) : Qt.rgba(222/255,222/255,222/255,1) + property alias textColor: btn_text.textColor + property real size: 18 + property bool textRight: true + property real textSpacing: 6 + property var clickListener : function(){ + checked = !checked + } + Accessible.role: Accessible.Button + Accessible.name: control.text + Accessible.description: contentDescription + Accessible.onPressAction: control.clicked() + id:control + enabled: !disabled + horizontalPadding:2 + verticalPadding: 2 + background: Item{ + FluFocusRectangle{ + visible: control.activeFocus + } + } + focusPolicy:Qt.TabFocus + font:FluTextStyle.Body + onClicked: clickListener() + contentItem: RowLayout{ + spacing: control.textSpacing + layoutDirection:control.textRight ? Qt.LeftToRight : Qt.RightToLeft + Rectangle{ + id:rect_check + width: control.size + height: control.size + radius: size/2 + border.width: { + if(checked&&!enabled){ + return 3 + } + if(pressed){ + if(checked){ + return 4 + } + return 1 + } + if(hovered){ + if(checked){ + return 3 + } + return 1 + } + return checked ? 4 : 1 + } + Behavior on border.width { + enabled: FluTheme.animationEnabled + NumberAnimation{ + duration: 167 + easing.type: Easing.OutCubic + } + } + border.color: { + if(!enabled){ + return borderDisableColor + } + return borderNormalColor + } + color:{ + if(!enabled){ + return disableColor + } + if(hovered){ + return hoverColor + } + return normalColor + } + } + FluText{ + id:btn_text + text: control.text + Layout.alignment: Qt.AlignVCenter + font: control.font + visible: text !== "" + } + } +} diff --git a/Fluent/qml/RadioButtons.qml b/Fluent/qml/RadioButtons.qml new file mode 100644 index 0000000..7bb82e6 --- /dev/null +++ b/Fluent/qml/RadioButtons.qml @@ -0,0 +1,90 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Controls.Basic +import QtQuick.Layouts +import FluentUI + +Item{ + id:control + default property list buttons + property int currentIndex : -1 + property int spacing: 8 + property int orientation: Qt.Vertical + property bool disabled: false + property bool manuallyDisabled: false + QtObject{ + id: d + function updateChecked(){ + if(buttons.length === 0){ + return + } + for(var i = 0;i=0 && currentIndex