From 00981214729e74af37509a709a33c5f2685c60a7 Mon Sep 17 00:00:00 2001 From: hewenfei Date: Sat, 6 May 2023 09:20:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=A4=E6=96=AD=E5=8F=B3?= =?UTF-8?q?=E9=94=AE=E4=BD=8D=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + qml/AppUI/AppList.qml | 4 +- qml/AppUI/AppPageContent.qml | 2 +- qml/AppUI/FullScreenContent.qml | 17 ++-- qml/AppUI/FullScreenFolder.qml | 3 +- src/appdata/app-folder-helper.cpp | 82 +++++++++++++------ .../extensions/favorite-extension.cpp | 48 +++++++---- src/menu/menu-manager.cpp | 62 +++++++++----- src/menu/menu-manager.h | 6 +- src/menu/menu-provider.h | 17 +++- src/model/app-group-model.cpp | 6 ++ src/model/app-group-model.h | 1 + src/model/app-model.cpp | 4 +- src/model/app-model.h | 3 +- src/ukui-menu-application.cpp | 2 + 15 files changed, 180 insertions(+), 78 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb1f31f..6037207 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,6 +118,7 @@ set(SOURCE_FILES src/utils/app-page-header-utils.cpp src/utils/app-page-header-utils.h src/utils/power-button.cpp src/utils/power-button.h src/utils/app-manager.cpp src/utils/app-manager.h + src/menu/menu-provider.h src/menu/menu-manager.cpp src/menu/menu-manager.h src/items/theme-icon.h src/items/theme-icon.cpp ) diff --git a/qml/AppUI/AppList.qml b/qml/AppUI/AppList.qml index 20439f2..9505500 100644 --- a/qml/AppUI/AppList.qml +++ b/qml/AppUI/AppList.qml @@ -85,7 +85,7 @@ Item { Drag.hotSpot.y: height / 2 onClicked: { if (mouse.button === Qt.RightButton) { - appListView.model.openMenu(index); + appListView.model.openMenu(index, MenuInfo.AppList); return; } if (mouse.button === Qt.LeftButton) { @@ -156,7 +156,7 @@ Item { acceptedButtons: Qt.LeftButton | Qt.RightButton onClicked: { if (mouse.button === Qt.RightButton) { - appListView.model.openMenu(index); + appListView.model.openMenu(index, MenuInfo.AppList); return; } if (mouse.button === Qt.LeftButton) { diff --git a/qml/AppUI/AppPageContent.qml b/qml/AppUI/AppPageContent.qml index 609a24b..fc658da 100644 --- a/qml/AppUI/AppPageContent.qml +++ b/qml/AppUI/AppPageContent.qml @@ -72,7 +72,7 @@ SwipeView { acceptedButtons: Qt.LeftButton | Qt.RightButton onClicked: { if (mouse.button === Qt.RightButton) { - menuManager.showMenu(id); + menuManager.showMenu(id, MenuInfo.FolderPage); return; } if (mouse.button === Qt.LeftButton) { diff --git a/qml/AppUI/FullScreenContent.qml b/qml/AppUI/FullScreenContent.qml index e3f53c1..0c1330a 100644 --- a/qml/AppUI/FullScreenContent.qml +++ b/qml/AppUI/FullScreenContent.qml @@ -212,7 +212,7 @@ RowLayout { onClicked: { if (mouse.button === Qt.RightButton) { - parent.parent.GridView.view.model.openMenu(index); + modelManager.getAppModel().openMenu(index, MenuInfo.FullScreen); return; } if (mouse.button === Qt.LeftButton) { @@ -268,7 +268,7 @@ RowLayout { onClicked: { if (mouse.button === Qt.RightButton) { - parent.parent.GridView.view.model.openMenu(index); + modelManager.getAppModel().openMenu(index, MenuInfo.FullScreen); return; } if (mouse.button === Qt.LeftButton) { @@ -362,6 +362,7 @@ RowLayout { anchors.centerIn: parent hoverEnabled: true width: 170; height: width + acceptedButtons: Qt.LeftButton | Qt.RightButton AppControls2.StyleBackground { anchors.fill: parent @@ -379,9 +380,15 @@ RowLayout { } } - onClicked: { - //console.log("clicked", Object.keys(model)) - labelRepeater.model.openApp(labelAppsGridView.labelIndex, model.index); + onClicked: function (mouse) { + if (mouse.button === Qt.RightButton) { + labelRepeater.model.openMenu(labelAppsGridView.labelIndex, model.index); + return; + } + if (mouse.button === Qt.LeftButton) { + labelRepeater.model.openApp(labelAppsGridView.labelIndex, model.index); + return; + } } } } diff --git a/qml/AppUI/FullScreenFolder.qml b/qml/AppUI/FullScreenFolder.qml index 6f793c6..4b1c40a 100644 --- a/qml/AppUI/FullScreenFolder.qml +++ b/qml/AppUI/FullScreenFolder.qml @@ -275,7 +275,7 @@ Loader { } onClicked: { if (mouse.button === Qt.RightButton) { - menuManager.showMenu(id); + menuManager.showMenu(id, MenuInfo.FullScreenFolder); return; } if (mouse.button === Qt.LeftButton) { @@ -305,4 +305,3 @@ Loader { } } - diff --git a/src/appdata/app-folder-helper.cpp b/src/appdata/app-folder-helper.cpp index 5ab3bf5..68dc1e6 100644 --- a/src/appdata/app-folder-helper.cpp +++ b/src/appdata/app-folder-helper.cpp @@ -40,11 +40,12 @@ class FolderMenuProvider : public MenuProvider public: FolderMenuProvider(); int index() override { return 256; } - QList generateActions(QObject *parent, const RequestType &type, const QVariant &data) override; - + bool isSupport(const RequestType &type) override; + QList generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location, const QString &locationId) override; private: - void folderMenuForNormal(QObject *parent, const QString &appId, QList &list); - void folderMenuForFolder(QObject *parent, const QString &folderId, QList &list); + static void folderMenuForNormal(QObject *parent, const QString &appId, QList &list); + static void dissolveFolder(QObject *parent, const QString &folderId, QList &list); + static void renameFolder(QObject *parent, const QString &folderId, QList &list); }; FolderMenuProvider::FolderMenuProvider() @@ -52,24 +53,52 @@ FolderMenuProvider::FolderMenuProvider() } -QList FolderMenuProvider::generateActions(QObject *parent, const MenuProvider::RequestType &type, const QVariant &data) +bool FolderMenuProvider::isSupport(const MenuProvider::RequestType &type) { - if (!parent || (type != DataType)) { + return type == DataType; +} + +QList +FolderMenuProvider::generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location, + const QString &locationId) +{ + if (!parent) { return {}; } DataEntity app = data.value(); QList list; - if (app.type() == DataType::Normal) { - // 应用菜单 - folderMenuForNormal(parent, app.id(), list); - return list; - } - if (app.type() == DataType::Folder) { - //文件夹菜单 - folderMenuForFolder(parent, app.id(), list); - return list; + + switch (location) { + case MenuInfo::FullScreen: { + if (app.type() == DataType::Folder) { + dissolveFolder(parent, app.id(), list); + break; + } + } + case MenuInfo::AppList: { + if (app.type() == DataType::Folder) { + renameFolder(parent, app.id(), list); + dissolveFolder(parent, app.id(), list); + break; + } + + if (app.type() != DataType::Normal || locationId != "all") { + break; + } + } + case MenuInfo::FullScreenFolder: + case MenuInfo::FolderPage: { + if (app.type() == DataType::Normal) { + folderMenuForNormal(parent, app.id(), list); + } + break; + } + case MenuInfo::Extension: + default: + break; } + return list; } @@ -98,24 +127,19 @@ void FolderMenuProvider::folderMenuForNormal(QObject *parent, const QString &app subMenu->addAction(newAct); QList folders = AppFolderHelper::instance()->folderData(); - for (const Folder &folder : folders) { - QString name = QObject::tr("Add to \"%1\"").arg(folder.getName()); + for (const Folder &f : folders) { + QString name = QObject::tr("Add to \"%1\"").arg(f.getName()); QAction* act = new QAction(name, subMenu); - QObject::connect(act, &QAction::triggered, parent, [appId, folder] { - AppFolderHelper::instance()->addAppToFolder(appId, folder.getId()); + QObject::connect(act, &QAction::triggered, parent, [appId, f] { + AppFolderHelper::instance()->addAppToFolder(appId, f.getId()); }); subMenu->addAction(act); } menu->addMenu(subMenu); } -void FolderMenuProvider::folderMenuForFolder(QObject *parent, const QString &folderId, QList &list) +void FolderMenuProvider::dissolveFolder(QObject *parent, const QString &folderId, QList &list) { - list << new QAction(QObject::tr("Rename"), parent); - QObject::connect(list.last(), &QAction::triggered, parent, [folderId] { - ModelManager::instance()->getAppModel()->toRenameFolder(folderId); - }); - list << new QAction(QObject::tr("Dissolve folder"), parent); QObject::connect(list.last(), &QAction::triggered, parent, [folderId] { AppFolderHelper::instance()->deleteFolder(folderId.toInt()); @@ -123,6 +147,14 @@ void FolderMenuProvider::folderMenuForFolder(QObject *parent, const QString &fol }); } +void FolderMenuProvider::renameFolder(QObject *parent, const QString &folderId, QList &list) +{ + list << new QAction(QObject::tr("Rename"), parent); + QObject::connect(list.last(), &QAction::triggered, parent, [folderId] { + ModelManager::instance()->getAppModel()->toRenameFolder(folderId); + }); +} + QString AppFolderHelper::s_folderConfigFile = QDir::homePath() + "/" + FOLDER_FILE_PATH + FOLDER_FILE_NAME; AppFolderHelper *AppFolderHelper::instance() diff --git a/src/extension/extensions/favorite-extension.cpp b/src/extension/extensions/favorite-extension.cpp index 98d9e7f..9a1b5a8 100644 --- a/src/extension/extensions/favorite-extension.cpp +++ b/src/extension/extensions/favorite-extension.cpp @@ -31,7 +31,8 @@ class FavoriteMenuProvider : public MenuProvider { public: int index() override { return 512; } - QList generateActions(QObject *parent, const RequestType &type, const QVariant &data) override; + bool isSupport(const RequestType &type) override; + QList generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location, const QString &locationId) override; }; class FavoriteAppsModel : public QAbstractListModel @@ -170,7 +171,7 @@ void FavoriteAppsModel::openMenu(const int &index) return; } - MenuManager::instance()->showMenu(m_favoriteAppsData.at(index)); + MenuManager::instance()->showMenu(m_favoriteAppsData.at(index), MenuInfo::Extension, "favorite"); } void FavoriteAppsModel::exchangedAppsOrder(int startIndex, int endIndex) @@ -180,9 +181,16 @@ void FavoriteAppsModel::exchangedAppsOrder(int startIndex, int endIndex) AppDataManager::instance()->changedFavoriteOrderSignal(startId, endNum); } -QList FavoriteMenuProvider::generateActions(QObject *parent, const MenuProvider::RequestType &type, const QVariant &data) +bool FavoriteMenuProvider::isSupport(const MenuProvider::RequestType &type) { - if (!parent || (type != DataType)) { + return type == DataType; +} + +QList +FavoriteMenuProvider::generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location, + const QString &locationId) +{ + if (!parent) { return {}; } @@ -193,19 +201,29 @@ QList FavoriteMenuProvider::generateActions(QObject *parent, const Me QList list; - if (app.favorite() == 0) { - list << new QAction(QObject::tr("Fix to favorite"), parent); - QObject::connect(list.last(), &QAction::triggered, parent, [app] { - Q_EMIT AppDataManager::instance()->fixToFavoriteSignal(app.id(), 1); - }); - } else { - list << new QAction(QObject::tr("Remove from favorite"), parent); - QObject::connect(list.last(), &QAction::triggered, parent, [app] { - Q_EMIT AppDataManager::instance()->fixToFavoriteSignal(app.id(), 0); - }); + switch (location) { + case MenuInfo::AppList: + case MenuInfo::FolderPage: + case MenuInfo::Extension: { + if (app.favorite() == 0) { + list << new QAction(QObject::tr("Fix to favorite"), parent); + QObject::connect(list.last(), &QAction::triggered, parent, [app] { + Q_EMIT AppDataManager::instance()->fixToFavoriteSignal(app.id(), 1); + }); + } else if (locationId == "favorite") { + list << new QAction(QObject::tr("Remove from favorite"), parent); + QObject::connect(list.last(), &QAction::triggered, parent, [app] { + Q_EMIT AppDataManager::instance()->fixToFavoriteSignal(app.id(), 0); + }); + } + break; + } + case MenuInfo::FullScreen: + case MenuInfo::FullScreenFolder: + default: + break; } - return list; } diff --git a/src/menu/menu-manager.cpp b/src/menu/menu-manager.cpp index c0b398b..ebc0737 100644 --- a/src/menu/menu-manager.cpp +++ b/src/menu/menu-manager.cpp @@ -41,7 +41,8 @@ class AppMenuProvider : public MenuProvider public: AppMenuProvider(); int index() override { return 1024; } - QList generateActions(QObject *parent, const RequestType &type, const QVariant &data) override; + bool isSupport(const RequestType &type) override; + QList generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location, const QString &locationId) override; private: void addToTop(QObject *parent, const QString &appId, const int &appTop, QList &list); @@ -62,10 +63,16 @@ AppMenuProvider::AppMenuProvider() } } -QList -AppMenuProvider::generateActions(QObject *parent, const MenuProvider::RequestType &type, const QVariant &data) +bool AppMenuProvider::isSupport(const MenuProvider::RequestType &type) { - if (!parent || (type != DataType)) { + return type == DataType; +} + +QList +AppMenuProvider::generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location, + const QString &locationId) +{ + if (!parent) { return {}; } @@ -78,17 +85,27 @@ AppMenuProvider::generateActions(QObject *parent, const MenuProvider::RequestTyp QString appId = app.id(); int appTop = app.top(); - //置顶 - addToTop(parent, appId, appTop ,list); - - // 添加到任务栏 - addToPanelAction(parent, appId, list); - - //添加到桌面快捷方式 - addToDesktopAction(parent, appId, list); - - // 卸载 - addUninstall(parent, appId, list); + switch (location) { + case MenuInfo::AppList: { + //置顶 + if (locationId == "all") { + addToTop(parent, appId, appTop, list); + } + } + case MenuInfo::Extension: + case MenuInfo::FolderPage: + case MenuInfo::FullScreen: + case MenuInfo::FullScreenFolder: + // 卸载 + addToPanelAction(parent, appId, list); + // 添加到任务栏 + addUninstall(parent, appId, list); + //添加到桌面快捷方式 + addToDesktopAction(parent, appId, list); + break; + default: + break; + } return list; } @@ -213,26 +230,29 @@ void MenuManager::registerMenuProvider(MenuProvider *provider) }); } -void MenuManager::showMenu(const QString &appid, const QPoint &point) +void MenuManager::showMenu(const QString &appid, const MenuInfo::Location location, const QString &lid, const QPoint &point) { DataEntity app; if (AppDataManager::instance()->getApp(appid, app)) { - showMenu(MenuProvider::DataType, QVariant::fromValue(app), point); + showMenu(MenuProvider::DataType, QVariant::fromValue(app), location, lid, point); } } -void MenuManager::showMenu(const DataEntity &entity, const QPoint &point) +void MenuManager::showMenu(const DataEntity &entity, const MenuInfo::Location location, const QString &lid, + const QPoint &point) { - showMenu(MenuProvider::DataType, QVariant::fromValue(entity), point); + showMenu(MenuProvider::DataType, QVariant::fromValue(entity), location, lid, point); } -void MenuManager::showMenu(const MenuProvider::RequestType &type, QVariant data, const QPoint &point) +void MenuManager::showMenu(const MenuProvider::RequestType &type, QVariant data, const MenuInfo::Location location, const QString &lid, const QPoint &point) { QMenu menu; QList actions; for (const auto &provider : d->providers) { - actions.append(provider->generateActions(&menu, type, data)); + if (provider->isSupport(type)) { + actions.append(provider->generateActions(&menu, data, location, lid)); + } } if (actions.isEmpty() && menu.isEmpty()) { diff --git a/src/menu/menu-manager.h b/src/menu/menu-manager.h index e15f455..2a11552 100644 --- a/src/menu/menu-manager.h +++ b/src/menu/menu-manager.h @@ -36,9 +36,9 @@ 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, QVariant data, const QPoint &point = QPoint()); + Q_INVOKABLE void showMenu(const QString &appid, MenuInfo::Location, const QString& lid = QString(), const QPoint &point = QPoint()); + void showMenu(const DataEntity &entity, MenuInfo::Location location, const QString& lid = QString(), const QPoint &point = QPoint()); + void showMenu(const MenuProvider::RequestType &type, QVariant data, MenuInfo::Location location, const QString& lid = QString(), const QPoint &point = QPoint()); private: MenuManager(); diff --git a/src/menu/menu-provider.h b/src/menu/menu-provider.h index 4c9a7c5..45273a9 100644 --- a/src/menu/menu-provider.h +++ b/src/menu/menu-provider.h @@ -28,6 +28,20 @@ namespace UkuiMenu { +class MenuInfo +{ + Q_GADGET +public: + enum Location { + AppList = 0, + Extension, + FolderPage, + FullScreen, + FullScreenFolder, + }; + Q_ENUM(Location) +}; + class MenuProvider { public: @@ -37,7 +51,8 @@ public: }; virtual ~MenuProvider() = default; virtual int index() = 0; - virtual QList generateActions(QObject *parent, const RequestType &type, const QVariant &data) = 0; + virtual bool isSupport(const RequestType &type) = 0; + virtual QList generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location, const QString &locationId) = 0; }; } // UkuiMenu diff --git a/src/model/app-group-model.cpp b/src/model/app-group-model.cpp index 712a48b..5d35255 100644 --- a/src/model/app-group-model.cpp +++ b/src/model/app-group-model.cpp @@ -177,4 +177,10 @@ inline void AppGroupModel::resetModel(QVector &labels) d->labelIndex = QVector(d->labels.size(), -1); } +void AppGroupModel::openMenu(int labelIndex, int appIndex) +{ + int index = d->labelIndex.at(labelIndex); + d->appModel->openMenu(++index + appIndex, MenuInfo::FullScreen); +} + } // UkuiMenu diff --git a/src/model/app-group-model.h b/src/model/app-group-model.h index dd03c9a..ce772e9 100644 --- a/src/model/app-group-model.h +++ b/src/model/app-group-model.h @@ -40,6 +40,7 @@ public: bool containLabel(); + Q_INVOKABLE void openMenu(int labelIndex, int appIndex); Q_INVOKABLE void openApp(int labelIndex, int appIndex); Q_INVOKABLE int getLabelIndex(const QString &labelId); diff --git a/src/model/app-model.cpp b/src/model/app-model.cpp index cfea11e..27f127e 100644 --- a/src/model/app-model.cpp +++ b/src/model/app-model.cpp @@ -187,13 +187,13 @@ void AppModel::insertData(QVector &data, int index) Q_EMIT endInsertRows(); } -void AppModel::openMenu(const int &index) +void AppModel::openMenu(const int &index, MenuInfo::Location location) { if (index < 0 || index >= m_apps.size()) { return; } - MenuManager::instance()->showMenu(m_apps.at(index)); + MenuManager::instance()->showMenu(m_apps.at(index), location, DataProviderManager::instance()->activatedProvider()); } void AppModel::renameFolder(const QString &index, const QString &folderName) diff --git a/src/model/app-model.h b/src/model/app-model.h index e91b755..61e63c6 100644 --- a/src/model/app-model.h +++ b/src/model/app-model.h @@ -24,6 +24,7 @@ #include "commons.h" #include "data-provider-manager.h" +#include "menu-provider.h" namespace UkuiMenu { @@ -41,7 +42,7 @@ public: Q_INVOKABLE int getLabelIndex(const QString &id); Q_INVOKABLE QVariantList folderApps(const QString &folderName); Q_INVOKABLE void appClicked(const int &index); - Q_INVOKABLE void openMenu(const int &index); + Q_INVOKABLE void openMenu(const int &index, MenuInfo::Location location); Q_INVOKABLE void renameFolder(const QString &index, const QString &folderName); Q_INVOKABLE void addAppsToFolder(const QString &appIdA, const QString &appIdB, const QString &folderName); Q_INVOKABLE void addAppToFolder(const QString &appId, const QString &folderId); diff --git a/src/ukui-menu-application.cpp b/src/ukui-menu-application.cpp index e1009a0..1284136 100644 --- a/src/ukui-menu-application.cpp +++ b/src/ukui-menu-application.cpp @@ -66,8 +66,10 @@ void UkuiMenuApplication::registerQmlTypes() // commons qRegisterMetaType("DataType::Type"); qRegisterMetaType("DataEntity"); + qRegisterMetaType("MenuInfo::Location"); qmlRegisterUncreatableType(uri, versionMajor, versionMinor, "Display", "Use enums only."); qmlRegisterUncreatableType(uri, versionMajor, versionMinor, "DataType", "Use enums only"); + qmlRegisterUncreatableType(uri, versionMajor, versionMinor, "MenuInfo", "Use enums only."); // qmlRegisterUncreatableType(uri, versionMajor, versionMinor, "DataEntity", "unknown"); // vis colors