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.Controls 2.15 as Controls
0022 import QtQuick.Layouts 1.2
0023 import QtGraphicalEffects 1.0
0024 import org.kde.kirigami 2.19 as Kirigami
0025 import "HeuristicConverter.js" as HeuristicConverter
0026
0027 Controls.Control {
0028 id: root
0029
0030 Layout.fillWidth: true
0031
0032 property Item page
0033 required property QtObject availableGradesModel
0034 required property string name
0035 required property string url
0036 required property string description
0037 required property bool scaleEnabled
0038 required property int index
0039 required property bool isLast
0040
0041 visible: scaleEnabled
0042
0043 function increment() {
0044 print("Decimal grade: " + availableGradesModel.currentGrade);
0045
0046 availableGradesModel.currentGrade++;
0047 }
0048
0049 function decrement() {
0050 print("Decimal grade: " + availableGradesModel.currentGrade);
0051 availableGradesModel.currentGrade = Math.max(0, availableGradesModel.currentGrade - 1);
0052 }
0053
0054 function format(decimalGrade) {
0055 var formattedGrade = dataStore.gradeName(root.name, decimalGrade);
0056 if (formattedGrade) {
0057 return formattedGrade;
0058 }
0059 var func = HeuristicConverter["format"+root.name.replace(/\s+/g, '')]
0060 if (func) {
0061 return func(decimalGrade);
0062 }
0063 return "--";
0064 }
0065
0066 signal infoClicked
0067
0068 contentItem: ColumnLayout {
0069 Kirigami.Heading {
0070 Layout.alignment: Qt.AlignHCenter
0071 level: 2
0072 text: root.name
0073 }
0074 RowLayout {
0075 Layout.fillWidth: true
0076 Controls.ToolButton {
0077 icon.name: "go-previous"
0078 onClicked: availableGradesModel.currentGrade -= 2;
0079 }
0080 Kirigami.Heading {
0081 Layout.fillWidth: true
0082 horizontalAlignment: Text.AlignHCenter
0083 color: availableGradesModel.currentGrade <= 100 ? Kirigami.Theme.textColor : "red"
0084 text: format(availableGradesModel.currentGrade);
0085 }
0086 Controls.ToolButton {
0087 icon.name: "go-next"
0088 onClicked: availableGradesModel.currentGrade += 2;
0089 }
0090 }
0091
0092 RowLayout {
0093 Layout.fillWidth: true
0094 Controls.Label {
0095 Layout.fillWidth: true
0096 text: page.model.personalRecord > 0 ? (qsTr("Record: ") + format(page.model.personalRecord)) : "";
0097 }
0098 Controls.ToolButton {
0099 icon.name: "documentinfo"
0100
0101 onClicked: {
0102 sheet.description = description
0103 sheet.url = url
0104 sheet.open();
0105 }
0106 }
0107 }
0108 }
0109 MouseArea {
0110 id: mouseArea
0111 anchors.fill: parent
0112 property int startX
0113 preventStealing: true
0114 onPressed: {
0115 startX = mouse.x
0116 }
0117 onPositionChanged: {
0118 var change = false;
0119
0120 if (mouse.x - startX > Kirigami.Units.gridUnit) {
0121 startX = mouse.x;
0122 increment();
0123
0124 } else if (mouse.x - startX < -Kirigami.Units.gridUnit) {
0125 startX = mouse.x;
0126 decrement();
0127 }
0128 }
0129 }
0130 background: Item {
0131 visible: !root.isLast
0132 Kirigami.Separator {
0133 anchors {
0134 left: parent.left
0135 right: parent.right
0136 bottom: parent.bottom
0137 }
0138 }
0139 }
0140 }