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-03-16 00:02:20 -07:00
import MeuiKit 1.0 as Meui
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-03-16 00:02:20 -07:00
leftMargin: Meui.Units.smallSpacing
rightMargin: Meui.Units.smallSpacing
2021-03-30 18:22:32 -07:00
bottomMargin: Meui.Units.smallSpacing
2021-03-29 01:51:34 -07:00
spacing: Meui.Units.largeSpacing
2021-03-16 00:02:20 -07:00
2021-03-30 18:22:32 -07:00
ScrollBar.vertical: ScrollBar {
bottomPadding: Meui.Units.smallSpacing
}
2021-03-16 00:02:20 -07:00
highlightFollowsCurrentItem: true
highlightMoveDuration: 0
highlightResizeDuration : 0
highlight: Rectangle {
radius: Meui.Theme.smallRadius
color: Meui.Theme.highlightColor
}
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
property color hoveredColor: Meui.Theme.darkMode ? Qt.lighter(Meui.Theme.backgroundColor, 1.1)
: Qt.darker(Meui.Theme.backgroundColor, 1.1)
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
radius: Meui.Theme.smallRadius
color: _mouseArea.containsMouse && !checked ? _item.hoveredColor : "transparent"
}
RowLayout {
anchors.fill: parent
anchors.leftMargin: Meui.Units.smallSpacing
anchors.rightMargin: Meui.Units.smallSpacing
spacing: Meui.Units.smallSpacing
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
visible: Meui.Theme.darkMode && model.iconPath || checked
}
}
Label {
id: _label
text: model.name
color: checked ? Meui.Theme.highlightedTextColor : Meui.Theme.textColor
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
}
}
}