filemanager/qml/SideBar.qml

111 lines
3.2 KiB
QML
Raw Normal View History

2021-03-29 01:51:34 -07:00
import QtQuick 2.12
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.12
import QtGraphicalEffects 1.0
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-03-16 00:02:20 -07:00
PlacesModel {
id: placesModel
}
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 {
2021-04-09 07:49:19 -07:00
radius: FishUI.Theme.smallRadius
color: FishUI.Theme.highlightColor
2021-03-16 00:02:20 -07:00
}
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
height: 40
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
acceptedButtons: Qt.LeftButton
onClicked: {
2021-03-29 18:48:59 -07:00
if (model.isDevice && model.setupNeeded)
placesModel.requestSetup(index)
// sideBar.currentIndex = index
sideBar.clicked(model.path ? model.path : model.url)
2021-03-29 01:51:34 -07:00
}
}
Rectangle {
anchors.fill: parent
2021-04-09 07:49:19 -07:00
radius: FishUI.Theme.smallRadius
2021-03-29 01:51:34 -07:00
color: _mouseArea.containsMouse && !checked ? _item.hoveredColor : "transparent"
}
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 {
height: _item.height * 0.55
width: height
sourceSize: Qt.size(width, height)
source: model.iconPath ? model.iconPath : "image://icontheme/" + model.iconName
Layout.alignment: Qt.AlignVCenter
ColorOverlay {
anchors.fill: parent
source: parent
color: _label.color
2021-04-09 07:49:19 -07:00
visible: FishUI.Theme.darkMode && model.iconPath || checked
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-03-29 01:51:34 -07:00
elide: Text.ElideRight
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
}
}
}