Warning, /utilities/klimbgrades/src/GradeWidgetBase.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.0
0021 import QtQuick.Layouts 1.2
0022 import QtGraphicalEffects 1.0
0023 import org.kde.kirigami 2.0 as Kirigami
0024 import "HeuristicConverter.js" as HeuristicConverter
0025 
0026 Rectangle {
0027     id: root
0028 
0029     color: Kirigami.Theme.viewBackgroundColor
0030     width: mainLayout.width + Kirigami.Units.gridUnit * 2
0031     height: mainLayout.height + Kirigami.Units.gridUnit * 2
0032 
0033     property Item page
0034     property QtObject availableGradesModel
0035     property alias scaleName: scaleNameLabel.text
0036     property string url
0037     property string description
0038 
0039     function increment() {
0040         print("Decimal grade: " + availableGradesModel.currentGrade);
0041 
0042         availableGradesModel.currentGrade++;
0043     }
0044 
0045     function decrement() {
0046         print("Decimal grade: " + availableGradesModel.currentGrade);
0047         availableGradesModel.currentGrade = Math.max(0, availableGradesModel.currentGrade - 1);
0048     }
0049 
0050     function format(decimalGrade) {
0051         var formattedGrade = dataStore.gradeName(scaleName, decimalGrade);
0052         if (formattedGrade) {
0053             return formattedGrade;
0054         }
0055         var func = HeuristicConverter["format"+root.scaleName.replace(/\s+/g, '')]
0056         if (func) {
0057             return func(decimalGrade);
0058         }
0059         return "--";
0060     }
0061 
0062     signal infoClicked
0063 
0064     Column {
0065         id: mainLayout
0066         z: 2
0067         width: Math.max(Kirigami.Units.gridUnit * 8, implicitWidth)
0068         anchors {
0069             top: parent.top
0070             left: parent.left
0071             margins: Kirigami.Units.gridUnit
0072         }
0073         Kirigami.Label {
0074             id: scaleNameLabel
0075         }
0076         RowLayout {
0077             anchors {
0078                 left: parent.left
0079                 right: parent.right
0080             }
0081             IconButton {
0082                 source: "go-previous"
0083                 onClicked: availableGradesModel.currentGrade -= 2;
0084             }
0085             Kirigami.Heading {
0086                 Layout.fillWidth: true
0087                 horizontalAlignment: Text.AlignHCenter
0088                 color: availableGradesModel.currentGrade <= 100 ? Kirigami.Theme.viewTextColor : "red"
0089                 text: format(availableGradesModel.currentGrade);
0090             }
0091             IconButton {
0092                 source: "go-next"
0093                 onClicked: availableGradesModel.currentGrade += 2;
0094             }
0095         }
0096     
0097         RowLayout {
0098             width: parent.width
0099             Kirigami.Label {
0100                 Layout.fillWidth: true
0101                 text: page.model.personalRecord > 0 ? (qsTr("Record: ") + format(page.model.personalRecord)) : "";
0102             }
0103             IconButton {
0104                 source: "documentinfo"
0105 
0106                 onClicked: {
0107                     sheet.description = description
0108                     sheet.url = url
0109                     sheet.open();
0110                 }
0111             }
0112         }
0113     }
0114     MouseArea {
0115         id: mouseArea
0116         anchors.fill: parent
0117         property int startX
0118         preventStealing: true
0119         onPressed: {
0120             startX = mouse.x
0121         }
0122         onPositionChanged: {
0123             var change = false;
0124 
0125             if (mouse.x - startX > Kirigami.Units.gridUnit) {
0126                 startX = mouse.x;
0127                 increment();
0128 
0129             } else if (mouse.x - startX < -Kirigami.Units.gridUnit) {
0130                 startX = mouse.x;
0131                 decrement();
0132             }
0133         }
0134     }
0135     layer.enabled: true
0136     layer.effect: DropShadow {
0137         horizontalOffset: 0
0138         verticalOffset: 0
0139         radius: Kirigami.Units.gridUnit/1.6
0140         samples: 32
0141         color: Qt.rgba(0, 0, 0, 0.5)
0142     }
0143 }