增加判断右键位置功能
This commit is contained in:
parent
07410beab5
commit
0098121472
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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))
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -40,11 +40,12 @@ class FolderMenuProvider : public MenuProvider
|
|||
public:
|
||||
FolderMenuProvider();
|
||||
int index() override { return 256; }
|
||||
QList<QAction *> generateActions(QObject *parent, const RequestType &type, const QVariant &data) override;
|
||||
|
||||
bool isSupport(const RequestType &type) override;
|
||||
QList<QAction *> generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location, const QString &locationId) override;
|
||||
private:
|
||||
void folderMenuForNormal(QObject *parent, const QString &appId, QList<QAction *> &list);
|
||||
void folderMenuForFolder(QObject *parent, const QString &folderId, QList<QAction *> &list);
|
||||
static void folderMenuForNormal(QObject *parent, const QString &appId, QList<QAction *> &list);
|
||||
static void dissolveFolder(QObject *parent, const QString &folderId, QList<QAction *> &list);
|
||||
static void renameFolder(QObject *parent, const QString &folderId, QList<QAction *> &list);
|
||||
};
|
||||
|
||||
FolderMenuProvider::FolderMenuProvider()
|
||||
|
@ -52,24 +53,52 @@ FolderMenuProvider::FolderMenuProvider()
|
|||
|
||||
}
|
||||
|
||||
QList<QAction *> 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<QAction *>
|
||||
FolderMenuProvider::generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location,
|
||||
const QString &locationId)
|
||||
{
|
||||
if (!parent) {
|
||||
return {};
|
||||
}
|
||||
|
||||
DataEntity app = data.value<DataEntity>();
|
||||
QList<QAction *> list;
|
||||
if (app.type() == DataType::Normal) {
|
||||
// 应用菜单
|
||||
folderMenuForNormal(parent, app.id(), list);
|
||||
return list;
|
||||
}
|
||||
|
||||
switch (location) {
|
||||
case MenuInfo::FullScreen: {
|
||||
if (app.type() == DataType::Folder) {
|
||||
//文件夹菜单
|
||||
folderMenuForFolder(parent, app.id(), list);
|
||||
return list;
|
||||
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<Folder> 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<QAction *> &list)
|
||||
void FolderMenuProvider::dissolveFolder(QObject *parent, const QString &folderId, QList<QAction *> &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<QAction *> &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()
|
||||
|
|
|
@ -31,7 +31,8 @@ class FavoriteMenuProvider : public MenuProvider
|
|||
{
|
||||
public:
|
||||
int index() override { return 512; }
|
||||
QList<QAction *> generateActions(QObject *parent, const RequestType &type, const QVariant &data) override;
|
||||
bool isSupport(const RequestType &type) override;
|
||||
QList<QAction *> 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<QAction *> 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<QAction *>
|
||||
FavoriteMenuProvider::generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location,
|
||||
const QString &locationId)
|
||||
{
|
||||
if (!parent) {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -193,18 +201,28 @@ QList<QAction *> FavoriteMenuProvider::generateActions(QObject *parent, const Me
|
|||
|
||||
QList<QAction *> list;
|
||||
|
||||
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 {
|
||||
} 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;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,8 @@ class AppMenuProvider : public MenuProvider
|
|||
public:
|
||||
AppMenuProvider();
|
||||
int index() override { return 1024; }
|
||||
QList<QAction *> generateActions(QObject *parent, const RequestType &type, const QVariant &data) override;
|
||||
bool isSupport(const RequestType &type) override;
|
||||
QList<QAction *> 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<QAction *> &list);
|
||||
|
@ -62,10 +63,16 @@ AppMenuProvider::AppMenuProvider()
|
|||
}
|
||||
}
|
||||
|
||||
QList<QAction *>
|
||||
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<QAction *>
|
||||
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();
|
||||
|
||||
switch (location) {
|
||||
case MenuInfo::AppList: {
|
||||
//置顶
|
||||
addToTop(parent, appId, appTop ,list);
|
||||
|
||||
// 添加到任务栏
|
||||
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);
|
||||
|
||||
// 卸载
|
||||
addUninstall(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<QAction*> 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()) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<QAction*> generateActions(QObject *parent, const RequestType &type, const QVariant &data) = 0;
|
||||
virtual bool isSupport(const RequestType &type) = 0;
|
||||
virtual QList<QAction*> generateActions(QObject *parent, const QVariant &data, const MenuInfo::Location &location, const QString &locationId) = 0;
|
||||
};
|
||||
|
||||
} // UkuiMenu
|
||||
|
|
|
@ -177,4 +177,10 @@ inline void AppGroupModel::resetModel(QVector<LabelItem> &labels)
|
|||
d->labelIndex = QVector<int>(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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -187,13 +187,13 @@ void AppModel::insertData(QVector<DataEntity> &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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -66,8 +66,10 @@ void UkuiMenuApplication::registerQmlTypes()
|
|||
// commons
|
||||
qRegisterMetaType<UkuiMenu::DataType::Type>("DataType::Type");
|
||||
qRegisterMetaType<UkuiMenu::DataEntity>("DataEntity");
|
||||
qRegisterMetaType<UkuiMenu::MenuInfo::Location>("MenuInfo::Location");
|
||||
qmlRegisterUncreatableType<Display>(uri, versionMajor, versionMinor, "Display", "Use enums only.");
|
||||
qmlRegisterUncreatableType<UkuiMenu::DataType>(uri, versionMajor, versionMinor, "DataType", "Use enums only");
|
||||
qmlRegisterUncreatableType<UkuiMenu::MenuInfo>(uri, versionMajor, versionMinor, "MenuInfo", "Use enums only.");
|
||||
// qmlRegisterUncreatableType<UkuiMenu::DataEntity>(uri, versionMajor, versionMinor, "DataEntity", "unknown");
|
||||
|
||||
// vis colors
|
||||
|
|
Loading…
Reference in New Issue