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
|
2021-03-30 05:44:50 -07:00
|
|
|
property var fileName: model.fileName
|
|
|
|
|
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-04-09 07:49:19 -07:00
|
|
|
anchors.topMargin: FishUI.Units.largeSpacing
|
|
|
|
anchors.bottomMargin: FishUI.Units.largeSpacing
|
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
|
|
|
|
|
|
|
|
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-06-17 06:22:18 -07:00
|
|
|
|
|
|
|
ColorOverlay {
|
|
|
|
anchors.fill: _icon
|
|
|
|
source: _icon
|
|
|
|
color: FishUI.Theme.highlightColor
|
|
|
|
opacity: 0.5
|
|
|
|
visible: control.selected
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorOverlay {
|
|
|
|
anchors.fill: _icon
|
|
|
|
source: _icon
|
2021-06-22 21:37:42 -07:00
|
|
|
color: "white"
|
|
|
|
opacity: FishUI.Theme.darkMode ? 0.3 : 0.4
|
2021-06-17 06:22:18 -07:00
|
|
|
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
|
|
|
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
|
|
|
|
sourceSize.width: width
|
|
|
|
sourceSize.height: height
|
|
|
|
source: model.thumbnail ? model.thumbnail : ""
|
|
|
|
asynchronous: true
|
2021-07-28 12:30:17 -07:00
|
|
|
cache: false
|
2021-03-30 09:20:52 -07:00
|
|
|
|
2021-06-17 06:22:18 -07:00
|
|
|
// Because of the effect of OpacityMask.
|
|
|
|
ColorOverlay {
|
|
|
|
anchors.fill: _image
|
|
|
|
source: _image
|
|
|
|
color: FishUI.Theme.highlightColor
|
|
|
|
opacity: 0.5
|
|
|
|
visible: control.selected
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorOverlay {
|
|
|
|
anchors.fill: _image
|
|
|
|
source: _image
|
2021-06-22 21:37:42 -07:00
|
|
|
color: "white"
|
|
|
|
opacity: FishUI.Theme.darkMode ? 0.3 : 0.4
|
2021-06-17 06:22:18 -07:00
|
|
|
visible: control.hovered && !control.selected
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2021-04-05 00:21:39 -07:00
|
|
|
radius: height * 0.1
|
2021-03-29 01:51:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-17 06:22:18 -07:00
|
|
|
|
|
|
|
// ColorOverlay {
|
|
|
|
// id: _selectedColorOverlay
|
|
|
|
// anchors.fill: _image.visible ? _image : _icon
|
|
|
|
// source: _image.visible ? _image : _icon
|
|
|
|
// color: FishUI.Theme.highlightColor
|
|
|
|
// opacity: 0.5
|
|
|
|
// visible: control.selected
|
|
|
|
// }
|
|
|
|
|
|
|
|
// ColorOverlay {
|
|
|
|
// id: _hoveredColorOverlay
|
|
|
|
// anchors.fill: _image.visible ? _image : _icon
|
|
|
|
// source: _image.visible ? _image : _icon
|
|
|
|
// color: Qt.lighter(FishUI.Theme.highlightColor, 1.6)
|
|
|
|
// opacity: FishUI.Theme.darkMode ? 0.4 : 0.6
|
|
|
|
// 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-03-30 09:20:52 -07:00
|
|
|
maximumLineCount: 2
|
|
|
|
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: model.fileName
|
|
|
|
color: control.GridView.view.isDesktopView ? "white"
|
2021-04-09 07:49:19 -07:00
|
|
|
: selected ? FishUI.Theme.highlightedTextColor : FishUI.Theme.textColor
|
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
|
|
|
|
x: _label.x
|
|
|
|
y: _label.y
|
|
|
|
width: _label.width
|
|
|
|
height: _label.height
|
|
|
|
radius: 4
|
|
|
|
color: FishUI.Theme.highlightColor
|
|
|
|
opacity: control.selected ? 1.0 : 0
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|