filemanager/qml/Desktop/main.qml

211 lines
5.9 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
import QtQuick.Layouts 1.12
2021-04-12 22:56:09 -07:00
import QtQuick.Window 2.12
2021-03-29 01:51:34 -07:00
import QtGraphicalEffects 1.0
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 "../"
Item {
id: rootItem
DesktopSettings {
id: settings
}
2021-03-29 07:53:21 -07:00
GlobalSettings {
id: globalSettings
}
2021-03-29 01:51:34 -07:00
Loader {
id: backgroundLoader
anchors.fill: parent
sourceComponent: settings.backgroundType === 0 ? wallpaper : background
}
Component {
id: background
Rectangle {
anchors.fill: parent
color: settings.backgroundColor
}
}
Component {
id: wallpaper
Image {
source: "file://" + settings.wallpaper
2021-04-12 22:56:09 -07:00
sourceSize: Qt.size(width * Screen.devicePixelRatio,
height * Screen.devicePixelRatio)
2021-03-29 01:51:34 -07:00
fillMode: Image.PreserveAspectCrop
clip: true
cache: false
ColorOverlay {
id: dimsWallpaper
anchors.fill: parent
source: parent
color: "#000000"
2021-04-09 07:49:19 -07:00
opacity: FishUI.Theme.darkMode && settings.dimsWallpaper ? 0.4 : 0.0
2021-03-29 01:51:34 -07:00
Behavior on opacity {
NumberAnimation {
duration: 200
}
}
}
}
}
2021-03-30 21:45:51 -07:00
FolderModel {
2021-04-05 00:24:52 -07:00
id: dirModel
2021-03-30 21:45:51 -07:00
url: desktopPath()
isDesktop: true
2021-04-04 13:06:24 -07:00
viewAdapter: viewAdapter
}
ItemViewAdapter {
id: viewAdapter
adapterView: _folderView
2021-04-05 00:24:52 -07:00
adapterModel: dirModel
2021-04-04 13:06:24 -07:00
adapterIconSize: 40
adapterVisibleArea: Qt.rect(_folderView.contentX, _folderView.contentY,
_folderView.contentWidth, _folderView.contentHeight)
2021-03-30 21:45:51 -07:00
}
2021-03-29 01:51:34 -07:00
FolderGridView {
2021-03-30 21:45:51 -07:00
id: _folderView
2021-03-29 01:51:34 -07:00
anchors.fill: parent
2021-03-30 09:20:52 -07:00
isDesktopView: true
iconSize: globalSettings.desktopIconSize
maximumIconSize: globalSettings.maximumIconSize
minimumIconSize: globalSettings.minimumIconSize
2021-03-30 21:54:58 -07:00
focus: true
2021-04-05 00:24:52 -07:00
model: dirModel
2021-03-29 01:51:34 -07:00
2021-04-05 20:40:27 -07:00
ScrollBar.vertical.policy: ScrollBar.AlwaysOff
2021-06-01 22:25:04 -07:00
// Handle for topbar
anchors.topMargin: desktopView.screenAvailableRect.y
2021-06-01 22:25:04 -07:00
leftMargin: desktopView.screenAvailableRect.x
topMargin: 0
2021-03-29 01:51:34 -07:00
rightMargin: desktopView.screenRect.width - (desktopView.screenAvailableRect.x + desktopView.screenAvailableRect.width)
bottomMargin: desktopView.screenRect.height - (desktopView.screenAvailableRect.y + desktopView.screenAvailableRect.height)
2021-06-01 22:25:04 -07:00
Behavior on anchors.topMargin {
2021-06-05 04:08:57 -07:00
NumberAnimation { duration: 125; easing.type: Easing.Linear }
2021-06-01 22:25:04 -07:00
}
Behavior on leftMargin {
2021-06-05 04:08:57 -07:00
NumberAnimation { duration: 125; easing.type: Easing.Linear }
2021-06-01 22:25:04 -07:00
}
Behavior on rightMargin {
2021-06-05 04:08:57 -07:00
NumberAnimation { duration: 125; easing.type: Easing.Linear }
2021-06-01 22:25:04 -07:00
}
Behavior on bottomMargin {
2021-06-05 04:08:57 -07:00
NumberAnimation { duration: 125; easing.type: Easing.Linear }
2021-06-01 22:25:04 -07:00
}
flow: GridView.FlowTopToBottom
2021-03-29 01:51:34 -07:00
delegate: FolderGridItem {}
2021-06-01 22:25:04 -07:00
onIconSizeChanged: {
globalSettings.desktopIconSize = _folderView.iconSize
}
onActiveFocusChanged: {
if (!activeFocus) {
_folderView.cancelRename()
2021-04-05 00:24:52 -07:00
dirModel.clearSelection()
}
}
2021-04-04 13:06:24 -07:00
Component.onCompleted: {
2021-04-05 00:24:52 -07:00
dirModel.requestRename.connect(rename)
2021-04-04 13:06:24 -07:00
}
2021-03-29 01:51:34 -07:00
}
2021-03-30 21:45:51 -07:00
Connections {
target: _folderView
function onKeyPress(event) {
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return)
2021-04-05 00:24:52 -07:00
dirModel.openSelected()
2021-03-30 21:45:51 -07:00
else if (event.key === Qt.Key_C && event.modifiers & Qt.ControlModifier)
2021-04-05 00:24:52 -07:00
dirModel.copy()
2021-03-30 21:45:51 -07:00
else if (event.key === Qt.Key_X && event.modifiers & Qt.ControlModifier)
2021-04-05 00:24:52 -07:00
dirModel.cut()
2021-03-30 21:45:51 -07:00
else if (event.key === Qt.Key_V && event.modifiers & Qt.ControlModifier)
2021-04-05 00:24:52 -07:00
dirModel.paste()
2021-03-30 21:45:51 -07:00
else if (event.key === Qt.Key_F2)
2021-04-05 00:24:52 -07:00
dirModel.requestRename()
2021-03-30 21:45:51 -07:00
else if (event.key === Qt.Key_A && event.modifiers & Qt.ControlModifier)
2021-04-05 00:24:52 -07:00
dirModel.selectAll()
2021-04-09 07:49:19 -07:00
else if (event.key === Qt.Key_Delete)
dirModel.keyDeletePress()
2021-03-30 21:45:51 -07:00
}
}
2021-03-29 01:51:34 -07:00
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()
}
}
}
}
}