filemanager/qml/FolderGridItem.qml

141 lines
4.6 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.fileName
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-04-09 07:49:19 -07:00
color: selected || hovered ? FishUI.Theme.highlightColor : "transparent"
radius: FishUI.Theme.mediumRadius
2021-03-30 09:20:52 -07:00
visible: selected || hovered
2021-04-04 08:38:01 -07:00
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-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
cache: true
layer.enabled: true
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-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-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
visible: control.GridView.view.isDesktopView
2021-03-29 01:51:34 -07:00
}
}