Warning, /utilities/klimbgrades/src/Main.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *   Copyright 2016 Marco Martin <mart@kde.org>
0003  *
0004  *   This program is free software; you can redistribute it and/or modify
0005  *   it under the terms of the GNU Library General Public License as
0006  *   published by the Free Software Foundation; either version 2 or
0007  *   (at your option) any later version.
0008  *
0009  *   This program is distributed in the hope that it will be useful,
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *   GNU Library General Public License for more details
0013  *
0014  *   You should have received a copy of the GNU Library General Public
0015  *   License along with this program; if not, write to the
0016  *   Free Software Foundation, Inc.,
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018  */
0019 
0020 import QtQuick 2.1
0021 import QtQuick.Layouts 1.2
0022 import QtQuick.Controls 2.0 as Controls
0023 import org.kde.kirigami 2.0 as Kirigami
0024 
0025 Kirigami.ApplicationWindow {
0026     id: root
0027 
0028     property bool french: true
0029     property bool yds: true
0030     property bool uiaa: true
0031 
0032     globalDrawer: Kirigami.GlobalDrawer {
0033         id: drawer
0034         title: "Klimbgrades"
0035         titleIcon: "klimbgrades"
0036         bannerImageSource: "halfdome.jpg"
0037         contentItem.implicitWidth: Math.min (Kirigami.Units.gridUnit * 15, root.width * 0.8)
0038 
0039         topContent: Column {
0040             anchors {
0041                 left: parent.left
0042                 right: parent.right
0043                 margins: -Kirigami.Units.smallSpacing
0044             }
0045             Kirigami.Heading {
0046                 text: qsTr("Lead")
0047                 anchors {
0048                     left: parent.left
0049                     margins: Kirigami.Units.smallSpacing
0050                 }
0051             }
0052             Rectangle {
0053                 anchors {
0054                     left: parent.left
0055                     right: parent.right
0056                 }
0057                 color: Kirigami.Theme.textColor
0058                 opacity: 0.2
0059                 height: Math.floor(Kirigami.Units.devicePixelRatio)
0060             }
0061             Repeater {
0062                 model: dataStore.availableLeadModel
0063                 delegate: Controls.CheckDelegate {
0064                     width: drawer.width
0065                     text: model.nameRole
0066                     checkState: model.enabledRole ? Qt.Checked : Qt.Unchecked
0067                     onCheckStateChanged: {
0068                         dataStore.availableLeadModel.setScaleEnabled(index, checkState == Qt.Checked);
0069                     }
0070                 }
0071             }
0072             Item {
0073                 width: 1
0074                 height: Kirigami.Units.largeSpacing
0075             }
0076             Kirigami.Heading {
0077                 text: qsTr("Boulder")
0078                 anchors {
0079                     left: parent.left
0080                     margins: Kirigami.Units.smallSpacing
0081                 }
0082             }
0083             Rectangle {
0084                 anchors {
0085                     left: parent.left
0086                     right: parent.right
0087                 }
0088                 color: Kirigami.Theme.textColor
0089                 opacity: 0.2
0090                 height: Math.floor(Kirigami.Units.devicePixelRatio)
0091             }
0092             Repeater {
0093                 model: dataStore.availableBoulderModel
0094                 delegate: Controls.CheckDelegate {
0095                     width: drawer.width
0096                     text: model.nameRole
0097                     checkState: model.enabledRole ? Qt.Checked : Qt.Unchecked
0098                     onCheckStateChanged: {
0099                         dataStore.availableBoulderModel.setScaleEnabled(index, checkState == Qt.Checked);
0100                     }
0101                 }
0102             }
0103             Item {
0104                 width: 1
0105                 height: Kirigami.Units.largeSpacing
0106             }
0107             Rectangle {
0108                 anchors {
0109                     left: parent.left
0110                     right: parent.right
0111                 }
0112                 color: Kirigami.Theme.textColor
0113                 opacity: 0.2
0114                 height: Math.floor(Kirigami.Units.devicePixelRatio)
0115             }
0116             Controls.SwitchDelegate {
0117                 width: drawer.width
0118                 text: qsTr("Link Lead and Boulder")
0119                 checked: dataStore.leadAndBoulderLinked
0120                 onCheckedChanged: {
0121                     dataStore.leadAndBoulderLinked = checked;
0122                 }
0123             }
0124         }
0125     }
0126 
0127     pageStack.initialPage: [leadPageComponent, boulderPageComponent]
0128     pageStack.onCurrentIndexChanged: {
0129         if (loaded) {
0130             dataStore.currentTab = pageStack.currentIndex;
0131         }
0132     }
0133     //HACK: use this as semaphore, don't know other ways to make this not
0134     //emit a signal otherwise
0135     property bool loaded: false;
0136 
0137 
0138     Component.onCompleted: {
0139         pageStack.currentIndex = dataStore.currentTab;
0140         loaded = true
0141     }
0142 
0143     Connections {
0144         target: dataStore.availableLeadModel
0145         onCurrentGradeChanged: {
0146             if (dataStore.leadAndBoulderLinked) {
0147                 dataStore.availableBoulderModel.currentGrade = dataStore.availableLeadModel.currentGrade;
0148             }
0149         }
0150     }
0151 
0152     Connections {
0153         target: dataStore.availableBoulderModel
0154         onCurrentGradeChanged: {
0155             if (dataStore.leadAndBoulderLinked) {
0156                 dataStore.availableLeadModel.currentGrade = dataStore.availableBoulderModel.currentGrade;
0157             }
0158         }
0159     }
0160 
0161     Component {
0162         id: leadPageComponent
0163         Global {
0164             title: qsTr("Lead")
0165             model: dataStore.availableLeadModel
0166             defaultGrade: 45
0167         }
0168     }
0169     Component {
0170         id: boulderPageComponent
0171         Global {
0172             title: qsTr("Boulder")
0173             model: dataStore.availableBoulderModel
0174             defaultGrade: 65
0175         }
0176     }
0177 }