From 80d92c01c423036d6be3c525135588e10a1dd56b Mon Sep 17 00:00:00 2001 From: hewenfei Date: Fri, 31 Mar 2023 16:20:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=88=97=E8=A1=A8=E7=95=8C=E9=9D=A2,qml?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=A2=9E=E5=8A=A0=E6=89=93=E5=BC=80=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E5=92=8C=E5=BA=94=E7=94=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qml/AppUI/AppPage.qml | 2 + qml/AppUI/AppPageContent.qml | 116 +++++++++++++++--- qml/AppUI/AppPageHeader.qml | 225 ++++++++++++++++++---------------- src/menu/menu-manager.cpp | 9 ++ src/menu/menu-manager.h | 1 + src/ukui-menu-application.cpp | 4 + src/utils/app-manager.h | 4 +- 7 files changed, 238 insertions(+), 123 deletions(-) diff --git a/qml/AppUI/AppPage.qml b/qml/AppUI/AppPage.qml index 21063db..95f114f 100644 --- a/qml/AppUI/AppPage.qml +++ b/qml/AppUI/AppPage.qml @@ -32,11 +32,13 @@ AppControls2.StyleBackground { spacing: 0 AppPageHeader { + id: appPageHeader Layout.fillWidth: true Layout.preferredHeight: 40 } AppPageContent { + appPageHeader: appPageHeader Layout.fillWidth: true Layout.fillHeight: true } diff --git a/qml/AppUI/AppPageContent.qml b/qml/AppUI/AppPageContent.qml index 389818e..4e27feb 100644 --- a/qml/AppUI/AppPageContent.qml +++ b/qml/AppUI/AppPageContent.qml @@ -22,24 +22,108 @@ import QtQuick.Controls 2.5 import AppControls2 1.0 as AppControls2 import org.ukui.menu.core 1.0 -Item { - AppList { - id: appList - clip: true - anchors.fill: parent - anchors.leftMargin: 4 - onLabelItemClicked: { - appList.visible = false; - selectionPage.viewShowStart(); +SwipeView { + id: root + interactive: false + required property AppPageHeader appPageHeader + + Item { + id: appListBase + AppList { + id: appList + anchors.fill: parent + anchors.leftMargin: 4 + onLabelItemClicked: { + appList.visible = false; + selectionPage.viewShowStart(); + } + } + + SelectionPage { + id: selectionPage + anchors.fill: parent + anchors.bottomMargin: 54 + visible: !appList.visible + onViewHideFinished: appList.visible = true + onLabelSelected: appList.labelSelection(labelId) } } - SelectionPage { - id: selectionPage - anchors.fill: parent - anchors.bottomMargin: 54 - visible: !appList.visible - onViewHideFinished: appList.visible = true - onLabelSelected: appList.labelSelection(labelId) + Loader { + id: folderPageLoader + active: false + sourceComponent: Component { + AppListView { + model: modelManager.getFolderModel() + delegate: Component { + Loader { + width: ListView.view ? ListView.view.width : 0; height: 40 + property string id: model.id + property string name: model.name + property string icon: model.icon + sourceComponent: AppControls2.AppItem { + acceptedButtons: Qt.LeftButton | Qt.RightButton + onClicked: { + if (mouse.button === Qt.RightButton) { + menuManager.showMenu(id); + return; + } + if (mouse.button === Qt.LeftButton) { + appManager.launchApp(id); + return; + } + } + } + } + } + } + } + + function showFolderPage(folderId, folderName) { + active = true; + item.model.setFolderId(folderId); + appPageHeader.title = folderName; + appPageHeader.content = folderPageHeader; + root.currentIndex = SwipeView.index; + } + function hideFolderPage() { + root.currentIndex = appListBase.SwipeView.index; + appPageHeader.title = appList.title; + appPageHeader.content = null; + //active = false; + } + + Component.onCompleted: { + appList.openFolderPageSignal.connect(showFolderPage); + } + } + + Component { + id: folderPageHeader + Item { + RowLayout { + anchors.fill: parent + anchors.leftMargin: 12 + + Image { + Layout.fillWidth: true + Layout.fillHeight: true + Layout.maximumWidth: 16 + Layout.maximumHeight: 16 + Layout.alignment: Qt.AlignVCenter + source: "image://appicon/ukui-start-symbolic" + MouseArea { + anchors.fill: parent + onClicked: folderPageLoader.hideFolderPage(); + } + } + Text { + Layout.fillWidth: true + Layout.fillHeight: true + verticalAlignment: Text.AlignVCenter + text: title + } + } + } } } diff --git a/qml/AppUI/AppPageHeader.qml b/qml/AppUI/AppPageHeader.qml index e8eb6a6..a2fc48b 100644 --- a/qml/AppUI/AppPageHeader.qml +++ b/qml/AppUI/AppPageHeader.qml @@ -26,124 +26,139 @@ import org.ukui.menu.utils 1.0 Item { id: appPageHeaderRoot property string title: "" + property Component content: null clip: true - state: "normal" - states: [ - State { - name: "normal" - PropertyChanges { target: searchBar; scale: 0.9; y: -pluginSelectionBar.height } - PropertyChanges { target: pluginSelectionBar; scale: 1.0; y: 0 } - StateChangeScript { script: pluginSelectMenu.model.reactivateProvider() } - }, - State { - name: "search" - PropertyChanges { target: searchBar; scale: 1.0; y: 0 } - PropertyChanges { target: pluginSelectionBar; scale: 0.9; y: pluginSelectionBar.height } - } - ] - - transitions:[ - Transition { - to: "normal" - SequentialAnimation { - NumberAnimation { easing.type: Easing.InOutQuad; properties: "scale,y"; duration: 300 } - ScriptAction { script: searchBar.visible = false } - } - }, - Transition { - to: "search" - SequentialAnimation { - ScriptAction { script: searchBar.visible = true } - NumberAnimation { easing.type: Easing.InOutQuad; properties: "scale,y"; duration: 300} - } - } - ] - - Item { - id: searchBar - width: parent.width; height: 30 - - RowLayout { - anchors.fill: parent - anchors.leftMargin: 15 - anchors.rightMargin: 15 - spacing: 10 - - SearchInputBar { - id: searchInputBar - property string providerId: "" - - Layout.fillWidth: true - Layout.fillHeight: true - radius: 16 - onTextChanged: { - if (text === "") { - pluginSelectMenu.model.reactivateProvider(); - } else { - appPageHeaderUtils.activateProvider(providerId); - appPageHeaderUtils.startSearch(text); - } - } - } - - AppControls2.RoundButton { - Layout.preferredWidth: parent.height; Layout.preferredHeight: parent.height - buttonIcon: "image://appicon/edit-clear-symbolic" - - onClicked: { - searchInputBar.clear(); - appPageHeaderRoot.state = "normal"; - } - } + Loader { + anchors.fill: parent + property string title: appPageHeaderRoot.title + sourceComponent: { + return appPageHeaderRoot.content === null ? defaultComponent : appPageHeaderRoot.content } } - Item { - id: pluginSelectionBar - width: parent.width - height: parent.height - RowLayout { - anchors.fill: parent - anchors.leftMargin: 16 - spacing: 12 - Text { - Layout.fillWidth: true - Layout.fillHeight: true - verticalAlignment: Qt.AlignVCenter - text: appPageHeaderRoot.title - font.bold: true - } + Component { + id: defaultComponent + Item { + id: root + state: "normal" + states: [ + State { + name: "normal" + PropertyChanges { target: searchBar; scale: 0.9; y: -pluginSelectionBar.height } + PropertyChanges { target: pluginSelectionBar; scale: 1.0; y: 0 } + StateChangeScript { script: pluginSelectMenu.model.reactivateProvider() } + }, + State { + name: "search" + PropertyChanges { target: searchBar; scale: 1.0; y: 0 } + PropertyChanges { target: pluginSelectionBar; scale: 0.9; y: pluginSelectionBar.height } + } + ] - ListView { - Layout.preferredWidth: childrenRect.width - Layout.preferredHeight: 32 - Layout.maximumWidth: 68 - Layout.alignment: Qt.AlignVCenter + transitions:[ + Transition { + to: "normal" + SequentialAnimation { + NumberAnimation { easing.type: Easing.InOutQuad; properties: "scale,y"; duration: 300 } + ScriptAction { script: searchBar.visible = false } + } + }, + Transition { + to: "search" + SequentialAnimation { + ScriptAction { script: searchBar.visible = true } + NumberAnimation { easing.type: Easing.InOutQuad; properties: "scale,y"; duration: 300} + } + } + ] - clip: true - spacing: 4 - orientation: ListView.Horizontal + Item { + id: searchBar + width: parent.width; height: 30 - model: appPageHeaderUtils.model(PluginGroup.Button) - delegate: AppControls2.RoundButton { - width: height; height: ListView.view ? ListView.view.height : 0 - buttonIcon: model.icon + RowLayout { + anchors.fill: parent + anchors.leftMargin: 15 + anchors.rightMargin: 15 + spacing: 10 - onClicked: { - appPageHeaderRoot.state = "search"; - searchInputBar.providerId = model.id; + SearchInputBar { + id: searchInputBar + property string providerId: "" + + Layout.fillWidth: true + Layout.fillHeight: true + radius: 16 + onTextChanged: { + if (text === "") { + pluginSelectMenu.model.reactivateProvider(); + } else { + appPageHeaderUtils.activateProvider(providerId); + appPageHeaderUtils.startSearch(text); + } + } + } + + AppControls2.RoundButton { + Layout.preferredWidth: parent.height; Layout.preferredHeight: parent.height + buttonIcon: "image://appicon/edit-clear-symbolic" + + onClicked: { + searchInputBar.clear(); + root.state = "normal"; + } } } } - PluginSelectMenu { - id: pluginSelectMenu - Layout.preferredWidth: childrenRect.width - Layout.preferredHeight: 32 - Layout.maximumHeight: 32 - Layout.rightMargin: 8 - Layout.alignment: Qt.AlignVCenter + Item { + id: pluginSelectionBar + width: parent.width + height: parent.height + RowLayout { + anchors.fill: parent + anchors.leftMargin: 16 + spacing: 12 + Text { + Layout.fillWidth: true + Layout.fillHeight: true + verticalAlignment: Qt.AlignVCenter + text: appPageHeaderRoot.title + font.bold: true + } + + ListView { + Layout.preferredWidth: childrenRect.width + Layout.preferredHeight: 32 + Layout.maximumWidth: 68 + Layout.alignment: Qt.AlignVCenter + + clip: true + spacing: 4 + orientation: ListView.Horizontal + + model: appPageHeaderUtils.model(PluginGroup.Button) + delegate: AppControls2.RoundButton { + width: height; height: ListView.view ? ListView.view.height : 0 + buttonIcon: model.icon + + onClicked: { + root.state = "search"; + searchInputBar.providerId = model.id; + } + } + } + + PluginSelectMenu { + id: pluginSelectMenu + Layout.preferredWidth: childrenRect.width + Layout.preferredHeight: 32 + Layout.maximumHeight: 32 + Layout.rightMargin: 8 + Layout.alignment: Qt.AlignVCenter + } + } } } } diff --git a/src/menu/menu-manager.cpp b/src/menu/menu-manager.cpp index 596a613..329ab71 100644 --- a/src/menu/menu-manager.cpp +++ b/src/menu/menu-manager.cpp @@ -18,6 +18,7 @@ #include "menu-manager.h" #include "app-manager.h" +#include "app-data-manager.h" #include #include @@ -178,6 +179,14 @@ void MenuManager::registerMenuProvider(MenuProvider *provider) m_providers.append(provider); } +void MenuManager::showMenu(const QString &appid, const QPoint &point) +{ + DataEntity app; + if (AppDataManager::instance()->getApp(appid, app)) { + showMenu(MenuProvider::DataType, QVariant::fromValue(app), point); + } +} + void MenuManager::showMenu(const DataEntity &entity, const QPoint &point) { showMenu(MenuProvider::DataType, QVariant::fromValue(entity), point); diff --git a/src/menu/menu-manager.h b/src/menu/menu-manager.h index 470ef63..4e3d199 100644 --- a/src/menu/menu-manager.h +++ b/src/menu/menu-manager.h @@ -46,6 +46,7 @@ public: static MenuManager *instance(); ~MenuManager() override; void registerMenuProvider(MenuProvider *provider); + Q_INVOKABLE void showMenu(const QString &appid, const QPoint &point = QPoint()); void showMenu(const DataEntity &entity, const QPoint &point = QPoint()); void showMenu(const MenuProvider::RequestType &type, const QVariant &data, const QPoint &point = QPoint()); diff --git a/src/ukui-menu-application.cpp b/src/ukui-menu-application.cpp index ef6a3e3..d1bc280 100644 --- a/src/ukui-menu-application.cpp +++ b/src/ukui-menu-application.cpp @@ -28,6 +28,8 @@ #include "app-page-header-utils.h" #include "power-button.h" #include "items/theme-icon.h" +#include "app-manager.h" +#include "menu-manager.h" #include #include @@ -83,6 +85,8 @@ void UkuiMenuApplication::initQmlEngine() context->setContextProperty("modelManager", ModelManager::instance()); context->setContextProperty("extensionManager", MenuExtension::instance()); context->setContextProperty("appPageHeaderUtils", new AppPageHeaderUtils(this)); + context->setContextProperty("menuManager", MenuManager::instance()); + context->setContextProperty("appManager", AppManager::instance()); // MenuMainWindow // const QUrl url(QStringLiteral("qrc:/qml/MenuMainWindow.qml")); diff --git a/src/utils/app-manager.h b/src/utils/app-manager.h index eabcbf0..5b8cf7a 100644 --- a/src/utils/app-manager.h +++ b/src/utils/app-manager.h @@ -32,8 +32,8 @@ public: AppManager(const AppManager &obj) = delete; AppManager &operator = (const AppManager &obj) = delete; - bool launchApp(const QString &desktopFilePath); - bool launchBinaryApp(const QString &app, const QString &args = QString()); + Q_INVOKABLE bool launchApp(const QString &desktopFilePath); + Q_INVOKABLE bool launchBinaryApp(const QString &app, const QString &args = QString()); private: explicit AppManager(QObject *parent = nullptr);