添加开始菜单置顶功能

This commit is contained in:
gjq 2023-04-12 17:13:28 +08:00 committed by hewenfei
parent a9fae261c6
commit 178e64a96d
11 changed files with 107 additions and 11 deletions

View File

@ -15,13 +15,53 @@ MouseArea {
ToolTip.visible: content.textTruncated && control.containsMouse
ToolTip.text: name
RowLayout {
anchors.fill: parent
spacing: 2
IconLabel {
id: content
anchors.fill: parent
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
}
}
}
}

View File

@ -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;

View File

@ -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();
}

View File

@ -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();

View File

@ -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);

View File

@ -178,6 +178,7 @@ QHash<int, QByteArray> DataEntity::AppRoleNames()
names.insert(DataEntity::Name, "name");
names.insert(DataEntity::Comment, "comment");
names.insert(DataEntity::ExtraData, "extraData");
names.insert(DataEntity::Top, "top");
return names;
}

View File

@ -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);

View File

@ -44,6 +44,7 @@ public:
QList<QAction *> generateActions(QObject *parent, const RequestType &type, const QVariant &data) override;
private:
void addToTop(QObject *parent, const QString &appId, const int &appTop, QList<QAction *> &list);
void addToPanelAction(QObject *parent, const QString &appId, QList<QAction *> &list);
void addToDesktopAction(QObject *parent, const QString &appId, QList<QAction *> &list);
void addUninstall(QObject *parent, const QString &appId, QList<QAction *> &list);
@ -75,6 +76,10 @@ AppMenuProvider::generateActions(QObject *parent, const MenuProvider::RequestTyp
QList<QAction *> 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<QAction *> &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<QAction *> &list)
{
QDBusInterface iface("com.ukui.panel.desktop", "/", "com.ukui.panel.desktop", QDBusConnection::sessionBus());

View File

@ -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;
}

View File

@ -66,6 +66,14 @@
<source>Add to taskbar</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Fixed to all applications</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unfixed from all applications</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SearchInputBar</name>

View File

@ -32,7 +32,7 @@
</message>
<message>
<source>Add to folder</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
<message>
<source>Add to new folder</source>
@ -74,6 +74,14 @@
<source>Add to taskbar</source>
<translation></translation>
</message>
<message>
<source>Fixed to all applications</source>
<translation></translation>
</message>
<message>
<source>Unfixed from all applications</source>
<translation></translation>
</message>
</context>
<context>
<name>SearchInputBar</name>
@ -86,14 +94,14 @@
<name>UkuiMenu::AllAppDataProvider</name>
<message>
<source>All</source>
<translation></translation>
<translation></translation>
</message>
</context>
<context>
<name>UkuiMenu::AppCategoryPlugin</name>
<message>
<source>Category</source>
<translation></translation>
<translation></translation>
</message>
<message>
<source>Audio</source>