File indexing completed on 2024-04-21 04:05:09

0001 /*
0002     SPDX-FileCopyrightText: 2008 Ian Wadham <iandw.au@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KUBRICK_H
0008 #define KUBRICK_H
0009 
0010 #include <KXmlGuiWindow>
0011 #include <KSelectAction>
0012 #include <KShortcutsDialog>
0013 #include <KLazyLocalizedString>
0014 
0015 #include "kbkglobal.h"      // Needed for definition of SingmasterMove enum.
0016 
0017 class Game;
0018 class GameGLView;
0019 class QLabel;
0020 class QAction;
0021 class QLineEdit;
0022 class QAction;
0023 
0024 /**
0025  * @short Application Main Window
0026  * @author Ian Wadham <iandw.au@gmail.com>
0027  * @version 0.1
0028  */
0029 class Kubrick : public KXmlGuiWindow
0030 {
0031 public:
0032     /**
0033      * Default Constructor.
0034      */
0035     Kubrick ();
0036 
0037     /**
0038      * Default Destructor.
0039      */
0040     ~Kubrick () override;
0041 
0042     void setToggle      (const QString &actionName, bool onOff);
0043     void setAvail       (const QString &actionName, bool onOff);
0044     void setSingmaster  (const QString & smString);
0045     void setSingmasterSelection (const int start, const int length);
0046     void describePuzzle (int xDim, int yDim, int zDim, int shMoves);
0047 
0048     struct PuzzleItem {
0049     const KLazyLocalizedString menuText;        // Description of the puzzle, or "END".
0050     const int    x;         // X dimension.
0051     const int    y;         // Y dimension.
0052     const int    z;         // Z dimension.
0053     const int    shuffleMoves;  // Number of shuffling moves.
0054     const bool   viewShuffle;   // Whether to animate shuffling moves.
0055     const bool   viewMoves;     // Whether to animate the user's moves.
0056     };
0057 
0058 protected:
0059     /**
0060      * Initialise the GUI elements (menus, keystroke actions, etc.).
0061      */
0062     void initGUI();
0063 
0064     /**
0065      * Exit the program: invoked during Quit action or window-close by X-widget.
0066      * It saves the current cube and its state unconditionally, except when
0067      * there is a demo in progress and the player's cube and state have already
0068      * been saved.  This is as with a real Rubik Cube, which stays how it is
0069      * when you stop playing with it.
0070      */
0071     bool queryClose() override;
0072 
0073 protected:
0074     void optionsConfigureKeys();
0075 
0076     // Slots for puzzle-selection actions.
0077     void easySelected      (int index);
0078     void notSoEasySelected (int index);
0079     void hardSelected      (int index);
0080     void veryHardSelected  (int index);
0081 
0082     // Slots for demo-selection actions.
0083     void patternSelected   ();
0084     void movesSelected     ();
0085 
0086     void saveNewToolbarConfig() override;
0087 
0088 private:
0089     Game *       game;          // The game object.
0090     GameGLView * gameView;      // The main game view.
0091 
0092     QLineEdit *  singmasterMoves;   // A place to display Singmaster moves.
0093     QLabel *     singmasterLabel;
0094     QLabel *     statusBarLabel;
0095 
0096     static const PuzzleItem easyItems [];
0097     static const PuzzleItem notSoEasyItems [];
0098     static const PuzzleItem hardItems [];
0099     static const PuzzleItem veryHardItems [];
0100 
0101     struct DemoItem {
0102     QString filename;       // File containing demo or "END".
0103     const KLazyLocalizedString menuText;        // Description of the pattern or moves.
0104     };
0105     static const DemoItem patterns [];
0106     static const KLazyLocalizedString patternMovesInfo;
0107     static const DemoItem solvingMoves [];
0108     static const KLazyLocalizedString solvingMovesInfo;
0109 
0110     // Puzzle-selection actions.
0111     KSelectAction * easyList;
0112     KSelectAction * notSoEasyList;
0113     KSelectAction * hardList;
0114     KSelectAction * veryHardList;
0115 
0116     // Demo-selection actions.
0117     QList<QAction*> patternList;
0118     QList<QAction*> movesList;
0119 
0120     int fillPuzzleList (KSelectAction * s, const PuzzleItem itemList []);
0121     void fillDemoList  (const DemoItem itemList [], QList<QAction*> &list,
0122             const QString &uilist, void(Kubrick::*slot)());
0123 
0124     QAction * mapAction (const QString & name,
0125     const QString & text, const Qt::Key key, SingmasterMove mapping);
0126 };
0127 
0128 #endif // KUBRICK_H