增加标题显示

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
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 {

View File

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

View File

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

View File

@ -129,6 +129,24 @@ QVector<ProviderInfo> 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) {

View File

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

View File

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

View File

@ -84,7 +84,7 @@ QString AppCategoryPlugin::icon()
QString AppCategoryPlugin::title()
{
return "Category";
return tr("Category");
}
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)
{
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"

View File

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