Warning, /utilities/daykountdown/src/contents/ui/KountdownCard.qml is written in an unsupported language. File is not indexed.

0001 /*
0002 * SPDX-FileCopyrightText: (C) 2021 Claudio Cambra <claudio.cambra@gmail.com>
0003 * 
0004 * SPDX-LicenseRef: GPL-3.0-or-later
0005 */
0006 
0007 import QtQuick 2.6
0008 import QtQuick.Controls 2.0 as Controls
0009 import QtQuick.Layouts 1.2
0010 import org.kde.kirigami 2.13 as Kirigami
0011 
0012 // Delegate is how the information will be presented in the ListView
0013 Kirigami.Card {
0014         id: kountdownDelegate
0015         
0016         showClickFeedback: true
0017         onReleased: openPopulateSheet("edit", index, name, description, date, colour)
0018         
0019         // contentItem property includes the content to be displayed on the card
0020         contentItem: Item {
0021                 id: cardContents
0022                 // implicitWidth/Height define the natural width/height of an item if no width or height is specified
0023                 // The setting below defines a component's preferred size based on its content
0024                 implicitWidth: delegateLayout.implicitWidth
0025                 implicitHeight: delegateLayout.implicitHeight
0026                 
0027                 GridLayout {
0028                         id: delegateLayout
0029                         // QtQuick anchoring system allows quick definition of anchor points for positioning
0030                         anchors {
0031                                 left: parent.left
0032                                 top: parent.top
0033                                 right: parent.right
0034                         }
0035                         rowSpacing: Kirigami.Units.largeSpacing
0036                         columnSpacing: Kirigami.Units.largeSpacing
0037                         columns: 2
0038                         RowLayout {
0039                                 Rectangle {
0040                                         Layout.fillHeight: true
0041                                         width: 5
0042                                         color: colour
0043                                 }
0044                                 Kirigami.Heading {
0045                                         // Heading will be as tall as possible while respecting constraints
0046                                         Layout.fillHeight: true
0047                                         // Level determines the size of the heading
0048                                         level: 1
0049                                         property var daysLeft: Math.ceil((date.getTime()-nowDate.getTime())/86400000)
0050                                         // Changes 'day' word depending on quantity of days
0051                                         property var daysWord: daysLeft <= -2 || daysLeft >= 2 ? "days" : "day"
0052                                         text: daysLeft < 0 ? 
0053                                                 i18n("%1 " + daysWord + " ago", daysLeft*-1) : i18n("%1 " + daysWord, daysLeft)
0054                                         color: colour
0055                                 }
0056                         }
0057                         
0058                         // Layout for positioning elements vertically
0059                         ColumnLayout {
0060                                 Kirigami.Heading {
0061                                         Layout.fillWidth: true
0062                                         wrapMode: Text.Wrap
0063                                         level: 2
0064                                         text: name
0065                                 }
0066                                 // Horizontal rule
0067                                 Kirigami.Separator {
0068                                         Layout.fillWidth: true
0069                                         visible: description.length > 0
0070                                 }
0071                                 // Labels contain text
0072                                 Controls.Label {
0073                                         Layout.fillWidth: true
0074                                         // Word wrap makes text stay within box and shift with size
0075                                         wrapMode: Text.Wrap
0076                                         text: description
0077                                         visible: description.length > 0
0078                                 }
0079                         }
0080                 }
0081         }
0082 }