feat: 在全屏界面上显示Widget插件

This commit is contained in:
hewenfei 2024-01-24 10:16:54 +08:00
parent e29052607f
commit 970dc89f26
5 changed files with 113 additions and 8 deletions

View File

@ -18,11 +18,12 @@
* *
*/ */
import QtQuick 2.12 import QtQuick 2.15
import QtQml.Models 2.12 import QtQml.Models 2.12
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import org.ukui.menu.core 1.0 import org.ukui.menu.core 1.0
import org.ukui.menu.extension 1.0
import AppControls2 1.0 as AppControls2 import AppControls2 1.0 as AppControls2
import org.ukui.quick.items 1.0 as UkuiItems import org.ukui.quick.items 1.0 as UkuiItems
@ -54,6 +55,7 @@ ListView {
width: parent.width width: parent.width
height: root.itemHeight height: root.itemHeight
displayName: model.name displayName: model.name
visible: displayName !== ""
} }
GridView { 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});
}
}
}
}
}
} }

View File

@ -117,6 +117,28 @@ UkuiItems.StyleBackground {
labelColum: 1 labelColum: 1
cellHeight: 34 cellHeight: 34
// TODO: widgetmodelmodel
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 interactive: height > parent.height
highlightMoveDuration: 300 highlightMoveDuration: 300
highlight: UkuiItems.StyleBackground { highlight: UkuiItems.StyleBackground {
@ -148,19 +170,32 @@ UkuiItems.StyleBackground {
sourceModel: AppPageBackend.appModel sourceModel: AppPageBackend.appModel
function positionLabel(label) { function positionLabel(label) {
// Widget
// console.log("=positionLabel=", label)
if (headerItem.widgets.includes(label)) {
positionViewAtBeginning();
} else {
let index = model.findLabelIndex(label); let index = model.findLabelIndex(label);
if (index >= 0) { if (index >= 0) {
positionViewAtIndex(index, ListView.Beginning) positionViewAtIndex(index, ListView.Beginning)
} }
} }
}
onContentYChanged: { onContentYChanged: {
// 200 // 200, item
let index = indexAt(10, contentY + 200); let index = indexAt(10, contentY + 200);
if (index >= 0) { if (index >= 0) {
appLabelPage.currentIndex = index + 1; appLabelPage.currentIndex = index + headerItem.widgetCount;
} else if (contentY < 0) {
appLabelPage.currentIndex = 0;
} }
} }
Component.onCompleted: {
positionViewAtBeginning();
}
} }
} }
} }

View File

@ -25,7 +25,7 @@ namespace UkuiMenu {
FavoriteWidget::FavoriteWidget(QObject *parent) : WidgetExtension(parent) FavoriteWidget::FavoriteWidget(QObject *parent) : WidgetExtension(parent)
{ {
m_metadata.insert(WidgetMetadata::Id, "favorite"); 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::Name, tr("Favorite"));
m_metadata.insert(WidgetMetadata::Tooltip, tr("favorite")); m_metadata.insert(WidgetMetadata::Tooltip, tr("favorite"));
m_metadata.insert(WidgetMetadata::Version, "1.0.0"); m_metadata.insert(WidgetMetadata::Version, "1.0.0");

View File

@ -65,7 +65,7 @@ bool WidgetModel::filterAcceptsRow(int source_row, const QModelIndex &source_par
bool acceptFlag = m_types.testFlag(index.data(WidgetMetadata::Type).value<WidgetMetadata::TypeValue>()); bool acceptFlag = m_types.testFlag(index.data(WidgetMetadata::Type).value<WidgetMetadata::TypeValue>());
if (acceptFlag) { if (acceptFlag) {
return m_flags.testFlag(index.data(WidgetMetadata::Flag).value<WidgetMetadata::FlagValue>()); return m_flags & index.data(WidgetMetadata::Flag).value<WidgetMetadata::FlagValue>();
} }
return false; return false;
} }

View File

@ -75,6 +75,7 @@ void UkuiMenuApplication::registerQmlTypes()
qmlRegisterUncreatableType<UkuiMenu::DataType>(uri, versionMajor, versionMinor, "DataType", "Use enums only"); qmlRegisterUncreatableType<UkuiMenu::DataType>(uri, versionMajor, versionMinor, "DataType", "Use enums only");
qmlRegisterUncreatableType<UkuiMenu::MenuInfo>(uri, versionMajor, versionMinor, "MenuInfo", "Use enums only."); qmlRegisterUncreatableType<UkuiMenu::MenuInfo>(uri, versionMajor, versionMinor, "MenuInfo", "Use enums only.");
qmlRegisterUncreatableType<UkuiMenu::LabelItem>(uri, versionMajor, versionMinor, "LabelItem", "Use enums only."); qmlRegisterUncreatableType<UkuiMenu::LabelItem>(uri, versionMajor, versionMinor, "LabelItem", "Use enums only.");
qmlRegisterUncreatableType<UkuiMenu::WidgetMetadata>(uri, versionMajor, versionMinor, "WidgetMetadata", "Use enums only.");
// qmlRegisterUncreatableType<UkuiMenu::DataEntity>(uri, versionMajor, versionMinor, "DataEntity", "unknown"); // qmlRegisterUncreatableType<UkuiMenu::DataEntity>(uri, versionMajor, versionMinor, "DataEntity", "unknown");
qmlRegisterUncreatableType<EventTrack>(uri, versionMajor, versionMinor, "EventTrack", "Attached only."); qmlRegisterUncreatableType<EventTrack>(uri, versionMajor, versionMinor, "EventTrack", "Attached only.");