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
|
|
|
|
2021-12-16 07:26:56 -08:00
|
|
|
Rectangle {
|
|
|
|
anchors.fill: parent
|
|
|
|
color: FishUI.Theme.darkMode ? Qt.lighter(FishUI.Theme.secondBackgroundColor, 1.3)
|
|
|
|
: FishUI.Theme.secondBackgroundColor
|
|
|
|
radius: FishUI.Theme.smallRadius
|
|
|
|
z: -1
|
|
|
|
}
|
|
|
|
|
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-12-16 07:26:56 -08:00
|
|
|
anchors.topMargin: 2
|
|
|
|
anchors.bottomMargin: 2
|
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()
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
acceptedButtons: Qt.LeftButton
|
|
|
|
onClicked: openEditor()
|
|
|
|
z: -1
|
2021-03-16 00:02:20 -07:00
|
|
|
}
|
|
|
|
|
2021-12-16 07:26:56 -08:00
|
|
|
highlight: Rectangle {
|
2021-12-18 06:48:51 -08:00
|
|
|
radius: FishUI.Theme.smallRadius
|
|
|
|
color: Qt.rgba(FishUI.Theme.highlightColor.r,
|
|
|
|
FishUI.Theme.highlightColor.g,
|
|
|
|
FishUI.Theme.highlightColor.b, FishUI.Theme.darkMode ? 0.3 : 0.1)
|
2021-12-16 07:26:56 -08:00
|
|
|
smooth: true
|
|
|
|
}
|
|
|
|
|
2021-03-16 00:02:20 -07:00
|
|
|
delegate: MouseArea {
|
2021-03-29 01:51:34 -07:00
|
|
|
id: _item
|
2021-12-16 07:26:56 -08:00
|
|
|
height: ListView.view.height - ListView.view.topMargin - ListView.view.bottomMargin
|
2021-04-09 07:49:19 -07:00
|
|
|
width: _name.width + FishUI.Units.largeSpacing
|
2021-12-16 07:26:56 -08:00
|
|
|
hoverEnabled: true
|
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-12-18 06:48:51 -08:00
|
|
|
radius: FishUI.Theme.smallRadius
|
2021-12-16 07:26:56 -08:00
|
|
|
color: _item.pressed ? Qt.rgba(FishUI.Theme.textColor.r,
|
|
|
|
FishUI.Theme.textColor.g,
|
|
|
|
FishUI.Theme.textColor.b, FishUI.Theme.darkMode ? 0.05 : 0.1) :
|
|
|
|
_item.containsMouse ? 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-16 00:02:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
2021-03-29 01:51:34 -07:00
|
|
|
id: _name
|
|
|
|
text: model.name
|
2021-03-16 00:02:20 -07:00
|
|
|
anchors.centerIn: parent
|
2021-12-18 06:48:51 -08:00
|
|
|
color: selected ? FishUI.Theme.highlightColor : FishUI.Theme.textColor
|
2021-03-16 00:02:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2021-07-08 08:48:56 -07:00
|
|
|
color: FishUI.Theme.darkMode ? Qt.lighter(FishUI.Theme.secondBackgroundColor, 1.7)
|
|
|
|
: FishUI.Theme.secondBackgroundColor
|
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
|
|
|
}
|
|
|
|
}
|