Warning, /utilities/powerplant/src/contents/ui/PlantEditorPage.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-License-Identifier: GPL-2.0-or-later 0002 // SPDX-FileCopyrightText: 2023 Mathis <mbb@kaidan.im> 0003 0004 import QtQuick 2.15 0005 import QtQuick.Controls 2.15 as Controls 0006 import QtQuick.Layouts 1.15 0007 import org.kde.kirigami 2.19 as Kirigami 0008 import org.kde.kirigamiaddons.formcard 1.0 as FormCard 0009 import QtGraphicalEffects 1.0 0010 import Qt.labs.platform 1.1 0011 import org.kde.kirigamiaddons.dateandtime 0.1 as KirigamiDateTime 0012 0013 import "components" 0014 0015 import org.kde.powerplant 1.0 0016 0017 FormCard.FormCardPage { 0018 id: root 0019 0020 required property PlantsModel plantsModel 0021 property int waterInterval: 2 0022 required property int mode 0023 property int plantId: -1 0024 0025 readonly property PlantEditor plantEditor: PlantEditor { 0026 plantId: root.plantId 0027 mode: root.mode 0028 plantsModel: root.plantsModel 0029 } 0030 0031 title: mode === PlantEditor.Creator ? i18n("Add Plant") : i18n("Edit %1", plantEditor.plant.name) 0032 0033 FormCard.FormCard { 0034 FormCard.AbstractFormDelegate { 0035 background: null 0036 contentItem: ColumnLayout { 0037 clip: true 0038 Controls.Label { 0039 text: i18n("Image:") 0040 } 0041 0042 ListView { 0043 id: imageView 0044 0045 Layout.preferredHeight: Kirigami.Units.gridUnit * 10 0046 Layout.fillWidth: true 0047 onCurrentIndexChanged: if (currentIndex >= 0) { 0048 plantEditor.plant.imgUrl = currentItem.url 0049 } 0050 currentIndex: -1 0051 0052 Connections { 0053 target: plantEditor.plant 0054 function onImgUrlChanged() { 0055 plantImageModel.customImage = plantEditor.plant.imgUrl; 0056 imageView.currentIndex = plantImageModel.urlToIndex(plantEditor.plant.imgUrl); 0057 } 0058 } 0059 0060 orientation: ListView.Horizontal 0061 0062 header: Item { 0063 width: 120 0064 height: ListView.view.height 0065 0066 ActionButton { 0067 anchors.centerIn: parent 0068 icon.name: "list-add" 0069 text: i18n("Use custom image") 0070 onClicked: fileDialog.open() 0071 } 0072 0073 FileDialog { 0074 id: fileDialog 0075 title: i18n("Please choose a file") 0076 folder: StandardPaths.writableLocation(StandardPaths.PicturesLocation) 0077 onAccepted: { 0078 plantImageModel.customImage = file; 0079 0080 // Hack force refresh 0081 imageView.currentIndex = -1; 0082 imageView.currentIndex = 0; 0083 } 0084 0085 nameFilters: [i18nc("Name filter for image files", "Image files (*.png *.jpg* *.webp)")] 0086 } 0087 } 0088 0089 model: PlantImageModel { 0090 id: plantImageModel 0091 } 0092 0093 delegate: Controls.ItemDelegate { 0094 id: imageDelegate 0095 0096 required property string index 0097 required property string url 0098 0099 y: 2 0100 0101 height: ListView.view.height 0102 width: ListView.view.height 0103 0104 onClicked: imageView.currentIndex = index 0105 0106 background: RadialGradient { 0107 visible: imageDelegate.ListView.isCurrentItem 0108 0109 gradient: Gradient { 0110 GradientStop { 0111 position: 0.0 0112 color: Kirigami.ColorUtils.tintWithAlpha( 0113 Kirigami.Theme.backgroundColor, 0114 healthSlider.healthColor, 0115 0.5 0116 ) 0117 } 0118 GradientStop { 0119 position: 0.5 0120 color: Kirigami.Theme.backgroundColor 0121 } 0122 } 0123 } 0124 0125 Image { 0126 id: image 0127 anchors.fill: parent 0128 fillMode: Image.PreserveAspectFit 0129 source: parent.url 0130 layer { 0131 enabled: true 0132 effect: OpacityMask { 0133 maskSource: mask 0134 } 0135 } 0136 } 0137 Rectangle { 0138 id: mask 0139 anchors.fill: parent 0140 visible: false 0141 gradient: Gradient { 0142 GradientStop { 0143 position: 0.5 0144 color: "white" 0145 } 0146 GradientStop { 0147 position: 0.75 0148 color: "transparent" 0149 } 0150 } 0151 } 0152 } 0153 } 0154 } 0155 } 0156 0157 FormCard.FormDelegateSeparator {} 0158 0159 FormCard.FormTextFieldDelegate { 0160 label: i18n("Name") 0161 text: plantEditor.plant.name 0162 onTextChanged: plantEditor.plant.name = text 0163 } 0164 0165 FormCard.FormDelegateSeparator {} 0166 0167 FormCard.FormTextFieldDelegate { 0168 label: i18n("Species") 0169 text: plantEditor.plant.species 0170 onTextChanged: plantEditor.plant.species = text 0171 } 0172 0173 FormCard.FormDelegateSeparator {} 0174 0175 FormCard.FormTextFieldDelegate { 0176 label: i18n("Room") 0177 text: plantEditor.plant.location 0178 onTextChanged: plantEditor.plant.location = text 0179 } 0180 0181 FormCard.FormDelegateSeparator {} 0182 0183 FormCard.AbstractFormDelegate { 0184 id: interval 0185 background: null 0186 contentItem: ColumnLayout { 0187 Controls.Label { 0188 text: i18n("How often does the plant need Watering?") 0189 } 0190 Controls.ButtonGroup { 0191 id: buttonGroup 0192 } 0193 0194 RowLayout { 0195 id: row 0196 0197 Layout.fillHeight: true 0198 Layout.fillWidth: true 0199 spacing: Kirigami.Units.smallSpacing 0200 0201 Controls.Button { 0202 text: i18n("2 days") 0203 checkable: true 0204 Controls.ButtonGroup.group: buttonGroup 0205 Layout.fillWidth: true 0206 onClicked: plantEditor.plant.waterIntervall = 2 0207 } 0208 0209 Controls.Button { 0210 text: i18n("5 days") 0211 checkable: true 0212 Controls.ButtonGroup.group: buttonGroup 0213 Layout.fillWidth: true 0214 onClicked: plantEditor.plant.waterIntervall = 5 0215 } 0216 0217 Controls.Button { 0218 text: i18n("weekly") 0219 checkable: true 0220 Controls.ButtonGroup.group: buttonGroup 0221 Layout.fillWidth: true 0222 onClicked: plantEditor.plant.waterIntervall = 7 0223 } 0224 0225 Controls.Button { 0226 id: buttonWeeks 0227 text: i18n("2 weeks") 0228 checkable: true 0229 Controls.ButtonGroup.group: buttonGroup 0230 Layout.fillWidth: true 0231 onClicked: plantEditor.plant.waterIntervall = 14 0232 } 0233 } 0234 0235 RowLayout { 0236 Layout.fillWidth: true 0237 Layout.fillHeight: true 0238 0239 Controls.Label { 0240 text: i18n("Custom:") 0241 } 0242 0243 Controls.SpinBox { 0244 onValueChanged: plantEditor.plant.waterIntervall = value 0245 value: plantEditor.plant.waterIntervall 0246 Layout.fillWidth: true 0247 } 0248 } 0249 } 0250 } 0251 0252 FormCard.FormDelegateSeparator { 0253 visible: root.mode === PlantEditor.Creator 0254 } 0255 0256 FormCard.AbstractFormDelegate { 0257 id: health 0258 visible: root.mode === PlantEditor.Creator 0259 background: null 0260 contentItem: ColumnLayout { 0261 Controls.Label { 0262 text: i18n("How healthy is your plant at the moment?") 0263 } 0264 0265 HealthSlider { 0266 id: healthSlider 0267 Layout.fillWidth: true 0268 Layout.alignment: Qt.AlignHCenter 0269 Layout.maximumWidth: 200 0270 from: 0 0271 to: 100 0272 onValueChanged: plantEditor.plant.currentHealth = value 0273 } 0274 } 0275 } 0276 0277 FormCard.FormDelegateSeparator {} 0278 0279 FormCard.AbstractFormDelegate{ 0280 background: null 0281 contentItem: ColumnLayout{ 0282 Controls.Label { 0283 text: i18n("Birthday") 0284 Layout.fillWidth: true 0285 } 0286 0287 KirigamiDateTime.DateInput { 0288 id: birthday 0289 // selectedDate: plantEditor.plant.dateOfBirth 0290 onSelectedDateChanged: { 0291 console.log(selectedDate) 0292 plantEditor.plant.dateOfBirth = selectedDate 0293 } 0294 } 0295 } 0296 } 0297 } 0298 0299 footer: Controls.ToolBar { 0300 contentItem: RowLayout { 0301 Item { 0302 Layout.fillWidth: true 0303 } 0304 0305 Controls.Button { 0306 text: plantEditor.mode === PlantEditor.Editor ? i18n("Edit") : i18n("Add") 0307 icon.name: plantEditor.mode === PlantEditor.Editor ? "document-edit" : "list-add" 0308 onClicked: { 0309 plantEditor.save(); 0310 root.closeDialog() 0311 } 0312 } 0313 } 0314 } 0315 }