From cad6456a44f2e6125ca7bb151a42b7d604f74b00 Mon Sep 17 00:00:00 2001 From: hewenfei Date: Wed, 22 Feb 2023 10:23:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E7=95=8C=E9=9D=A2=E8=B7=9F=E9=9A=8F?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=E9=80=8F=E6=98=8E=E5=BA=A6=EF=BC=8C=E8=B0=83?= =?UTF-8?q?=E6=95=B4ui=E7=BB=86=E8=8A=82=EF=BC=8Cmodel=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E6=95=B0=E6=8D=AE=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qml/AppUI/AppPageHeader.qml | 93 ++++++++++++++++++------------------- qml/AppUI/NormalUI.qml | 2 - src/model/model.cpp | 21 ++++++--- src/model/model.h | 4 ++ 4 files changed, 64 insertions(+), 56 deletions(-) diff --git a/qml/AppUI/AppPageHeader.qml b/qml/AppUI/AppPageHeader.qml index 4efe42f..e00a6f0 100644 --- a/qml/AppUI/AppPageHeader.qml +++ b/qml/AppUI/AppPageHeader.qml @@ -41,19 +41,18 @@ Item { ListView { Layout.preferredWidth: childrenRect.width Layout.preferredHeight: 32 + Layout.maximumWidth: 68 Layout.alignment: Qt.AlignVCenter clip: true + spacing: 4 orientation: ListView.Horizontal model: appPageHeaderUtils.model(PluginGroup.Button) - delegate: Item { - width: 32 + delegate: Image { + width: height height: ListView.view ? ListView.view.height : 0 - Image { - anchors.fill: parent - source: model.icon - } + source: model.icon } } @@ -107,7 +106,8 @@ Item { Menu { id: sortMenu width: 128 - height: 112 + height: 120 + padding: 8 clip: true property var sortMenuModel: appPageHeaderUtils.model(PluginGroup.SortMenuItem) @@ -132,54 +132,51 @@ Item { contentItem: ListView { clip: true + spacing: 4 model: sortMenu.sortMenuModel - delegate: Item { + delegate: AppControls2.StyleBackground { width: ListView.view ? ListView.view.width : 0 - height: 48 - AppControls2.StyleBackground { + height: 32 + radius: 4 + alpha: (model.isChecked || mouseArea.isHoverd) ? 0.2 : 1 + paletteRole: (model.isChecked || mouseArea.isHoverd) ? Palette.Text : Palette.Window + useStyleTransparent: false + + Item { anchors.fill: parent anchors.margins: 8 - radius: 4 - paletteRole: (model.isChecked || mouseArea.isHoverd) ? Palette.Text : Palette.Window - useStyleTransparent: false - alpha: (model.isChecked || mouseArea.isHoverd) ? 0.2 : 1 - - Item { - anchors.fill: parent - anchors.margins: 8 - Image { - visible: model.isChecked - anchors.verticalCenter: parent.verticalCenter - width: 16 - height: 16 - source: "image://appicon/object-select.symbolic" - } - AppControls2.StyleText { - x: 24 - verticalAlignment: Text.AlignVCenter - width: parent.width - x - height: parent.height - text: model.name - } + Image { + visible: model.isChecked + anchors.verticalCenter: parent.verticalCenter + width: 16 + height: 16 + source: "image://appicon/object-select.symbolic" } + AppControls2.StyleText { + x: 24 + verticalAlignment: Text.AlignVCenter + width: parent.width - x + height: parent.height + text: model.name + } + } - MouseArea { - id: mouseArea - anchors.fill: parent - hoverEnabled: true - property bool isHoverd: false - onClicked: { - if (model.isChecked) { - return; - } - appPageHeaderUtils.activateProvider(model.id); - } - onEntered: { - isHoverd = true; - } - onExited: { - isHoverd = false; + MouseArea { + id: mouseArea + anchors.fill: parent + hoverEnabled: true + property bool isHoverd: false + onClicked: { + if (model.isChecked) { + return; } + appPageHeaderUtils.activateProvider(model.id); + } + onEntered: { + isHoverd = true; + } + onExited: { + isHoverd = false; } } } diff --git a/qml/AppUI/NormalUI.qml b/qml/AppUI/NormalUI.qml index 18f6e86..48a6051 100644 --- a/qml/AppUI/NormalUI.qml +++ b/qml/AppUI/NormalUI.qml @@ -6,8 +6,6 @@ import org.ukui.menu.core 1.0 AppControls2.StyleBackground { paletteRole: Palette.Window radius: 12 - useStyleTransparent: false - alpha: 0.75 Row { anchors.fill: parent; diff --git a/src/model/model.cpp b/src/model/model.cpp index ab8fff9..fb22bd2 100644 --- a/src/model/model.cpp +++ b/src/model/model.cpp @@ -28,12 +28,9 @@ namespace UkuiMenu { AppModel::AppModel(QObject *parent) : QAbstractListModel(parent) { - m_apps.append(DataProviderManager::instance()->data()); - connect(DataProviderManager::instance(), &DataProviderManager::dataChanged, this, [this] (QVector data) { - Q_EMIT beginResetModel(); - m_apps.swap(data); - Q_EMIT endResetModel(); - }); + reloadPluginData(); + connect(DataProviderManager::instance(), &DataProviderManager::dataChanged, this, &AppModel::onPluginDataChanged); + connect(DataProviderManager::instance(), &DataProviderManager::pluginChanged, this, &AppModel::reloadPluginData); } int AppModel::rowCount(const QModelIndex &parent) const @@ -102,4 +99,16 @@ void AppModel::appClicked(const int &index) AppManager::instance()->launchApp(m_apps.at(index).id()); } +void AppModel::reloadPluginData() +{ + onPluginDataChanged(DataProviderManager::instance()->data()); +} + +void AppModel::onPluginDataChanged(QVector data) +{ + Q_EMIT beginResetModel(); + m_apps.swap(data); + Q_EMIT endResetModel(); +} + } // UkuiMenu diff --git a/src/model/model.h b/src/model/model.h index 36de9e4..60fcb4e 100644 --- a/src/model/model.h +++ b/src/model/model.h @@ -39,6 +39,10 @@ public: Q_INVOKABLE QVariantList folderApps(const QString &folderName); Q_INVOKABLE void appClicked(const int &index); +private Q_SLOTS: + void onPluginDataChanged(QVector data); + void reloadPluginData(); + private: QVector m_apps; };