Warning, /plasma/plasma-bigscreen/components/qml/IconDelegate.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2022 Aditya Mehra <aix.m@outlook.com>
0003     SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 import QtQuick 2.14
0009 import QtQuick.Layouts 1.14
0010 import QtGraphicalEffects 1.14
0011 import QtQuick.Controls 2.14
0012 import org.kde.plasma.core 2.0 as PlasmaCore
0013 import org.kde.plasma.components 3.0 as PlasmaComponents
0014 import org.kde.kirigami 2.13 as Kirigami
0015 import org.kde.mycroft.bigscreen 1.0 as BigScreen
0016 
0017 AbstractDelegate {
0018     id: delegate
0019 
0020     implicitWidth: listView.cellWidth
0021     implicitHeight: listView.height
0022 
0023     property var iconImage
0024     property string comment
0025     property bool useIconColors: true
0026     property bool compactMode: false
0027     property bool hasComment: commentLabel.text.length > 5 ? 1 : 0
0028 
0029     Kirigami.Theme.inherit: !imagePalette.useColors
0030     Kirigami.Theme.textColor: imagePalette.textColor
0031     Kirigami.Theme.backgroundColor: imagePalette.backgroundColor
0032     Kirigami.Theme.highlightColor: imagePalette.accentColor
0033 
0034     Kirigami.ImageColors {
0035         id: imagePalette
0036         source: iconItem.source
0037         property bool useColors: useIconColors
0038         property color backgroundColor: useColors ? dominantContrast : PlasmaCore.ColorScope.backgroundColor
0039         property color accentColor: useColors ? highlight : PlasmaCore.ColorScope.highlightColor
0040         property color textColor: useColors
0041             ? (Kirigami.ColorUtils.brightnessForColor(dominantContrast) === Kirigami.ColorUtils.Light ? imagePalette.closestToBlack : imagePalette.closestToWhite)
0042             : PlasmaCore.ColorScope.textColor
0043     }
0044 
0045     contentItem: Item {
0046         id: content
0047 
0048         GridLayout {
0049             id: topArea
0050             width:  parent.width
0051             height: parent.height * 0.25
0052             anchors.top: parent.top
0053             columns: 2
0054 
0055             Behavior on columns {
0056                 PauseAnimation {
0057                     duration: Kirigami.Units.longDuration / 2
0058                 }
0059             }
0060 
0061             PlasmaCore.IconItem {
0062                 id: iconItem
0063                 Layout.preferredWidth: topArea.columns > 1 ? parent.height * 0.75 : (delegate.compactMode ? parent.height / 2 : parent.height)
0064                 Layout.preferredHeight: width
0065                 source: delegate.iconImage || delegate.icon.name || delegate.icon.source ? delegate.iconImage || delegate.icon.name || delegate.icon.source : "application-x-executable"
0066 
0067                 Behavior on Layout.preferredWidth {
0068                     ParallelAnimation {
0069                         NumberAnimation {
0070                             duration: Kirigami.Units.longDuration / 2;
0071                             easing.type: Easing.InOutQuad
0072                         }
0073                         NumberAnimation {
0074                             target: textLabel
0075                             from: 0
0076                             to: 1
0077                             properties: "opacity"
0078                             duration: delegate.hasComment ? Kirigami.Units.longDuration * 3 : 0
0079                             easing.type: Easing.InOutQuad
0080                         }
0081                     }
0082                 }
0083             }
0084 
0085             Rectangle {
0086                 Layout.fillWidth: true
0087                 Layout.fillHeight: true
0088                 color: "transparent"
0089 
0090                 Label {
0091                     id: textLabel
0092                     width: parent.width
0093                     height: parent.height
0094                     wrapMode: Text.WordWrap
0095                     verticalAlignment: Text.AlignVCenter
0096                     font.pixelSize: delegate.compactMode ? width * 0.2 : height * 0.9
0097                     font.bold: true
0098                     fontSizeMode: Text.Fit
0099                     minimumPixelSize: 2
0100                     maximumLineCount: 1
0101                     elide: Text.ElideRight
0102                     text: delegate.text
0103                     color: imagePalette.textColor
0104                 }
0105             }
0106         }
0107 
0108         Label {
0109             id: commentLabel
0110             anchors.top: topArea.bottom
0111             anchors.bottom: parent.bottom
0112             anchors.topMargin: Kirigami.Units.largeSpacing
0113             verticalAlignment: Text.AlignTop
0114             width: parent.width
0115             height: parent.height
0116             font.pixelSize: height * 0.25
0117             maximumLineCount: 2
0118             elide: Text.ElideRight
0119             wrapMode: Text.WordWrap
0120             text: delegate.comment
0121             color: imagePalette.textColor
0122 
0123             Behavior on opacity  {
0124                 NumberAnimation { duration: Kirigami.Units.longDuration * 2.5; easing.type: Easing.InOutQuad }
0125             }
0126         }
0127     }
0128 
0129     states: [
0130         State {
0131             name: "selectedNoComment"
0132             when: delegate.isCurrent && !hasComment
0133 
0134             PropertyChanges {
0135                 target: delegate
0136                 implicitWidth: delegate.compactMode ? listView.cellWidth + (listView.cellWidth  / 1.25) : listView.cellWidth
0137             }
0138 
0139             PropertyChanges {
0140                 target: topArea
0141                 height: content.height
0142                 columns: 1
0143                 rows: 2
0144             }
0145             PropertyChanges {
0146                 target: iconItem
0147                 Layout.preferredHeight: parent.height * 0.75
0148                 Layout.preferredWidth: height
0149                 Layout.alignment: Qt.AlignHCenter
0150             }
0151             PropertyChanges {
0152                 target: textLabel
0153                 horizontalAlignment: Text.AlignHCenter
0154             }
0155 
0156             PropertyChanges {
0157                 target: commentLabel
0158                 opacity: 0
0159             }
0160         },
0161         State {
0162             name: "selectedWithComment"
0163             when: delegate.isCurrent && hasComment
0164 
0165             PropertyChanges {
0166                     target: delegate
0167                     implicitWidth: delegate.compactMode ? listView.cellWidth + (listView.cellWidth  / 1.25) : listView.cellWidth
0168             }
0169 
0170             PropertyChanges {
0171                 target: topArea
0172                 height: parent.height * 0.25
0173                 columns: 2
0174             }
0175             PropertyChanges {
0176                 target: commentLabel
0177                 opacity: 1
0178             }
0179         },
0180         State {
0181             name: "normal"
0182             when: !delegate.isCurrent
0183 
0184             PropertyChanges {
0185                 target: topArea
0186                 height: content.height
0187                 columns: 1
0188                 rows: 2
0189             }
0190             PropertyChanges {
0191                 target: iconItem
0192                 Layout.preferredHeight: delegate.compactMode ? parent.height / 2 : parent.height * 0.75
0193                 Layout.preferredWidth: height
0194                 Layout.alignment: Qt.AlignHCenter
0195             }
0196             PropertyChanges {
0197                 target: textLabel
0198                 horizontalAlignment: Text.AlignHCenter
0199             }
0200 
0201             PropertyChanges {
0202                 target: commentLabel
0203                 opacity: 0
0204             }
0205         }
0206     ]
0207 }