ukui-menu/qml/AppUI/Sidebar.qml

191 lines
5.9 KiB
QML

/*
* 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.0
import QtQuick.Layouts 1.12
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
Item {
ColumnLayout {
anchors.fill: parent
anchors.topMargin: 12
spacing: 0
Row {
Layout.fillWidth: true
Layout.preferredHeight: 40
Layout.rightMargin: 12
ListView {
id: extensionListView
width: parent.width - 34
height: parent.height
clip: true
orientation: ListView.Horizontal
model: extensionManager.extensionModel()
delegate: headerDelegate
function send(data) {
if (currentItem !== null) {
model.send(currentIndex, data);
}
}
onCurrentIndexChanged: {
if (currentItem !== null) {
currentItem.select();
}
}
}
AppControls2.StyleBackground {
width: 34; height: width
radius: 4
useStyleTransparent: false
alpha: buttonMouseArea.containsPress ? 0.65 : buttonMouseArea.containsMouse ? 0.40 : 0.00
ThemeIcon {
anchors.centerIn: parent
width: parent.width / 2; height: width
source: "image://appicon/view-fullscreen-symbolic"
MouseArea {
id: buttonMouseArea
hoverEnabled: true
anchors.fill: parent
onClicked: mainWindow.isFullScreen = true
}
}
}
}
Item {
Layout.fillWidth: true
Layout.fillHeight: true
Loader {
id: extensionLoader
anchors.fill: parent
clip: true
focus: true
onLoaded: {
item.send.connect(extensionListView.send);
}
}
}
Row {
Layout.fillWidth: true
Layout.preferredHeight: 40
Layout.rightMargin: 12
layoutDirection: Qt.RightToLeft
AppControls2.StyleBackground {
width: 32
height: 32
paletteRole: Palette.Base
useStyleTransparent: false
alpha: powerButtonArea.pressed ? 0.85 : powerButtonArea.hovered ? 0.65 : 0
radius: height / 2
PowerButton {
id: powerButtonBase
}
Image {
anchors.centerIn: parent
width: Math.floor(parent.width / 2)
height: width
source: powerButtonBase.icon
}
MouseArea {
id: powerButtonArea
property bool hovered: false
anchors.fill: parent
hoverEnabled: true
ToolTip.visible: hovered
ToolTip.text: powerButtonBase.toolTip
acceptedButtons: Qt.LeftButton | Qt.RightButton
property int spacingFromMenu: 16
onClicked: {
var buttonPosition = powerButtonArea.mapToGlobal(width, height);
powerButtonBase.clicked(mouse.button === Qt.LeftButton, buttonPosition.x + spacingFromMenu, buttonPosition.y + spacingFromMenu, mainWindow.isFullScreen);
}
onEntered: {
hovered = true
}
onExited: {
hovered = false
}
}
}
}
}
Component {
id: headerDelegate
Item {
property var extensionData: model.data
width: 100
height: ListView.view ? ListView.view.height : 0
onExtensionDataChanged: {
if (extensionLoader.source === model.url) {
extensionLoader.item.extensionData = extensionData;
}
}
function select() {
if (extensionLoader.source !== model.url) {
extensionLoader.setSource(model.url, {extensionData: extensionData});
}
}
Text {
anchors.fill: parent
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.bold: true
wrapMode: Text.ElideRight
color: parent.ListView.isCurrentItem ? "blue" : "black"
text: model.name
}
MouseArea {
anchors.fill: parent
onClicked: {
parent.ListView.view.currentIndex = model.index;
}
}
}
}
Component.onCompleted: {
if (extensionListView.count > 0) {
extensionListView.currentIndex = 0;
}
}
}