新增文件夹应用列表界面,qml环境增加打开菜单和应用接口

This commit is contained in:
hewenfei 2023-03-31 16:20:05 +08:00
parent 8f40eb3af1
commit 80d92c01c4
7 changed files with 238 additions and 123 deletions

View File

@ -32,11 +32,13 @@ AppControls2.StyleBackground {
spacing: 0 spacing: 0
AppPageHeader { AppPageHeader {
id: appPageHeader
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: 40 Layout.preferredHeight: 40
} }
AppPageContent { AppPageContent {
appPageHeader: appPageHeader
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
} }

View File

@ -22,24 +22,108 @@ import QtQuick.Controls 2.5
import AppControls2 1.0 as AppControls2 import AppControls2 1.0 as AppControls2
import org.ukui.menu.core 1.0 import org.ukui.menu.core 1.0
Item { SwipeView {
AppList { id: root
id: appList interactive: false
clip: true required property AppPageHeader appPageHeader
anchors.fill: parent
anchors.leftMargin: 4 Item {
onLabelItemClicked: { id: appListBase
appList.visible = false; AppList {
selectionPage.viewShowStart(); 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 { Loader {
id: selectionPage id: folderPageLoader
anchors.fill: parent active: false
anchors.bottomMargin: 54 sourceComponent: Component {
visible: !appList.visible AppListView {
onViewHideFinished: appList.visible = true model: modelManager.getFolderModel()
onLabelSelected: appList.labelSelection(labelId) 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
}
}
}
} }
} }

View File

@ -26,124 +26,139 @@ import org.ukui.menu.utils 1.0
Item { Item {
id: appPageHeaderRoot id: appPageHeaderRoot
property string title: "" property string title: ""
property Component content: null
clip: true clip: true
state: "normal" Loader {
states: [ anchors.fill: parent
State { property string title: appPageHeaderRoot.title
name: "normal" sourceComponent: {
PropertyChanges { target: searchBar; scale: 0.9; y: -pluginSelectionBar.height } return appPageHeaderRoot.content === null ? defaultComponent : appPageHeaderRoot.content
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";
}
}
} }
} }
Item { Component {
id: pluginSelectionBar id: defaultComponent
width: parent.width Item {
height: parent.height id: root
RowLayout { state: "normal"
anchors.fill: parent states: [
anchors.leftMargin: 16 State {
spacing: 12 name: "normal"
Text { PropertyChanges { target: searchBar; scale: 0.9; y: -pluginSelectionBar.height }
Layout.fillWidth: true PropertyChanges { target: pluginSelectionBar; scale: 1.0; y: 0 }
Layout.fillHeight: true StateChangeScript { script: pluginSelectMenu.model.reactivateProvider() }
verticalAlignment: Qt.AlignVCenter },
text: appPageHeaderRoot.title State {
font.bold: true name: "search"
} PropertyChanges { target: searchBar; scale: 1.0; y: 0 }
PropertyChanges { target: pluginSelectionBar; scale: 0.9; y: pluginSelectionBar.height }
}
]
ListView { transitions:[
Layout.preferredWidth: childrenRect.width Transition {
Layout.preferredHeight: 32 to: "normal"
Layout.maximumWidth: 68 SequentialAnimation {
Layout.alignment: Qt.AlignVCenter 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 Item {
spacing: 4 id: searchBar
orientation: ListView.Horizontal width: parent.width; height: 30
model: appPageHeaderUtils.model(PluginGroup.Button) RowLayout {
delegate: AppControls2.RoundButton { anchors.fill: parent
width: height; height: ListView.view ? ListView.view.height : 0 anchors.leftMargin: 15
buttonIcon: model.icon anchors.rightMargin: 15
spacing: 10
onClicked: { SearchInputBar {
appPageHeaderRoot.state = "search"; id: searchInputBar
searchInputBar.providerId = model.id; 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 { Item {
id: pluginSelectMenu id: pluginSelectionBar
Layout.preferredWidth: childrenRect.width width: parent.width
Layout.preferredHeight: 32 height: parent.height
Layout.maximumHeight: 32 RowLayout {
Layout.rightMargin: 8 anchors.fill: parent
Layout.alignment: Qt.AlignVCenter 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
}
}
} }
} }
} }

View File

@ -18,6 +18,7 @@
#include "menu-manager.h" #include "menu-manager.h"
#include "app-manager.h" #include "app-manager.h"
#include "app-data-manager.h"
#include <QMenu> #include <QMenu>
#include <QCursor> #include <QCursor>
@ -178,6 +179,14 @@ void MenuManager::registerMenuProvider(MenuProvider *provider)
m_providers.append(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) void MenuManager::showMenu(const DataEntity &entity, const QPoint &point)
{ {
showMenu(MenuProvider::DataType, QVariant::fromValue(entity), point); showMenu(MenuProvider::DataType, QVariant::fromValue(entity), point);

View File

@ -46,6 +46,7 @@ public:
static MenuManager *instance(); static MenuManager *instance();
~MenuManager() override; ~MenuManager() override;
void registerMenuProvider(MenuProvider *provider); 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 DataEntity &entity, const QPoint &point = QPoint());
void showMenu(const MenuProvider::RequestType &type, const QVariant &data, const QPoint &point = QPoint()); void showMenu(const MenuProvider::RequestType &type, const QVariant &data, const QPoint &point = QPoint());

View File

@ -28,6 +28,8 @@
#include "app-page-header-utils.h" #include "app-page-header-utils.h"
#include "power-button.h" #include "power-button.h"
#include "items/theme-icon.h" #include "items/theme-icon.h"
#include "app-manager.h"
#include "menu-manager.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QCommandLineParser> #include <QCommandLineParser>
@ -83,6 +85,8 @@ void UkuiMenuApplication::initQmlEngine()
context->setContextProperty("modelManager", ModelManager::instance()); context->setContextProperty("modelManager", ModelManager::instance());
context->setContextProperty("extensionManager", MenuExtension::instance()); context->setContextProperty("extensionManager", MenuExtension::instance());
context->setContextProperty("appPageHeaderUtils", new AppPageHeaderUtils(this)); context->setContextProperty("appPageHeaderUtils", new AppPageHeaderUtils(this));
context->setContextProperty("menuManager", MenuManager::instance());
context->setContextProperty("appManager", AppManager::instance());
// MenuMainWindow // MenuMainWindow
// const QUrl url(QStringLiteral("qrc:/qml/MenuMainWindow.qml")); // const QUrl url(QStringLiteral("qrc:/qml/MenuMainWindow.qml"));

View File

@ -32,8 +32,8 @@ public:
AppManager(const AppManager &obj) = delete; AppManager(const AppManager &obj) = delete;
AppManager &operator = (const AppManager &obj) = delete; AppManager &operator = (const AppManager &obj) = delete;
bool launchApp(const QString &desktopFilePath); Q_INVOKABLE bool launchApp(const QString &desktopFilePath);
bool launchBinaryApp(const QString &app, const QString &args = QString()); Q_INVOKABLE bool launchBinaryApp(const QString &app, const QString &args = QString());
private: private:
explicit AppManager(QObject *parent = nullptr); explicit AppManager(QObject *parent = nullptr);