Warning, /utilities/powerplant/src/contents/ui/PlantsPage.qml is written in an unsupported language. File is not indexed.
0001 0002 // SPDX-FileCopyrightText: 2023 2023 Mathis BrĂ¼chert <mbb@kaidan.im> 0003 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu> 0004 // SPDX-License-Identifier: GPL-2.0-or-later 0005 import QtQuick 2.15 0006 import QtQuick.Controls 2.15 as Controls 0007 import QtQuick.Layouts 1.15 0008 import org.kde.kirigami 2.19 as Kirigami 0009 import QtGraphicalEffects 1.0 0010 0011 import org.kde.powerplant 1.0 0012 0013 import "components" 0014 0015 Kirigami.ScrollablePage { 0016 id: root 0017 rightPadding: 0 0018 // leftPadding:0 0019 bottomPadding: 0 0020 Layout.fillWidth: true 0021 0022 title: i18n("Plants") 0023 actions.main: Kirigami.Action { 0024 icon.name: "help-about-symbolic" 0025 onTriggered: pageStack.pushDialogLayer("qrc:/About.qml") 0026 } 0027 0028 Component { 0029 id: addPlantComponent 0030 0031 PlantEditorPage { 0032 plantsModel: grid.model 0033 mode: PlantEditor.Creator 0034 } 0035 } 0036 0037 ActionButton { 0038 parent: root.overlay 0039 x: root.width - width - margin 0040 y: root.height - height - pageStack.globalToolBar.preferredHeight - margin 0041 text: i18nc("@action:button", "Add Plant") 0042 icon.name: "list-add" 0043 onClicked: applicationWindow().pageStack.pushDialogLayer( 0044 addPlantComponent, {}, { 0045 "width": Kirigami.Units.gridUnit * 25, 0046 "height": Kirigami.Units.gridUnit * 35 0047 }) 0048 } 0049 0050 GridView { 0051 id: grid 0052 0053 cellWidth: applicationWindow( 0054 ).width < 500 ? grid.width / (Math.floor( 0055 grid.width / 160)) : grid.width 0056 / (Math.floor(grid.width / 230)) 0057 cellHeight: 310 0058 0059 header: ColumnLayout { 0060 spacing: 0 0061 width: parent.width 0062 0063 Controls.Label { 0064 text: i18n("Good Morning!") 0065 font { 0066 bold: true 0067 pixelSize: 30 0068 } 0069 0070 Layout.margins: Kirigami.Units.largeSpacing * 2 0071 Layout.topMargin: Kirigami.Units.largeSpacing * 2 0072 Layout.bottomMargin: Kirigami.Units.largeSpacing 0073 Layout.fillWidth: true 0074 } 0075 0076 Controls.Label { 0077 text: { 0078 switch (plantsModel.summary) { 0079 case PlantsModel.SomeNeedWater: 0080 return i18n("Some of your plants need attention"); 0081 case PlantsModel.NothingToDo: 0082 return i18n("No plants need water right now"); 0083 } 0084 } 0085 0086 wrapMode: Text.WordWrap 0087 font.pixelSize: 20 0088 0089 Layout.margins: Kirigami.Units.largeSpacing * 2 0090 Layout.topMargin: 0 0091 Layout.bottomMargin: Kirigami.Units.largeSpacing 0092 Layout.fillWidth: true 0093 } 0094 } 0095 0096 model: PlantsModel { 0097 id: plantsModel 0098 } 0099 0100 delegate: ColumnLayout { 0101 id: plantItem 0102 0103 required property string imgUrl 0104 required property string name 0105 required property string species 0106 required property string wantsToBeWateredIn 0107 required property int currentHealth 0108 required property var dateOfBirth 0109 required property int plantId 0110 0111 WaterHistoryModel { 0112 id: waterEvents 0113 plantId: plantItem.plantId 0114 } 0115 width: grid.cellWidth 0116 0117 Kirigami.Card { 0118 id: card 0119 0120 onClicked: pageStack.push("qrc:/PlantDetailPage.qml", { 0121 "plantId": plantItem.plantId, 0122 "plantsModel": plantsModel 0123 }) 0124 0125 background: Kirigami.ShadowedRectangle { 0126 radius: 5 0127 color: Kirigami.ColorUtils.tintWithAlpha( 0128 Kirigami.Theme.backgroundColor, 0129 healthSlider.healthColor, 0.2) 0130 0131 border { 0132 color: Kirigami.ColorUtils.linearInterpolation( 0133 Kirigami.Theme.backgroundColor, 0134 Kirigami.Theme.textColor, 0.3) 0135 width: 1 0136 } 0137 0138 shadow { 0139 size: 15 0140 xOffset: 5 0141 yOffset: 5 0142 color: Qt.rgba(0, 0, 0, 0.1) 0143 } 0144 0145 Item { 0146 y: 2 0147 height: parent.height - 80 0148 width: parent.width 0149 Image { 0150 anchors.fill: parent 0151 id: image 0152 fillMode: Image.PreserveAspectFit 0153 source: imgUrl 0154 layer { 0155 enabled: true 0156 effect: OpacityMask { 0157 maskSource: mask 0158 } 0159 } 0160 } 0161 Rectangle { 0162 id: mask 0163 anchors.fill: parent 0164 visible: false 0165 gradient: Gradient { 0166 GradientStop { 0167 position: 0.5 0168 color: "white" 0169 } 0170 GradientStop { 0171 position: 0.75 0172 color: "transparent" 0173 } 0174 } 0175 } 0176 } 0177 } 0178 Layout.alignment: Qt.AlignHCenter 0179 Layout.margins: 10 0180 padding: 0 0181 implicitHeight: grid.cellHeight - 2 * Layout.margins 0182 contentItem: ColumnLayout { 0183 Kirigami.Heading { 0184 text: name 0185 type: Kirigami.Heading.Type.Primary 0186 Layout.topMargin: 120 0187 } 0188 0189 Controls.Label { 0190 text: species 0191 color: Kirigami.Theme.disabledTextColor 0192 } 0193 0194 TextIconBox { 0195 Layout.fillWidth: true 0196 label { 0197 text: if (wantsToBeWateredIn > 1) { 0198 i18n("in %1 days", wantsToBeWateredIn) 0199 } else if (wantsToBeWateredIn == 1) { 0200 i18n("tomorrow") 0201 } else if (wantsToBeWateredIn == 0) { 0202 i18n("water today!") 0203 } else if (wantsToBeWateredIn < 0) { 0204 i18n("watering overdue!") 0205 } 0206 font.bold: wantsToBeWateredIn <= 0 0207 } 0208 icon { 0209 source: "raindrop" 0210 color: "#64ace1" 0211 } 0212 action { 0213 icon.name: "answer-correct" 0214 onClicked: { 0215 console.log(plantId) 0216 waterEvents.waterPlant() 0217 } 0218 visible: wantsToBeWateredIn <= 0 0219 } 0220 } 0221 0222 HealthSlider { 0223 id: healthSlider 0224 Layout.fillWidth: true 0225 from: 0 0226 to: 100 0227 value: currentHealth 0228 enabled: false 0229 0230 Layout.bottomMargin: 20 0231 } 0232 } 0233 } 0234 } 0235 } 0236 }