2023-02-14 09:58:57 +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
|
2023-04-26 17:04:22 +08:00
|
|
|
import QtQuick 2.12
|
2023-01-03 11:00:52 +08:00
|
|
|
import QtQuick.Layouts 1.12
|
2023-02-13 09:31:11 +08:00
|
|
|
import QtQuick.Controls 2.5
|
2023-02-14 09:58:57 +08:00
|
|
|
|
2023-02-13 09:31:11 +08:00
|
|
|
import AppControls2 1.0 as AppControls2
|
|
|
|
import org.ukui.menu.core 1.0
|
2023-02-14 09:58:57 +08:00
|
|
|
import org.ukui.menu.utils 1.0
|
2023-06-11 17:23:00 +08:00
|
|
|
import org.ukui.menu.extension 1.0
|
2022-12-23 11:32:21 +08:00
|
|
|
|
|
|
|
Item {
|
2023-01-03 11:00:52 +08:00
|
|
|
ColumnLayout {
|
2023-06-11 17:23:00 +08:00
|
|
|
id: sidebarLayout
|
|
|
|
|
2023-01-03 11:00:52 +08:00
|
|
|
anchors.fill: parent
|
2023-02-09 16:07:51 +08:00
|
|
|
anchors.topMargin: 12
|
2023-02-13 13:40:44 +08:00
|
|
|
spacing: 0
|
2023-02-09 16:07:51 +08:00
|
|
|
|
2023-11-15 16:05:40 +08:00
|
|
|
property bool liteMode: isLiteMode
|
|
|
|
onLiteModeChanged: {
|
|
|
|
updateSidebarLayout(extensionInfoList.currentItem.extensionOptions)
|
|
|
|
}
|
|
|
|
|
2023-06-11 17:23:00 +08:00
|
|
|
function updateSidebarLayout(options) {
|
|
|
|
sidebarBottomBar.visible = !options.includes(MenuExtension.HideBottomBar);
|
2023-11-15 16:05:40 +08:00
|
|
|
fullScreenbutton.visible = !isLiteMode && !options.includes(MenuExtension.HideFullScreenButton);
|
2023-06-11 17:23:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: sidebarTopBar
|
2023-01-03 11:00:52 +08:00
|
|
|
Layout.fillWidth: true
|
2023-02-09 16:07:51 +08:00
|
|
|
Layout.preferredHeight: 40
|
|
|
|
Layout.rightMargin: 12
|
2023-06-11 17:23:00 +08:00
|
|
|
Layout.leftMargin: 12
|
2023-01-03 11:00:52 +08:00
|
|
|
|
2023-06-11 17:23:00 +08:00
|
|
|
RowLayout {
|
|
|
|
anchors.fill: parent
|
2023-06-29 10:48:27 +08:00
|
|
|
spacing: 4
|
2023-06-11 17:23:00 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2023-01-03 11:00:52 +08:00
|
|
|
}
|
|
|
|
|
2023-06-11 17:23:00 +08:00
|
|
|
onCurrentIndexChanged: {
|
|
|
|
if (currentItem !== null) {
|
|
|
|
currentItem.select();
|
|
|
|
}
|
2023-01-03 11:00:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-29 10:48:27 +08:00
|
|
|
Loader {
|
|
|
|
id: extensionMenuLoader
|
|
|
|
visible: sourceComponent !== undefined
|
|
|
|
Layout.preferredWidth: 34
|
|
|
|
Layout.preferredHeight: 34
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
}
|
|
|
|
|
2023-06-11 17:23:00 +08:00
|
|
|
AppControls2.StyleBackground {
|
|
|
|
id: fullScreenbutton
|
|
|
|
Layout.preferredWidth: 34
|
|
|
|
Layout.preferredHeight: 34
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
2023-06-02 15:44:16 +08:00
|
|
|
|
2023-06-11 17:23:00 +08:00
|
|
|
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;
|
|
|
|
}
|
2023-04-26 17:04:22 +08:00
|
|
|
}
|
|
|
|
}
|
2023-03-17 17:25:50 +08:00
|
|
|
}
|
|
|
|
}
|
2023-02-09 16:07:51 +08:00
|
|
|
}
|
|
|
|
}
|
2023-02-13 13:40:44 +08:00
|
|
|
|
2023-01-03 11:00:52 +08:00
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: extensionLoader
|
|
|
|
anchors.fill: parent
|
|
|
|
clip: true
|
|
|
|
onLoaded: {
|
2023-06-11 17:23:00 +08:00
|
|
|
item.send.connect(extensionInfoList.send);
|
|
|
|
sidebarLayout.updateSidebarLayout(extensionInfoList.currentItem.extensionOptions);
|
2023-06-29 10:48:27 +08:00
|
|
|
updateMenu();
|
|
|
|
item.extensionMenuChanged.connect(updateMenu);
|
2023-01-03 11:00:52 +08:00
|
|
|
}
|
2023-05-23 11:54:17 +08:00
|
|
|
Keys.onTabPressed: {
|
2023-06-11 17:23:00 +08:00
|
|
|
extensionInfoList.focus = true
|
2023-05-23 11:54:17 +08:00
|
|
|
}
|
2023-06-29 10:48:27 +08:00
|
|
|
|
|
|
|
function updateMenu() {
|
|
|
|
if (item === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (item.extensionMenu !== null) {
|
|
|
|
extensionMenuLoader.sourceComponent = item.extensionMenu;
|
|
|
|
} else {
|
|
|
|
extensionMenuLoader.sourceComponent = undefined;
|
|
|
|
}
|
|
|
|
}
|
2023-01-03 11:00:52 +08:00
|
|
|
}
|
|
|
|
}
|
2023-02-09 16:07:51 +08:00
|
|
|
|
2023-06-11 17:23:00 +08:00
|
|
|
Item {
|
|
|
|
id: sidebarBottomBar
|
2023-02-09 16:07:51 +08:00
|
|
|
Layout.fillWidth: true
|
2023-06-11 17:23:00 +08:00
|
|
|
Layout.preferredHeight: 32
|
|
|
|
Layout.topMargin: 5
|
|
|
|
Layout.bottomMargin: 8
|
|
|
|
Layout.leftMargin: 12
|
2023-02-09 16:07:51 +08:00
|
|
|
Layout.rightMargin: 12
|
2023-02-13 09:31:11 +08:00
|
|
|
|
2023-06-11 17:23:00 +08:00
|
|
|
RowLayout {
|
|
|
|
anchors.fill: parent
|
|
|
|
layoutDirection: Qt.RightToLeft
|
|
|
|
spacing: 5
|
2023-02-13 09:31:11 +08:00
|
|
|
|
2023-06-11 17:23:00 +08:00
|
|
|
AppControls2.StyleBackground {
|
|
|
|
Layout.preferredWidth: 32
|
|
|
|
Layout.preferredHeight: 32
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
Image {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
width: 24
|
|
|
|
height: 24
|
|
|
|
source: powerButtonBase.icon
|
2023-04-26 17:04:22 +08:00
|
|
|
}
|
|
|
|
|
2023-06-11 17:23:00 +08:00
|
|
|
MouseArea {
|
|
|
|
id: powerButtonArea
|
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
|
|
|
ToolTip.delay: 500
|
|
|
|
ToolTip.visible: containsMouse
|
|
|
|
ToolTip.text: powerButtonBase.toolTip
|
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
2023-12-06 10:54:51 +08:00
|
|
|
property int spacingFromMenu: 4
|
2023-06-11 17:23:00 +08:00
|
|
|
|
|
|
|
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);
|
2023-12-06 10:54:51 +08:00
|
|
|
powerButtonBase.clicked(mouse.button === Qt.LeftButton, buttonPosition.x + sidebarBottomBar.Layout.rightMargin + 4,
|
|
|
|
buttonPosition.y + sidebarBottomBar.Layout.bottomMargin, mainWindow.isFullScreen);
|
2023-06-11 17:23:00 +08:00
|
|
|
}
|
2023-02-13 09:31:11 +08:00
|
|
|
}
|
|
|
|
}
|
2023-02-09 16:07:51 +08:00
|
|
|
}
|
|
|
|
}
|
2023-01-03 11:00:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
2023-06-11 17:23:00 +08:00
|
|
|
id: extensionInfoDelegate
|
2023-02-09 16:07:51 +08:00
|
|
|
|
2023-04-26 17:04:22 +08:00
|
|
|
AppControls2.StyleBackground {
|
|
|
|
useStyleTransparent: false
|
|
|
|
paletteRole: Palette.Highlight
|
|
|
|
alpha: 0
|
|
|
|
radius: 4
|
|
|
|
borderColor: Palette.Highlight
|
2023-06-11 17:23:00 +08:00
|
|
|
border.width: activeFocus ? 2 : 0
|
2023-04-26 17:04:22 +08:00
|
|
|
|
2023-01-03 11:00:52 +08:00
|
|
|
property var extensionData: model.data
|
2023-06-11 17:23:00 +08:00
|
|
|
property var extensionOptions: model.options
|
2023-04-20 09:44:52 +08:00
|
|
|
width: styleText.width
|
2023-01-03 11:00:52 +08:00
|
|
|
height: ListView.view ? ListView.view.height : 0
|
|
|
|
|
2023-04-26 17:04:22 +08:00
|
|
|
activeFocusOnTab: true
|
2023-05-23 11:54:17 +08:00
|
|
|
KeyNavigation.down: extensionLoader
|
2023-04-26 17:04:22 +08:00
|
|
|
Keys.onPressed: {
|
|
|
|
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
|
|
|
|
ListView.view.currentIndex = model.index;
|
2023-11-21 16:02:22 +08:00
|
|
|
EventTrack.sendClickEvent("switch_plugin", "Sidebar", {"plugin": model.name});
|
2023-04-26 17:04:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-03 11:00:52 +08:00
|
|
|
onExtensionDataChanged: {
|
|
|
|
if (extensionLoader.source === model.url) {
|
|
|
|
extensionLoader.item.extensionData = extensionData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function select() {
|
|
|
|
if (extensionLoader.source !== model.url) {
|
|
|
|
extensionLoader.setSource(model.url, {extensionData: extensionData});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-20 09:44:52 +08:00
|
|
|
AppControls2.StyleText {
|
|
|
|
height: parent.height
|
|
|
|
id: styleText
|
2023-01-03 11:00:52 +08:00
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
2023-04-20 09:44:52 +08:00
|
|
|
font.bold: parent.ListView.isCurrentItem
|
2023-01-03 11:00:52 +08:00
|
|
|
|
2023-04-20 09:44:52 +08:00
|
|
|
paletteRole: parent.ListView.isCurrentItem ? Palette.Highlight: Palette.Text
|
2023-01-03 11:00:52 +08:00
|
|
|
text: model.name
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
2023-05-15 17:28:48 +08:00
|
|
|
normalUI.focusToFalse();
|
2023-01-03 11:00:52 +08:00
|
|
|
parent.ListView.view.currentIndex = model.index;
|
2023-11-21 16:02:22 +08:00
|
|
|
EventTrack.sendClickEvent("switch_plugin", "Sidebar", {"plugin": model.name});
|
2023-01-03 11:00:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
2023-06-11 17:23:00 +08:00
|
|
|
if (extensionInfoList.count > 0) {
|
|
|
|
extensionInfoList.currentIndex = 0;
|
2023-01-03 11:00:52 +08:00
|
|
|
}
|
2022-12-23 11:32:21 +08:00
|
|
|
}
|
|
|
|
}
|