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.15 0021 import QtQuick.Layouts 1.15 0022 import QtQuick.Controls 2.15 as Controls 0023 import org.kde.kirigami 2.19 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 minimumWidth: Kirigami.Units.gridUnit * 15 0033 minimumHeight: Kirigami.Units.gridUnit * 20 0034 0035 pageStack { 0036 defaultColumnWidth: Kirigami.Units.gridUnit * 30 0037 globalToolBar { 0038 canContainHandles: !Kirigami.Settings.isMobile 0039 style: Kirigami.Settings.isMobile ? Kirigami.ApplicationHeaderStyle.Titles : Kirigami.ApplicationHeaderStyle.ToolBar 0040 showNavigationButtons: false//applicationWindow().pageStack.currentIndex > 0 ? Kirigami.ApplicationHeaderStyle.ShowBackButton : 0 0041 // HACK: ApplicationHeaderStyle.None doesn't load fabs 0042 preferredHeight: Kirigami.Settings.isMobile && !root.pageStack.wideMode ? 0 : (Kirigami.Units.gridUnit * 1.8) + Kirigami.Units.smallSpacing * 2 0043 } 0044 initialPage: [leadPageComponent, boulderPageComponent] 0045 } 0046 0047 Component.onCompleted: pageStack.currentIndex = 0; //TODO: save the state 0048 0049 header: Controls.ToolBar { 0050 //TODO: make the behavior of abstractapplicationheader sliding away work again 0051 visible: Kirigami.Settings.isMobile && !root.pageStack.wideMode 0052 height: visible ? implicitHeight : 0 0053 contentItem: Kirigami.Heading { 0054 text: qsTr("Climbing Grades") 0055 } 0056 } 0057 footer: Controls.ToolBar { 0058 id: bottomNavigation 0059 //FIXME: Kirigami.NavigationTabBar needs the possibility of setting stuff on either side 0060 position: Controls.TabBar.Footer 0061 visible: Kirigami.Settings.isMobile && !root.pageStack.wideMode 0062 height: visible ? implicitHeight : 0 0063 Kirigami.Theme.inherit: false 0064 Kirigami.Theme.colorSet: Kirigami.Theme.Header 0065 contentItem: RowLayout { 0066 Item { 0067 id: leftAnchor 0068 Layout.preferredWidth: Kirigami.Units.gridUnit * 2 0069 Layout.preferredHeight: Layout.preferredWidth 0070 Binding { 0071 target: globalDrawer.handle 0072 property: "handleAnchor" 0073 value: leftAnchor 0074 when: bottomNavigation.visible 0075 } 0076 } 0077 Kirigami.NavigationTabBar { 0078 Layout.fillWidth: true 0079 background: null 0080 actions: [ 0081 Kirigami.Action { 0082 text: qsTr("Lead") 0083 checked: root.pageStack.currentIndex === 0 0084 onTriggered: root.pageStack.currentIndex = 0 0085 }, 0086 Kirigami.Action { 0087 text: qsTr("Boulder") 0088 checked: root.pageStack.currentIndex === 1 0089 onTriggered: root.pageStack.currentIndex = 1 0090 } 0091 ] 0092 } 0093 Item { 0094 id: rightAnchor 0095 Layout.preferredWidth: Kirigami.Units.gridUnit * 2 0096 Layout.preferredHeight: Layout.preferredWidth 0097 Binding { 0098 target: contextDrawer.handle 0099 property: "handleAnchor" 0100 value: rightAnchor 0101 when: bottomNavigation.visible 0102 } 0103 } 0104 } 0105 } 0106 Component { 0107 id: leadPageComponent 0108 Global { 0109 title: qsTr("Lead") 0110 model: dataStore.availableLeadModel 0111 defaultGrade: 45 0112 } 0113 } 0114 Component { 0115 id: boulderPageComponent 0116 Global { 0117 title: qsTr("Boulder") 0118 model: dataStore.availableBoulderModel 0119 defaultGrade: 65 0120 } 0121 } 0122 0123 contextDrawer: Kirigami.ContextDrawer { 0124 id: contextDrawer 0125 } 0126 0127 globalDrawer: Kirigami.OverlayDrawer { 0128 id: drawer 0129 0130 edge: Qt.application.layoutDirection === Qt.RightToLeft ? Qt.RightEdge : Qt.LeftEdge 0131 modal: Kirigami.Settings.isMobile || (applicationWindow().width < Kirigami.Units.gridUnit * 50 && !collapsed) // Only modal when not collapsed, otherwise collapsed won't show. 0132 z: modal ? Math.round(position * 10000000) : 100 0133 drawerOpen: !Kirigami.Settings.isMobile && enabled 0134 width: Kirigami.Units.gridUnit * 16 0135 0136 Kirigami.Theme.colorSet: Kirigami.Theme.View 0137 handleClosedIcon.source: modal ? null : "sidebar-expand-left" 0138 handleOpenIcon.source: modal ? null : "sidebar-collapse-left" 0139 handleVisible: modal 0140 0141 onModalChanged: if (!modal) { 0142 drawerOpen = true; 0143 } 0144 0145 leftPadding: 0 0146 rightPadding: 0 0147 topPadding: 0 0148 bottomPadding: 0 0149 0150 contentItem: ColumnLayout { 0151 Controls.ToolBar { 0152 Layout.fillWidth: true 0153 Layout.preferredHeight: pageStack.globalToolBar.preferredHeight > 0 ? pageStack.globalToolBar.preferredHeight : undefined 0154 0155 leftPadding: 3 0156 rightPadding: 3 0157 topPadding: 3 0158 bottomPadding: 3 0159 0160 contentItem: Kirigami.SearchField { 0161 id: filterField 0162 placeholderText: qsTr("Filter…") 0163 } 0164 } 0165 Kirigami.AbstractListItem { 0166 Layout.fillWidth: true 0167 contentItem: Kirigami.Heading { 0168 text: qsTr("Lead") 0169 level: 2 0170 color: parent.checked ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor 0171 } 0172 checkable: !root.pageStack.wideMode 0173 checked: checkable && root.pageStack.currentIndex === 0 0174 onClicked: root.pageStack.currentIndex = 0 0175 } 0176 Kirigami.Separator { 0177 Layout.fillWidth: true 0178 } 0179 Repeater { 0180 model: dataStore.availableLeadModel 0181 delegate: Controls.CheckDelegate { 0182 required property int index 0183 required property string name 0184 required property bool scaleEnabled 0185 0186 visible: name.toUpperCase().indexOf(filterField.text.toUpperCase()) !== -1 0187 Layout.fillWidth: true 0188 text: name 0189 checkState: scaleEnabled ? Qt.Checked : Qt.Unchecked 0190 onToggled: { 0191 dataStore.availableLeadModel.setScaleEnabled(index, checkState == Qt.Checked); 0192 root.pageStack.currentIndex = 0; 0193 } 0194 } 0195 } 0196 Kirigami.AbstractListItem { 0197 Layout.fillWidth: true 0198 contentItem: Kirigami.Heading { 0199 text: qsTr("Boulder") 0200 level: 2 0201 color: parent.checked ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor 0202 } 0203 checkable: !root.pageStack.wideMode 0204 checked: checkable && root.pageStack.currentIndex === 1 0205 onClicked: root.pageStack.currentIndex = 1 0206 } 0207 Kirigami.Separator { 0208 Layout.fillWidth: true 0209 } 0210 Repeater { 0211 model: dataStore.availableBoulderModel 0212 delegate: Controls.CheckDelegate { 0213 required property int index 0214 required property string name 0215 required property bool scaleEnabled 0216 0217 visible: name.toUpperCase().indexOf(filterField.text.toUpperCase()) !== -1 0218 Layout.fillWidth: true 0219 text: name 0220 checkState: scaleEnabled ? Qt.Checked : Qt.Unchecked 0221 onToggled: { 0222 dataStore.availableBoulderModel.setScaleEnabled(index, checkState == Qt.Checked); 0223 root.pageStack.currentIndex = 1; 0224 } 0225 } 0226 } 0227 Kirigami.Separator { 0228 Layout.fillWidth: true 0229 } 0230 Controls.SwitchDelegate { 0231 Layout.fillWidth: true 0232 text: qsTr("Link Lead and Boulder") 0233 checked: dataStore.leadAndBoulderLinked 0234 onToggled: dataStore.leadAndBoulderLinked = checked 0235 } 0236 Item { 0237 Layout.fillHeight: true 0238 } 0239 } 0240 } 0241 0242 Connections { 0243 target: dataStore.availableLeadModel 0244 function onCurrentGradeChanged() { 0245 if (dataStore.leadAndBoulderLinked) { 0246 dataStore.availableBoulderModel.currentGrade = dataStore.availableLeadModel.currentGrade; 0247 } 0248 } 0249 } 0250 0251 Connections { 0252 target: dataStore.availableBoulderModel 0253 function onCurrentGradeChanged() { 0254 if (dataStore.leadAndBoulderLinked) { 0255 dataStore.availableLeadModel.currentGrade = dataStore.availableBoulderModel.currentGrade; 0256 } 0257 } 0258 } 0259 }