File indexing completed on 2024-10-13 03:43:39

0001 /*
0002     SPDX-FileCopyrightText: 2002 Marco Krüger <grisuji@gmx.de>
0003     SPDX-FileCopyrightText: 2002 Ian Wadham <iandw.au@gmail.com>
0004     SPDX-FileCopyrightText: 2009 Ian Wadham <iandw.au@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef KGOLDRUNNER_H
0010 #define KGOLDRUNNER_H
0011 
0012 #include "kgrglobals.h"
0013 
0014 #include <KXmlGuiWindow>
0015 
0016 class QAction;
0017 class KToggleAction;
0018 
0019 class KGrGame;
0020 class KGrView;
0021 class KGrScene;
0022 class KGrRenderer;
0023 
0024 /**
0025  * This class serves as the main window for KGoldrunner.  It handles the menu,
0026  * toolbar and keystroke actions and sets up the game, scene and view.
0027  *
0028  * @short Main window class
0029  */
0030 class KGoldrunner : public KXmlGuiWindow
0031 {
0032     Q_OBJECT
0033 public:
0034     /**
0035      * Default Constructor
0036      */
0037     KGoldrunner();
0038 
0039     /**
0040      * Default Destructor
0041      */
0042     ~KGoldrunner() override;
0043 
0044     /**
0045      * Used to indicate if the class initialised properly.
0046      */
0047     bool startedOK() {return (startupOK);}
0048 
0049     void setToggle      (const QString &actionName, const bool onOff);
0050     void setAvail       (const QString &actionName, const bool onOff);
0051     void redrawEditToolbar();
0052 
0053 protected:
0054     void keyPressEvent (QKeyEvent * event) override;
0055     void keyReleaseEvent (QKeyEvent * event) override;
0056 
0057 private:
0058     void setUpKeyboardControl();
0059     bool identifyMoveAction (QKeyEvent * event, bool pressed);
0060 
0061 protected:
0062     /**
0063      * This function is called when it is time for the app to save its
0064      * properties for session management purposes.
0065      */
0066     void saveProperties (KConfigGroup &) override;
0067 
0068     /**
0069      * This function is called when this app is restored.  The KConfig
0070      * object points to the session management config file that was saved
0071      * with @ref saveProperties.
0072      */
0073     void readProperties (const KConfigGroup &) override;
0074 
0075     /// To save edits before closing.
0076     bool queryClose() override;
0077 
0078 private Q_SLOTS:
0079     // An extension of the constructor.  Gives us two scans of the event queue.
0080     void KGoldrunner_2();
0081 
0082     // Slot to change the graphics theme.
0083     void changeTheme ();
0084 
0085     void optionsConfigureKeys();
0086 
0087     void gameFreeze (bool);     // Status feedback on Pause state.
0088 
0089     void adjustHintAction (bool);   // Enable/disable "Hint" action.
0090     void setEditMenu (bool on_off); // Enable/disable "Save Edits" action.
0091     void setEditIcon (const QString & actionName, const char iconType);
0092     void viewFullScreen (bool activation);
0093 
0094     QSize sizeHint() const override;
0095 
0096 private:
0097     void setupActions();
0098     void setupEditToolbarActions();
0099 
0100     QAction * gameAction (const QString & name, const int code,
0101                           const QString & text, const QString & toolTip,
0102                           const QString & whatsThis, const QKeySequence & key);
0103 
0104     QAction * editAction (const QString & name, const int code,
0105                           const QString & text, const QString & toolTip,
0106                           const QString & whatsThis);
0107 
0108     KToggleAction * settingAction (const QString & name,
0109                                    const int       code,
0110                                    const QString & text,
0111                                    const QString & toolTip,
0112                                    const QString & whatsThis);
0113 
0114     KToggleAction * editToolbarAction
0115                          (const QString & name, const char code,
0116                           const QString & shortText, const QString & text,
0117                           const QString & toolTip, const QString & whatsThis);
0118 
0119     void keyControl      (const QString & name, const QString & text,
0120                           const QKeySequence & shortcut, const int code,
0121                           const bool mover = false);
0122 
0123     void keyControlDebug (const QString & name, const QString & text,
0124                           const QKeySequence & shortcut, const int code,
0125                           const bool mover = false);
0126 
0127     bool startupOK;
0128 
0129     KGrGame     *   game;       // Overall control of the gameplay.
0130 
0131     KGrView     *   view;       // Central widget.
0132     KGrScene    *   scene;      // Sets text for game-status messages.
0133     KGrRenderer *   renderer;       // Changes themes and gets icon pixmaps.
0134 
0135     bool frozen;
0136     bool getDirectories();      // Get directory paths, as below.
0137 
0138     QString systemDataDir;      // Where the system levels are stored.
0139     QString userDataDir;        // Where the user levels are stored.
0140 
0141     QAction *       saveGame;   // Save game, level, lives and score.
0142 
0143     // A QAction is needed here, to get access to KShortcut::setAlternate().
0144     QAction *       myPause;    // Pause or resume the game.
0145 
0146     QAction *       hintAction; // Display a hint, if available.
0147     QAction *       killHero;   // Kill hero (disabled during edits).
0148     QAction *       highScore;  // High scores (disabled during edits).
0149 
0150     QAction *       saveEdits;  // Save a level that has been edited.
0151 
0152     KToolBar *      editToolbar;    // Toolbar for creating/editing levels.
0153 };
0154 
0155 #endif // KGOLDRUNNER_H