扩展接口增加隐藏界面组件功能,更新接口版本号

This commit is contained in:
hewenfei 2023-06-11 17:23:00 +08:00
parent 42958efa36
commit 287081aaad
5 changed files with 140 additions and 93 deletions

View File

@ -1,4 +1,4 @@
{ {
"Type": "UKUI_MENU_EXTENSION", "Type": "UKUI_MENU_EXTENSION",
"Version": "1.0.0" "Version": "1.0.1"
} }

View File

@ -24,67 +24,89 @@ import QtQuick.Controls 2.5
import AppControls2 1.0 as AppControls2 import AppControls2 1.0 as AppControls2
import org.ukui.menu.core 1.0 import org.ukui.menu.core 1.0
import org.ukui.menu.utils 1.0 import org.ukui.menu.utils 1.0
import org.ukui.menu.extension 1.0
Item { Item {
ColumnLayout { ColumnLayout {
id: sidebarLayout
anchors.fill: parent anchors.fill: parent
anchors.topMargin: 12 anchors.topMargin: 12
spacing: 0 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.fillWidth: true
Layout.preferredHeight: 40 Layout.preferredHeight: 40
Layout.rightMargin: 12 Layout.rightMargin: 12
Layout.leftMargin: 16 Layout.leftMargin: 12
ListView { RowLayout {
id: extensionListView anchors.fill: parent
width: parent.width - 34 // spacing: 5
height: parent.height
clip: true
spacing: 24
interactive: false
orientation: ListView.Horizontal
model: extensionManager.extensionModel()
delegate: headerDelegate
function send(data) { ListView {
if (currentItem !== null) { id: extensionInfoList
model.send(currentIndex, data);
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: { AppControls2.StyleBackground {
if (currentItem !== null) { id: fullScreenbutton
currentItem.select(); Layout.preferredWidth: 34
} Layout.preferredHeight: 34
} Layout.alignment: Qt.AlignVCenter
}
AppControls2.StyleBackground { radius: 4
width: 34; height: width useStyleTransparent: false
radius: 4 alpha: buttonMouseArea.containsPress ? 0.65 : buttonMouseArea.containsMouse ? 0.40 : 0.00
useStyleTransparent: false borderColor: Palette.Highlight
alpha: buttonMouseArea.containsPress ? 0.65 : buttonMouseArea.containsMouse ? 0.40 : 0.00 border.width: buttonMouseArea.activeFocus ? 2 : 0
borderColor: Palette.Highlight ThemeIcon {
border.width: buttonMouseArea.activeFocus ? 2 : 0 anchors.centerIn: parent
ThemeIcon { width: 16; height: 16
anchors.centerIn: parent source: "image://appicon/view-fullscreen-symbolic"
width: parent.width / 2; height: width MouseArea {
source: "image://appicon/view-fullscreen-symbolic" id: buttonMouseArea
MouseArea { hoverEnabled: true
id: buttonMouseArea anchors.fill: parent
hoverEnabled: true ToolTip.delay: 500
anchors.fill: parent ToolTip.text: qsTr("Expand")
ToolTip.delay: 500 ToolTip.visible: containsMouse
ToolTip.text: qsTr("Expand")
ToolTip.visible: containsMouse
onClicked: mainWindow.isFullScreen = true onClicked: mainWindow.isFullScreen = true
activeFocusOnTab: true activeFocusOnTab: true
Keys.onPressed: { Keys.onPressed: {
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
mainWindow.isFullScreen = true; mainWindow.isFullScreen = true;
}
} }
} }
} }
@ -101,60 +123,72 @@ Item {
anchors.fill: parent anchors.fill: parent
clip: true clip: true
onLoaded: { onLoaded: {
item.send.connect(extensionListView.send); item.send.connect(extensionInfoList.send);
sidebarLayout.updateSidebarLayout(extensionInfoList.currentItem.extensionOptions);
} }
Keys.onTabPressed: { Keys.onTabPressed: {
extensionListView.focus = true extensionInfoList.focus = true
} }
} }
} }
Row { Item {
id: sidebarBottomBar
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: 40 Layout.preferredHeight: 32
Layout.topMargin: 5
Layout.bottomMargin: 8
Layout.leftMargin: 12
Layout.rightMargin: 12 Layout.rightMargin: 12
layoutDirection: Qt.RightToLeft
AppControls2.StyleBackground { RowLayout {
width: 32 anchors.fill: parent
height: 32 layoutDirection: Qt.RightToLeft
paletteRole: Palette.Base spacing: 5
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
}
Image { AppControls2.StyleBackground {
anchors.centerIn: parent Layout.preferredWidth: 32
width: Math.floor(parent.width / 2) Layout.preferredHeight: 32
height: width Layout.alignment: Qt.AlignVCenter
source: powerButtonBase.icon
}
MouseArea { paletteRole: Palette.Base
id: powerButtonArea useStyleTransparent: false
anchors.fill: parent alpha: powerButtonArea.containsPress ? 0.85 : powerButtonArea.containsMouse ? 0.65 : 0
hoverEnabled: true radius: height / 2
ToolTip.delay: 500 borderColor: Palette.Highlight
ToolTip.visible: containsMouse border.width: powerButtonArea.activeFocus ? 2 : 0
ToolTip.text: powerButtonBase.toolTip PowerButton {
acceptedButtons: Qt.LeftButton | Qt.RightButton id: powerButtonBase
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: { Image {
var buttonPosition = powerButtonArea.mapToGlobal(width, height); anchors.centerIn: parent
powerButtonBase.clicked(mouse.button === Qt.LeftButton, buttonPosition.x + spacingFromMenu, buttonPosition.y + spacingFromMenu, mainWindow.isFullScreen); 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 { Component {
id: headerDelegate id: extensionInfoDelegate
AppControls2.StyleBackground { AppControls2.StyleBackground {
id: headerDelegateItem
useStyleTransparent: false useStyleTransparent: false
paletteRole: Palette.Highlight paletteRole: Palette.Highlight
alpha: 0 alpha: 0
radius: 4 radius: 4
borderColor: Palette.Highlight borderColor: Palette.Highlight
border.width: headerDelegateItem.activeFocus ? 2 : 0 border.width: activeFocus ? 2 : 0
property var extensionData: model.data property var extensionData: model.data
property var extensionOptions: model.options
width: styleText.width width: styleText.width
height: ListView.view ? ListView.view.height : 0 height: ListView.view ? ListView.view.height : 0
@ -219,8 +253,8 @@ Item {
} }
Component.onCompleted: { Component.onCompleted: {
if (extensionListView.count > 0) { if (extensionInfoList.count > 0) {
extensionListView.currentIndex = 0; extensionInfoList.currentIndex = 0;
} }
} }
} }

View File

@ -21,7 +21,7 @@
#define UKUI_MENU_EXTENSION_TYPE "UKUI_MENU_EXTENSION" #define UKUI_MENU_EXTENSION_TYPE "UKUI_MENU_EXTENSION"
#define UKUI_MENU_EXTENSION_IFACE_IID "org.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 <QObject> #include <QObject>
#include <QUrl> #include <QUrl>
@ -35,11 +35,18 @@ class Q_DECL_EXPORT MenuExtensionIFace : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
enum Option {
HideBottomBar,
HideFullScreenButton
};
Q_ENUM(Option)
explicit MenuExtensionIFace(QObject *parent = nullptr) : QObject(parent) {}; explicit MenuExtensionIFace(QObject *parent = nullptr) : QObject(parent) {};
virtual int index() = 0; virtual int index() = 0;
virtual QString name() = 0; virtual QString name() = 0;
virtual QUrl url() = 0; virtual QUrl url() = 0;
virtual QVariantMap data() = 0; virtual QVariantMap data() = 0;
virtual QVariantList options() { return {}; };
virtual void receive(QVariantMap data) = 0; virtual void receive(QVariantMap data) = 0;
Q_SIGNALS: Q_SIGNALS:

View File

@ -23,6 +23,7 @@
#include <QDir> #include <QDir>
#include <QPluginLoader> #include <QPluginLoader>
#include <QDebug> #include <QDebug>
#include <QtQml/qqml.h>
namespace UkuiMenu { namespace UkuiMenu {
@ -35,6 +36,7 @@ MenuExtension *MenuExtension::instance()
MenuExtension::MenuExtension() MenuExtension::MenuExtension()
{ {
qRegisterMetaType<ExtensionModel*>("ExtensionModel*"); qRegisterMetaType<ExtensionModel*>("ExtensionModel*");
qmlRegisterUncreatableType<MenuExtensionIFace>("org.ukui.menu.extension", 1, 0, "MenuExtension", "");
// TODO load extension from filesystem. // TODO load extension from filesystem.
loadExtensions(); loadExtensions();
@ -121,6 +123,7 @@ ExtensionModel::ExtensionModel(const QVector<MenuExtensionIFace*> &extensions, Q
m_roleNames.insert(Name, "name"); m_roleNames.insert(Name, "name");
m_roleNames.insert(Url, "url"); m_roleNames.insert(Url, "url");
m_roleNames.insert(Data, "data"); m_roleNames.insert(Data, "data");
m_roleNames.insert(Options, "options");
for (int i = 0; i < m_extensions.size(); ++i) { for (int i = 0; i < m_extensions.size(); ++i) {
connect(m_extensions.at(i), &MenuExtensionIFace::dataUpdated, this, [this, 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: { case Data: {
return m_extensions.at(row)->data(); return m_extensions.at(row)->data();
} }
case Options:
return m_extensions.at(row)->options();
default: default:
break; break;
} }

View File

@ -57,7 +57,8 @@ public:
enum Name { enum Name {
Name, Name,
Url, Url,
Data Data,
Options
}; };
explicit ExtensionModel(const QVector<MenuExtensionIFace*> &extensions, QObject *parent = nullptr); explicit ExtensionModel(const QVector<MenuExtensionIFace*> &extensions, QObject *parent = nullptr);