1 /* 2 * This file is part of Auralquiz 3 * Copyright 2011-2017 JanKusanagi JRR <jancoding@gmx.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the 17 * Free Software Foundation, Inc., 18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . 19 */ 20 21 #ifndef AURALWINDOW_H 22 #define AURALWINDOW_H 23 24 #include <QWidget> 25 #include <QSettings> 26 #include <QVBoxLayout> 27 #include <QHBoxLayout> 28 #include <QIcon> 29 #include <QLabel> 30 #include <QPixmap> 31 #include <QMovie> 32 #include <QPushButton> 33 #include <QProgressBar> 34 #include <QLCDNumber> 35 #include <QCloseEvent> 36 #include <QTimer> 37 #include <QDesktopServices> 38 #include <QDir> 39 #include <QFile> 40 #include <QString> 41 #include <QStringList> 42 #include <QGroupBox> 43 #include <QMessageBox> 44 #include <QTime> 45 #include <QKeySequence> 46 #include <QLibraryInfo> 47 48 #include <QDebug> 49 50 // FIXME: unnecessary? 51 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) 52 #include <phonon/MediaObject> 53 #include <phonon/BackendCapabilities> 54 #include <phonon/Global> 55 #else 56 #include <phonon4qt5/phonon/MediaObject> 57 #include <phonon4qt5/phonon/BackendCapabilities> 58 #include <phonon4qt5/phonon/Global> 59 #endif 60 61 #include "musicanalyzer.h" 62 #include "optionsdialog.h" 63 #include "answerbox.h" 64 #include "ranking.h" 65 66 67 68 #define MAXPLAYERS 8 69 70 71 class AuralWindow : public QWidget 72 { 73 Q_OBJECT 74 75 public: 76 AuralWindow(QWidget *parent = 0); 77 ~AuralWindow(); 78 79 void shuffleMusicFiles(); 80 void updateStatistics(); 81 82 void initWelcomeScreen(); 83 void initPlayingScreen(); 84 85 void toggleScreen(); 86 87 void setThemedColors(); 88 89 void enablePlayerInput(bool state); 90 91 92 protected: 93 void closeEvent(QCloseEvent *event); 94 95 96 public slots: 97 void playerStateChanged(Phonon::State newstate, 98 Phonon::State oldstate); 99 100 void timerTick(); 101 102 void updateConfig(bool startGame, QString directory, bool forceReload, 103 int difficulty, int questions, int players, 104 QStringList playerNameList, bool ownColors); 105 void showAbout(); 106 107 void modifyStartGameButton(bool enabledState, 108 QString text, 109 QString tooltip); 110 111 112 void newQuestion(); 113 void nextSongLoaded(); 114 void preQuestion(); 115 116 void answerQuestion(int numAnswer); 117 void answer1(); 118 void answer2(); 119 void answer3(); 120 void answer4(); 121 void answerFromAnswerBox(bool correct); 122 123 void confirmEndGame(); 124 125 void killRanking(); 126 127 private: 128 QVBoxLayout *mainLayout; 129 130 QWidget *welcomeWidget; 131 QVBoxLayout *welcomeLayout; 132 QLabel *logoLabel; 133 QPushButton *startGameButton; 134 QPushButton *configureButton; 135 QPushButton *aboutButton; 136 QPushButton *quitButton; 137 QAction *quitAction; 138 QTimer *postInitTimer; 139 QTimer *postConfigUpdatedTimer; 140 141 142 QWidget *playingWidget; 143 QVBoxLayout *playingLayout; 144 QVBoxLayout *playingTopLayout; 145 QHBoxLayout *playingMiddleLayout; 146 QVBoxLayout *statisticsLayout; 147 QVBoxLayout *answersLayout; 148 QHBoxLayout *playingProgressLayout; 149 QHBoxLayout *playingBottomLayout; 150 151 QTimer *preQuestionTimer; 152 QTimer *postQuestionTimer; 153 154 QLabel *playerNameLabel; 155 QLabel *questionLabel; 156 157 QLabel *infoLabel; 158 //const QString infoLabelCorrectStyle; 159 //const QString infoLabelWrongStyle; 160 //const QString infoLabelTimeUpStyle; 161 162 QLabel *aniNoteLabel; 163 QMovie aniNoteMovie; 164 QGroupBox *statisticsBox; 165 QVBoxLayout *statisticsBoxLayout; 166 QLabel *statisticsLabel; 167 QTimer *gameTimer; 168 QProgressBar *timeBar; 169 QProgressBar *gameProgressBar; 170 QLabel *gameScoreLabel; 171 QLCDNumber *gameScore; 172 173 QLabel *statusLabel; 174 QPushButton *endGameButton; 175 176 QPushButton *answerButton[4]; 177 QAction *answerAction1; 178 QAction *answerAction2; 179 QAction *answerAction3; 180 QAction *answerAction4; 181 182 Phonon::MediaObject *musicPlayer; 183 184 OptionsDialog *optionsDialog; // Options (configuration) window 185 186 MusicAnalyzer *musicAnalyzer; 187 188 189 bool firstRun; 190 bool useOwnColorTheme; 191 192 bool playing; 193 194 int difficultyLevel; 195 int numQuestions; 196 int numPlayers; 197 int currentPlayer; 198 199 QStringList playerNames; 200 201 int maxTime; // depends on difficulty 202 int warningTime; 203 int dangerTime; 204 205 int pieceDuration; 206 207 int questionType; 208 int correctAnswer; 209 210 int currentMusicFile; 211 QString musicDirectory; 212 QStringList musicFiles[4]; 213 QString dataDirectory; 214 215 216 // For statistics 217 QList<int> goodAnswers; 218 QList<int> badAnswers; 219 QList<int> timedOutAnswers; 220 QList<int> score; 221 222 // Widget for the "type-the-answer" mode 223 AnswerBox *answerBox; 224 225 // Ranking window 226 Ranking *ranking; 227 QTimer *rankingTimer; 228 }; 229 230 231 232 #endif // AURALWINDOW_H 233