增加标题显示

This commit is contained in:
hewenfei 2023-05-17 14:03:33 +08:00 committed by He Sir
parent aabf9bd747
commit 89b0d68778
9 changed files with 81 additions and 9 deletions

View File

@ -24,6 +24,7 @@ import AppControls2 1.0 as AppControls2
import org.ukui.menu.core 1.0 import org.ukui.menu.core 1.0
Item { Item {
id: appListRoot
property string title: "" property string title: ""
property string idSelect: "" property string idSelect: ""
signal labelItemClicked() 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 { Component {

View File

@ -44,6 +44,9 @@ SwipeView {
appList.visible = false; appList.visible = false;
selectionPage.viewShowStart(); selectionPage.viewShowStart();
} }
onTitleChanged: {
appPageHeader.title = title;
}
} }
SelectionPage { SelectionPage {

View File

@ -179,6 +179,7 @@ Item {
id: searchListView id: searchListView
Layout.preferredWidth: childrenRect.width Layout.preferredWidth: childrenRect.width
Layout.preferredHeight: 32 Layout.preferredHeight: 32
Layout.minimumWidth: 32
Layout.maximumWidth: 68 Layout.maximumWidth: 68
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
@ -210,11 +211,25 @@ Item {
Layout.preferredWidth: childrenRect.width Layout.preferredWidth: childrenRect.width
Layout.preferredHeight: 32 Layout.preferredHeight: 32
Layout.maximumHeight: 32 Layout.maximumHeight: 32
Layout.minimumWidth: 32
Layout.rightMargin: 8 Layout.rightMargin: 8
Layout.alignment: Qt.AlignVCenter 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);
}
} }
} }
} }

View File

@ -129,6 +129,24 @@ QVector<ProviderInfo> DataProviderManager::providers(PluginGroup::Group group) c
return infos; 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) void DataProviderManager::activateProvider(const QString &id)
{ {
if (!m_providers.contains(id) || m_activatedPlugin == id) { if (!m_providers.contains(id) || m_activatedPlugin == id) {

View File

@ -47,6 +47,7 @@ public:
QStringList providers() const; QStringList providers() const;
QVector<ProviderInfo> providers(PluginGroup::Group group) const; QVector<ProviderInfo> providers(PluginGroup::Group group) const;
ProviderInfo providerInfo(const QString &id) const;
QString activatedProvider() const; QString activatedProvider() const;
void activateProvider(const QString &id); void activateProvider(const QString &id);
QVector<DataEntity> data() const; QVector<DataEntity> data() const;

View File

@ -60,7 +60,7 @@ QString AllAppDataProvider::icon()
QString AllAppDataProvider::title() QString AllAppDataProvider::title()
{ {
return "Recently installed"; return tr("All applications");
} }
PluginGroup::Group AllAppDataProvider::group() PluginGroup::Group AllAppDataProvider::group()

View File

@ -84,7 +84,7 @@ QString AppCategoryPlugin::icon()
QString AppCategoryPlugin::title() QString AppCategoryPlugin::title()
{ {
return "Category"; return tr("Category");
} }
PluginGroup::Group AppCategoryPlugin::group() PluginGroup::Group AppCategoryPlugin::group()

View File

@ -196,24 +196,42 @@ AppPageHeaderUtils::AppPageHeaderUtils(QObject *parent) : QObject(parent)
void AppPageHeaderUtils::onPluginChanged(const QString &id, PluginGroup::Group group) 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); return m_models.value(group);
} }
void AppPageHeaderUtils::activateProvider(const QString &name) void AppPageHeaderUtils::activateProvider(const QString &name) const
{ {
DataProviderManager::instance()->activateProvider(name); DataProviderManager::instance()->activateProvider(name);
} }
void AppPageHeaderUtils::startSearch(QString key) void AppPageHeaderUtils::startSearch(QString key) const
{ {
DataProviderManager::instance()->forceUpdate(key); 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 } // UkuiMenu
#include "app-page-header-utils.moc" #include "app-page-header-utils.moc"

View File

@ -35,11 +35,16 @@ public:
explicit AppPageHeaderUtils(QObject *parent = nullptr); explicit AppPageHeaderUtils(QObject *parent = nullptr);
// 激活某插件 // 激活某插件
Q_INVOKABLE void activateProvider(const QString &name); Q_INVOKABLE void activateProvider(const QString &name) const;
// 获取不同的model // 获取不同的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: private Q_SLOTS:
void onPluginChanged(const QString &id, PluginGroup::Group group); void onPluginChanged(const QString &id, PluginGroup::Group group);