diff --git a/qml/AppUI/AppList.qml b/qml/AppUI/AppList.qml index 9505500..2f2882a 100644 --- a/qml/AppUI/AppList.qml +++ b/qml/AppUI/AppList.qml @@ -24,6 +24,7 @@ import AppControls2 1.0 as AppControls2 import org.ukui.menu.core 1.0 Item { + id: appListRoot property string title: "" property string idSelect: "" signal labelItemClicked() @@ -68,6 +69,17 @@ Item { } } } + + view.onContentYChanged: { + if (appPageHeaderUtils.currentPluginId() === "all") { + return; + } + + var obj = view.itemAt(10, view.contentY); + if (obj !== null && obj.type === DataType.Label) { + appListRoot.title = obj.name; + } + } } Component { diff --git a/qml/AppUI/AppPageContent.qml b/qml/AppUI/AppPageContent.qml index fc658da..dae0063 100644 --- a/qml/AppUI/AppPageContent.qml +++ b/qml/AppUI/AppPageContent.qml @@ -44,6 +44,9 @@ SwipeView { appList.visible = false; selectionPage.viewShowStart(); } + onTitleChanged: { + appPageHeader.title = title; + } } SelectionPage { diff --git a/qml/AppUI/AppPageHeader.qml b/qml/AppUI/AppPageHeader.qml index 34e8c28..2c0f149 100644 --- a/qml/AppUI/AppPageHeader.qml +++ b/qml/AppUI/AppPageHeader.qml @@ -179,6 +179,7 @@ Item { id: searchListView Layout.preferredWidth: childrenRect.width Layout.preferredHeight: 32 + Layout.minimumWidth: 32 Layout.maximumWidth: 68 Layout.alignment: Qt.AlignVCenter @@ -210,11 +211,25 @@ Item { Layout.preferredWidth: childrenRect.width Layout.preferredHeight: 32 Layout.maximumHeight: 32 + Layout.minimumWidth: 32 Layout.rightMargin: 8 Layout.alignment: Qt.AlignVCenter } } } + + function updateTitle(id) { + appPageHeaderRoot.title = appPageHeaderUtils.getPluginTitle(id); + } + + Component.onCompleted: { + updateTitle(""); + appPageHeaderUtils.pluginChanged.connect(updateTitle); + } + + Component.onDestruction: { + appPageHeaderUtils.pluginChanged.disconnect(updateTitle); + } } } } diff --git a/src/appdata/data-provider-manager.cpp b/src/appdata/data-provider-manager.cpp index f5189cd..3a9ea2b 100644 --- a/src/appdata/data-provider-manager.cpp +++ b/src/appdata/data-provider-manager.cpp @@ -129,6 +129,24 @@ QVector DataProviderManager::providers(PluginGroup::Group group) c return infos; } +ProviderInfo DataProviderManager::providerInfo(const QString &id) const +{ + ProviderInfo info; + DataProviderPluginIFace* provider = m_providers.value(id, nullptr); + if (provider) { + info = { + provider->index(), + provider->id(), + provider->name(), + provider->icon(), + provider->title(), + provider->group() + }; + } + + return info; +} + void DataProviderManager::activateProvider(const QString &id) { if (!m_providers.contains(id) || m_activatedPlugin == id) { diff --git a/src/appdata/data-provider-manager.h b/src/appdata/data-provider-manager.h index 6c3e30a..10afb18 100644 --- a/src/appdata/data-provider-manager.h +++ b/src/appdata/data-provider-manager.h @@ -47,6 +47,7 @@ public: QStringList providers() const; QVector providers(PluginGroup::Group group) const; + ProviderInfo providerInfo(const QString &id) const; QString activatedProvider() const; void activateProvider(const QString &id); QVector data() const; diff --git a/src/appdata/plugin/all-app-data-provider.cpp b/src/appdata/plugin/all-app-data-provider.cpp index b11d846..3c9f229 100644 --- a/src/appdata/plugin/all-app-data-provider.cpp +++ b/src/appdata/plugin/all-app-data-provider.cpp @@ -60,7 +60,7 @@ QString AllAppDataProvider::icon() QString AllAppDataProvider::title() { - return "Recently installed"; + return tr("All applications"); } PluginGroup::Group AllAppDataProvider::group() diff --git a/src/appdata/plugin/app-category-plugin.cpp b/src/appdata/plugin/app-category-plugin.cpp index 8228e42..62c4183 100644 --- a/src/appdata/plugin/app-category-plugin.cpp +++ b/src/appdata/plugin/app-category-plugin.cpp @@ -84,7 +84,7 @@ QString AppCategoryPlugin::icon() QString AppCategoryPlugin::title() { - return "Category"; + return tr("Category"); } PluginGroup::Group AppCategoryPlugin::group() diff --git a/src/utils/app-page-header-utils.cpp b/src/utils/app-page-header-utils.cpp index 4ee6940..0a6d86d 100644 --- a/src/utils/app-page-header-utils.cpp +++ b/src/utils/app-page-header-utils.cpp @@ -196,24 +196,42 @@ AppPageHeaderUtils::AppPageHeaderUtils(QObject *parent) : QObject(parent) void AppPageHeaderUtils::onPluginChanged(const QString &id, PluginGroup::Group group) { - m_models.value(group)->updateCurrentPId(id); + ProviderModel *model = m_models.value(group); + if (model) { + model->updateCurrentPId(id); + Q_EMIT pluginChanged(id); + } } -ProviderModel *AppPageHeaderUtils::model(PluginGroup::Group group) +ProviderModel *AppPageHeaderUtils::model(PluginGroup::Group group) const { return m_models.value(group); } -void AppPageHeaderUtils::activateProvider(const QString &name) +void AppPageHeaderUtils::activateProvider(const QString &name) const { DataProviderManager::instance()->activateProvider(name); } -void AppPageHeaderUtils::startSearch(QString key) +void AppPageHeaderUtils::startSearch(QString key) const { DataProviderManager::instance()->forceUpdate(key); } +QString AppPageHeaderUtils::getPluginTitle(QString id) const +{ + if (id.isEmpty()) { + id = DataProviderManager::instance()->activatedProvider(); + } + + return DataProviderManager::instance()->providerInfo(id).title; +} + +QString AppPageHeaderUtils::currentPluginId() const +{ + return DataProviderManager::instance()->activatedProvider(); +} + } // UkuiMenu #include "app-page-header-utils.moc" diff --git a/src/utils/app-page-header-utils.h b/src/utils/app-page-header-utils.h index 1e51cb8..f6c87af 100644 --- a/src/utils/app-page-header-utils.h +++ b/src/utils/app-page-header-utils.h @@ -35,11 +35,16 @@ public: explicit AppPageHeaderUtils(QObject *parent = nullptr); // 激活某插件 - Q_INVOKABLE void activateProvider(const QString &name); + Q_INVOKABLE void activateProvider(const QString &name) const; // 获取不同的model - Q_INVOKABLE ProviderModel *model(PluginGroup::Group group); + Q_INVOKABLE ProviderModel *model(PluginGroup::Group group) const; - Q_INVOKABLE void startSearch(QString key); + Q_INVOKABLE void startSearch(QString key) const; + Q_INVOKABLE QString getPluginTitle(QString id) const; + Q_INVOKABLE QString currentPluginId() const; + +Q_SIGNALS: + void pluginChanged(const QString &id); private Q_SLOTS: void onPluginChanged(const QString &id, PluginGroup::Group group);