File indexing completed on 2024-04-28 04:05:20

0001 /*
0002     SPDX-FileCopyrightText: 2015 Jakob Gruber <jakob.gruber@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef MAINWINDOW_H
0008 #define MAINWINDOW_H
0009 
0010 #include <config.h>
0011 
0012 #include <QTimer>
0013 #include <QAction>
0014 
0015 #include <KToggleAction>
0016 #include <KXmlGuiWindow>
0017 
0018 #include <KGameHighScoreDialog>
0019 #include <KGameDifficulty>
0020 
0021 #include "view.h"
0022 
0023 class Level;
0024 class Picmi;
0025 class Scene;
0026 class QLabel;
0027 
0028 class MainWindow : public KXmlGuiWindow
0029 {
0030     Q_OBJECT
0031 public:
0032     explicit MainWindow(QWidget *parent = nullptr);
0033 
0034 protected:
0035     void closeEvent(QCloseEvent *event) override;
0036 
0037 private Q_SLOTS:
0038     void startRandomGame();
0039     void restartGame();
0040     void togglePaused(bool paused);
0041     void settings();
0042     void gameCompleted();
0043     void gameWon();
0044     void undo();
0045     void hint();
0046     void solve();
0047     void saveState();
0048     void loadState();
0049     void highscores();
0050     void levelChanged(const KGameDifficultyLevel* level);
0051     void updatePlayedTime();
0052     void updatePositions();
0053     void loadBoard();
0054     void toggleFullscreen(bool full_screen);
0055 
0056     /* Enable or disable undo/save state related actions. */
0057     void undoStackSizeChanged(int size);
0058     void saveStackSizeChanged(int size);
0059 
0060 private:
0061     enum Mode {
0062         Random, /* board is randomly generated, highscores enabled */
0063         Preset  /* board is fixed, highscores disabled */
0064     };
0065 
0066     void startGame();
0067     void startPresetGame(QSharedPointer<Level> board);
0068 
0069     void restoreWindowState();
0070     void saveWindowState();
0071     void pauseGame();
0072     QSharedPointer<KGameHighScoreDialog> createScoreDialog();
0073     void setupActions();
0074 
0075     QAction *m_action_undo,
0076             *m_action_save_state,
0077             *m_action_load_state,
0078             *m_action_hint,
0079             *m_action_solve;
0080     KToggleAction *m_action_pause;
0081     QLabel *m_status_time, *m_status_position;
0082     QPushButton *m_new_game, *m_load_game;
0083     View m_view;
0084     QSharedPointer<Picmi> m_game;
0085     QSharedPointer<Scene> m_scene;
0086     QTimer m_timer;
0087 
0088     const QString m_key_pos;
0089 
0090     bool m_in_progress;
0091     enum Mode m_mode;
0092 
0093     QSharedPointer<Level> m_current_level;
0094 };
0095 
0096 #endif // MAINWINDOW_H