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

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",
"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 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;
}
}
}

View File

@ -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 <QObject>
#include <QUrl>
@ -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:

View File

@ -23,6 +23,7 @@
#include <QDir>
#include <QPluginLoader>
#include <QDebug>
#include <QtQml/qqml.h>
namespace UkuiMenu {
@ -35,6 +36,7 @@ MenuExtension *MenuExtension::instance()
MenuExtension::MenuExtension()
{
qRegisterMetaType<ExtensionModel*>("ExtensionModel*");
qmlRegisterUncreatableType<MenuExtensionIFace>("org.ukui.menu.extension", 1, 0, "MenuExtension", "");
// TODO load extension from filesystem.
loadExtensions();
@ -121,6 +123,7 @@ ExtensionModel::ExtensionModel(const QVector<MenuExtensionIFace*> &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;
}

View File

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