1 /* 2 This file is part of the game 'KJumpingCube' 3 4 SPDX-FileCopyrightText: 1998-2000 Matthias Kiefer <matthias.kiefer@gmx.de> 5 6 SPDX-License-Identifier: GPL-2.0-or-later 7 */ 8 9 #ifndef KCUBEBOXWIDGET_H 10 #define KCUBEBOXWIDGET_H 11 12 #include <QSvgRenderer> 13 14 #include "ai_globals.h" 15 #include "kcubewidget.h" 16 17 #include <QWidget> 18 #include <QPaintEvent> 19 #include <QResizeEvent> 20 #include <QList> 21 22 class QTimer; 23 class QLabel; 24 25 class KCubeBoxWidget : public QWidget 26 { 27 Q_OBJECT 28 public: 29 explicit KCubeBoxWidget (const int dim = 1, QWidget * parent = nullptr); 30 31 ~KCubeBoxWidget() override; 32 33 void displayCube (int index, Player owner, int value); 34 void highlightCube (int index, bool highlight); 35 void timedCubeHighlight (int index); cubeValue(int index)36 int cubeValue (int index) { return cubes.at(index)->value(); } 37 38 /** 39 * reset cubebox for a new game 40 */ 41 void reset(); 42 43 /** 44 * Set colors that are used to show owners of the cubes. 45 */ 46 void setColors (); 47 48 /** 49 * Set the number of cubes in a row or column. If the number has changed, 50 * delete the existing set of cubes and create a new one. 51 */ 52 virtual void setDim (int dim); 53 54 void makeStatusPixmaps (const int width); 55 const QPixmap & playerPixmap (const int p); 56 57 /** sets the cursor to an waitcursor */ 58 void setWaitCursor(); 59 /** restores the original cursor */ 60 void setNormalCursor(); 61 62 bool loadSettings(); 63 64 Q_SIGNALS: 65 void animationDone (int index); 66 void mouseClick (int x, int y); 67 68 protected: 69 QSize sizeHint() const override; 70 virtual void initCubes(); 71 void paintEvent (QPaintEvent * event) override; 72 void resizeEvent (QResizeEvent * event) override; 73 74 private: 75 enum AnimationType {None, ComputerMove, Darken, RapidBlink, Scatter}; 76 77 void init(); 78 79 QSvgRenderer svg; 80 void makeSVGBackground (const int w, const int h); 81 void makeSVGCubes (const int width); 82 void colorImage (QImage & img, const QColor & c, const int w); 83 void reCalculateGraphics (const int w, const int h); 84 85 int sWidth; // Width of status pixmaps (used if recoloring). 86 QPixmap status1; // Status-bar pixmaps for players 1 and 2. 87 QPixmap status2; 88 QPixmap background; // Pixmap for background. 89 QList<QPixmap> elements; // Pixmaps for cubes, pips and blinking. 90 QColor color1; // Player 1's color. 91 QColor color2; // Player 2's color. 92 QColor color0; // Color for neutral cubes. 93 94 QPoint topLeft; 95 int cubeSize; 96 97 int m_side; 98 QList<KCubeWidget *> cubes; 99 100 QTimer *animationTimer; 101 102 int m_index; 103 AnimationType cascadeAnimation; 104 AnimationType currentAnimation; 105 int animationCount; 106 int animationSteps; 107 int animationTime; 108 109 QTimer * m_highlightTimer; // Timer for highlighted cube. 110 int m_highlighted; // Cube that has been highlighted. 111 112 QLabel * m_popup; 113 114 public: 115 /** 116 * Starts the animation loop. 117 */ 118 void startAnimation (bool cascading, int index); 119 int killAnimation(); 120 121 void showPopup (const QString & message); 122 void hidePopup(); 123 124 private: 125 void setPopup(); 126 void scatterDots (int step); 127 128 private Q_SLOTS: 129 void nextAnimationStep(); 130 void highlightDone(); // Timeout of the highlighted cube. 131 132 bool checkClick (int x, int y); 133 }; 134 135 #endif // KCUBEBOXWIDGET_H 136