From 069a39267940059755070a38966118f26fa5da10 Mon Sep 17 00:00:00 2001 From: gjq Date: Wed, 12 Apr 2023 17:13:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BC=80=E5=A7=8B=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E7=BD=AE=E9=A1=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qml/AppControls2/AppItem.qml | 52 +++++++++++++++++--- qml/AppUI/AppList.qml | 1 + src/appdata/app-data-manager.cpp | 11 +++++ src/appdata/app-data-manager.h | 1 + src/appdata/plugin/all-app-data-provider.cpp | 8 ++- src/data-entity.cpp | 1 + src/data-entity.h | 3 +- src/menu/menu-manager.cpp | 14 ++++++ src/model/app-model.cpp | 5 ++ translations/ukui-menu_bo_CN.ts | 8 +++ translations/ukui-menu_zh_CN.ts | 14 ++++-- 11 files changed, 107 insertions(+), 11 deletions(-) diff --git a/qml/AppControls2/AppItem.qml b/qml/AppControls2/AppItem.qml index 66ec400..b0f570b 100644 --- a/qml/AppControls2/AppItem.qml +++ b/qml/AppControls2/AppItem.qml @@ -15,13 +15,53 @@ MouseArea { ToolTip.visible: content.textTruncated && control.containsMouse ToolTip.text: name - IconLabel { - id: content + RowLayout { anchors.fill: parent - iconHeight: 32; iconWidth: iconHeight - appName: name; appIcon: icon - display: Display.TextBesideIcon - spacing: 12 + spacing: 2 + + IconLabel { + id: content + Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter + Layout.fillWidth: true + Layout.fillHeight: true + + iconHeight: 32; iconWidth: iconHeight + appName: name; appIcon: icon + display: Display.TextBesideIcon + spacing: 12 + } + + Loader { + id: tag + property bool recentInsatlled: false + visible: (toTop !== 0) || recentInsatlled + Layout.alignment: Qt.AlignRight | Qt.AlignVCenter + Layout.fillWidth: true + Layout.fillHeight: true + Layout.maximumWidth: visible ? 16 : 0 + Layout.maximumHeight: width + Layout.rightMargin: visible ? 25 : 0 + + Component { + id: tagImage + Image { + source: "image://appicon/ukui-fixed-symbolic" + } + } + + Component { + id: tagPoint + Item { + Rectangle { + anchors.centerIn: parent + width: 8; height: width + radius: width / 2 + color: themePalette.paletteColor(Palette.Highlight) + } + } + } + sourceComponent: (toTop === 0) ? tag.recentInsatlled ? tagPoint : null : tagImage + } } } } diff --git a/qml/AppUI/AppList.qml b/qml/AppUI/AppList.qml index 58398b7..41cc434 100644 --- a/qml/AppUI/AppList.qml +++ b/qml/AppUI/AppList.qml @@ -45,6 +45,7 @@ Item { property string id: model.id property string name: model.name property string icon: model.icon + property int toTop: model.top sourceComponent: { if (type === DataType.Normal) { return appItem; diff --git a/src/appdata/app-data-manager.cpp b/src/appdata/app-data-manager.cpp index 170da5d..68f19c1 100644 --- a/src/appdata/app-data-manager.cpp +++ b/src/appdata/app-data-manager.cpp @@ -47,6 +47,7 @@ private Q_SLOTS: public Q_SLOTS: void fixToFavoriteSlot(const QString &path, const int &num); void changedFavoriteOrderSlot(const QString &path, const int &num); + void fixToTopSlot(const QString &path, const int &num); private: void updateFavoriteApps(); @@ -287,6 +288,15 @@ void AppDataWorker::changedFavoriteOrderSlot(const QString &path, const int &num m_applicationInfo->setFavoritesOfApp(path, num); } +void AppDataWorker::fixToTopSlot(const QString &path, const int &num) +{ + if (num == 0) { + m_applicationInfo->setAppToTop(path); + } else { + m_applicationInfo->setTopOfApp(path, 0); + } +} + void AppDataWorker::removeApps(QStringList &appIdList, QStringList &removedIdList) { QMutexLocker locker(&m_appManager->m_mutex); @@ -317,6 +327,7 @@ AppDataManager::AppDataManager() connect(appDataWorker, &AppDataWorker::favoriteAppChanged, this, &AppDataManager::favoriteAppChanged); connect(this, &AppDataManager::fixToFavoriteSignal, appDataWorker, &AppDataWorker::fixToFavoriteSlot); connect(this, &AppDataManager::changedFavoriteOrderSignal, appDataWorker, &AppDataWorker::changedFavoriteOrderSlot); + connect(this, &AppDataManager::fixToTop, appDataWorker, &AppDataWorker::fixToTopSlot); m_workerThread.start(); } diff --git a/src/appdata/app-data-manager.h b/src/appdata/app-data-manager.h index 40411ff..b807f88 100644 --- a/src/appdata/app-data-manager.h +++ b/src/appdata/app-data-manager.h @@ -57,6 +57,7 @@ Q_SIGNALS: void favoriteAppChanged(); void fixToFavoriteSignal(const QString &path, const int &num); void changedFavoriteOrderSignal(const QString &path, const int &num); + void fixToTop(const QString &path, const int &num); private: AppDataManager(); diff --git a/src/appdata/plugin/all-app-data-provider.cpp b/src/appdata/plugin/all-app-data-provider.cpp index e5edae4..63349cd 100644 --- a/src/appdata/plugin/all-app-data-provider.cpp +++ b/src/appdata/plugin/all-app-data-provider.cpp @@ -100,7 +100,13 @@ void AllAppDataProvider::reloadAppData() } std::sort(appData.begin(), appData.end(), [](const DataEntity &a, const DataEntity &b) { - return (a.top() > b.top()) || (a.launchTimes() > b.launchTimes()); + if (a.top() == 0) { + return (a.top() == b.top()) ? (a.launchTimes() > b.launchTimes()) : (a.top() > b.top()); + } else if (b.top() == 0) { + return a.top() > b.top(); + } else { + return a.top() < b.top(); + } }); m_appData.swap(appData); diff --git a/src/data-entity.cpp b/src/data-entity.cpp index 0b7ffd6..0d19325 100644 --- a/src/data-entity.cpp +++ b/src/data-entity.cpp @@ -178,6 +178,7 @@ QHash DataEntity::AppRoleNames() names.insert(DataEntity::Name, "name"); names.insert(DataEntity::Comment, "comment"); names.insert(DataEntity::ExtraData, "extraData"); + names.insert(DataEntity::Top, "top"); return names; } diff --git a/src/data-entity.h b/src/data-entity.h index ddd00e7..ec09661 100644 --- a/src/data-entity.h +++ b/src/data-entity.h @@ -57,7 +57,8 @@ public: Icon, Name, Comment, - ExtraData + ExtraData, + Top }; DataEntity(); DataEntity(DataType::Type type, const QString& name, const QString& icon, const QString& comment, const QString& extraData); diff --git a/src/menu/menu-manager.cpp b/src/menu/menu-manager.cpp index 8aad0e0..9b758d5 100644 --- a/src/menu/menu-manager.cpp +++ b/src/menu/menu-manager.cpp @@ -44,6 +44,7 @@ public: QList generateActions(QObject *parent, const RequestType &type, const QVariant &data) override; private: + void addToTop(QObject *parent, const QString &appId, const int &appTop, QList &list); void addToPanelAction(QObject *parent, const QString &appId, QList &list); void addToDesktopAction(QObject *parent, const QString &appId, QList &list); void addUninstall(QObject *parent, const QString &appId, QList &list); @@ -75,6 +76,10 @@ AppMenuProvider::generateActions(QObject *parent, const MenuProvider::RequestTyp QList list; QString appId = app.id(); + int appTop = app.top(); + + //置顶 + addToTop(parent, appId, appTop ,list); // 添加到任务栏 addToPanelAction(parent, appId, list); @@ -88,6 +93,15 @@ AppMenuProvider::generateActions(QObject *parent, const MenuProvider::RequestTyp return list; } +void AppMenuProvider::addToTop(QObject *parent, const QString &appId, const int &appTop, QList &list) +{ + QString actionName = (appTop == 0) ? QObject::tr("Fixed to all applications") : QObject::tr("Unfixed from all applications"); + list << new QAction(actionName, parent); + QObject::connect(list.last(), &QAction::triggered, parent, [appId, appTop] { + AppDataManager::instance()->fixToTop(appId, appTop); + }); +} + void AppMenuProvider::addToPanelAction(QObject *parent, const QString &appId, QList &list) { QDBusInterface iface("com.ukui.panel.desktop", "/", "com.ukui.panel.desktop", QDBusConnection::sessionBus()); diff --git a/src/model/app-model.cpp b/src/model/app-model.cpp index 0f8bbb2..1bc9c87 100644 --- a/src/model/app-model.cpp +++ b/src/model/app-model.cpp @@ -58,6 +58,11 @@ QVariant AppModel::data(const QModelIndex &index, int role) const return m_apps.at(i).comment(); case DataEntity::ExtraData: return m_apps.at(i).extraData(); + case DataEntity::Top: + if (DataProviderManager::instance()->activatedProvider() == "all") { + return m_apps.at(i).top(); + } + return 0; default: break; } diff --git a/translations/ukui-menu_bo_CN.ts b/translations/ukui-menu_bo_CN.ts index dc28e74..67f25f2 100644 --- a/translations/ukui-menu_bo_CN.ts +++ b/translations/ukui-menu_bo_CN.ts @@ -66,6 +66,14 @@ Add to taskbar + + Fixed to all applications + + + + Unfixed from all applications + + SearchInputBar diff --git a/translations/ukui-menu_zh_CN.ts b/translations/ukui-menu_zh_CN.ts index d111fa8..1d91cf0 100644 --- a/translations/ukui-menu_zh_CN.ts +++ b/translations/ukui-menu_zh_CN.ts @@ -32,7 +32,7 @@ Add to folder - 添加至应用组 + 添加至应用组 Add to new folder @@ -74,6 +74,14 @@ Add to taskbar 固定到任务栏 + + Fixed to all applications + 固定到所有应用 + + + Unfixed from all applications + 从所有应用取消固定 + SearchInputBar @@ -86,14 +94,14 @@ UkuiMenu::AllAppDataProvider All - 全部 + 所有应用 UkuiMenu::AppCategoryPlugin Category - 分类 + 功能排序 Audio