Warning, /education/kwordquiz/src/qml/BasePage.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: LGPL-2.0-or-later
0003 
0004 import QtQuick 2.15
0005 import QtQuick.Layouts 1.15
0006 import QtQuick.Controls 2.15 as QQC2
0007 import org.kde.kirigami 2.20 as Kirigami
0008 import org.kde.kwordquiz 1.0
0009 
0010 Kirigami.Page {
0011     id: root
0012 
0013     property alias document: cardModel.document
0014     property alias listView: listView
0015     property alias randomSortModel: randomSortModel
0016     property alias cardModel: cardModel
0017     property var documentModel
0018 
0019     property bool finished: false
0020     property int errors: 0
0021     property bool showAnswer: false
0022 
0023     title: if (Prefs.percent) {
0024         i18n("Cards %1% Errors %2", Math.round((listView.currentIndex + (finished ? 1 : 0)) / listView.count * 100), root.errors)
0025     } else {
0026         i18n("Cards %1/%2 Errors %3", listView.currentIndex + 1, listView.count, root.errors)
0027     }
0028 
0029     actions: [
0030         OptionsAction {
0031             cardModel: root.cardModel
0032         },
0033         EditAction {
0034             cardModel: root.cardModel
0035             documentModel: root.documentModel
0036         }
0037     ]
0038 
0039     function reset() {
0040         root.randomSortModel.showErrorsOnly = false;
0041         root.randomSortModel.reset();
0042         root.errors = 0;
0043         root.showAnswer = false;
0044         root.finished = false;
0045         listView.currentIndex = 0;
0046     }
0047 
0048     ListView {
0049         id: listView
0050 
0051         anchors.fill: parent
0052 
0053         highlightMoveVelocity: width * 2
0054 
0055         model: RandomSortModel {
0056             id: randomSortModel
0057 
0058             cardModel: CardModel {
0059                 id: cardModel
0060 
0061                 onReloaded: root.reset()
0062             }
0063         }
0064 
0065         snapMode: ListView.SnapOneItem
0066         orientation: ListView.Horizontal
0067         interactive: false
0068 
0069         Kirigami.PlaceholderMessage {
0070             anchors.centerIn: parent
0071             width: parent.width - Kirigami.Units.gridUnit * 4
0072             visible: root.finished
0073             text: i18nc("@label", "Finished")
0074 
0075             explanation: root.errors === 0 ? i18n("You got a perfect score") : i18np("You made one mistake", "You made %1 mistakes", root.errors)
0076 
0077             RowLayout {
0078                 Layout.alignment: Qt.AlignHCenter
0079                 Layout.topMargin: Kirigami.Units.gridUnit
0080 
0081                 QQC2.Button {
0082                     text: i18n("Repeat Errors")
0083                     visible: root.errors > 0
0084                     onClicked: {
0085                         root.randomSortModel.showErrorsOnly = true;
0086                         root.listView.currentIndex = 0;
0087                         root.errors = 0;
0088                         root.finished = 0;
0089                     }
0090                 }
0091 
0092                 QQC2.Button {
0093                     text: i18n("Try Again")
0094                     onClicked: root.reset();
0095                 }
0096             }
0097         }
0098     }
0099 }