File indexing completed on 2024-05-19 07:52:02

0001 /*
0002     This file is part of the game 'KJumpingCube'
0003 
0004     SPDX-FileCopyrightText: 1998-2000 Matthias Kiefer <matthias.kiefer@gmx.de>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef KCUBEBOXWIDGET_H
0010 #define KCUBEBOXWIDGET_H
0011 
0012 #include <QSvgRenderer>
0013 
0014 #include "ai_globals.h"
0015 #include "kcubewidget.h"
0016 
0017 #include <QWidget>
0018 #include <QPaintEvent>
0019 #include <QResizeEvent>
0020 #include <QList>
0021 
0022 class QTimer;
0023 class QLabel;
0024 
0025 class KCubeBoxWidget : public QWidget
0026 {
0027    Q_OBJECT
0028 public:
0029    explicit KCubeBoxWidget (const int dim = 1, QWidget * parent = nullptr);
0030 
0031    ~KCubeBoxWidget() override;
0032 
0033    void displayCube        (int index, Player owner, int value);
0034    void highlightCube      (int index, bool highlight);
0035    void timedCubeHighlight (int index);
0036    int  cubeValue          (int index) { return cubes.at(index)->value(); }
0037 
0038    /**
0039    * reset cubebox for a new game
0040    */
0041    void reset();
0042 
0043    /**
0044    * Set colors that are used to show owners of the cubes.
0045    */
0046    void setColors ();
0047 
0048    /**
0049    * Set the number of cubes in a row or column.  If the number has changed,
0050    * delete the existing set of cubes and create a new one.
0051    */
0052    virtual void setDim (int dim);
0053 
0054    void makeStatusPixmaps (const int width);
0055    const QPixmap & playerPixmap (const int p);
0056 
0057    /** sets the cursor to an waitcursor */
0058    void setWaitCursor();
0059    /** restores the original cursor */
0060    void setNormalCursor();
0061 
0062    bool loadSettings();
0063 
0064 Q_SIGNALS:
0065    void animationDone (int index);
0066    void mouseClick (int x, int y);
0067 
0068 protected:
0069    QSize sizeHint() const override;
0070    virtual void initCubes();
0071    void paintEvent (QPaintEvent * event) override;
0072    void resizeEvent (QResizeEvent * event) override;
0073 
0074 private:
0075    enum AnimationType {None, ComputerMove, Darken, RapidBlink, Scatter};
0076 
0077    void init();
0078 
0079    QSvgRenderer svg;
0080    void makeSVGBackground (const int w, const int h);
0081    void makeSVGCubes (const int width);
0082    void colorImage (QImage & img, const QColor & c, const int w);
0083    void reCalculateGraphics (const int w, const int h);
0084 
0085    int sWidth;          // Width of status pixmaps (used if recoloring).
0086    QPixmap status1;     // Status-bar pixmaps for players 1 and 2.
0087    QPixmap status2;
0088    QPixmap background;      // Pixmap for background.
0089    QList<QPixmap> elements; // Pixmaps for cubes, pips and blinking.
0090    QColor color1;       // Player 1's color.
0091    QColor color2;       // Player 2's color.
0092    QColor color0;       // Color for neutral cubes.
0093 
0094    QPoint topLeft;
0095    int cubeSize;
0096 
0097    int      m_side;
0098    QList<KCubeWidget *> cubes;
0099 
0100    QTimer *animationTimer;
0101 
0102    int  m_index;
0103    AnimationType cascadeAnimation;
0104    AnimationType currentAnimation;
0105    int  animationCount;
0106    int  animationSteps;
0107    int  animationTime;
0108 
0109    QTimer * m_highlightTimer;   // Timer for highlighted cube.
0110    int  m_highlighted;      // Cube that has been highlighted.
0111 
0112    QLabel * m_popup;
0113 
0114 public:
0115    /**
0116    * Starts the animation loop.
0117    */
0118    void startAnimation (bool cascading, int index);
0119    int killAnimation();
0120 
0121    void showPopup (const QString & message);
0122    void hidePopup();
0123 
0124 private:
0125    void setPopup();
0126    void scatterDots (int step);
0127 
0128 private Q_SLOTS:
0129    void nextAnimationStep();
0130    void highlightDone();    // Timeout of the highlighted cube.
0131 
0132    bool checkClick (int x, int y);
0133 };
0134 
0135 #endif // KCUBEBOXWIDGET_H