File: FormTestApp.qml

package info (click to toggle)
kirigami-addons 1.11.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,324 kB
  • sloc: ansic: 31,525; cpp: 3,607; xml: 82; java: 76; makefile: 4; sh: 1
file content (533 lines) | stat: -rw-r--r-- 17,469 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
/*
 * Copyright 2022 Devin Lin <devin@kde.org>
 * SPDX-License-Identifier: LGPL-2.0-or-later
 */

import QtCore
import QtQuick
import QtQuick.Controls as Controls
import QtQuick.Layouts
import QtQuick.Layouts
import QtQuick.Dialogs

import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.formcard as FormCard
import org.kde.kirigamiaddons.components as Components

Kirigami.ApplicationWindow {
    id: appwindow

    title: "Form Card Example"

    width: Kirigami.Settings.isMobile ? 400 : 800
    height: Kirigami.Settings.isMobile ? 550 : 500

    pageStack.defaultColumnWidth: Kirigami.Units.gridUnit * 35
    pageStack.globalToolBar.style: Kirigami.ApplicationHeaderStyle.ToolBar;
    pageStack.globalToolBar.showNavigationButtons: Kirigami.ApplicationHeaderStyle.ShowBackButton;

    pageStack.initialPage: pageComponent
    // Dummy implementation of ki18n
    function i18nd(context, text) {
        return text;
    }

    function i18ndp(context, text1, text2, number) {
        return number === 1 ? text1 : text2;
    }

    function i18nc(context, text) {
        return text;
    }

    function i18ndc(context, strng, text) {
        return text;
    }

    LayoutMirroring.enabled: false

    FormCard.FormCardDialog {
        id: formDialog

        title: "Add Thingy"

        standardButtons: Controls.Dialog.Ok | Controls.Dialog.Cancel

        FormCard.FormTextFieldDelegate {
            label: i18nc("@label:textbox Notebook name", "Name:")
        }

        FormCard.FormDelegateSeparator {}

        FormCard.FormButtonDelegate {
            text: i18nc("@action:button", "Color")
            icon.name: "color-picker"
        }

        FormCard.FormDelegateSeparator {}

        FormCard.FormButtonDelegate {
            text: i18nc("@action:button", "Icon")
            icon.name: "preferences-desktop-emoticons"
        }
    }

    Component {
        id: aboutComponent
        FormCard.AboutPage {
            aboutData: {
                "displayName": "KirigamiApp",
               "productName" : "kirigami/app",
               "componentName" : "kirigamiapp",
               "shortDescription" : "A Kirigami example",
               "homepage" : "",
               "bugAddress" : "submit@bugs.kde.org",
               "version" : "5.14.80",
               "otherText" : "",
               "authors" : [
                   {
                       "name" : "Paul Müller",
                       "task" : "Concept and development",
                       "emailAddress" : "somebody@kde.org",
                       "webAddress" : "",
                       "ocsUsername" : ""
                   }
               ],
               "credits" : [],
               "translators" : [],
               "licenses" : [
                   {
                       "name" : "GPL v2",
                       "text" : "long, boring, license text",
                       "spdx" : "GPL-2.0"
                   }
               ],
               "copyrightStatement" : "© 2010-2018 Plasma Development Team",
               "desktopFileName" : "org.kde.kirigamiapp"
           }
        }
    }

    Component {
        id: pageComponent
        FormCard.FormCardPage {
            id: page
            title: "Mobile Form Layout"

            // Form Grid
            FormCard.FormGridContainer {
                id: container

                Layout.fillWidth: true
                Layout.topMargin: Kirigami.Units.gridUnit

                infoCards: [
                    FormCard.FormGridContainer.InfoCard {
                        title: "42"
                        subtitle: "Posts"
                    },
                    FormCard.FormGridContainer.InfoCard {
                        title: "42"
                        subtitle: "Followers"
                    },
                    FormCard.FormGridContainer.InfoCard {
                        title: "42"
                        subtitle: "Follows"
                        action: Kirigami.Action {
                            onTriggered: applicationWindow().showPassiveNotification("42 Follows")
                        }
                    }
                ]
            }

            FormCard.FormHeader {
                title: "About"
            }
            FormCard.FormCard {
                FormCard.FormButtonDelegate {
                    id: aboutDelegate
                    text: "About"
                    onClicked: applicationWindow().pageStack.push(aboutComponent)
                }
            }

            FormCard.FormHeader {
                title: "Date and time"
            }

            FormCard.FormCard {
                FormCard.FormDateTimeDelegate {}

                FormCard.FormDelegateSeparator {}

                FormCard.FormDateTimeDelegate {
                    text: "Arrival day:"
                    minimumDate: new Date()
                    dateTimeDisplay: FormCard.FormDateTimeDelegate.DateTimeDisplay.Date
                }

                FormCard.FormDelegateSeparator {}

                FormCard.FormDateTimeDelegate {
                    text: "Arrival time:"
                    dateTimeDisplay: FormCard.FormDateTimeDelegate.DateTimeDisplay.Time
                    status: Kirigami.MessageType.Warning
                    statusMessage: value.getHours() < 8 ? "Very early!" : ""
                }
            }

            FormCard.FormHeader {
                title: "Buttons"
            }
            FormCard.FormCard {
                Layout.fillWidth: true

                FormCard.FormButtonDelegate {
                    id: delegate1
                    text: "Button"
                    description: "Click me!"
                    onClicked: applicationWindow().pageStack.push(pageComponent)
                }

                FormCard.FormDelegateSeparator { above: delegate1; below: delegate2 }

                FormCard.FormButtonDelegate {
                    id: delegate2
                    text: "Form Dialog"
                    onClicked: formDialog.open()
                }

                FormCard.FormDelegateSeparator { above: delegate2; below: delegate3 }

                FormCard.FormButtonDelegate {
                    id: delegate3
                    text: "Notification Settings"
                    icon.name: "notifications"
                }
            }

            FormCard.FormSectionText {
                text: "The form components support keyboard navigation with Tab and Shift+Tab."
            }

            // checkboxes
            FormCard.FormHeader {
                title: "Checkboxes"
            }
            FormCard.FormCard {
                FormCard.FormCheckDelegate {
                    id: checkbox1
                    text: "Check the first box"
                }

                FormCard.FormCheckDelegate {
                    id: checkbox2
                    text: "Check the second box"
                }

                FormCard.FormCheckDelegate {
                    id: checkbox3
                    text: "Check the third box"
                }
            }
            
            FormCard.FormSectionText {
                text: "Use cards to denote relevant groups of settings."
            }

            // switches
            FormCard.FormHeader {
                title: "Switches"
            }
            FormCard.FormCard {
                FormCard.FormSwitchDelegate {
                    id: switch1
                    text: "Toggle the first switch"
                }

                FormCard.FormDelegateSeparator { above: switch1; below: switch2 }

                FormCard.FormSwitchDelegate {
                    id: switch2
                    text: "Toggle the second switch"
                }

                FormCard.FormDelegateSeparator { above: switch2; below: switch3 }

                FormCard.FormSwitchDelegate {
                    id: switch3
                    text: "Toggle the third switch"
                    description: "This is a description for the switch."
                }
                
                FormCard.FormDelegateSeparator { above: switch3; below: layoutMirroring }

                FormCard.FormSwitchDelegate {
                    id: layoutMirroring
                    text: "Layout mirroring"
                    description: "Toggle layout mirroring to test flipped layouts."
                    onCheckedChanged: {
                        applicationWindow().LayoutMirroring.enabled = checked;
                    }
                }
            }

            // dropdowns
            // large amount of options -> push a new page
            // small amount of options -> open dialog
            FormCard.FormHeader {
                title: "Dropdowns"
            }
            FormCard.FormCard {
                FormCard.FormComboBoxDelegate {
                    id: dropdown1
                    text: "Select a color"
                    Component.onCompleted: currentIndex = indexOfValue("Breeze Blue")
                    model: ["Breeze Blue", "Konqi Green", "Velvet Red", "Bright Yellow"]
                }

                FormCard.FormDelegateSeparator { above: dropdown1; below: dropdown2 }

                FormCard.FormComboBoxDelegate {
                    id: dropdown2
                    text: "Select a shape"
                    Component.onCompleted: currentIndex = indexOfValue("Pentagon")
                    model: ["Circle", "Square", "Pentagon", "Triangle"]
                }

                FormCard.FormDelegateSeparator { above: dropdown2; below: dropdown3 }

                FormCard.FormComboBoxDelegate {
                    id: dropdown3
                    text: "Select a time format"
                    description: "This will be used system-wide."
                    Component.onCompleted: currentIndex = indexOfValue("Use System Default")
                    model: ["Use System Default", "24 Hour Time", "12 Hour Time"]
                }

                FormCard.FormDelegateSeparator { above: dropdown3; below: dropdown4 }

                FormCard.FormComboBoxDelegate {
                    id: dropdown4
                    text: "Select a color (page)"
                    displayMode: FormCard.FormComboBoxDelegate.DisplayMode.Page
                    Component.onCompleted: currentIndex = indexOfValue("Breeze Blue")
                    model: ["Breeze Blue", "Konqi Green", "Velvet Red", "Bright Yellow"]
                }
            }

            // radio buttons
            FormCard.FormHeader {
                title: "Radio buttons"
            }
            FormCard.FormCard {
                FormCard.FormRadioDelegate {
                    id: radio1
                    text: "Always on"
                }

                FormCard.FormRadioDelegate {
                    id: radio2
                    text: "On during the day"
                }

                FormCard.FormRadioDelegate {
                    id: radio3
                    text: "Always off"
                }
            }

            // misc
            FormCard.FormCard {
                Layout.topMargin: Kirigami.Units.largeSpacing

                FormCard.AbstractFormDelegate {
                    id: slider1
                    Layout.fillWidth: true

                    background: Item {}

                    contentItem: RowLayout {
                        spacing: Kirigami.Units.gridUnit
                        Kirigami.Icon {
                            implicitWidth: Kirigami.Units.iconSizes.smallMedium
                            implicitHeight: Kirigami.Units.iconSizes.smallMedium
                            source: "brightness-low"
                        }

                        Controls.Slider {
                            Layout.fillWidth: true
                        }

                        Kirigami.Icon {
                            implicitWidth: Kirigami.Units.iconSizes.smallMedium
                            implicitHeight: Kirigami.Units.iconSizes.smallMedium
                            source: "brightness-high"
                        }
                    }
                }

                FormCard.FormDelegateSeparator { below: textinput1 }

                FormCard.AbstractFormDelegate {
                    id: textinput1
                    Layout.fillWidth: true
                    contentItem: RowLayout {
                        Controls.Label {
                            Layout.fillWidth: true
                            text: "Enter text"
                        }

                        Controls.TextField {
                            Layout.preferredWidth: Kirigami.Units.gridUnit * 8
                            placeholderText: "Insert text…"
                        }
                    }
                }

                FormCard.FormDelegateSeparator { above: textinput1; below: action1 }

                FormCard.AbstractFormDelegate {
                    id: action1
                    Layout.fillWidth: true
                    contentItem: RowLayout {
                        Controls.Label {
                            Layout.fillWidth: true
                            text: "Do an action"
                        }

                        Controls.Button {
                            text: "Do Action"
                            icon.name: "edit-clear-all"
                        }
                    }
                }
            }

            // info block
            FormCard.FormHeader {
                title: "Information"
            }
            FormCard.FormCard {
                FormCard.FormTextDelegate {
                    id: info1
                    text: "Color"
                    description: "Blue"
                }

                FormCard.FormDelegateSeparator {}

                FormCard.FormTextDelegate {
                    id: info2
                    text: "Best Desktop Environment"
                    description: "KDE Plasma (Mobile)"
                }

                FormCard.FormDelegateSeparator {}

                FormCard.FormTextDelegate {
                    id: info3
                    text: "Best Dragon"
                    description: "Konqi"
                    trailing: Controls.Button {
                        text: "Agree"
                        icon.name: "dialog-ok"
                    }
                }
            }

            FormCard.FormSectionText {
                text: "Use the text form delegates to display information."
            }

            // text fields
            FormCard.FormHeader {
                title: "Text Fields"
            }

            FormCard.FormCard {
                FormCard.FormTextFieldDelegate {
                    id: account
                    label: "Account name"
                }

                FormCard.FormDelegateSeparator {}

                FormCard.FormPasswordFieldDelegate {
                    id: password1
                    label: "Password"
                    statusMessage: "Password incorrect"
                    status: Kirigami.MessageType.Error
                    echoMode: TextInput.Password
                    text: "666666666"
                    showPasswordQuality: true
                }

                FormCard.FormDelegateSeparator {}

                FormCard.FormPasswordFieldDelegate {
                    id: password2
                    label: "Password"
                    statusMessage: "Password match"
                    text: "4242424242"
                    status: Kirigami.MessageType.Positive
                    echoMode: TextInput.Password
                }
            }

            // spin boxes fields
            FormCard.FormHeader {
                title: "Spin boxes"
            }
            FormCard.FormCard {
                FormCard.FormSpinBoxDelegate {
                    label: "Amount"
                    value: 42
                }

                FormCard.FormDelegateSeparator {}

                FormCard.FormSpinBoxDelegate {
                    label: "Amount 2"
                    value: 84
                    statusMessage: "This is too high"
                    status: Kirigami.MessageType.Error
                }
            }

            // file fields
            FormCard.FormHeader {
                title: "File boxes"
            }
            FormCard.FormCard {
                FormCard.FormFileDelegate {
                    id: openFile

                    label: "Choose file"
                    currentFolder: StandardPaths.standardLocations(StandardPaths.DocumentsLocation)[0]
                    fileMode: FileDialog.OpenFile
                }

                FormCard.FormDelegateSeparator { above: saveFile; below: openFile }

                FormCard.FormFileDelegate {
                    id: saveFile

                    label: "Save file"
                    currentFolder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
                    fileMode: FileDialog.SaveFile
                }

                FormCard.FormDelegateSeparator { above: openFolder; below: saveFile }

                FormCard.FormFolderDelegate {
                    id: openFolder

                    label: "Choose folder"
                    currentFolder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
                }
            }
        }
    }
}