Warning, /education/kwordquiz/src/qml/WelcomePage.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 Qt.labs.platform 1.1
0008 import org.kde.kirigami 2.20 as Kirigami
0009 import org.kde.kirigamiaddons.formcard 1.0 as FormCard
0010 import org.kde.kwordquiz 1.0
0011 import org.kde.newstuff 1.91 as NewStuff
0012 import QtQml 2.15
0013
0014 FormCard.FormCardPage {
0015 id: root
0016
0017 function openFile(file, mode) {
0018 const row = documentModel.add(file);
0019 switch (mode) {
0020 case Prefs.MultipleChoice:
0021 multipleChoiceRadio.checked = true;
0022 break;
0023 case Prefs.QA:
0024 qaRadio.checked = true;
0025 break;
0026 case Prefs.Flashcard:
0027 default:
0028 flashcardRadio.checked = true;
0029 break;
0030 }
0031 applicationWindow().pageStack.layers.clear();
0032 documentRepeater.itemAt(row).open();
0033 }
0034
0035 title: i18nc("@title:window", "Welcome")
0036
0037 data: FileDialog {
0038 id: fileDialog
0039
0040 title: i18n("Please choose a KWordQuiz document")
0041 folder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
0042 nameFilters: [i18n("KEduDocument (*.kvtml)"), i18n("Wql documents (*.wql)"), i18n("CSV documents (*.csv)"), i18n("XDXF documents (*.xdxf)")]
0043
0044 onAccepted: {
0045 documentModel.add(file);
0046 documentRepeater.itemAt(documentRepeater.count - 1).open();
0047 }
0048 }
0049
0050 Kirigami.Icon {
0051 source: "org.kde.kwordquiz"
0052 Layout.alignment: Qt.AlignHCenter
0053 implicitWidth: Math.round(Kirigami.Units.iconSizes.huge * 1.5)
0054 implicitHeight: Math.round(Kirigami.Units.iconSizes.huge * 1.5)
0055 }
0056
0057 Kirigami.Heading {
0058 text: i18n("Welcome to KWordQuiz")
0059
0060 Layout.alignment: Qt.AlignHCenter
0061 Layout.topMargin: Kirigami.Units.largeSpacing
0062 }
0063
0064 FormCard.FormGridContainer {
0065 Layout.fillWidth: true
0066 Layout.topMargin: Kirigami.Units.largeSpacing
0067
0068 infoCards: [
0069 FormCard.FormGridContainer.InfoCard {
0070 title: i18n("Open Existing Document")
0071 action: Kirigami.Action {
0072 onTriggered: fileDialog.open();
0073 }
0074 },
0075 FormCard.FormGridContainer.InfoCard {
0076 title: i18n("Create Deck")
0077 action: Kirigami.Action {
0078 onTriggered: applicationWindow().pageStack.layers.push("qrc:/qml/DeckEditorPage.qml", {
0079 documentModel: documentModel,
0080 })
0081 }
0082 },
0083 FormCard.FormGridContainer.InfoCard {
0084 title: i18n("Download Deck")
0085 action: NewStuff.Action {
0086 id: newStuffButton
0087 configFile: "kwordquiz.knsrc"
0088 viewMode: NewStuff.Page.ViewMode.Preview
0089 onEntryEvent: function(entry, event) {
0090 if (event === NewStuff.Entry.StatusChangedEvent) {
0091 documentModel.entryChanged(entry);
0092 }
0093 }
0094 }
0095 }
0096 ]
0097 }
0098
0099 FormCard.FormHeader {
0100 title: i18nc("@title:group", "Mode")
0101 }
0102
0103 FormCard.FormCard {
0104 data: QQC2.ButtonGroup {
0105 id: modeGroup
0106
0107 checkedButton: switch (Prefs.startSession) {
0108 case Prefs.MultipleChoice:
0109 return multipleChoiceRadio;
0110 case Prefs.QA:
0111 return qaRadio;
0112 case Prefs.Flashcard:
0113 default:
0114 return flashcardRadio;
0115 }
0116
0117 onCheckedButtonChanged: {
0118 switch (checkedButton) {
0119 case qaRadio:
0120 Prefs.startSession = Prefs.QA;
0121 break;
0122 case multipleChoiceRadio:
0123 Prefs.startSession = Prefs.MultipleChoice;
0124 break;
0125 case flashcardRadio:
0126 Prefs.startSession = Prefs.Flashcard;
0127 break;
0128 }
0129
0130 Prefs.save();
0131 }
0132 }
0133
0134 FormCard.FormRadioDelegate {
0135 id: flashcardRadio
0136
0137 text: i18nc("@option:check Mode selector", "Flashcard")
0138 QQC2.ButtonGroup.group: modeGroup
0139 }
0140
0141 FormCard.FormRadioDelegate {
0142 id: multipleChoiceRadio
0143
0144 text: i18nc("@option:check Mode selector", "Multiple choice")
0145 QQC2.ButtonGroup.group: modeGroup
0146 }
0147
0148 FormCard.FormRadioDelegate {
0149 id: qaRadio
0150
0151 text: i18nc("@option:check Mode selector", "Question-Answer")
0152 QQC2.ButtonGroup.group: modeGroup
0153 }
0154 }
0155
0156 FormCard.FormHeader {
0157 title: i18n("Decks")
0158 }
0159
0160 FormCard.FormCard {
0161 visible: documentRepeater.count > 0
0162
0163 Repeater {
0164 id: documentRepeater
0165
0166 model: DocumentModel {
0167 id: documentModel
0168 }
0169
0170 delegate: ColumnLayout {
0171 id: documentDelegate
0172
0173 required property int index
0174 required property string title
0175 required property var document
0176 readonly property alias documentButton: documentButton
0177
0178 spacing: 0
0179
0180 function open() {
0181 documentButton.clicked();
0182 }
0183
0184 FormCard.AbstractFormDelegate {
0185 id: documentButton
0186
0187 text: documentDelegate.title
0188
0189 contentItem: RowLayout {
0190 spacing: 0
0191
0192 QQC2.Label {
0193 Layout.fillWidth: true
0194 text: documentDelegate.title
0195 elide: Text.ElideRight
0196 wrapMode: Text.Wrap
0197 maximumLineCount: 2
0198 color: root.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor
0199 Accessible.ignored: true
0200 }
0201
0202 QQC2.ToolButton {
0203 text: i18nc("@action:button", "Remove")
0204 icon.name: "delete"
0205 display: QQC2.ToolButton.IconOnly
0206
0207 onClicked: documentModel.remove(documentDelegate.index)
0208
0209 Layout.rightMargin: Kirigami.Units.smallSpacing
0210
0211 QQC2.ToolTip.visible: hovered
0212 QQC2.ToolTip.text: text
0213 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0214 }
0215
0216 QQC2.ToolButton {
0217 text: i18nc("@action:button", "Edit")
0218 icon.name: "document-edit"
0219 display: QQC2.ToolButton.IconOnly
0220
0221 onClicked: {
0222 const editor = applicationWindow().pageStack.layers.push('qrc:/qml/DeckEditorPage.qml', {
0223 documentModel: documentModel,
0224 mode: DeckEditorPage.EditMode,
0225 });
0226 editor.editorModel.document = documentDelegate.document;
0227 }
0228
0229 Layout.rightMargin: Kirigami.Units.smallSpacing
0230
0231 QQC2.ToolTip.visible: hovered
0232 QQC2.ToolTip.text: text
0233 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0234 }
0235
0236 FormCard.FormArrow {
0237 Layout.leftMargin: Kirigami.Units.smallSpacing
0238 Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
0239 direction: Qt.RightArrow
0240 }
0241 }
0242
0243 onClicked: if (Prefs.startSession === Prefs.Flashcard){
0244 applicationWindow().pageStack.layers.push("qrc:/qml/FlashCardPage.qml", {
0245 document: documentDelegate.document,
0246 documentModel: documentModel,
0247 });
0248 } else if (Prefs.startSession === Prefs.QA) {
0249 applicationWindow().pageStack.layers.push("qrc:/qml/QuestionAnswerPage.qml", {
0250 document: documentDelegate.document,
0251 documentModel: documentModel,
0252 });
0253 } else {
0254 applicationWindow().pageStack.layers.push("qrc:/qml/MultipleChoicePage.qml", {
0255 document: documentDelegate.document,
0256 documentModel: documentModel,
0257 });
0258 }
0259
0260 Layout.fillWidth: true
0261 }
0262
0263 FormCard.FormDelegateSeparator {
0264 below: documentButton
0265 above: if (index === documentRepeater.count - 1) {
0266 null
0267 } else {
0268 documentRepeater.itemAt(index + 1).children[0]
0269 }
0270 visible: index !== documentRepeater.count - 1
0271 }
0272 }
0273 }
0274 }
0275 }