filemanager/qml/FolderGridItem.qml

222 lines
7 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.Layouts 1.12
import QtQuick.Controls 2.12
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
Item {
id: control
width: GridView.view.cellWidth
height: GridView.view.cellHeight
property Item iconArea: _image.visible ? _image : _icon
2021-04-01 01:05:15 -07:00
property Item labelArea: _label
2021-03-30 09:20:52 -07:00
property Item background: _background
2021-03-29 01:51:34 -07:00
property int index: model.index
property bool hovered: GridView.view.hoveredItem === control
property bool selected: model.selected
property bool blank: model.blank
property var fileName: model.displayName
2021-07-26 10:28:54 -07:00
// For desktop
visible: GridView.view.isDesktopView ? !blank : true
onSelectedChanged: {
if (!GridView.view.isDesktopView)
return
if (selected && !blank) {
control.grabToImage(function(result) {
dirModel.addItemDragImage(control.index,
control.x,
control.y,
control.width,
control.height,
result.image)
})
}
}
2021-03-30 09:20:52 -07:00
Rectangle {
id: _background
2021-03-30 18:22:32 -07:00
width: Math.max(_iconItem.width, _label.paintedWidth)
2021-04-09 07:49:19 -07:00
height: _iconItem.height + _label.paintedHeight + FishUI.Units.largeSpacing
2021-03-30 09:20:52 -07:00
x: (parent.width - width) / 2
y: _iconItem.y
2021-06-17 06:22:18 -07:00
// (Deprecated) Rectangle rounded corner.
//color: selected || hovered ? FishUI.Theme.highlightColor : "transparent"
color: "transparent"
// radius: FishUI.Theme.mediumRadius
// visible: selected || hovered
// opacity: selected ? 1.0 : 0.2
2021-03-30 09:20:52 -07:00
}
2021-03-29 01:51:34 -07:00
2021-03-30 09:20:52 -07:00
Item {
id: _iconItem
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
2021-09-10 23:41:22 -07:00
anchors.topMargin: FishUI.Units.smallSpacing
anchors.bottomMargin: FishUI.Units.smallSpacing
2021-03-30 09:20:52 -07:00
z: 2
2021-04-09 07:49:19 -07:00
width: parent.width - FishUI.Units.largeSpacing * 2
2021-03-30 09:20:52 -07:00
height: control.GridView.view.iconSize
2021-09-12 04:30:01 -07:00
opacity: model.isHidden ? 0.5 : 1.0
2021-03-30 09:20:52 -07:00
Image {
id: _icon
width: control.GridView.view.iconSize
height: control.GridView.view.iconSize
anchors.centerIn: parent
sourceSize: Qt.size(width, height)
source: "image://icontheme/" + model.iconName
visible: !_image.visible
2021-08-17 00:58:29 -07:00
smooth: true
2021-08-16 18:53:52 -07:00
antialiasing: true
2021-03-30 09:20:52 -07:00
}
2021-03-29 01:51:34 -07:00
2021-03-30 09:20:52 -07:00
Image {
id: _image
anchors.fill: parent
2021-04-09 07:49:19 -07:00
anchors.topMargin: FishUI.Units.smallSpacing
anchors.leftMargin: FishUI.Units.smallSpacing
anchors.rightMargin: FishUI.Units.smallSpacing
2021-03-30 09:20:52 -07:00
fillMode: Image.PreserveAspectFit
visible: status === Image.Ready
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
2021-08-16 18:53:52 -07:00
sourceSize: Qt.size(width, height)
2021-03-30 09:20:52 -07:00
source: model.thumbnail ? model.thumbnail : ""
asynchronous: true
2021-07-28 12:30:17 -07:00
cache: false
2021-08-17 00:58:29 -07:00
smooth: true
2021-08-16 18:53:52 -07:00
antialiasing: true
2021-03-30 09:20:52 -07:00
2021-06-17 06:22:18 -07:00
layer.enabled: _image.visible
2021-03-30 09:20:52 -07:00
layer.effect: OpacityMask {
maskSource: Item {
width: _image.width
height: _image.height
Rectangle {
anchors.centerIn: parent
width: Math.min(parent.width, _image.paintedWidth)
height: Math.min(parent.height, _image.paintedHeight)
radius: height * 0.1
2021-03-29 01:51:34 -07:00
}
}
}
}
2021-06-17 06:22:18 -07:00
2021-10-22 02:31:30 -07:00
Image {
anchors.right: _icon.visible ? _icon.right : _image.right
anchors.bottom: _icon.visible ? _icon.bottom : _image.bottom
source: "image://icontheme/emblem-symbolic-link"
width: 16
height: 16
visible: model.isLink
sourceSize: Qt.size(width, height)
}
2021-12-21 06:16:38 -08:00
ColorOverlay {
id: _selectedColorOverlay
anchors.fill: _iconItem
source: _iconItem
color: FishUI.Theme.highlightColor
opacity: 0.5
visible: control.selected
}
ColorOverlay {
id: _hoveredColorOverlay
anchors.fill: _iconItem
source: _iconItem
color: "white"
opacity: 0.3
visible: control.hovered && !control.selected
}
2021-03-30 09:20:52 -07:00
}
2021-03-29 01:51:34 -07:00
2021-03-30 09:20:52 -07:00
Label {
id: _label
z: 2
anchors.top: _iconItem.bottom
anchors.horizontalCenter: parent.horizontalCenter
2021-04-09 07:49:19 -07:00
anchors.topMargin: FishUI.Units.smallSpacing
2021-09-10 23:41:22 -07:00
maximumLineCount: control.selected ? 3 : 2
2021-03-30 09:20:52 -07:00
horizontalAlignment: Text.AlignHCenter
2021-04-09 07:49:19 -07:00
width: parent.width - FishUI.Units.largeSpacing * 2 - FishUI.Units.smallSpacing
2021-03-30 09:20:52 -07:00
textFormat: Text.PlainText
elide: Qt.ElideRight
wrapMode: Text.Wrap
text: control.fileName
2021-03-30 09:20:52 -07:00
color: control.GridView.view.isDesktopView ? "white"
2021-12-18 07:18:52 -08:00
: selected ? FishUI.Theme.highlightColor
2021-09-12 04:30:01 -07:00
: FishUI.Theme.textColor
opacity: model.isHidden ? 0.8 : 1.0
2021-03-30 09:20:52 -07:00
}
2021-03-29 01:51:34 -07:00
2021-06-17 06:22:18 -07:00
Rectangle {
z: 1
2021-09-14 05:25:01 -07:00
x: _label.x + (_label.width - _label.paintedWidth) / 2 - (FishUI.Units.smallSpacing / 2)
2021-06-17 06:22:18 -07:00
y: _label.y
2021-09-14 05:25:01 -07:00
width: _label.paintedWidth + FishUI.Units.smallSpacing
height: _label.paintedHeight
2021-06-17 06:22:18 -07:00
radius: 4
color: FishUI.Theme.highlightColor
2021-12-18 07:18:52 -08:00
2021-12-21 06:16:38 -08:00
opacity: {
if (control.selected && control.GridView.view.isDesktopView)
return 1
if (control.selected)
return 0.2
if (control.hovered)
return 0.05
return 0
}
2021-06-17 06:22:18 -07:00
}
2021-03-30 09:20:52 -07:00
DropShadow {
anchors.fill: _label
source: _label
z: 1
horizontalOffset: 1
verticalOffset: 1
2021-04-09 07:49:19 -07:00
radius: Math.round(4 * FishUI.Units.devicePixelRatio)
2021-03-30 09:20:52 -07:00
samples: radius * 2 + 1
spread: 0.35
color: Qt.rgba(0, 0, 0, 0.3)
opacity: model.isHidden ? 0.6 : 1
2021-06-17 06:22:18 -07:00
visible: control.GridView.view.isDesktopView && !control.selected
2021-03-29 01:51:34 -07:00
}
}