主界面跟随主题透明度,调整ui细节,model监听插件数据变化

This commit is contained in:
hewenfei 2023-02-22 10:23:18 +08:00
parent 7ccf808411
commit cad6456a44
4 changed files with 64 additions and 56 deletions

View File

@ -41,21 +41,20 @@ Item {
ListView { ListView {
Layout.preferredWidth: childrenRect.width Layout.preferredWidth: childrenRect.width
Layout.preferredHeight: 32 Layout.preferredHeight: 32
Layout.maximumWidth: 68
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
clip: true clip: true
spacing: 4
orientation: ListView.Horizontal orientation: ListView.Horizontal
model: appPageHeaderUtils.model(PluginGroup.Button) model: appPageHeaderUtils.model(PluginGroup.Button)
delegate: Item { delegate: Image {
width: 32 width: height
height: ListView.view ? ListView.view.height : 0 height: ListView.view ? ListView.view.height : 0
Image {
anchors.fill: parent
source: model.icon source: model.icon
} }
} }
}
Row { Row {
Layout.preferredWidth: childrenRect.width Layout.preferredWidth: childrenRect.width
@ -107,7 +106,8 @@ Item {
Menu { Menu {
id: sortMenu id: sortMenu
width: 128 width: 128
height: 112 height: 120
padding: 8
clip: true clip: true
property var sortMenuModel: appPageHeaderUtils.model(PluginGroup.SortMenuItem) property var sortMenuModel: appPageHeaderUtils.model(PluginGroup.SortMenuItem)
@ -132,17 +132,15 @@ Item {
contentItem: ListView { contentItem: ListView {
clip: true clip: true
spacing: 4
model: sortMenu.sortMenuModel model: sortMenu.sortMenuModel
delegate: Item { delegate: AppControls2.StyleBackground {
width: ListView.view ? ListView.view.width : 0 width: ListView.view ? ListView.view.width : 0
height: 48 height: 32
AppControls2.StyleBackground {
anchors.fill: parent
anchors.margins: 8
radius: 4 radius: 4
alpha: (model.isChecked || mouseArea.isHoverd) ? 0.2 : 1
paletteRole: (model.isChecked || mouseArea.isHoverd) ? Palette.Text : Palette.Window paletteRole: (model.isChecked || mouseArea.isHoverd) ? Palette.Text : Palette.Window
useStyleTransparent: false useStyleTransparent: false
alpha: (model.isChecked || mouseArea.isHoverd) ? 0.2 : 1
Item { Item {
anchors.fill: parent anchors.fill: parent
@ -184,5 +182,4 @@ Item {
} }
} }
} }
}
} }

View File

@ -6,8 +6,6 @@ import org.ukui.menu.core 1.0
AppControls2.StyleBackground { AppControls2.StyleBackground {
paletteRole: Palette.Window paletteRole: Palette.Window
radius: 12 radius: 12
useStyleTransparent: false
alpha: 0.75
Row { Row {
anchors.fill: parent; anchors.fill: parent;

View File

@ -28,12 +28,9 @@ namespace UkuiMenu {
AppModel::AppModel(QObject *parent) : QAbstractListModel(parent) AppModel::AppModel(QObject *parent) : QAbstractListModel(parent)
{ {
m_apps.append(DataProviderManager::instance()->data()); reloadPluginData();
connect(DataProviderManager::instance(), &DataProviderManager::dataChanged, this, [this] (QVector<DataEntity> data) { connect(DataProviderManager::instance(), &DataProviderManager::dataChanged, this, &AppModel::onPluginDataChanged);
Q_EMIT beginResetModel(); connect(DataProviderManager::instance(), &DataProviderManager::pluginChanged, this, &AppModel::reloadPluginData);
m_apps.swap(data);
Q_EMIT endResetModel();
});
} }
int AppModel::rowCount(const QModelIndex &parent) const 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()); AppManager::instance()->launchApp(m_apps.at(index).id());
} }
void AppModel::reloadPluginData()
{
onPluginDataChanged(DataProviderManager::instance()->data());
}
void AppModel::onPluginDataChanged(QVector<DataEntity> data)
{
Q_EMIT beginResetModel();
m_apps.swap(data);
Q_EMIT endResetModel();
}
} // UkuiMenu } // UkuiMenu

View File

@ -39,6 +39,10 @@ public:
Q_INVOKABLE QVariantList folderApps(const QString &folderName); Q_INVOKABLE QVariantList folderApps(const QString &folderName);
Q_INVOKABLE void appClicked(const int &index); Q_INVOKABLE void appClicked(const int &index);
private Q_SLOTS:
void onPluginDataChanged(QVector<DataEntity> data);
void reloadPluginData();
private: private:
QVector<DataEntity> m_apps; QVector<DataEntity> m_apps;
}; };