Warning, file /education/khangman/src/khangman.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /*************************************************************************** 0002 * Copyright 2001-2009 Anne-Marie Mahfouf <annma@kde.org> * 0003 * Copyright 2014 Rahul Chowdhury <rahul.chowdhury@kdemail.net> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 0019 ***************************************************************************/ 0020 0021 0022 #ifndef _KHANGMAN_H_ 0023 #define _KHANGMAN_H_ 0024 0025 #include <KSharedConfig> 0026 0027 #include <QMainWindow> 0028 0029 #include "khmthemefactory.h" 0030 0031 class QQmlEngine; 0032 class QQuickWidget; 0033 class KHelpMenu; 0034 0035 /** 0036 * @short KHangMan Main Window 0037 * @author Anne-Marie Mahfouf <annemarie.mahfouf@free.fr> 0038 * @version 3.0 0039 */ 0040 class KHangMan : public QMainWindow 0041 { 0042 Q_OBJECT 0043 0044 Q_PROPERTY( int resolveTime READ resolveTime WRITE setResolveTime NOTIFY resolveTimeChanged ) 0045 Q_PROPERTY( bool soundEnabled READ soundEnabled WRITE setSoundEnabled NOTIFY soundEnabledChanged ) 0046 0047 Q_PROPERTY( int currentLanguage READ currentLanguage WRITE setCurrentLanguage NOTIFY currentLanguageChanged ) 0048 Q_PROPERTY( QStringList languages READ languages NOTIFY languagesChanged) 0049 0050 Q_PROPERTY( int currentCategory READ currentCategory WRITE setCurrentCategory NOTIFY currentCategoryChanged ) 0051 Q_PROPERTY( QStringList categories READ categories NOTIFY categoriesChanged) 0052 0053 Q_PROPERTY( int currentTheme READ currentTheme WRITE setCurrentTheme NOTIFY currentThemeChanged ) 0054 Q_PROPERTY( QStringList themes READ themes NOTIFY themesChanged) 0055 Q_PROPERTY( QString backgroundUrl READ backgroundUrl NOTIFY currentThemeChanged) 0056 Q_PROPERTY( QColor letterColor READ currentThemeLetterColor NOTIFY currentThemeChanged) 0057 0058 Q_PROPERTY( QStringList currentWord READ currentWord NOTIFY currentWordChanged) 0059 Q_PROPERTY( QString currentHint READ getCurrentHint NOTIFY currentHintChanged) 0060 Q_PROPERTY( QStringList alphabet READ alphabet NOTIFY currentLanguageChanged) 0061 0062 Q_PROPERTY( int winCount READ winCount WRITE setWinCount NOTIFY winCountChanged ) 0063 Q_PROPERTY( int lossCount READ lossCount WRITE setLossCount NOTIFY lossCountChanged ) 0064 0065 Q_PROPERTY( int scoreMultiplyingFactor READ scoreMultiplyingFactor WRITE setScoreMultiplyingFactor NOTIFY scoreMultiplyingFactorChanged ) 0066 0067 Q_PROPERTY( int netScore READ netScore NOTIFY netScoreChanged ) 0068 0069 public: 0070 /** 0071 * Default Constructor 0072 */ 0073 KHangMan(); 0074 0075 /** 0076 * Default Destructor 0077 */ 0078 ~KHangMan() override; 0079 0080 // These accessor and mutator methods are not needed once the 0081 // kconfig_compiler can generate Q_INVOKABLE methods, slots or/and 0082 // properties 0083 int resolveTime(); 0084 void setResolveTime(int resolveTime); 0085 0086 /** Getter and Setter for soundEnabled property */ 0087 bool soundEnabled(); 0088 void setSoundEnabled(bool sound); 0089 0090 int currentCategory(); 0091 QStringList categories(); 0092 0093 int currentLanguage(); 0094 QStringList languages(); 0095 0096 int winCount() const; 0097 int lossCount() const; 0098 0099 int scoreMultiplyingFactor() const; 0100 int netScore() const; 0101 0102 int currentTheme(); 0103 QStringList themes(); 0104 QString backgroundUrl(); 0105 QColor currentThemeLetterColor(); 0106 0107 //Display the mainwindow only when kvtml files are present, else show an error message and quit. 0108 void show(); 0109 0110 // get m_view->engine() 0111 QQmlEngine* getEngine(); 0112 0113 /** Calculate the net score */ 0114 void calculateNetScore(); 0115 0116 Q_INVOKABLE QStringList currentWord() const; 0117 0118 /** Get the current hint */ 0119 Q_INVOKABLE QString getCurrentHint() const; 0120 0121 Q_INVOKABLE QStringList alphabet() const; 0122 0123 /** Return true if the word contains the char in the QString */ 0124 Q_INVOKABLE bool containsChar(const QString &original); 0125 0126 /** Return true if the answer and the current word match */ 0127 Q_INVOKABLE bool isResolved() const; 0128 0129 /** Reveals the solution to the current puzzle */ 0130 Q_INVOKABLE void revealCurrentWord(); 0131 0132 public Q_SLOTS: 0133 ///When the language is changed in the Language menu 0134 void setCurrentLanguage(int index); 0135 0136 ///When the category is changed in the Category menu 0137 void setCurrentCategory(int index); 0138 0139 /** Set the current theme */ 0140 void setCurrentTheme(int index); 0141 0142 ///access the KNewStuff class to install new data 0143 void slotDownloadNewStuff(); 0144 0145 ///Load kvtml file and get a word and its tip in random 0146 void readFile(); 0147 0148 /** Generate a new word */ 0149 void nextWord(); 0150 0151 /** Sets the count for number of words correctly guessed */ 0152 void setWinCount(int count); 0153 0154 /** Sets the count for number of words wrongly guessed */ 0155 void setLossCount(int count); 0156 0157 /** Sets the score multiplying factor */ 0158 void setScoreMultiplyingFactor( int factor ); 0159 0160 /** Handle the guessed letter */ 0161 void replaceLetters(const QString& charString); 0162 0163 void showAboutKHangMan(); 0164 void showAboutKDE(); 0165 void showHandbook(); 0166 0167 Q_SIGNALS: 0168 0169 void resolveTimeChanged(); 0170 void soundEnabledChanged(); 0171 void currentLanguageChanged(); 0172 void currentCategoryChanged(); 0173 void currentWordChanged(); 0174 void currentHintChanged(); 0175 void languagesChanged(); 0176 void categoriesChanged(); 0177 void themesChanged(); 0178 void currentThemeChanged(); 0179 void winCountChanged(); 0180 void lossCountChanged(); 0181 void scoreMultiplyingFactorChanged(); 0182 void netScoreChanged(); 0183 0184 private: 0185 KConfigGroup config(const QString &group); 0186 0187 /** Strip the accents off given string 0188 * @params original string to strip accents off of 0189 * @returns string without accents 0190 */ 0191 QString stripAccents(const QString & original); 0192 0193 ///Scan the files in the selected language dir to set the levels 0194 void loadLevels(); 0195 // Populate m_specialCharacters if the 0196 // current language has special characters. 0197 void loadLanguageSpecialCharacters(); 0198 0199 /** Scan the languages found on disk and load the current 0200 * language from settings with en as default. 0201 */ 0202 void scanLanguages(); 0203 0204 //shuffle words+hints 0205 void slotSetWordsSequence(); 0206 0207 ///the different data titles and files in the current language dir 0208 QMap<QString, QString> m_titleLevels; 0209 0210 int m_currentCategory; 0211 int m_currentLanguage; 0212 0213 // language information 0214 QStringList m_languages; 0215 QStringList m_languageNames; 0216 0217 // Some important members: the view and newStuff. 0218 QQuickWidget *m_view; 0219 0220 // Contains all the words that are read from the data file. 0221 QStringList m_specialCharacters; 0222 0223 //Theme manager 0224 KHMThemeFactory m_themeFactory; 0225 0226 //Config group 0227 KSharedConfig::Ptr m_config; 0228 0229 int m_winCount; 0230 int m_lossCount; 0231 0232 //The index to the random sequence 0233 int m_randomInt; 0234 0235 // Multiplying factor for scores 0236 int m_scoreMultiplyingFactor; 0237 0238 int m_netScore; 0239 0240 //The random sequence of words of the current level file 0241 QList<QPair<QString, QString> > m_randomList; 0242 0243 /** The word to be guessed */ 0244 QString m_originalWord; 0245 0246 /** The hidden word that is filled in during the game. */ 0247 QString m_currentWord; 0248 0249 //Current hint 0250 QString m_hint; 0251 0252 /** help menu for displaying about box */ 0253 KHelpMenu *m_helpMenu; 0254 }; 0255 0256 #endif // _KHANGMAN_H_ 0257 0258 // kate: space-indent on; tab-width 4; indent-width 4; mixed-indent off; replace-tabs on; 0259 // vim: set et sw=4 ts=4 cino=l1,cs,U1: