filemanager/qml/PathBar.qml

150 lines
3.8 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.Controls 2.12
2021-03-16 00:02:20 -07:00
import QtGraphicalEffects 1.0
2021-03-29 01:51:34 -07:00
2021-03-16 00:02:20 -07:00
import Cutefish.FileManager 1.0
2021-04-09 07:49:19 -07:00
import FishUI 1.0 as FishUI
2021-03-16 00:02:20 -07:00
Item {
id: control
property string url: ""
2021-03-29 01:51:34 -07:00
signal itemClicked(string path)
signal editorAccepted(string path)
2021-03-16 00:02:20 -07:00
ListView {
2021-03-29 01:51:34 -07:00
id: _pathView
2021-03-16 00:02:20 -07:00
anchors.fill: parent
2021-03-29 01:51:34 -07:00
model: _pathBarModel
2021-03-16 00:02:20 -07:00
orientation: Qt.Horizontal
layoutDirection: Qt.LeftToRight
clip: true
2021-03-29 01:51:34 -07:00
leftMargin: 3
rightMargin: 3
2021-04-09 07:49:19 -07:00
spacing: FishUI.Units.smallSpacing
2021-03-16 00:02:20 -07:00
onCountChanged: {
2021-03-29 01:51:34 -07:00
_pathView.currentIndex = _pathView.count - 1
_pathView.positionViewAtEnd()
}
Rectangle {
anchors.fill: parent
2021-04-09 07:49:19 -07:00
color: FishUI.Theme.backgroundColor
radius: FishUI.Theme.smallRadius
2021-03-29 01:51:34 -07:00
z: -1
}
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton
onClicked: openEditor()
z: -1
2021-03-16 00:02:20 -07:00
}
delegate: MouseArea {
2021-03-29 01:51:34 -07:00
id: _item
height: ListView.view.height
2021-04-09 07:49:19 -07:00
width: _name.width + FishUI.Units.largeSpacing
2021-03-29 01:51:34 -07:00
z: -1
2021-03-16 00:02:20 -07:00
2021-03-29 01:51:34 -07:00
property bool selected: index === _pathView.count - 1
2021-03-16 00:02:20 -07:00
2021-03-29 01:51:34 -07:00
onClicked: control.itemClicked(model.path)
2021-03-16 00:02:20 -07:00
Rectangle {
anchors.fill: parent
2021-03-29 01:51:34 -07:00
anchors.topMargin: 2
anchors.bottomMargin: 2
2021-04-09 07:49:19 -07:00
color: FishUI.Theme.highlightColor
radius: FishUI.Theme.smallRadius
2021-03-16 00:02:20 -07:00
visible: selected
}
Label {
2021-03-29 01:51:34 -07:00
id: _name
text: model.name
2021-04-09 07:49:19 -07:00
color: selected ? FishUI.Theme.highlightedTextColor : FishUI.Theme.textColor
2021-03-16 00:02:20 -07:00
anchors.centerIn: parent
}
}
}
TextField {
2021-03-29 01:51:34 -07:00
id: _pathEditor
anchors.fill: parent
2021-03-16 00:02:20 -07:00
visible: false
selectByMouse: true
inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhNoAutoUppercase
2021-04-21 10:51:17 -07:00
text: _pathBarModel.url
2021-04-09 07:49:19 -07:00
color: FishUI.Theme.darkMode ? "white" : "black"
2021-03-16 00:02:20 -07:00
2021-04-04 22:01:49 -07:00
background: Rectangle {
2021-04-09 07:49:19 -07:00
radius: FishUI.Theme.smallRadius
color: FishUI.Theme.darkMode ? Qt.darker(FishUI.Theme.backgroundColor, 1.1) : "white"
2021-04-18 03:47:27 -07:00
border.width: 1
2021-04-09 07:49:19 -07:00
border.color: FishUI.Theme.highlightColor
2021-04-04 22:01:49 -07:00
}
2021-03-16 00:02:20 -07:00
onAccepted: {
2021-03-29 01:51:34 -07:00
control.editorAccepted(text)
2021-03-16 00:02:20 -07:00
closeEditor()
}
Keys.onPressed: {
if (event.key === Qt.Key_Escape)
focus = false
}
onActiveFocusChanged: {
if (!activeFocus) {
closeEditor()
}
}
}
2021-03-29 01:51:34 -07:00
PathBarModel {
id: _pathBarModel
}
function updateUrl(url) {
control.url = url
_pathBarModel.url = url
2021-03-16 00:02:20 -07:00
}
function openEditor() {
2021-04-21 10:51:17 -07:00
_pathEditor.text = _pathBarModel.url
2021-03-29 01:51:34 -07:00
_pathEditor.visible = true
_pathEditor.forceActiveFocus()
_pathEditor.selectAll()
_pathView.visible = false
}
function closeEditor() {
_pathEditor.visible = false
_pathView.visible = true
2021-03-16 00:02:20 -07:00
}
}