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

0001 // SPDX-FileCopyrightText: 2023 2023 Mathis BrĂ¼chert <mbb@kaidan.im>
0002 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlhwan.eu>
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
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 org.kde.kirigamiaddons.formcard 1.0 as FormCard
0010 import QtGraphicalEffects 1.15
0011 import org.kde.quickcharts 1.0 as Charts
0012 import org.kde.powerplant 1.0
0013 
0014 import "components"
0015 
0016 Kirigami.ScrollablePage {
0017     id: root
0018 
0019     required property var plantsModel
0020     required property int plantId
0021     property bool wideScreen: applicationWindow().width >= 800
0022 
0023     Plant {
0024         id: plant
0025         plantId: root.plantId
0026     }
0027 
0028     WaterHistoryModel {
0029         id: waterEvents
0030         plantId: root.plantId
0031     }
0032 
0033     HealthHistoryModel {
0034         id: healthEvents
0035         plantId: root.plantId
0036     }
0037 
0038     Component {
0039         id: editPlantComponent
0040 
0041         PlantEditorPage {
0042             mode: PlantEditor.Editor
0043             plantsModel: root.plantsModel
0044             plantId: root.plantId
0045         }
0046     }
0047 
0048     actions.contextualActions: [
0049         Kirigami.Action {
0050             icon.name: "document-edit"
0051             text: i18nc("@action:button", "Edit")
0052             onTriggered: {
0053                 applicationWindow().pageStack.pushDialogLayer(editPlantComponent, {}, {
0054                     width: Kirigami.Units.gridUnit * 25,
0055                     height: Kirigami.Units.gridUnit * 35,
0056                 })
0057             }
0058         },
0059         Kirigami.Action {
0060             icon.name: "delete"
0061             text: i18nc("@action:button", "Delete")
0062             onTriggered: {
0063                 plantsModel.deletePlant(plant.plantId);
0064                 applicationWindow().pageStack.pop();
0065             }
0066         }
0067     ]
0068 
0069     leftPadding: 0
0070     rightPadding: 0
0071 
0072     title: i18n("Plants")
0073     background: GridLayout {
0074         columnSpacing: 0
0075         rowSpacing: 0
0076         flow: wideScreen ? GridLayout.LeftToRight : GridLayout.TopToBottom
0077         anchors.fill: parent
0078         columns: 2
0079         Rectangle{
0080 //            Layout.maximumWidth: 400
0081 
0082             color: Kirigami.Theme.backgroundColor
0083             Layout.fillHeight: true
0084             Layout.fillWidth: true
0085             Item {
0086                 height: wideScreen? width*1.3: width
0087                 width: parent.width
0088                 anchors.centerIn:parent
0089                 RadialGradient {
0090                     anchors.fill: parent
0091                     gradient: Gradient {
0092                         GradientStop { position: 0.0; color: Kirigami.ColorUtils.tintWithAlpha(
0093                                                                  Kirigami.Theme.backgroundColor,
0094                                                                  healthSlider.healthColor, 0.5)}
0095                         GradientStop { position: 0.5; color: Kirigami.Theme.backgroundColor }
0096                     }
0097                 }
0098             }
0099         }
0100         Rectangle{
0101             color: Kirigami.Theme.backgroundColor
0102             Layout.fillHeight: true
0103             Layout.fillWidth: true
0104         }
0105     }
0106     GridLayout {
0107         flow: wideScreen ? GridLayout.LeftToRight : GridLayout.TopToBottom
0108 
0109         anchors.fill: parent
0110         columns: 2
0111 
0112         ColumnLayout {
0113             Layout.maximumWidth: wideScreen ? 400: applicationWindow().width
0114             Layout.fillHeight: true
0115             Layout.fillWidth: true
0116             Item {
0117                 Layout.fillHeight: true
0118             }
0119 
0120             Item {
0121                 height: 300
0122                 Layout.fillWidth: true
0123                 Image {
0124                     anchors.fill: parent
0125                     id: image
0126                     fillMode: Image.PreserveAspectFit
0127                     source: plant.imgUrl
0128                     layer {
0129                         enabled: true
0130                         effect: OpacityMask {
0131                             maskSource: mask
0132                         }
0133                     }
0134                 }
0135                 Rectangle {
0136                     id: mask
0137                     anchors.fill: parent
0138                     visible: false
0139                     gradient: Gradient {
0140                         GradientStop {
0141                             position: 0.5
0142                             color: "white"
0143                         }
0144                         GradientStop {
0145                             position: 1
0146                             color: "transparent"
0147                         }
0148                     }
0149                 }
0150             }
0151             Kirigami.Heading {
0152                 text: plant.name
0153                 type: Kirigami.Heading.Type.Primary
0154                 Layout.alignment: Qt.AlignHCenter
0155             }
0156             Controls.Label {
0157                 text: plant.species
0158                 color: Kirigami.Theme.disabledTextColor
0159                 Layout.alignment: Qt.AlignHCenter
0160             }
0161             Item {
0162                 Layout.fillHeight: true
0163             }
0164         }
0165 
0166         ColumnLayout {
0167             spacing: 0
0168 
0169             Layout.fillHeight: true
0170             Layout.fillWidth: true
0171 
0172             Layout.maximumWidth: wideScreen ? 400: applicationWindow().width
0173 
0174             RowLayout {
0175                 spacing: Kirigami.Units.largeSpacing
0176 
0177                 Layout.topMargin: Kirigami.Units.gridUnit
0178                 Layout.alignment: Qt.AlignHCenter
0179                 Layout.maximumWidth: Kirigami.Units.gridUnit * 30
0180                 TextIconBox {
0181                     label.text: plant.location
0182                     icon.source: "mark-location"
0183                     Layout.fillWidth: true
0184                 }
0185                 TextIconBox {
0186                     label.text: Qt.formatDate(plant.dateOfBirth)
0187                     icon.source: "chronometer"
0188                     Layout.fillWidth: true
0189                 }
0190                 TextIconBox {
0191                     label.text: i18n("Parent")
0192                     icon.source: "view-list-tree"
0193                     Layout.fillWidth: true
0194                 }
0195             }
0196 
0197             FormCard.FormHeader {
0198                 title: i18n("Water")
0199             }
0200 
0201             FormCard.FormCard {
0202                 FormCard.AbstractFormDelegate {
0203                     id: name
0204                     background: null
0205                     contentItem: RowLayout {
0206                         Kirigami.Icon {
0207                             id: icon
0208                             source: "raindrop"
0209                             color: "#64ace1"
0210                             isMask: true
0211                             implicitHeight: Kirigami.Units.gridUnit * 1.5
0212                         }
0213                         Controls.Label {
0214                             Layout.fillWidth: true
0215                             text: if (plant.wantsToBeWateredIn > 1) {
0216                                       i18n("has to be watered in %1 days", plant.wantsToBeWateredIn)
0217                                   } else if (plant.wantsToBeWateredIn == 1) {
0218                                       i18n("has to be watered tomorrow")
0219                                   } else if (plant.wantsToBeWateredIn == 0) {
0220                                       i18n("needs to be watered today!")
0221                                   } else if (plant.wantsToBeWateredIn < 0) {
0222                                       i18n("should have been watered already!")
0223                                   }
0224                         }
0225                         Controls.Button {
0226                             text: i18n("Watered")
0227                             icon.name: "answer-correct"
0228                             onClicked: waterEvents.waterPlant()
0229                         }
0230                     }
0231                 }
0232 
0233 //              FormCard.FormDelegateSeparator {}
0234 
0235 //              Repeater {
0236 //                  model: waterEvents
0237 //                  delegate: FormCard.AbstractFormDelegate {
0238 //                      required property date modelData
0239 //                      background: null
0240 //                      contentItem: ColumnLayout {
0241 //                          Controls.Label {
0242 //                              text: modelData
0243 //                          }
0244 //                      }
0245 //                  }
0246 //              }
0247             }
0248 
0249             FormCard.FormHeader {
0250                 title: i18n("Health")
0251             }
0252 
0253             FormCard.FormCard {
0254                 FormCard.AbstractFormDelegate {
0255                     id: health
0256 
0257                     background: null
0258                     text: i18n("How healthy is your plant today?")
0259 
0260                     contentItem: ColumnLayout {
0261                         Controls.Label {
0262                             text: health.text
0263                         }
0264                         RowLayout {
0265                             HealthSlider {
0266                                 id: healthSlider
0267                                 Layout.fillWidth: true
0268                                 Layout.alignment: Qt.AlignHCenter
0269                                 Layout.maximumWidth: 200
0270                                 value: plant.currentHealth
0271                                 from: 0
0272                                 to: 100
0273                             }
0274 
0275                             Item {
0276                                 Layout.fillWidth: true
0277                             }
0278 
0279                             Controls.Button {
0280                                 text: i18n("Add")
0281                                 icon.name: "list-add"
0282                                 onClicked: healthEvents.addHealthEvent(healthSlider.value)
0283                             }
0284                         }
0285                     }
0286                 }
0287 
0288                 FormCard.FormDelegateSeparator {}
0289 
0290                 FormCard.AbstractFormDelegate {
0291                     id: healthHistory
0292 
0293                     text: i18n("Health History")
0294 
0295                     background: null
0296                     contentItem: ColumnLayout {
0297                         Controls.Label {
0298                             text: healthHistory.text
0299                         }
0300 
0301                         Charts.LineChart {
0302                             height: 60
0303                             Layout.topMargin: 10
0304                             Layout.bottomMargin: 10
0305                             clip: false
0306                             Layout.fillWidth: true
0307                             colorSource: Charts.SingleValueSource {
0308                                 value: "#b4e479"
0309                             }
0310                             nameSource: Charts.SingleValueSource {
0311                                 value: health
0312                             }
0313                             fillOpacity: 0.3
0314 
0315                             smooth: true
0316 
0317                             valueSources: Charts.ModelSource {
0318                                 model: healthEvents
0319                                 roleName: "health"
0320                             }
0321                         }
0322                     }
0323                 }
0324             }
0325 //            Timer{
0326 //                id: healthTimer
0327 //                repeat: false
0328 //                interval: 1000
0329 //                running: false
0330 //                triggeredOnStart: false
0331 //                onTriggered: {
0332 //                    healthEvents.addHealthEvent(healthSlider.value)
0333 //                }
0334 //            }
0335             Item {
0336                 Layout.fillHeight: true
0337             }
0338         }
0339     }
0340 }