From 287081aaaded3e17264afc36fc0a5e0317214a71 Mon Sep 17 00:00:00 2001 From: hewenfei Date: Sun, 11 Jun 2023 17:23:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=A9=E5=B1=95=E6=8E=A5=E5=8F=A3=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=9A=90=E8=97=8F=E7=95=8C=E9=9D=A2=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=9B=B4=E6=96=B0=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extension/recent-file/metadata.json | 2 +- qml/AppUI/Sidebar.qml | 214 ++++++++++++++++----------- src/extension/menu-extension-iface.h | 9 +- src/extension/menu-extension.cpp | 5 + src/extension/menu-extension.h | 3 +- 5 files changed, 140 insertions(+), 93 deletions(-) diff --git a/extension/recent-file/metadata.json b/extension/recent-file/metadata.json index 9079b7e..d076fa2 100644 --- a/extension/recent-file/metadata.json +++ b/extension/recent-file/metadata.json @@ -1,4 +1,4 @@ { "Type": "UKUI_MENU_EXTENSION", - "Version": "1.0.0" + "Version": "1.0.1" } diff --git a/qml/AppUI/Sidebar.qml b/qml/AppUI/Sidebar.qml index cd9212e..4eb182a 100644 --- a/qml/AppUI/Sidebar.qml +++ b/qml/AppUI/Sidebar.qml @@ -24,67 +24,89 @@ import QtQuick.Controls 2.5 import AppControls2 1.0 as AppControls2 import org.ukui.menu.core 1.0 import org.ukui.menu.utils 1.0 +import org.ukui.menu.extension 1.0 Item { ColumnLayout { + id: sidebarLayout + anchors.fill: parent anchors.topMargin: 12 spacing: 0 - Row { + function updateSidebarLayout(options) { + sidebarBottomBar.visible = !options.includes(MenuExtension.HideBottomBar); + fullScreenbutton.visible = !options.includes(MenuExtension.HideFullScreenButton); + } + + Item { + id: sidebarTopBar Layout.fillWidth: true Layout.preferredHeight: 40 Layout.rightMargin: 12 - Layout.leftMargin: 16 + Layout.leftMargin: 12 - ListView { - id: extensionListView - width: parent.width - 34 - height: parent.height - clip: true - spacing: 24 - interactive: false - orientation: ListView.Horizontal - model: extensionManager.extensionModel() - delegate: headerDelegate + RowLayout { + anchors.fill: parent + // spacing: 5 - function send(data) { - if (currentItem !== null) { - model.send(currentIndex, data); + ListView { + id: extensionInfoList + + Layout.fillWidth: true + Layout.fillHeight: true + Layout.leftMargin: 4 + Layout.rightMargin: 4 + + clip: true + spacing: 24 + interactive: false + orientation: ListView.Horizontal + model: extensionManager.extensionModel() + delegate: extensionInfoDelegate + + function send(data) { + if (currentItem !== null) { + model.send(currentIndex, data); + } + } + + onCurrentIndexChanged: { + if (currentItem !== null) { + currentItem.select(); + } } } - onCurrentIndexChanged: { - if (currentItem !== null) { - currentItem.select(); - } - } - } + AppControls2.StyleBackground { + id: fullScreenbutton + Layout.preferredWidth: 34 + Layout.preferredHeight: 34 + Layout.alignment: Qt.AlignVCenter - AppControls2.StyleBackground { - width: 34; height: width - radius: 4 - useStyleTransparent: false - alpha: buttonMouseArea.containsPress ? 0.65 : buttonMouseArea.containsMouse ? 0.40 : 0.00 - borderColor: Palette.Highlight - border.width: buttonMouseArea.activeFocus ? 2 : 0 - ThemeIcon { - anchors.centerIn: parent - width: parent.width / 2; height: width - source: "image://appicon/view-fullscreen-symbolic" - MouseArea { - id: buttonMouseArea - hoverEnabled: true - anchors.fill: parent - ToolTip.delay: 500 - ToolTip.text: qsTr("Expand") - ToolTip.visible: containsMouse + radius: 4 + useStyleTransparent: false + alpha: buttonMouseArea.containsPress ? 0.65 : buttonMouseArea.containsMouse ? 0.40 : 0.00 + borderColor: Palette.Highlight + border.width: buttonMouseArea.activeFocus ? 2 : 0 + ThemeIcon { + anchors.centerIn: parent + width: 16; height: 16 + source: "image://appicon/view-fullscreen-symbolic" + MouseArea { + id: buttonMouseArea + hoverEnabled: true + anchors.fill: parent + ToolTip.delay: 500 + ToolTip.text: qsTr("Expand") + ToolTip.visible: containsMouse - onClicked: mainWindow.isFullScreen = true - activeFocusOnTab: true - Keys.onPressed: { - if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { - mainWindow.isFullScreen = true; + onClicked: mainWindow.isFullScreen = true + activeFocusOnTab: true + Keys.onPressed: { + if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { + mainWindow.isFullScreen = true; + } } } } @@ -101,60 +123,72 @@ Item { anchors.fill: parent clip: true onLoaded: { - item.send.connect(extensionListView.send); + item.send.connect(extensionInfoList.send); + sidebarLayout.updateSidebarLayout(extensionInfoList.currentItem.extensionOptions); } Keys.onTabPressed: { - extensionListView.focus = true + extensionInfoList.focus = true } } } - Row { + Item { + id: sidebarBottomBar Layout.fillWidth: true - Layout.preferredHeight: 40 + Layout.preferredHeight: 32 + Layout.topMargin: 5 + Layout.bottomMargin: 8 + Layout.leftMargin: 12 Layout.rightMargin: 12 - layoutDirection: Qt.RightToLeft - AppControls2.StyleBackground { - width: 32 - height: 32 - paletteRole: Palette.Base - useStyleTransparent: false - alpha: powerButtonArea.containsPress ? 0.85 : powerButtonArea.containsMouse ? 0.65 : 0 - radius: height / 2 - borderColor: Palette.Highlight - border.width: powerButtonArea.activeFocus ? 2 : 0 - PowerButton { - id: powerButtonBase - } + RowLayout { + anchors.fill: parent + layoutDirection: Qt.RightToLeft + spacing: 5 - Image { - anchors.centerIn: parent - width: Math.floor(parent.width / 2) - height: width - source: powerButtonBase.icon - } + AppControls2.StyleBackground { + Layout.preferredWidth: 32 + Layout.preferredHeight: 32 + Layout.alignment: Qt.AlignVCenter - MouseArea { - id: powerButtonArea - anchors.fill: parent - hoverEnabled: true - ToolTip.delay: 500 - ToolTip.visible: containsMouse - ToolTip.text: powerButtonBase.toolTip - acceptedButtons: Qt.LeftButton | Qt.RightButton - property int spacingFromMenu: 16 - - activeFocusOnTab: true - Keys.onPressed: { - if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { - powerButtonBase.clicked(true, 0, 0, mainWindow.isFullScreen); - } + paletteRole: Palette.Base + useStyleTransparent: false + alpha: powerButtonArea.containsPress ? 0.85 : powerButtonArea.containsMouse ? 0.65 : 0 + radius: height / 2 + borderColor: Palette.Highlight + border.width: powerButtonArea.activeFocus ? 2 : 0 + PowerButton { + id: powerButtonBase } - onClicked: { - var buttonPosition = powerButtonArea.mapToGlobal(width, height); - powerButtonBase.clicked(mouse.button === Qt.LeftButton, buttonPosition.x + spacingFromMenu, buttonPosition.y + spacingFromMenu, mainWindow.isFullScreen); + Image { + anchors.centerIn: parent + width: 24 + height: 24 + source: powerButtonBase.icon + } + + MouseArea { + id: powerButtonArea + anchors.fill: parent + hoverEnabled: true + ToolTip.delay: 500 + ToolTip.visible: containsMouse + ToolTip.text: powerButtonBase.toolTip + acceptedButtons: Qt.LeftButton | Qt.RightButton + property int spacingFromMenu: 16 + + activeFocusOnTab: true + Keys.onPressed: { + if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { + powerButtonBase.clicked(true, 0, 0, mainWindow.isFullScreen); + } + } + + onClicked: { + var buttonPosition = powerButtonArea.mapToGlobal(width, height); + powerButtonBase.clicked(mouse.button === Qt.LeftButton, buttonPosition.x + spacingFromMenu, buttonPosition.y + spacingFromMenu, mainWindow.isFullScreen); + } } } } @@ -162,18 +196,18 @@ Item { } Component { - id: headerDelegate + id: extensionInfoDelegate AppControls2.StyleBackground { - id: headerDelegateItem useStyleTransparent: false paletteRole: Palette.Highlight alpha: 0 radius: 4 borderColor: Palette.Highlight - border.width: headerDelegateItem.activeFocus ? 2 : 0 + border.width: activeFocus ? 2 : 0 property var extensionData: model.data + property var extensionOptions: model.options width: styleText.width height: ListView.view ? ListView.view.height : 0 @@ -219,8 +253,8 @@ Item { } Component.onCompleted: { - if (extensionListView.count > 0) { - extensionListView.currentIndex = 0; + if (extensionInfoList.count > 0) { + extensionInfoList.currentIndex = 0; } } } diff --git a/src/extension/menu-extension-iface.h b/src/extension/menu-extension-iface.h index 9ea2fbb..818df9e 100644 --- a/src/extension/menu-extension-iface.h +++ b/src/extension/menu-extension-iface.h @@ -21,7 +21,7 @@ #define UKUI_MENU_EXTENSION_TYPE "UKUI_MENU_EXTENSION" #define UKUI_MENU_EXTENSION_IFACE_IID "org.ukui.menu.extension" -#define UKUI_MENU_EXTENSION_IFACE_VERSION "1.0.0" +#define UKUI_MENU_EXTENSION_IFACE_VERSION "1.0.1" #include #include @@ -35,11 +35,18 @@ class Q_DECL_EXPORT MenuExtensionIFace : public QObject { Q_OBJECT public: + enum Option { + HideBottomBar, + HideFullScreenButton + }; + Q_ENUM(Option) + explicit MenuExtensionIFace(QObject *parent = nullptr) : QObject(parent) {}; virtual int index() = 0; virtual QString name() = 0; virtual QUrl url() = 0; virtual QVariantMap data() = 0; + virtual QVariantList options() { return {}; }; virtual void receive(QVariantMap data) = 0; Q_SIGNALS: diff --git a/src/extension/menu-extension.cpp b/src/extension/menu-extension.cpp index e915f66..0b5d9cb 100644 --- a/src/extension/menu-extension.cpp +++ b/src/extension/menu-extension.cpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace UkuiMenu { @@ -35,6 +36,7 @@ MenuExtension *MenuExtension::instance() MenuExtension::MenuExtension() { qRegisterMetaType("ExtensionModel*"); + qmlRegisterUncreatableType("org.ukui.menu.extension", 1, 0, "MenuExtension", ""); // TODO load extension from filesystem. loadExtensions(); @@ -121,6 +123,7 @@ ExtensionModel::ExtensionModel(const QVector &extensions, Q m_roleNames.insert(Name, "name"); m_roleNames.insert(Url, "url"); m_roleNames.insert(Data, "data"); + m_roleNames.insert(Options, "options"); for (int i = 0; i < m_extensions.size(); ++i) { connect(m_extensions.at(i), &MenuExtensionIFace::dataUpdated, this, [this, i] { @@ -150,6 +153,8 @@ QVariant ExtensionModel::data(const QModelIndex &index, int role) const case Data: { return m_extensions.at(row)->data(); } + case Options: + return m_extensions.at(row)->options(); default: break; } diff --git a/src/extension/menu-extension.h b/src/extension/menu-extension.h index fb7e882..4de4a2e 100644 --- a/src/extension/menu-extension.h +++ b/src/extension/menu-extension.h @@ -57,7 +57,8 @@ public: enum Name { Name, Url, - Data + Data, + Options }; explicit ExtensionModel(const QVector &extensions, QObject *parent = nullptr);