filemanager/qml/FolderPage.qml

257 lines
6.8 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
import MeuiKit 1.0 as Meui
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
anchors.rightMargin: Meui.Theme.smallRadius
anchors.bottomMargin: Meui.Theme.smallRadius
2021-03-29 01:51:34 -07:00
radius: Meui.Theme.smallRadius
color: Meui.Theme.backgroundColor
}
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)
}
ColumnLayout {
anchors.fill: parent
anchors.bottomMargin: Meui.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
anchors.leftMargin: Meui.Units.largeSpacing
anchors.rightMargin: Meui.Units.largeSpacing
2021-03-29 07:53:21 -07:00
anchors.bottomMargin: 1
2021-04-01 01:05:15 -07:00
spacing: Meui.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-03-29 07:53:21 -07:00
leftMargin: Meui.Units.largeSpacing
rightMargin: Meui.Units.largeSpacing
topMargin: Meui.Units.smallSpacing
bottomMargin: Meui.Units.smallSpacing
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-01 01:05:15 -07:00
topMargin: Meui.Units.largeSpacing
2021-03-29 01:51:34 -07:00
leftMargin: Meui.Units.largeSpacing
rightMargin: Meui.Units.largeSpacing + Meui.Theme.smallRadius
2021-03-29 01:51:34 -07:00
spacing: Meui.Units.largeSpacing
onCountChanged: {
_fileTips.visible = count === 0
}
delegate: FolderListItem {}
}
}
Component {
id: rubberBandObject
RubberBand {
id: rubberBand
width: 0
height: 0
z: 99999
color: Meui.Theme.highlightColor
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
}
}