From 970dc89f269ef9014f9c1bac43770c5982ed4379 Mon Sep 17 00:00:00 2001 From: hewenfei Date: Wed, 24 Jan 2024 10:16:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=E5=85=A8=E5=B1=8F=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E4=B8=8A=E6=98=BE=E7=A4=BAWidget=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qml/AppUI/FullScreenAppList.qml | 71 +++++++++++++++++++++- qml/AppUI/FullScreenUI.qml | 45 ++++++++++++-- src/extension/favorite/favorite-widget.cpp | 2 +- src/extension/widget-model.cpp | 2 +- src/ukui-menu-application.cpp | 1 + 5 files changed, 113 insertions(+), 8 deletions(-) diff --git a/qml/AppUI/FullScreenAppList.qml b/qml/AppUI/FullScreenAppList.qml index c921db7..ea383c3 100644 --- a/qml/AppUI/FullScreenAppList.qml +++ b/qml/AppUI/FullScreenAppList.qml @@ -18,11 +18,12 @@ * */ -import QtQuick 2.12 +import QtQuick 2.15 import QtQml.Models 2.12 import QtQuick.Layouts 1.12 import org.ukui.menu.core 1.0 +import org.ukui.menu.extension 1.0 import AppControls2 1.0 as AppControls2 import org.ukui.quick.items 1.0 as UkuiItems @@ -54,6 +55,7 @@ ListView { width: parent.width height: root.itemHeight displayName: model.name + visible: displayName !== "" } GridView { @@ -94,4 +96,71 @@ ListView { } } } + + header: Item { + width: ListView.view.width + height: childrenRect.height + ListView.view.spacing + + property alias widgets: widgetView.widgets + property alias widgetCount: widgetView.count + property alias widgetInfos: widgetView.widgetInfos + + ListView { + id: widgetView + + property var widgets: [] + property var widgetInfos: [] + + anchors.top: parent.top + width: parent.width + height: childrenRect.height + interactive: false + spacing: parent.ListView.view.spacing + + onCountChanged: { + widgets = []; + widgetInfos = []; + for (let i = 0; i < count; ++i) { + let item = itemAtIndex(i); + widgetInfos.push({label: item.widgetId, display: item.icon, type: LabelItem.Icon}); + widgets.push(item.widgetId); + } + } + + model: WidgetModel { + flags: WidgetMetadata.OnlyFullScreen + } + delegate: Column { + property string icon: model.icon + property string widgetId: model.id + + width: ListView.view.width + height: childrenRect.height + spacing: ListView.view.spacing + + AppControls2.LabelItem { + width: parent.width + height: root.itemHeight + displayName: model.name + } + + Loader { + width: parent.width + // height: item === null ? 0 : item.height + height: item === null ? 0 : 200 + + property var extensionData: model.data + onExtensionDataChanged: { + if (item !== null) { + item.extensionData = extensionData; + } + } + + Component.onCompleted: { + setSource(model.main, {extensionData: extensionData}); + } + } + } + } + } } diff --git a/qml/AppUI/FullScreenUI.qml b/qml/AppUI/FullScreenUI.qml index ca42007..87c18df 100644 --- a/qml/AppUI/FullScreenUI.qml +++ b/qml/AppUI/FullScreenUI.qml @@ -117,6 +117,28 @@ UkuiItems.StyleBackground { labelColum: 1 cellHeight: 34 + // TODO: 潜在的优化点,尝试组合widget的model和应用model + model: { + if (labelBottle !== null) { + let labelItems = [], i = 0, item = null; + let widgetInfos = fullScreenAppList.headerItem.widgetInfos; + for (i = 0; i < widgetInfos.length; ++i) { + item = widgetInfos[i]; + labelItems.push({label: item.label, type: item.type, display: item.display}); + } + + let labels = labelBottle.labels; + for (i = 0; i < labels.length; ++i) { + item = labels[i]; + labelItems.push({label: item.label, type: item.type, display: item.display}); + } + + return labelItems; + } + + return []; + } + interactive: height > parent.height highlightMoveDuration: 300 highlight: UkuiItems.StyleBackground { @@ -148,19 +170,32 @@ UkuiItems.StyleBackground { sourceModel: AppPageBackend.appModel function positionLabel(label) { - let index = model.findLabelIndex(label); - if (index >= 0) { - positionViewAtIndex(index, ListView.Beginning) + // 如果是Widget那么直接滚动到最顶上 + // console.log("=positionLabel=", label) + if (headerItem.widgets.includes(label)) { + positionViewAtBeginning(); + + } else { + let index = model.findLabelIndex(label); + if (index >= 0) { + positionViewAtIndex(index, ListView.Beginning) + } } } onContentYChanged: { - // 向下偏移200 + // 向下偏移200, 计算偏移后在那个item里 let index = indexAt(10, contentY + 200); if (index >= 0) { - appLabelPage.currentIndex = index + 1; + appLabelPage.currentIndex = index + headerItem.widgetCount; + } else if (contentY < 0) { + appLabelPage.currentIndex = 0; } } + + Component.onCompleted: { + positionViewAtBeginning(); + } } } } diff --git a/src/extension/favorite/favorite-widget.cpp b/src/extension/favorite/favorite-widget.cpp index 36c4166..19bd7a6 100644 --- a/src/extension/favorite/favorite-widget.cpp +++ b/src/extension/favorite/favorite-widget.cpp @@ -25,7 +25,7 @@ namespace UkuiMenu { FavoriteWidget::FavoriteWidget(QObject *parent) : WidgetExtension(parent) { m_metadata.insert(WidgetMetadata::Id, "favorite"); - m_metadata.insert(WidgetMetadata::Icon, ""); + m_metadata.insert(WidgetMetadata::Icon, "non-starred-symbolic"); m_metadata.insert(WidgetMetadata::Name, tr("Favorite")); m_metadata.insert(WidgetMetadata::Tooltip, tr("favorite")); m_metadata.insert(WidgetMetadata::Version, "1.0.0"); diff --git a/src/extension/widget-model.cpp b/src/extension/widget-model.cpp index b73f997..de3fa4b 100644 --- a/src/extension/widget-model.cpp +++ b/src/extension/widget-model.cpp @@ -65,7 +65,7 @@ bool WidgetModel::filterAcceptsRow(int source_row, const QModelIndex &source_par bool acceptFlag = m_types.testFlag(index.data(WidgetMetadata::Type).value()); if (acceptFlag) { - return m_flags.testFlag(index.data(WidgetMetadata::Flag).value()); + return m_flags & index.data(WidgetMetadata::Flag).value(); } return false; } diff --git a/src/ukui-menu-application.cpp b/src/ukui-menu-application.cpp index d23bcdb..7a03f23 100644 --- a/src/ukui-menu-application.cpp +++ b/src/ukui-menu-application.cpp @@ -75,6 +75,7 @@ void UkuiMenuApplication::registerQmlTypes() qmlRegisterUncreatableType(uri, versionMajor, versionMinor, "DataType", "Use enums only"); qmlRegisterUncreatableType(uri, versionMajor, versionMinor, "MenuInfo", "Use enums only."); qmlRegisterUncreatableType(uri, versionMajor, versionMinor, "LabelItem", "Use enums only."); + qmlRegisterUncreatableType(uri, versionMajor, versionMinor, "WidgetMetadata", "Use enums only."); // qmlRegisterUncreatableType(uri, versionMajor, versionMinor, "DataEntity", "unknown"); qmlRegisterUncreatableType(uri, versionMajor, versionMinor, "EventTrack", "Attached only.");