feat: 在全屏界面上显示Widget插件
This commit is contained in:
parent
e29052607f
commit
970dc89f26
|
@ -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});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,18 +170,31 @@ UkuiItems.StyleBackground {
|
|||
sourceModel: AppPageBackend.appModel
|
||||
|
||||
function positionLabel(label) {
|
||||
// 如果是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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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>());
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -75,6 +75,7 @@ void UkuiMenuApplication::registerQmlTypes()
|
|||
qmlRegisterUncreatableType<UkuiMenu::DataType>(uri, versionMajor, versionMinor, "DataType", "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::WidgetMetadata>(uri, versionMajor, versionMinor, "WidgetMetadata", "Use enums only.");
|
||||
// qmlRegisterUncreatableType<UkuiMenu::DataEntity>(uri, versionMajor, versionMinor, "DataEntity", "unknown");
|
||||
|
||||
qmlRegisterUncreatableType<EventTrack>(uri, versionMajor, versionMinor, "EventTrack", "Attached only.");
|
||||
|
|
Loading…
Reference in New Issue