filemanager/qml/SideBar.qml

186 lines
6.2 KiB
QML
Raw Normal View History

2021-05-24 04:01:26 -07:00
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: revenmartin <revenmartin@gmail.com>
*
* 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
* 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 <http://www.gnu.org/licenses/>.
*/
2021-03-29 01:51:34 -07:00
import QtQuick 2.12
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.12
2021-09-03 10:47:54 -07:00
import QtQuick.Window 2.12
2021-03-29 01:51:34 -07:00
2021-04-09 07:49:19 -07:00
import FishUI 1.0 as FishUI
2021-03-16 00:02:20 -07:00
import Cutefish.FileManager 1.0
ListView {
2021-03-29 01:51:34 -07:00
id: sideBar
2021-03-16 00:02:20 -07:00
2021-03-29 01:51:34 -07:00
signal clicked(string path)
2021-12-02 11:58:55 -08:00
signal openInNewWindow(string path)
2021-03-16 00:02:20 -07:00
2021-08-26 10:25:53 -07:00
FishUI.WheelHandler {
target: sideBar
}
2021-03-16 00:02:20 -07:00
PlacesModel {
id: placesModel
onDeviceSetupDone: sideBar.clicked(filePath) // 设备挂载上后,模拟点击了该设备以打开该页面
2021-03-16 00:02:20 -07:00
}
2021-03-29 01:51:34 -07:00
model: placesModel
2021-03-16 00:02:20 -07:00
clip: true
2021-03-29 01:51:34 -07:00
2021-04-13 10:09:01 -07:00
leftMargin: FishUI.Units.smallSpacing * 1.5
rightMargin: FishUI.Units.smallSpacing * 1.5
2021-04-09 07:49:19 -07:00
bottomMargin: FishUI.Units.smallSpacing
spacing: FishUI.Units.smallSpacing
2021-03-16 00:02:20 -07:00
2021-03-30 18:22:32 -07:00
ScrollBar.vertical: ScrollBar {
2021-04-09 07:49:19 -07:00
bottomPadding: FishUI.Units.smallSpacing
2021-03-30 18:22:32 -07:00
}
2021-03-16 00:02:20 -07:00
highlightFollowsCurrentItem: true
highlightMoveDuration: 0
highlightResizeDuration : 0
highlight: Rectangle {
radius: FishUI.Theme.mediumRadius
2021-04-09 07:49:19 -07:00
color: FishUI.Theme.highlightColor
2021-03-16 00:02:20 -07:00
}
2021-08-17 14:52:05 -07:00
section.property: "category"
section.delegate: Item {
width: ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin
height: FishUI.Units.fontMetrics.height + FishUI.Units.largeSpacing + FishUI.Units.smallSpacing
Text {
anchors.left: parent.left
anchors.top: parent.top
anchors.leftMargin: Qt.application.layoutDirection === Qt.RightToLeft ? 0 : FishUI.Units.smallSpacing
anchors.rightMargin: FishUI.Units.smallSpacing
anchors.topMargin: FishUI.Units.largeSpacing
anchors.bottomMargin: FishUI.Units.smallSpacing
color: FishUI.Theme.textColor
font.pointSize: 9
font.bold: true
text: section
}
}
2021-03-29 01:51:34 -07:00
delegate: Item {
id: _item
2021-03-16 00:02:20 -07:00
width: ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin
2021-04-14 19:26:54 -07:00
height: FishUI.Units.fontMetrics.height + FishUI.Units.largeSpacing * 1.5
2021-03-16 00:02:20 -07:00
2021-03-29 01:51:34 -07:00
property bool checked: sideBar.currentIndex === index
2021-04-09 07:49:19 -07:00
property color hoveredColor: FishUI.Theme.darkMode ? Qt.lighter(FishUI.Theme.backgroundColor, 1.1)
: Qt.darker(FishUI.Theme.backgroundColor, 1.1)
2021-03-29 01:51:34 -07:00
MouseArea {
id: _mouseArea
anchors.fill: parent
hoverEnabled: true
2021-12-02 11:58:55 -08:00
acceptedButtons: Qt.LeftButton | Qt.RightButton
2021-03-29 01:51:34 -07:00
onClicked: {
2021-12-02 11:58:55 -08:00
if (mouse.button === Qt.LeftButton) {
if (model.isDevice && model.setupNeeded)
placesModel.requestSetup(index)
// sideBar.currentIndex = index
sideBar.clicked(model.path ? model.path : model.url)
} else if (mouse.button === Qt.RightButton) {
_menu.popup()
}
}
}
FishUI.DesktopMenu {
id: _menu
MenuItem {
text: qsTr("Open")
onTriggered: {
if (model.isDevice && model.setupNeeded)
placesModel.requestSetup(index)
sideBar.clicked(model.path ? model.path : model.url)
}
}
MenuItem {
text: qsTr("Open in new window")
2021-03-29 18:48:59 -07:00
2021-12-02 11:58:55 -08:00
onTriggered: {
sideBar.openInNewWindow(model.path ? model.path : model.url)
}
2021-03-29 01:51:34 -07:00
}
}
Rectangle {
anchors.fill: parent
2021-06-23 02:29:47 -07:00
radius: FishUI.Theme.mediumRadius
color: _mouseArea.pressed ? Qt.rgba(FishUI.Theme.textColor.r,
FishUI.Theme.textColor.g,
FishUI.Theme.textColor.b, FishUI.Theme.darkMode ? 0.05 : 0.1) :
_mouseArea.containsMouse || checked ? Qt.rgba(FishUI.Theme.textColor.r,
FishUI.Theme.textColor.g,
FishUI.Theme.textColor.b, FishUI.Theme.darkMode ? 0.1 : 0.05) :
"transparent"
smooth: true
2021-03-29 01:51:34 -07:00
}
RowLayout {
anchors.fill: parent
2021-04-09 07:49:19 -07:00
anchors.leftMargin: FishUI.Units.smallSpacing
anchors.rightMargin: FishUI.Units.smallSpacing
spacing: FishUI.Units.smallSpacing
2021-03-29 01:51:34 -07:00
Image {
2021-05-25 00:24:56 -07:00
height: 22
2021-03-29 01:51:34 -07:00
width: height
2021-09-03 10:47:54 -07:00
sourceSize: Qt.size(22, 22)
// source: "image://icontheme/" + model.iconName
2021-05-25 00:24:56 -07:00
source: "qrc:/images/" + (FishUI.Theme.darkMode || _item.checked ? "dark/" : "light/") + model.iconPath
2021-03-29 01:51:34 -07:00
Layout.alignment: Qt.AlignVCenter
2021-08-07 18:29:04 -07:00
smooth: false
2021-08-16 18:53:52 -07:00
antialiasing: true
2021-03-29 01:51:34 -07:00
}
Label {
id: _label
text: model.name
2021-04-09 07:49:19 -07:00
color: checked ? FishUI.Theme.highlightedTextColor : FishUI.Theme.textColor
2021-08-16 18:53:52 -07:00
elide: Text.ElideRight
2021-03-29 01:51:34 -07:00
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
}
}
}
function updateSelection(path) {
sideBar.currentIndex = -1
for (var i = 0; i < sideBar.count; ++i) {
2021-03-29 18:48:59 -07:00
if (path === sideBar.model.get(i).path ||
path === sideBar.model.get(i).url) {
2021-03-29 01:51:34 -07:00
sideBar.currentIndex = i
break
}
2021-03-16 00:02:20 -07:00
}
}
}