Warning, /libraries/kirigami-addons/tests/FormTestApp.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * Copyright 2022 Devin Lin <devin@kde.org>
0003  * SPDX-License-Identifier: LGPL-2.0-or-later
0004  */
0005 
0006 import QtQuick 2.15
0007 import QtQuick.Controls 2.15 as Controls
0008 import QtQuick.Layouts 1.2
0009 import QtQuick.Layouts 1.15
0010 
0011 import org.kde.kirigami 2.20 as Kirigami
0012 import org.kde.kirigamiaddons.labs.mobileform 0.1 as MobileForm
0013 import org.kde.kirigamiaddons.labs.components 1.0 as Components
0014 
0015 Kirigami.ApplicationWindow {
0016     id: appwindow
0017 
0018     title: "Mobile Form Test"
0019 
0020     width: Kirigami.Settings.isMobile ? 400 : 800
0021     height: Kirigami.Settings.isMobile ? 550 : 500
0022 
0023     pageStack.defaultColumnWidth: Kirigami.Units.gridUnit * 35
0024     pageStack.globalToolBar.style: Kirigami.ApplicationHeaderStyle.ToolBar;
0025     pageStack.globalToolBar.showNavigationButtons: Kirigami.ApplicationHeaderStyle.ShowBackButton;
0026 
0027     pageStack.initialPage: pageComponent
0028     // Dummy implementation of ki18n
0029     function i18nd(context, text) {
0030         return text;
0031     }
0032 
0033     function i18ndp(context, text1, text2, number) {
0034         return number === 1 ? text1 : text2;
0035     }
0036 
0037     function i18nc(context, text) {
0038         return text;
0039     }
0040     
0041     LayoutMirroring.enabled: false
0042 
0043 
0044     Component {
0045         id: aboutComponent
0046         MobileForm.AboutPage {
0047             aboutData: {
0048                 "displayName": "KirigamiApp",
0049                "productName" : "kirigami/app",
0050                "componentName" : "kirigamiapp",
0051                "shortDescription" : "A Kirigami example",
0052                "homepage" : "",
0053                "bugAddress" : "submit@bugs.kde.org",
0054                "version" : "5.14.80",
0055                "otherText" : "",
0056                "authors" : [
0057                    {
0058                        "name" : "Paul Müller",
0059                        "task" : "Concept and development",
0060                        "emailAddress" : "somebody@kde.org",
0061                        "webAddress" : "",
0062                        "ocsUsername" : ""
0063                    }
0064                ],
0065                "credits" : [],
0066                "translators" : [],
0067                "licenses" : [
0068                    {
0069                        "name" : "GPL v2",
0070                        "text" : "long, boring, license text",
0071                        "spdx" : "GPL-2.0"
0072                    }
0073                ],
0074                "copyrightStatement" : "© 2010-2018 Plasma Development Team",
0075                "desktopFileName" : "org.kde.kirigamiapp"
0076            }
0077         }
0078     }
0079 
0080     Component {
0081         id: pageComponent
0082         Kirigami.ScrollablePage {
0083             id: page
0084             title: "Mobile Form Layout"
0085 
0086             Kirigami.Theme.colorSet: Kirigami.Theme.Window
0087             Kirigami.Theme.inherit: false
0088 
0089             topPadding: Kirigami.Units.gridUnit
0090             leftPadding: 0
0091             rightPadding: 0
0092             bottomPadding: Kirigami.Units.gridUnit
0093 
0094             header: Components.Banner {
0095                 title: "My title"
0096                 text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Inde sermone vario sex illa a Dipylo stadia confecimus. In eo enim positum est id, quod dicimus esse expetendum.\n\n\
0097 Duo Reges: constructio interrete. Primum Theophrasti, Strato, physicum se voluit; Aliter enim explicari, quod quaeritur, non potest. Quamquam id quidem, infinitum est in hac urbe;"
0098                 type: Kirigami.MessageType.Warning
0099                 width: page.width
0100                 visible: true
0101 
0102                 showCloseButton: true
0103 
0104                 actions: Kirigami.Action {
0105                     text: "Do something"
0106                 }
0107             }
0108 
0109             ColumnLayout {
0110                 spacing: 0
0111 
0112                 // Form Grid
0113                 MobileForm.FormGridContainer {
0114                     id: container
0115 
0116                     Layout.fillWidth: true
0117 
0118                     infoCards: [
0119                         MobileForm.FormGridContainer.InfoCard {
0120                             title: "42"
0121                             subtitle: "Posts"
0122                         },
0123                         MobileForm.FormGridContainer.InfoCard {
0124                             title: "42"
0125                             subtitle: "Followers"
0126                         },
0127                         MobileForm.FormGridContainer.InfoCard {
0128                             title: "42"
0129                             subtitle: "Follows"
0130                             action: Kirigami.Action {
0131                                 onTriggered: applicationWindow().showPassiveNotification("42 Follows")
0132                             }
0133                         }
0134                     ]
0135                 }
0136 
0137                 MobileForm.FormHeader {
0138                     Layout.fillWidth: true
0139                     title: "About"
0140                 }
0141                 MobileForm.FormCard {
0142                     Layout.fillWidth: true
0143                     Layout.topMargin: Kirigami.Units.largeSpacing
0144 
0145                     contentItem: ColumnLayout {
0146                         spacing: 0
0147 
0148                         MobileForm.FormButtonDelegate {
0149                             id: aboutDelegate
0150                             text: "About"
0151                             onClicked: applicationWindow().pageStack.push(aboutComponent)
0152                         }
0153                     }
0154                 }
0155                 
0156                 MobileForm.FormHeader {
0157                     Layout.fillWidth: true
0158                     title: "Buttons"
0159                 }
0160                 MobileForm.FormCard {
0161                     Layout.fillWidth: true
0162 
0163                     contentItem: ColumnLayout {
0164                         spacing: 0
0165 
0166                         MobileForm.FormButtonDelegate {
0167                             id: delegate1
0168                             text: "Button"
0169                             description: "Click me!"
0170                             onClicked: applicationWindow().pageStack.push(pageComponent)
0171                         }
0172 
0173                         MobileForm.FormDelegateSeparator { above: delegate1; below: delegate2 }
0174 
0175                         MobileForm.FormButtonDelegate {
0176                             id: delegate2
0177                             text: "Button 2"
0178                         }
0179 
0180                         MobileForm.FormDelegateSeparator { above: delegate2; below: delegate3 }
0181 
0182                         MobileForm.FormButtonDelegate {
0183                             id: delegate3
0184                             text: "Notification Settings"
0185                             icon.name: "notifications"
0186                         }
0187                     }
0188                 }
0189 
0190                 MobileForm.FormSectionText {
0191                     text: "The form components support keyboard navigation with Tab and Shift+Tab."
0192                 }
0193 
0194                 // checkboxes
0195                 MobileForm.FormHeader {
0196                     Layout.fillWidth: true
0197                     title: "Checkboxes"
0198                 }
0199                 MobileForm.FormCard {
0200                     Layout.fillWidth: true
0201 
0202                     contentItem: ColumnLayout {
0203                         spacing: 0
0204 
0205                         MobileForm.FormCheckDelegate {
0206                             id: checkbox1
0207                             text: "Check the first box"
0208                         }
0209 
0210                         MobileForm.FormCheckDelegate {
0211                             id: checkbox2
0212                             text: "Check the second box"
0213                         }
0214 
0215                         MobileForm.FormCheckDelegate {
0216                             id: checkbox3
0217                             text: "Check the third box"
0218                         }
0219                     }
0220                 }
0221                 
0222                 MobileForm.FormSectionText {
0223                     text: "Use cards to denote relevant groups of settings."
0224                 }
0225 
0226                 // switches
0227                 MobileForm.FormHeader {
0228                     Layout.fillWidth: true
0229                     title: "Switches"
0230                 }
0231                 MobileForm.FormCard {
0232                     Layout.fillWidth: true
0233 
0234                     contentItem: ColumnLayout {
0235                         spacing: 0
0236 
0237                         MobileForm.FormSwitchDelegate {
0238                             id: switch1
0239                             text: "Toggle the first switch"
0240                         }
0241 
0242                         MobileForm.FormDelegateSeparator { above: switch1; below: switch2 }
0243 
0244                         MobileForm.FormSwitchDelegate {
0245                             id: switch2
0246                             text: "Toggle the second switch"
0247                         }
0248 
0249                         MobileForm.FormDelegateSeparator { above: switch2; below: switch3 }
0250 
0251                         MobileForm.FormSwitchDelegate {
0252                             id: switch3
0253                             text: "Toggle the third switch"
0254                             description: "This is a description for the switch."
0255                         }
0256                         
0257                         MobileForm.FormDelegateSeparator { above: switch3; below: layoutMirroring }
0258 
0259                         MobileForm.FormSwitchDelegate {
0260                             id: layoutMirroring
0261                             text: "Layout mirroring"
0262                             description: "Toggle layout mirroring to test flipped layouts."
0263                             onCheckedChanged: {
0264                                 applicationWindow().LayoutMirroring.enabled = checked;
0265                             }
0266                         }
0267                     }
0268                 }
0269 
0270                 // dropdowns
0271                 // large amount of options -> push a new page
0272                 // small amount of options -> open dialog
0273                 MobileForm.FormHeader {
0274                     Layout.fillWidth: true
0275                     title: "Dropdowns"
0276                 }
0277                 MobileForm.FormCard {
0278                     Layout.fillWidth: true
0279 
0280                     contentItem: ColumnLayout {
0281                         spacing: 0
0282 
0283                         MobileForm.FormComboBoxDelegate {
0284                             id: dropdown1
0285                             text: "Select a color"
0286                             Component.onCompleted: currentIndex = indexOfValue("Breeze Blue")
0287                             model: ["Breeze Blue", "Konqi Green", "Velvet Red", "Bright Yellow"]
0288                         }
0289 
0290                         MobileForm.FormDelegateSeparator { above: dropdown1; below: dropdown2 }
0291 
0292                         MobileForm.FormComboBoxDelegate {
0293                             id: dropdown2
0294                             text: "Select a shape"
0295                             Component.onCompleted: currentIndex = indexOfValue("Pentagon")
0296                             model: ["Circle", "Square", "Pentagon", "Triangle"]
0297                         }
0298 
0299                         MobileForm.FormDelegateSeparator { above: dropdown2; below: dropdown3 }
0300 
0301                         MobileForm.FormComboBoxDelegate {
0302                             id: dropdown3
0303                             text: "Select a time format"
0304                             description: "This will be used system-wide."
0305                             Component.onCompleted: currentIndex = indexOfValue("Use System Default")
0306                             model: ["Use System Default", "24 Hour Time", "12 Hour Time"]
0307                         }
0308 
0309                         MobileForm.FormDelegateSeparator { above: dropdown3; below: dropdown4 }
0310 
0311                         MobileForm.FormComboBoxDelegate {
0312                             id: dropdown4
0313                             text: "Select a color (page)"
0314                             displayMode: MobileForm.FormComboBoxDelegate.DisplayMode.Page
0315                             Component.onCompleted: currentIndex = indexOfValue("Breeze Blue")
0316                             model: ["Breeze Blue", "Konqi Green", "Velvet Red", "Bright Yellow"]
0317                         }
0318                     }
0319                 }
0320 
0321                 // radio buttons
0322                 MobileForm.FormHeader {
0323                     Layout.fillWidth: true
0324                     title: "Radio buttons"
0325                 }
0326                 MobileForm.FormCard {
0327                     Layout.fillWidth: true
0328 
0329                     contentItem: ColumnLayout {
0330                         spacing: 0
0331 
0332                         MobileForm.FormRadioDelegate {
0333                             id: radio1
0334                             text: "Always on"
0335                         }
0336 
0337                         MobileForm.FormRadioDelegate {
0338                             id: radio2
0339                             text: "On during the day"
0340                         }
0341 
0342                         MobileForm.FormRadioDelegate {
0343                             id: radio3
0344                             text: "Always off"
0345                         }
0346                     }
0347                 }
0348 
0349                 // misc
0350                 MobileForm.FormCard {
0351                     Layout.fillWidth: true
0352                     Layout.topMargin: Kirigami.Units.largeSpacing
0353 
0354                     contentItem: ColumnLayout {
0355                         spacing: 0
0356 
0357                         MobileForm.AbstractFormDelegate {
0358                             id: slider1
0359                             Layout.fillWidth: true
0360 
0361                             background: Item {}
0362 
0363                             contentItem: RowLayout {
0364                                 spacing: Kirigami.Units.gridUnit
0365                                 Kirigami.Icon {
0366                                     implicitWidth: Kirigami.Units.iconSizes.smallMedium
0367                                     implicitHeight: Kirigami.Units.iconSizes.smallMedium
0368                                     source: "brightness-low"
0369                                 }
0370 
0371                                 Controls.Slider {
0372                                     Layout.fillWidth: true
0373                                 }
0374 
0375                                 Kirigami.Icon {
0376                                     implicitWidth: Kirigami.Units.iconSizes.smallMedium
0377                                     implicitHeight: Kirigami.Units.iconSizes.smallMedium
0378                                     source: "brightness-high"
0379                                 }
0380                             }
0381                         }
0382 
0383                         MobileForm.FormDelegateSeparator { below: textinput1 }
0384 
0385                         MobileForm.AbstractFormDelegate {
0386                             id: textinput1
0387                             Layout.fillWidth: true
0388                             contentItem: RowLayout {
0389                                 Controls.Label {
0390                                     Layout.fillWidth: true
0391                                     text: "Enter text"
0392                                 }
0393 
0394                                 Controls.TextField {
0395                                     Layout.preferredWidth: Kirigami.Units.gridUnit * 8
0396                                     placeholderText: "Insert text…"
0397                                 }
0398                             }
0399                         }
0400 
0401                         MobileForm.FormDelegateSeparator { above: textinput1; below: action1 }
0402 
0403                         MobileForm.AbstractFormDelegate {
0404                             id: action1
0405                             Layout.fillWidth: true
0406                             contentItem: RowLayout {
0407                                 Controls.Label {
0408                                     Layout.fillWidth: true
0409                                     text: "Do an action"
0410                                 }
0411 
0412                                 Controls.Button {
0413                                     text: "Do Action"
0414                                     icon.name: "edit-clear-all"
0415                                 }
0416                             }
0417                         }
0418                     }
0419                 }
0420 
0421                 // info block
0422                 MobileForm.FormHeader {
0423                     Layout.fillWidth: true
0424                     title: "Information"
0425                 }
0426                 MobileForm.FormCard {
0427                     Layout.fillWidth: true
0428 
0429                     contentItem: ColumnLayout {
0430                         spacing: 0
0431 
0432                         MobileForm.FormTextDelegate {
0433                             id: info1
0434                             text: "Color"
0435                             description: "Blue"
0436                         }
0437 
0438                         MobileForm.FormDelegateSeparator {}
0439 
0440                         MobileForm.FormTextDelegate {
0441                             id: info2
0442                             text: "Best Desktop Environment"
0443                             description: "KDE Plasma (Mobile)"
0444                         }
0445 
0446                         MobileForm.FormDelegateSeparator {}
0447 
0448                         MobileForm.FormTextDelegate {
0449                             id: info3
0450                             text: "Best Dragon"
0451                             description: "Konqi"
0452                             trailing: Controls.Button {
0453                                 text: "Agree"
0454                                 icon.name: "dialog-ok"
0455                             }
0456                         }
0457                     }
0458                 }
0459 
0460                 MobileForm.FormSectionText {
0461                     text: "Use the text form delegates to display information."
0462                 }
0463                 
0464                 // text fields
0465                 MobileForm.FormHeader {
0466                     Layout.fillWidth: true
0467                     title: "Text Fields"
0468                 }
0469                 MobileForm.FormCard {
0470                     Layout.fillWidth: true
0471 
0472                     contentItem: ColumnLayout {
0473                         spacing: 0
0474                         
0475                         MobileForm.FormTextFieldDelegate {
0476                             id: account
0477                             label: "Account name"
0478                         }
0479 
0480                         MobileForm.FormTextFieldDelegate {
0481                             id: password1
0482                             label: "Password"
0483                             statusMessage: "Password incorrect"
0484                             status: Kirigami.MessageType.Error
0485                             echoMode: TextInput.Password
0486                             text: "666666666"
0487                         }
0488 
0489                         // don't put above and below, since we don't care about hover events
0490                         MobileForm.FormDelegateSeparator {}
0491 
0492                         MobileForm.FormTextFieldDelegate {
0493                             id: password2
0494                             label: "Password"
0495                             statusMessage: "Password match"
0496                             text: "4242424242"
0497                             status: Kirigami.MessageType.Positive
0498                             echoMode: TextInput.Password
0499                         }
0500                     }
0501                 }
0502 
0503                 // spin boxes fields
0504                 MobileForm.FormHeader {
0505                     Layout.fillWidth: true
0506                     title: "Spin boxes"
0507                 }
0508                 MobileForm.FormCard {
0509                     Layout.fillWidth: true
0510 
0511                     contentItem: ColumnLayout {
0512                         MobileForm.FormSpinBoxDelegate {
0513                             label: "Amount"
0514                             value: 42
0515                         }
0516 
0517                         MobileForm.FormDelegateSeparator {}
0518 
0519                         MobileForm.FormSpinBoxDelegate {
0520                             label: "Amount 2"
0521                             value: 84
0522                             statusMessage: "This is too high"
0523                             status: Kirigami.MessageType.Error
0524                         }
0525                     }
0526                 }
0527             }
0528         }
0529     }
0530 }
0531