主界面跟随主题透明度,调整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,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;
}
}
}

View File

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

View File

@ -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<DataEntity> 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<DataEntity> data)
{
Q_EMIT beginResetModel();
m_apps.swap(data);
Q_EMIT endResetModel();
}
} // UkuiMenu

View File

@ -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<DataEntity> data);
void reloadPluginData();
private:
QVector<DataEntity> m_apps;
};