Warning, file /education/parley/src/practice/flashcardmodewidget.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2009 Frederik Gladhorn <gladhorn@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "flashcardmodewidget.h" 0007 0008 #include "ui_practice_widget_flashcard.h" 0009 0010 #include <QUrl> 0011 0012 #include "guifrontend.h" 0013 #include "latexrenderer.h" 0014 0015 using namespace Practice; 0016 0017 FlashCardModeWidget::FlashCardModeWidget(GuiFrontend *frontend, QWidget *parent) 0018 : AbstractModeWidget(frontend, parent) 0019 { 0020 m_ui = new Ui::FlashCardPracticeWidget(); 0021 m_ui->setupUi(this); 0022 connect(frontend, &AbstractFrontend::continueAction, this, &AbstractModeWidget::stopAudio); 0023 connect(frontend, &AbstractFrontend::skipAction, this, &AbstractModeWidget::stopAudio); 0024 } 0025 0026 void FlashCardModeWidget::setQuestionFont(const QFont &font) 0027 { 0028 m_ui->questionLabel->setFont(font); 0029 } 0030 0031 void FlashCardModeWidget::setSolutionFont(const QFont &font) 0032 { 0033 m_ui->solutionLabel->setFont(font); 0034 } 0035 0036 void FlashCardModeWidget::setQuestion(const QVariant &question) 0037 { 0038 m_ui->questionLabel->setMinimumSize(QSize(0, 0)); 0039 if (LatexRenderer::isLatex(question.toString())) { 0040 if (!m_questionLatexRenderer) { 0041 m_questionLatexRenderer = new LatexRenderer(this); 0042 m_questionLatexRenderer->setResultLabel(m_ui->questionLabel); 0043 } 0044 m_questionLatexRenderer->renderLatex(question.toString()); 0045 return; 0046 } 0047 0048 if (question.canConvert<QUrl>()) { 0049 // A QUrl might be an image. 0050 QPixmap pixmap(question.value<QUrl>().path()); 0051 if (!pixmap.isNull()) { 0052 m_ui->questionLabel->setText(QString()); 0053 m_ui->questionLabel->setPixmap(pixmap.scaled(m_ui->questionLabel->size(), Qt::KeepAspectRatio)); 0054 return; 0055 } 0056 } 0057 0058 // A normal text. 0059 m_ui->questionLabel->setText(question.toString()); 0060 } 0061 0062 void FlashCardModeWidget::showQuestion() 0063 { 0064 m_ui->solutionLabel->setHidden(true); 0065 m_frontend->showSetResultButtons(false); 0066 0067 m_ui->questionPronunciationLabel->setVisible(m_ui->questionPronunciationLabel->isEnabled()); 0068 m_ui->questionSoundButton->setVisible(m_ui->questionSoundButton->isEnabled()); 0069 m_ui->solutionPronunciationLabel->setVisible(false); 0070 m_ui->solutionSoundButton->setVisible(false); 0071 } 0072 0073 void FlashCardModeWidget::setSolution(const QVariant &solution) 0074 { 0075 m_solution = solution.toString(); 0076 } 0077 0078 void FlashCardModeWidget::setSynonym(const QString & /*entry*/) 0079 { 0080 // TODO Do something here to show synonyms 0081 } 0082 0083 void FlashCardModeWidget::showSynonym() 0084 { 0085 // TODO Do something here to show synonyms 0086 } 0087 0088 void FlashCardModeWidget::showSolution() 0089 { 0090 m_ui->solutionLabel->setHidden(true); 0091 m_ui->solutionLabel->setPalette(m_correctPalette); 0092 0093 m_ui->solutionLabel->setMinimumSize(QSize(0, 0)); 0094 if (LatexRenderer::isLatex(m_solution)) { 0095 if (!m_solutionLatexRenderer) { 0096 m_solutionLatexRenderer = new LatexRenderer(this); 0097 m_solutionLatexRenderer->setResultLabel(m_ui->solutionLabel); 0098 } 0099 m_solutionLatexRenderer->renderLatex(m_solution); 0100 } else { 0101 m_ui->solutionLabel->setText(m_solution); 0102 } 0103 0104 m_ui->solutionLabel->setHidden(false); 0105 m_frontend->showSetResultButtons(true); 0106 0107 m_ui->solutionPronunciationLabel->setVisible(m_ui->solutionPronunciationLabel->isEnabled()); 0108 m_ui->solutionSoundButton->setVisible(m_ui->solutionSoundButton->isEnabled()); 0109 } 0110 0111 void FlashCardModeWidget::setHint(const QVariant &hint) 0112 { 0113 m_ui->solutionLabel->setHidden(true); 0114 m_ui->solutionLabel->setText(hint.toString()); 0115 m_ui->solutionLabel->setHidden(false); 0116 } 0117 0118 QVariant FlashCardModeWidget::userInput() 0119 { 0120 return QVariant(); 0121 } 0122 0123 void FlashCardModeWidget::setQuestionSound(const QUrl &soundUrl) 0124 { 0125 m_ui->questionSoundButton->setSoundFile(soundUrl); 0126 } 0127 0128 void FlashCardModeWidget::setSolutionSound(const QUrl &soundUrl) 0129 { 0130 m_ui->solutionSoundButton->setSoundFile(soundUrl); 0131 } 0132 0133 void FlashCardModeWidget::setSolutionPronunciation(const QString &pronunciationText) 0134 { 0135 m_ui->solutionPronunciationLabel->setText('[' + pronunciationText + ']'); 0136 m_ui->solutionPronunciationLabel->setEnabled(!pronunciationText.isNull()); 0137 } 0138 0139 void FlashCardModeWidget::setQuestionPronunciation(const QString &pronunciationText) 0140 { 0141 m_ui->questionPronunciationLabel->setText('[' + pronunciationText + ']'); 0142 m_ui->questionPronunciationLabel->setEnabled(!pronunciationText.isNull()); 0143 }