This commit is contained in:
zhuzihcu 2023-03-13 18:23:46 +08:00
parent 2b9e9b2159
commit 7282a6f8d1
15 changed files with 256 additions and 50 deletions

View File

@ -12,9 +12,9 @@ Window {
FluApp.init(app,properties)
FluTheme.isDark = false
FluApp.routes = {
"/":"qrc:/MainPage.qml",
"/Setting":"qrc:/SettingPage.qml",
"/About":"qrc:/AboutPage.qml",
"/":"qrc:/page/MainPage.qml",
"/about":"qrc:/page/AboutPage.qml",
"/login":"qrc:/page/LoginPage.qml",
}
FluApp.initialRoute = "/"
FluApp.run()

View File

@ -1,29 +0,0 @@
import QtQuick 2.15
import FluentUI 1.0
FluWindow {
width: 500
height: 600
title:"设置"
FluAppBar{
id:appbar
title:"设置"
}
FluText{
text:"设置"
fontStyle: FluText.Display
anchors.centerIn: parent
MouseArea{
anchors.fill: parent
onClicked: {
FluApp.navigate("/About")
}
}
}
}

54
example/T_Menu.qml Normal file
View File

@ -0,0 +1,54 @@
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtGraphicalEffects 1.15
import FluentUI 1.0
FluScrollablePage{
title:"Menu"
FluButton{
text:"左击菜单"
Layout.topMargin: 20
Layout.leftMargin: 15
onClicked:{
menu.popup()
}
}
FluButton{
text:"右击菜单"
Layout.topMargin: 20
Layout.leftMargin: 15
onClicked: {
showSuccess("请按鼠标右击")
}
MouseArea{
anchors.fill: parent
acceptedButtons: Qt.RightButton
onClicked: {
menu.popup()
}
}
}
FluMenu{
id:menu
FluMenuItem{
text:"删除"
onClicked: {
showError("删除")
}
}
FluMenuItem{
text:"修改"
onClicked: {
showError("修改")
}
}
}
}

65
example/T_Multiwindow.qml Normal file
View File

@ -0,0 +1,65 @@
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtGraphicalEffects 1.15
import FluentUI 1.0
FluScrollablePage{
title:"MultiWindow"
FluArea{
width: parent.width
height: 68
paddings: 10
Layout.topMargin: 20
Column{
spacing: 5
anchors{
verticalCenter: parent.verticalCenter
left: parent.left
}
FluText{
text:"页面跳转,不携带任何参数"
}
FluButton{
text:"点击跳转"
onClicked: {
FluApp.navigate("/about")
}
}
}
}
FluArea{
width: parent.width
height: 68
paddings: 10
Layout.topMargin: 20
Column{
spacing: 5
anchors{
verticalCenter: parent.verticalCenter
left: parent.left
}
FluText{
text:"页面跳转,并携带参数"
}
FluButton{
text:"点击跳转"
onClicked: {
FluApp.navigate("/login",{username:"zhuzichu"})
}
}
}
}
}

View File

@ -0,0 +1,71 @@
import QtQuick 2.15
import QtQuick.Layouts 1.15
import FluentUI 1.0
FluWindow {
id:window
width: 400
height: 400
minimumWidth: 400
minimumHeight: 400
maximumWidth: 400
maximumHeight: 400
modality:2
title:"登录"
onInitArgument:
(argument)=>{
textbox_uesrname.text = argument.username
textbox_password.focus = true
}
FluAppBar{
id:appbar
title:"登录"
}
ColumnLayout{
anchors{
left: parent.left
right: parent.right
verticalCenter: parent.verticalCenter
}
FluAutoSuggestBox{
id:textbox_uesrname
values:["Admin","User"]
placeholderText: "请输入账号"
Layout.preferredWidth: 260
Layout.alignment: Qt.AlignHCenter
}
FluTextBox{
id:textbox_password
Layout.topMargin: 20
Layout.preferredWidth: 260
placeholderText: "请输入密码"
echoMode:TextInput.Password
Layout.alignment: Qt.AlignHCenter
}
FluFilledButton{
text:"登录"
Layout.alignment: Qt.AlignHCenter
Layout.topMargin: 20
onClicked:{
if(textbox_password.text === ""){
showError("请随便输入一个密码")
return
}
window.close()
}
}
}
}

View File

@ -9,7 +9,7 @@ import FluentUI 1.0
FluWindow {
id:rootwindow
width: 860
height: 680
height: 600
title: "FluentUI"
minimumWidth: 500
minimumHeight: 400
@ -59,6 +59,13 @@ FluWindow {
}
}
FluPaneItem{
title:"Menu"
onTap:{
nav_view.push("qrc:/T_Menu.qml")
}
}
FluPaneItem{
title:"TimePicker"
onTap:{
@ -126,6 +133,14 @@ FluWindow {
}
}
FluPaneItem{
title:"MultiWindow"
onTap:{
nav_view.push("qrc:/T_MultiWindow.qml")
}
}
FluPaneItemHeader{
title:"Theming"
}
@ -164,7 +179,7 @@ FluWindow {
FluPaneItem{
title:"关于"
onTap:{
FluApp.navigate("/About")
FluApp.navigate("/about")
}
}
}

View File

@ -3,8 +3,6 @@
<file>T_ToggleSwitch.qml</file>
<file>T_Typography.qml</file>
<file>App.qml</file>
<file>SettingPage.qml</file>
<file>AboutPage.qml</file>
<file>T_Buttons.qml</file>
<file>T_Rectangle.qml</file>
<file>T_InfoBar.qml</file>
@ -29,8 +27,12 @@
<file>T_Dialog.qml</file>
<file>T_TreeView.qml</file>
<file>T_Expander.qml</file>
<file>MainPage.qml</file>
<file>T_TimePicker.qml</file>
<file>T_DatePicker.qml</file>
<file>T_Menu.qml</file>
<file>page/AboutPage.qml</file>
<file>page/MainPage.qml</file>
<file>T_MultiWindow.qml</file>
<file>page/LoginPage.qml</file>
</qresource>
</RCC>

View File

@ -33,14 +33,14 @@ void FluApp::run(){
navigate(initialRoute());
}
void FluApp::navigate(const QString& route){
void FluApp::navigate(const QString& route,const QJsonObject& argument){
if(!routes().contains(route)){
qErrnoWarning("没有找到当前路由");
return;
}
bool isAppWindow = route == initialRoute();
FramelessView *view = new FramelessView();
view->setProperty("argument",argument);
QMapIterator<QString, QVariant> iterator(properties);
while (iterator.hasNext()) {
iterator.next();

View File

@ -24,7 +24,7 @@ public:
Q_INVOKABLE void run();
Q_INVOKABLE void navigate(const QString& route);
Q_INVOKABLE void navigate(const QString& route,const QJsonObject& argument = {});
Q_INVOKABLE void init(QWindow *window,QMap<QString, QVariant> properties);

View File

@ -10,9 +10,9 @@ void WindowHelper::setTitle(const QString& text){
window->setTitle(text);
}
void WindowHelper::initWindow(FramelessView* window){
QJsonObject WindowHelper::initWindow(FramelessView* window){
this->window = window;
return window->property("argument").toJsonObject();
}
void WindowHelper::setMinimumWidth(int width){
@ -27,3 +27,19 @@ void WindowHelper::setMinimumHeight(int height){
void WindowHelper::setMaximumHeight(int height){
this->window->setMaximumHeight(height);
}
void WindowHelper::updateWindow(){
this->window->setFlag(Qt::Window,false);
this->window->setFlag(Qt::Window,true);
}
void WindowHelper::setModality(int type){
if(type == 0){
this->window->setModality(Qt::NonModal);
}else if(type == 1){
this->window->setModality(Qt::WindowModal);
}else if(type == 2){
this->window->setModality(Qt::ApplicationModal);
}else{
this->window->setModality(Qt::NonModal);
}
}

View File

@ -5,6 +5,7 @@
#include <QQuickWindow>
#include <QQuickItem>
#include <QWindow>
#include <QJsonObject>
#include "FramelessView.h"
class WindowHelper : public QObject
@ -14,12 +15,14 @@ class WindowHelper : public QObject
public:
explicit WindowHelper(QObject *parent = nullptr);
Q_INVOKABLE void initWindow(FramelessView* window);
Q_INVOKABLE QJsonObject initWindow(FramelessView* window);
Q_INVOKABLE void setTitle(const QString& text);
Q_INVOKABLE void setMinimumWidth(int width);
Q_INVOKABLE void setMaximumWidth(int width);
Q_INVOKABLE void setMinimumHeight(int height);
Q_INVOKABLE void setMaximumHeight(int height);
Q_INVOKABLE void updateWindow();
Q_INVOKABLE void setModality(int type);
private:
FramelessView* window;

View File

@ -7,7 +7,7 @@ TextField{
property var values:[]
property int fontStyle: FluText.Body
property int pixelSize : FluTheme.textSize
property int iconSource: -1
property int iconSource: 0
signal itemClicked(string data)
id:input
@ -112,7 +112,7 @@ TextField{
iconSource: input.iconSource
iconSize: 15
opacity: 0.5
visible: input.iconSource != -1
visible: input.iconSource != 0
anchors{
verticalCenter: parent.verticalCenter
right: parent.right

View File

@ -2,9 +2,9 @@
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
Popup {
Menu {
id: popup
default property alias content: container.children
default property alias content: container.data
background: Rectangle {
implicitWidth: 140

View File

@ -26,6 +26,9 @@ Item {
property int maximumWidth
property int minimumHeight
property int maximumHeight
property int modality:0
signal initArgument(var argument)
property int borderless:{
if(!FluTheme.isFrameless){
@ -76,8 +79,8 @@ Item {
target: FluApp
function onWindowReady(view){
if(FluApp.equalsWindow(view,window)){
helper.initWindow(view);
helper.setTitle(title);
initArgument(helper.initWindow(view))
helper.setTitle(title)
if(minimumWidth){
helper.setMinimumWidth(minimumWidth)
}
@ -90,6 +93,8 @@ Item {
if(maximumHeight){
helper.setMaximumHeight(maximumHeight)
}
helper.setModality(root.modality);
helper.updateWindow()
}
}
}
@ -119,4 +124,8 @@ Item {
window.close()
}
function onResult(data){
}
}