ukui-menu/qml/AppUI/Sidebar.qml

222 lines
7.3 KiB
QML
Raw Normal View History

/*
* 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
2023-02-13 09:31:11 +08:00
import QtQuick.Controls 2.5
2023-02-13 09:31:11 +08:00
import AppControls2 1.0 as AppControls2
import org.ukui.menu.core 1.0
import org.ukui.menu.utils 1.0
2022-12-23 11:32:21 +08:00
Item {
ColumnLayout {
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
Row {
Layout.fillWidth: true
2023-02-09 16:07:51 +08:00
Layout.preferredHeight: 40
Layout.rightMargin: 12
Layout.leftMargin: 16
ListView {
id: extensionListView
2023-02-09 16:07:51 +08:00
width: parent.width - 34
height: parent.height
2023-03-17 17:25:50 +08:00
clip: true
spacing: 24
interactive: false
orientation: ListView.Horizontal
model: extensionManager.extensionModel()
delegate: headerDelegate
function send(data) {
if (currentItem !== null) {
model.send(currentIndex, data);
}
}
onCurrentIndexChanged: {
if (currentItem !== null) {
currentItem.select();
}
}
}
2023-03-20 15:33:32 +08:00
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 {
2023-03-20 15:33:32 +08:00
anchors.centerIn: parent
width: parent.width / 2; height: width
source: "image://appicon/view-fullscreen-symbolic"
2023-03-17 17:25:50 +08:00
MouseArea {
2023-03-20 15:33:32 +08:00
id: buttonMouseArea
hoverEnabled: true
2023-03-17 17:25:50 +08:00
anchors.fill: parent
2023-03-20 15:33:32 +08:00
onClicked: mainWindow.isFullScreen = true
activeFocusOnTab: true
Keys.onPressed: {
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
mainWindow.isFullScreen = true;
}
}
2023-03-17 17:25:50 +08:00
}
}
2023-02-09 16:07:51 +08:00
}
}
2023-02-13 13:40:44 +08:00
Item {
Layout.fillWidth: true
Layout.fillHeight: true
Loader {
id: extensionLoader
anchors.fill: parent
clip: true
onLoaded: {
item.send.connect(extensionListView.send);
}
Keys.onTabPressed: {
extensionListView.focus = true
}
}
}
2023-02-09 16:07:51 +08:00
Row {
Layout.fillWidth: true
Layout.preferredHeight: 40
Layout.rightMargin: 12
layoutDirection: Qt.RightToLeft
2023-02-13 09:31:11 +08:00
AppControls2.StyleBackground {
2023-02-09 16:07:51 +08:00
width: 32
height: 32
2023-02-13 09:31:11 +08:00
paletteRole: Palette.Base
useStyleTransparent: false
alpha: powerButtonArea.containsPress ? 0.85 : powerButtonArea.containsMouse ? 0.65 : 0
2023-02-13 09:31:11 +08:00
radius: height / 2
borderColor: Palette.Highlight
border.width: powerButtonArea.activeFocus ? 2 : 0
2023-02-13 09:31:11 +08:00
PowerButton {
id: powerButtonBase
}
Image {
anchors.centerIn: parent
width: Math.floor(parent.width / 2)
height: width
source: powerButtonBase.icon
}
MouseArea {
id: powerButtonArea
anchors.fill: parent
hoverEnabled: true
ToolTip.visible: containsMouse
2023-02-13 09:31:11 +08:00
ToolTip.text: powerButtonBase.toolTip
2023-03-29 10:17:33 +08:00
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);
}
}
2023-02-13 09:31:11 +08:00
onClicked: {
2023-03-29 10:17:33 +08:00
var buttonPosition = powerButtonArea.mapToGlobal(width, height);
powerButtonBase.clicked(mouse.button === Qt.LeftButton, buttonPosition.x + spacingFromMenu, buttonPosition.y + spacingFromMenu, mainWindow.isFullScreen);
2023-02-13 09:31:11 +08:00
}
}
2023-02-09 16:07:51 +08:00
}
}
}
Component {
id: headerDelegate
2023-02-09 16:07:51 +08:00
AppControls2.StyleBackground {
id: headerDelegateItem
useStyleTransparent: false
paletteRole: Palette.Highlight
alpha: 0
radius: 4
borderColor: Palette.Highlight
border.width: headerDelegateItem.activeFocus ? 2 : 0
property var extensionData: model.data
width: styleText.width
height: ListView.view ? ListView.view.height : 0
activeFocusOnTab: true
KeyNavigation.down: extensionLoader
Keys.onPressed: {
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
ListView.view.currentIndex = model.index;
}
}
onExtensionDataChanged: {
if (extensionLoader.source === model.url) {
extensionLoader.item.extensionData = extensionData;
}
}
function select() {
if (extensionLoader.source !== model.url) {
extensionLoader.setSource(model.url, {extensionData: extensionData});
}
}
AppControls2.StyleText {
height: parent.height
id: styleText
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.bold: parent.ListView.isCurrentItem
paletteRole: parent.ListView.isCurrentItem ? Palette.Highlight: Palette.Text
text: model.name
}
MouseArea {
anchors.fill: parent
onClicked: {
normalUI.focusToFalse();
parent.ListView.view.currentIndex = model.index;
}
}
}
}
Component.onCompleted: {
if (extensionListView.count > 0) {
extensionListView.currentIndex = 0;
}
2022-12-23 11:32:21 +08:00
}
}