File indexing completed on 2024-04-14 03:40:32
0001 // SPDX-FileCopyrightText: 2001-2009 Anne-Marie Mahfouf <annma@kde.org> 0002 // SPDX-FileCopyrightText: 2014 Rahul Chowdhury <rahul.chowdhury@kdemail.net> 0003 // SPDX-License-Identifier: GPL-2.0-or-later 0004 0005 #pragma once 0006 0007 #include <KSharedConfig> 0008 #include <KNSCore/Entry> 0009 #include <QtQml> 0010 0011 #include "khmthemefactory.h" 0012 0013 /** 0014 * @short KHangMan Main Window 0015 * @author Anne-Marie Mahfouf <annemarie.mahfouf@free.fr> 0016 * @version 3.0 0017 */ 0018 class KHangMan : public QObject 0019 { 0020 Q_OBJECT 0021 QML_ELEMENT 0022 QML_SINGLETON 0023 0024 Q_PROPERTY( int resolveTime READ resolveTime WRITE setResolveTime NOTIFY resolveTimeChanged ) 0025 Q_PROPERTY( bool soundEnabled READ soundEnabled WRITE setSoundEnabled NOTIFY soundEnabledChanged ) 0026 0027 Q_PROPERTY( int currentLanguage READ currentLanguage WRITE setCurrentLanguage NOTIFY currentLanguageChanged ) 0028 Q_PROPERTY( QStringList languages READ languages NOTIFY languagesChanged) 0029 0030 Q_PROPERTY( int currentCategory READ currentCategory WRITE setCurrentCategory NOTIFY currentCategoryChanged ) 0031 Q_PROPERTY( QStringList categories READ categories NOTIFY categoriesChanged) 0032 0033 Q_PROPERTY( int currentTheme READ currentTheme WRITE setCurrentTheme NOTIFY currentThemeChanged ) 0034 Q_PROPERTY( QStringList themes READ themes NOTIFY themesChanged) 0035 Q_PROPERTY( QUrl backgroundUrl READ backgroundUrl NOTIFY currentThemeChanged) 0036 Q_PROPERTY( QColor letterColor READ currentThemeLetterColor NOTIFY currentThemeChanged) 0037 0038 Q_PROPERTY( QStringList currentWord READ currentWord NOTIFY currentWordChanged) 0039 Q_PROPERTY( QString currentHint READ getCurrentHint NOTIFY currentHintChanged) 0040 Q_PROPERTY( QStringList alphabet READ alphabet NOTIFY currentLanguageChanged) 0041 0042 Q_PROPERTY( int winCount READ winCount WRITE setWinCount NOTIFY winCountChanged ) 0043 Q_PROPERTY( int lossCount READ lossCount WRITE setLossCount NOTIFY lossCountChanged ) 0044 0045 Q_PROPERTY( int scoreMultiplyingFactor READ scoreMultiplyingFactor WRITE setScoreMultiplyingFactor NOTIFY scoreMultiplyingFactorChanged ) 0046 0047 Q_PROPERTY( int netScore READ netScore NOTIFY netScoreChanged ) 0048 0049 public: 0050 /** 0051 * Default Constructor 0052 */ 0053 KHangMan(); 0054 0055 // These accessor and mutator methods are not needed once the 0056 // kconfig_compiler can generate Q_INVOKABLE methods, slots or/and 0057 // properties 0058 int resolveTime(); 0059 void setResolveTime(int resolveTime); 0060 0061 /** Getter and Setter for soundEnabled property */ 0062 bool soundEnabled() const; 0063 void setSoundEnabled(bool sound); 0064 0065 int currentCategory() const; 0066 QStringList categories() const; 0067 0068 int currentLanguage() const; 0069 QStringList languages() const; 0070 0071 int winCount() const; 0072 int lossCount() const; 0073 0074 int scoreMultiplyingFactor() const; 0075 int netScore() const; 0076 0077 int currentTheme() const; 0078 QStringList themes() const; 0079 QUrl backgroundUrl() const; 0080 QColor currentThemeLetterColor() const; 0081 0082 /** Calculate the net score */ 0083 void calculateNetScore(); 0084 0085 Q_INVOKABLE QStringList currentWord() const; 0086 0087 /** Get the current hint */ 0088 Q_INVOKABLE QString getCurrentHint() const; 0089 0090 Q_INVOKABLE QStringList alphabet() const; 0091 0092 /** Return true if the word contains the char in the QString */ 0093 Q_INVOKABLE bool containsChar(const QString &original) const; 0094 0095 /** Return true if the answer and the current word match */ 0096 Q_INVOKABLE bool isResolved() const; 0097 0098 /** Reveals the solution to the current puzzle */ 0099 Q_INVOKABLE void revealCurrentWord(); 0100 0101 public Q_SLOTS: 0102 ///When the language is changed in the Language menu 0103 void setCurrentLanguage(int index); 0104 0105 ///When the category is changed in the Category menu 0106 void setCurrentCategory(int index); 0107 0108 /** Set the current theme */ 0109 void setCurrentTheme(int index); 0110 0111 ///access the KNewStuff class to install new data 0112 void slotDownloadNewStuff(KNSCore::Entry *entry); 0113 0114 ///Load kvtml file and get a word and its tip in random 0115 void readFile(); 0116 0117 /** Generate a new word */ 0118 void nextWord(); 0119 0120 /** Sets the count for number of words correctly guessed */ 0121 void setWinCount(int count); 0122 0123 /** Sets the count for number of words wrongly guessed */ 0124 void setLossCount(int count); 0125 0126 /** Sets the score multiplying factor */ 0127 void setScoreMultiplyingFactor( int factor ); 0128 0129 /** Handle the guessed letter */ 0130 void replaceLetters(const QString& charString); 0131 0132 void showHandbook() const; 0133 0134 Q_SIGNALS: 0135 0136 void resolveTimeChanged(); 0137 void soundEnabledChanged(); 0138 void currentLanguageChanged(); 0139 void currentCategoryChanged(); 0140 void currentWordChanged(); 0141 void currentHintChanged(); 0142 void languagesChanged(); 0143 void categoriesChanged(); 0144 void themesChanged(); 0145 void currentThemeChanged(); 0146 void winCountChanged(); 0147 void lossCountChanged(); 0148 void scoreMultiplyingFactorChanged(); 0149 void netScoreChanged(); 0150 void errorOccured(const QString &text); 0151 0152 private: 0153 KConfigGroup config(const QString &group); 0154 0155 ///Scan the files in the selected language dir to set the levels 0156 void loadLevels(); 0157 // Populate m_specialCharacters if the 0158 // current language has special characters. 0159 void loadLanguageSpecialCharacters(); 0160 0161 /** Scan the languages found on disk and load the current 0162 * language from settings with en as default. 0163 */ 0164 void scanLanguages(); 0165 0166 //shuffle words+hints 0167 void slotSetWordsSequence(); 0168 0169 ///the different data titles and files in the current language dir 0170 QMap<QString, QString> m_titleLevels; 0171 0172 int m_currentCategory; 0173 int m_currentLanguage; 0174 0175 // language information 0176 QStringList m_languages; 0177 QStringList m_languageNames; 0178 0179 // Contains all the words that are read from the data file. 0180 QStringList m_specialCharacters; 0181 0182 //Theme manager 0183 KHMThemeFactory m_themeFactory; 0184 0185 //Config group 0186 KSharedConfig::Ptr m_config; 0187 0188 int m_winCount; 0189 int m_lossCount; 0190 0191 //The index to the random sequence 0192 int m_randomInt; 0193 0194 // Multiplying factor for scores 0195 int m_scoreMultiplyingFactor; 0196 0197 int m_netScore; 0198 0199 //The random sequence of words of the current level file 0200 QList<QPair<QString, QString> > m_randomList; 0201 0202 /** The word to be guessed */ 0203 QString m_originalWord; 0204 0205 /** The hidden word that is filled in during the game. */ 0206 QString m_currentWord; 0207 0208 //Current hint 0209 QString m_hint; 0210 }; 0211 0212 // kate: space-indent on; tab-width 4; indent-width 4; mixed-indent off; replace-tabs on; 0213 // vim: set et sw=4 ts=4 cino=l1,cs,U1: