File indexing completed on 2024-04-21 04:02:03

0001 /*
0002     KBlackBox - A simple game inspired by an emacs module
0003 
0004     SPDX-FileCopyrightText: 2007 Nicolas Roffet <nicolas-kde@roffet.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef KBBTUTORIAL_H
0010 #define KBBTUTORIAL_H
0011 
0012 
0013 
0014 #include <QGroupBox>
0015 class QHideEvent;
0016 class QLabel;
0017 class QProgressBar;
0018 class QWidget;
0019 
0020 
0021 class QPushButton;
0022 class KTextEdit;
0023 
0024 
0025 class KBBGraphicsItemTutorialMarker;
0026 class KBBScalableGraphicWidget;
0027 
0028 
0029 
0030 /**
0031  * @brief Tutorial widget
0032  */
0033 class KBBTutorial : public QGroupBox
0034 {
0035     Q_OBJECT
0036 
0037     public:
0038         /**
0039          * @brief Number of balls in the tutorial
0040          */
0041         static int const BALLS = 3;
0042 
0043         /**
0044          * @brief Number of columns in the tutorial
0045          */
0046         static int const COLUMNS = 6;
0047 
0048         /**
0049          * @brief Number of rows in the tutorial
0050          */
0051         static int const ROWS = 6;
0052 
0053 
0054         /**
0055          * @brief Constructor
0056          */
0057         explicit KBBTutorial(QWidget* parent);
0058 
0059 
0060         /**
0061          * @brief Event: Leaving the tutorial
0062          *
0063          * Called by exiting the tutorial
0064          */
0065         void hideEvent(QHideEvent*) override;
0066 
0067         /**
0068          * @brief May the player solve the running game?
0069          *
0070          * The player may solve the game only at the end of the tutorial during the last step.
0071          */
0072         bool maySolve();
0073 
0074         /**
0075          * @brief May the player shoot the ray?
0076          *
0077          * The player may only shoot given rays during the tutorial (except during the last step).
0078          */
0079         bool mayShootRay(const int incomingPosition);
0080 
0081         /**
0082          * @brief Define the scalable graphic widget
0083          */
0084         void setGameWidget(KBBScalableGraphicWidget* gameWidget, KBBGraphicsItemTutorialMarker* marker);
0085 
0086         /**
0087          * @brief Go to the given tutorial step
0088          */
0089         void setStep(const int step);
0090 
0091         /**
0092          * @brief Start the tutorial
0093          * Start or restart the tutorial at the 1st step.
0094          */
0095         void start();
0096 
0097 
0098     private Q_SLOTS:
0099         /**
0100          * @brief Go to the next tutorial step
0101          */
0102         void nextStep();
0103 
0104         /**
0105          * @brief Go to the previous tutorial step
0106          */
0107         void previousStep();
0108 
0109         /**
0110          * @brief Restore the default style of the label m_playerAction
0111          *
0112          * This slot is called by the timer.
0113          */
0114         void restoreStyle();
0115 
0116 
0117     private:
0118         /**
0119          * @brief First tutorial step
0120          */
0121         static int const FIRST_STEP = 1;
0122 
0123         /**
0124          * @brief Time to highlight the label m_playerAction
0125          *
0126          * If the player clicks on a disabled laser, the label m_playerAction is highlighted during this time (in ms).
0127          */
0128         static int const HIGHLIGHT_TIME = 600;
0129 
0130         /**
0131          * @brief Last tutorial step
0132          */
0133         static int const LAST_STEP = 11;
0134 
0135         /**
0136          * @brief Position of laser, if laser may not be used
0137          */
0138         static int const MAY_NOT_USE = -1;
0139 
0140         /**
0141          * @brief Fixed width and minimum height
0142          *
0143          * This is the fixed width and the minimum height of the widget. The widget needs a minimal size: it is ugly if it is too small.
0144          */
0145         static int const WIDTH = 275;
0146 
0147 
0148         /**
0149          * @brief define the maximal step
0150          *
0151          * The player may just navigate between the steps he already read.
0152          */
0153         void setNewStepMaxAllowed(const int newStepMax);
0154 
0155         /**
0156          * @brief Set the title and the main text
0157          */
0158         void setTexts(const QString &title, const QString &text, const QString &action);
0159 
0160         /**
0161          * @brief Show tutorial marker on the board
0162          */
0163         void showMarker(const int laserPosition) const;
0164 
0165 
0166         QPushButton* m_buttonNext;
0167         QPushButton* m_buttonPrevious;
0168         KTextEdit* m_explanation;
0169         KBBScalableGraphicWidget* m_gameWidget;
0170         int m_laserToUse;
0171         KBBGraphicsItemTutorialMarker* m_marker;
0172         QLabel* m_playerAction;
0173         QProgressBar* m_progression;
0174 
0175         /**
0176          * @brief Tutorial step number
0177          */
0178         int m_step;
0179 
0180         int m_stepMaxAllowed;
0181         QLabel* m_title;
0182 };
0183 
0184 #endif //KBBTUTORIAL_H