filemanager/qml/FolderPage.qml

271 lines
7.1 KiB
QML
Raw Normal View History

2021-03-29 01:51:34 -07:00
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import Cutefish.FileManager 1.0
2021-04-09 07:49:19 -07:00
import FishUI 1.0 as FishUI
2021-03-29 01:51:34 -07:00
import "./Dialogs"
Item {
id: folderPage
property alias currentUrl: dirModel.url
2021-03-29 01:51:34 -07:00
property Item currentView: _viewLoader.item
2021-03-29 07:53:21 -07:00
property int statusBarHeight: 30
2021-03-29 01:51:34 -07:00
signal requestPathEditor()
onCurrentUrlChanged: {
2021-04-04 13:06:24 -07:00
_viewLoader.item.reset()
2021-03-29 01:51:34 -07:00
_viewLoader.item.forceActiveFocus()
}
Rectangle {
id: _background
anchors.fill: parent
2021-04-09 07:49:19 -07:00
anchors.rightMargin: FishUI.Theme.smallRadius
anchors.bottomMargin: FishUI.Theme.smallRadius
radius: FishUI.Theme.smallRadius
color: FishUI.Theme.backgroundColor
2021-03-29 01:51:34 -07:00
}
Label {
id: _fileTips
2021-04-04 13:06:24 -07:00
text: qsTr("Empty folder")
font.pointSize: 20
2021-03-29 01:51:34 -07:00
anchors.centerIn: parent
visible: false
}
FolderModel {
id: dirModel
2021-03-29 01:51:34 -07:00
viewAdapter: viewAdapter
2021-03-29 01:51:34 -07:00
Component.onCompleted: {
2021-03-30 21:45:51 -07:00
if (arg)
dirModel.url = arg
2021-03-30 21:45:51 -07:00
else
dirModel.url = dirModel.homePath()
2021-03-29 01:51:34 -07:00
}
}
ItemViewAdapter {
id: viewAdapter
adapterView: _viewLoader.item
adapterModel: _viewLoader.item.positioner ? _viewLoader.item.positioner : dirModel
2021-03-29 01:51:34 -07:00
adapterIconSize: 40
adapterVisibleArea: Qt.rect(_viewLoader.item.contentX, _viewLoader.item.contentY,
_viewLoader.item.contentWidth, _viewLoader.item.contentHeight)
}
2021-04-09 07:49:19 -07:00
FishUI.DesktopMenu {
id: folderMenu
MenuItem {
text: qsTr("Open")
onTriggered: dirModel.openSelected()
}
MenuItem {
text: qsTr("Properties")
onTriggered: dirModel.openPropertiesDialog()
}
}
2021-03-29 01:51:34 -07:00
ColumnLayout {
anchors.fill: parent
2021-04-09 07:49:19 -07:00
anchors.bottomMargin: FishUI.Theme.smallRadius
2021-03-29 01:51:34 -07:00
spacing: 0
Loader {
id: _viewLoader
Layout.fillWidth: true
Layout.fillHeight: true
sourceComponent: switch (settings.viewMethod) {
case 0: return _listViewComponent
case 1: return _gridViewComponent
}
2021-04-04 13:06:24 -07:00
onSourceComponentChanged: {
// 焦点
_viewLoader.item.forceActiveFocus()
}
2021-03-29 01:51:34 -07:00
}
Loader {
Layout.fillWidth: true
sourceComponent: _statusBar
}
}
2021-03-30 18:22:32 -07:00
function rename() {
_viewLoader.item.rename()
}
Component.onCompleted: {
dirModel.requestRename.connect(rename)
2021-03-30 18:22:32 -07:00
}
2021-03-29 01:51:34 -07:00
Component {
id: _statusBar
Item {
height: statusBarHeight
z: 999
RowLayout {
anchors.fill: parent
2021-04-09 07:49:19 -07:00
anchors.leftMargin: FishUI.Units.largeSpacing
anchors.rightMargin: FishUI.Units.largeSpacing
2021-03-29 07:53:21 -07:00
anchors.bottomMargin: 1
2021-04-09 07:49:19 -07:00
spacing: FishUI.Units.largeSpacing
2021-03-29 01:51:34 -07:00
Label {
Layout.alignment: Qt.AlignLeft
text: dirModel.count == 1 ? qsTr("%1 item").arg(dirModel.count)
: qsTr("%1 items").arg(dirModel.count)
2021-04-01 01:05:15 -07:00
}
Label {
Layout.alignment: Qt.AlignLeft
text: qsTr("%1 selected").arg(dirModel.selectionCound)
visible: dirModel.selectionCound >= 1
2021-04-01 01:05:15 -07:00
}
Item {
Layout.fillWidth: true
2021-03-29 01:51:34 -07:00
}
Button {
Layout.fillHeight: true
Layout.alignment: Qt.AlignRight
text: qsTr("Empty Trash")
onClicked: dirModel.emptyTrash()
visible: dirModel.url === "trash:/"
2021-04-05 20:40:27 -07:00
focusPolicy: Qt.NoFocus
2021-03-29 01:51:34 -07:00
}
}
}
}
Component {
id: _gridViewComponent
FolderGridView {
id: _gridView
model: dirModel
2021-03-29 01:51:34 -07:00
delegate: FolderGridItem {}
2021-04-09 07:49:19 -07:00
leftMargin: FishUI.Units.largeSpacing
rightMargin: FishUI.Units.largeSpacing
topMargin: FishUI.Units.smallSpacing
bottomMargin: FishUI.Units.smallSpacing
2021-03-29 07:53:21 -07:00
onIconSizeChanged: {
// Save
settings.gridIconSize = _gridView.iconSize
}
2021-03-29 01:51:34 -07:00
onCountChanged: {
_fileTips.visible = count === 0
}
}
}
Component {
id: _listViewComponent
FolderListView {
id: _folderListView
model: dirModel
2021-03-29 01:51:34 -07:00
2021-04-09 07:49:19 -07:00
topMargin: FishUI.Units.largeSpacing
leftMargin: FishUI.Units.largeSpacing
rightMargin: FishUI.Units.largeSpacing + FishUI.Theme.smallRadius
spacing: FishUI.Units.largeSpacing
2021-03-29 01:51:34 -07:00
onCountChanged: {
_fileTips.visible = count === 0
}
delegate: FolderListItem {}
}
}
Component {
id: rubberBandObject
RubberBand {
id: rubberBand
width: 0
height: 0
z: 99999
2021-04-09 07:49:19 -07:00
color: FishUI.Theme.highlightColor
2021-03-29 01:51:34 -07:00
function close() {
opacityAnimation.restart()
}
OpacityAnimator {
id: opacityAnimation
target: rubberBand
to: 0
from: 1
duration: 150
easing {
bezierCurve: [0.4, 0.0, 1, 1]
type: Easing.Bezier
}
onFinished: {
rubberBand.visible = false
rubberBand.enabled = false
rubberBand.destroy()
}
}
}
}
Connections {
target: _viewLoader.item
function onKeyPress(event) {
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return)
dirModel.openSelected()
2021-03-29 01:51:34 -07:00
else if (event.key === Qt.Key_C && event.modifiers & Qt.ControlModifier)
dirModel.copy()
2021-03-29 01:51:34 -07:00
else if (event.key === Qt.Key_X && event.modifiers & Qt.ControlModifier)
dirModel.cut()
2021-03-29 01:51:34 -07:00
else if (event.key === Qt.Key_V && event.modifiers & Qt.ControlModifier)
dirModel.paste()
2021-03-29 01:51:34 -07:00
else if (event.key === Qt.Key_F2)
dirModel.requestRename()
2021-03-29 01:51:34 -07:00
else if (event.key === Qt.Key_L && event.modifiers & Qt.ControlModifier)
folderPage.requestPathEditor()
else if (event.key === Qt.Key_A && event.modifiers & Qt.ControlModifier)
dirModel.selectAll()
2021-03-29 01:51:34 -07:00
else if (event.key === Qt.Key_Backspace)
dirModel.up()
2021-03-31 19:25:20 -07:00
else if (event.key === Qt.Key_Delete)
dirModel.keyDeletePress()
2021-03-29 01:51:34 -07:00
}
}
function openUrl(url) {
dirModel.url = url
2021-03-29 01:51:34 -07:00
_viewLoader.item.forceActiveFocus()
}
function goBack() {
dirModel.goBack()
2021-03-29 01:51:34 -07:00
}
function goForward() {
dirModel.goForward()
2021-03-29 01:51:34 -07:00
}
}