2023-11-28 16:58:37 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQml 2.12
|
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import QtQuick.Controls 2.5
|
|
|
|
|
|
|
|
import AppControls2 1.0 as AppControls2
|
2023-12-11 16:13:53 +08:00
|
|
|
import org.ukui.quick.items 1.0 as UkuiItems
|
2023-11-28 16:58:37 +08:00
|
|
|
import org.ukui.menu.core 1.0
|
|
|
|
import org.ukui.menu.utils 1.0
|
|
|
|
import org.ukui.menu.extension 1.0
|
|
|
|
|
|
|
|
Item {
|
|
|
|
ColumnLayout {
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.topMargin: 12
|
2023-12-11 10:38:02 +08:00
|
|
|
spacing: 5
|
2023-11-28 16:58:37 +08:00
|
|
|
|
|
|
|
Item {
|
2023-12-11 10:38:02 +08:00
|
|
|
// header
|
2023-11-28 16:58:37 +08:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: 40
|
2023-12-11 10:38:02 +08:00
|
|
|
height: 40
|
2023-11-28 16:58:37 +08:00
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
anchors.fill: parent
|
2023-12-11 10:38:02 +08:00
|
|
|
anchors.leftMargin: 12
|
|
|
|
anchors.rightMargin:12
|
|
|
|
spacing: 0
|
2023-11-28 16:58:37 +08:00
|
|
|
|
|
|
|
ListView {
|
2023-12-11 10:38:02 +08:00
|
|
|
id: widgetList
|
2023-11-28 16:58:37 +08:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
|
|
|
clip: true
|
|
|
|
spacing: 24
|
|
|
|
interactive: false
|
|
|
|
orientation: ListView.Horizontal
|
|
|
|
function send(data) {
|
|
|
|
if (currentItem !== null) {
|
|
|
|
model.send(currentIndex, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onCurrentIndexChanged: {
|
|
|
|
if (currentItem !== null) {
|
|
|
|
currentItem.select();
|
|
|
|
}
|
|
|
|
}
|
2023-12-11 10:38:02 +08:00
|
|
|
model: WidgetModel {}
|
|
|
|
delegate: Component {
|
|
|
|
// 插件信息
|
|
|
|
UkuiItems.StyleBackground {
|
|
|
|
useStyleTransparency: false
|
|
|
|
paletteRole: Palette.Highlight
|
|
|
|
alpha: 0
|
|
|
|
radius: UkuiItems.Theme.minRadius
|
|
|
|
borderColor: Palette.Highlight
|
|
|
|
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
|
|
|
|
|
|
|
|
activeFocusOnTab: true
|
|
|
|
KeyNavigation.down: widgetLoader
|
|
|
|
Keys.onPressed: {
|
|
|
|
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
|
|
|
|
widgetList.currentIndex = model.index;
|
|
|
|
EventTrack.sendClickEvent("switch_plugin", "Sidebar", {"plugin": model.name});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onExtensionDataChanged: {
|
|
|
|
if (widgetLoader.source === model.main) {
|
|
|
|
widgetLoader.item.extensionData = extensionData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function select() {
|
|
|
|
if (widgetLoader.source !== model.main) {
|
|
|
|
widgetLoader.setSource(model.main, {extensionData: extensionData});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UkuiItems.StyleText {
|
|
|
|
height: parent.height
|
|
|
|
id: styleText
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
font.bold: parent.ListView.isCurrentItem
|
|
|
|
|
|
|
|
paletteRole: parent.ListView.isCurrentItem ? UkuiItems.Theme.Highlight: UkuiItems.Theme.Text
|
|
|
|
text: model.name
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
|
|
|
normalUI.focusToFalse();
|
|
|
|
widgetList.currentIndex = model.index;
|
|
|
|
EventTrack.sendClickEvent("switch_plugin", "Sidebar", {"plugin": model.name});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-28 16:58:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Loader {
|
2023-12-11 10:38:02 +08:00
|
|
|
id: widgetMenuLoader
|
2023-11-28 16:58:37 +08:00
|
|
|
Layout.preferredWidth: 34
|
|
|
|
Layout.preferredHeight: 34
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-11 10:38:02 +08:00
|
|
|
Loader {
|
|
|
|
id: widgetLoader
|
|
|
|
// 加载插件区域
|
2023-11-28 16:58:37 +08:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
2023-12-11 10:38:02 +08:00
|
|
|
clip: true
|
2023-11-28 16:58:37 +08:00
|
|
|
|
2023-12-11 10:38:02 +08:00
|
|
|
onLoaded: {
|
|
|
|
item.send.connect(widgetList.send);
|
|
|
|
// sidebarLayout.updateSidebarLayout(widgetList.currentItem.extensionOptions);
|
|
|
|
updateMenu();
|
|
|
|
item.extensionMenuChanged.connect(updateMenu);
|
2023-11-28 16:58:37 +08:00
|
|
|
}
|
2023-12-11 10:38:02 +08:00
|
|
|
Keys.onTabPressed: {
|
|
|
|
widgetList.focus = true
|
2023-11-28 16:58:37 +08:00
|
|
|
}
|
|
|
|
|
2023-12-11 10:38:02 +08:00
|
|
|
function updateMenu() {
|
|
|
|
if (item === null) {
|
|
|
|
return;
|
2023-11-28 16:58:37 +08:00
|
|
|
}
|
2023-12-11 10:38:02 +08:00
|
|
|
if (item.extensionMenu !== null) {
|
|
|
|
widgetMenuLoader.sourceComponent = item.extensionMenu;
|
|
|
|
} else {
|
|
|
|
widgetMenuLoader.sourceComponent = undefined;
|
2023-11-28 16:58:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
2023-12-11 10:38:02 +08:00
|
|
|
if (widgetList.count > 0) {
|
|
|
|
widgetList.currentIndex = 0;
|
2023-11-28 16:58:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|