File indexing completed on 2024-03-24 03:44:48
0001 /* 0002 SPDX-FileCopyrightText: 2001-2008 Anne-Marie Mahfouf <annma@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KLETTRESVIEW_H 0008 #define KLETTRESVIEW_H 0009 0010 #include <QLineEdit> 0011 0012 class QPixmap; 0013 class QRect; 0014 class QSvgRenderer; 0015 class KLettres; 0016 class KLTheme; 0017 0018 /** 0019 * This class serves as the view for KLettres. It holds the GUI for the kid and grown-up looks 0020 * and has the code to display the letter/syllable and play the sound. 0021 * 0022 * @short KLettres View class 0023 * @author Anne-Marie Mahfouf <annma@kde.org> 0024 * @version 2.1 0025 */ 0026 0027 0028 class KLettresView : public QWidget 0029 { 0030 Q_OBJECT 0031 public: 0032 /** 0033 * Default constructor 0034 */ 0035 explicit KLettresView(KLettres *parent); 0036 0037 /** 0038 * Destructor 0039 */ 0040 ~KLettresView() override; 0041 /// Enter a letter into the input widget. 0042 void enterLetter(const QString &letter) { m_letterEdit->setText(letter); } 0043 0044 ///The timer value i.e. the time for displaying the letters/syllables 0045 int m_timer; 0046 ///The index to the random sequence 0047 int randomInt; 0048 ///A Klettres object 0049 KLettres *m_klettres = nullptr; 0050 ///The line where the user enters his/her input 0051 QLineEdit *m_letterEdit = nullptr; 0052 ///set the chosen theme 0053 void setTheme(KLTheme *theme); 0054 0055 protected: 0056 0057 ///If the user hits backpace 0058 void keyReleaseEvent(QKeyEvent * e) Q_DECL_OVERRIDE; 0059 ///Cursor position in the line edit 0060 int m_cursorPos; 0061 ///Random number that decides on the letter/syllable and sound 0062 int m_random; 0063 ///Length of the syllables 0064 int m_length; 0065 ///Choose a sound in random and ensure that it's not the same than the previous one 0066 void chooseSound(); 0067 ///Current letter or syllable stored 0068 QString m_currentLetter; 0069 ///Current letter entered uppercase i.e. m_inputLetter.upper() 0070 QString m_upperLetter; 0071 ///Paint the letter/syllable in levels 1 and 3 and the background 0072 void paintEvent( QPaintEvent * ) Q_DECL_OVERRIDE; 0073 ///Paint the background picture 0074 void paintBackground(QPainter &p, const QRect& rect); 0075 ///Paint the letter/syllable in levels 1 and 3 0076 void paintLetter(QPainter &p, const QRect& rect); 0077 ///Current theme 0078 KLTheme *m_theme = nullptr; 0079 0080 // Graphics ---------------- 0081 QSvgRenderer *m_renderer = nullptr; 0082 QPixmap m_backgroundCache; 0083 0084 public Q_SLOTS: 0085 ///Start playing displaying a new letter/syllable, playing the associated sound 0086 void game(); 0087 0088 public Q_SLOTS: 0089 ///Play the same sound again 0090 void slotPlayAgain(); 0091 0092 void slotProcess(const QString &inputLetter); 0093 0094 void slotTimerDone(); 0095 0096 }; 0097 0098 #endif // KLETTRESVIEW_H