1 | /* **************************************************************************** |
2 | This file is part of the game 'KJumpingCube' |
3 | |
4 | Copyright (C) 1998-2000 by Matthias Kiefer |
5 | <matthias.kiefer@gmx.de> |
6 | |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | |
21 | **************************************************************************** */ |
22 | #ifndef KCUBEBOXWIDGET_H |
23 | #define KCUBEBOXWIDGET_H |
24 | |
25 | #include <QSvgRenderer> |
26 | |
27 | #include "ai_globals.h" |
28 | #include "kcubewidget.h" |
29 | |
30 | #include <QWidget> |
31 | #include <QPaintEvent> |
32 | #include <QResizeEvent> |
33 | #include <QList> |
34 | |
35 | class KConfigGroup; |
36 | class QTimer; |
37 | class QLabel; |
38 | |
39 | class KCubeBoxWidget : public QWidget |
40 | { |
41 | Q_OBJECT |
42 | public: |
43 | explicit KCubeBoxWidget (const int dim = 1, QWidget * parent = 0); |
44 | |
45 | virtual ~KCubeBoxWidget(); |
46 | |
47 | void displayCube (int index, Player owner, int value); |
48 | void highlightCube (int index, bool highlight); |
49 | void timedCubeHighlight (int index); |
50 | int cubeValue (int index) { return cubes.at(index)->value(); } |
51 | |
52 | /** |
53 | * reset cubebox for a new game |
54 | */ |
55 | void reset(); |
56 | |
57 | /** |
58 | * Set colors that are used to show owners of the cubes. |
59 | */ |
60 | void setColors (); |
61 | |
62 | /** |
63 | * Set the number of cubes in a row or column. If the number has changed, |
64 | * delete the existing set of cubes and create a new one. |
65 | */ |
66 | virtual void setDim (int dim); |
67 | |
68 | void makeStatusPixmaps (const int width); |
69 | const QPixmap & playerPixmap (const int p); |
70 | |
71 | /** sets the cursor to an waitcursor */ |
72 | void setWaitCursor(); |
73 | /** restores the original cursor */ |
74 | void setNormalCursor(); |
75 | |
76 | bool loadSettings(); |
77 | |
78 | signals: |
79 | void animationDone (int index); |
80 | void mouseClick (int x, int y); |
81 | |
82 | protected: |
83 | virtual QSize sizeHint() const; |
84 | virtual void initCubes(); |
85 | virtual void paintEvent (QPaintEvent * event); |
86 | virtual void resizeEvent (QResizeEvent * event); |
87 | |
88 | private: |
89 | enum AnimationType {None, ComputerMove, Darken, RapidBlink, Scatter}; |
90 | |
91 | void init(); |
92 | |
93 | QSvgRenderer svg; |
94 | void makeSVGBackground (const int w, const int h); |
95 | void makeSVGCubes (const int width); |
96 | void colorImage (QImage & img, const QColor & c, const int w); |
97 | void reCalculateGraphics (const int w, const int h); |
98 | |
99 | int sWidth; // Width of status pixmaps (used if recoloring). |
100 | QPixmap status1; // Status-bar pixmaps for players 1 and 2. |
101 | QPixmap status2; |
102 | QPixmap background; // Pixmap for background. |
103 | QList<QPixmap> elements; // Pixmaps for cubes, pips and blinking. |
104 | QColor color1; // Player 1's color. |
105 | QColor color2; // Player 2's color. |
106 | QColor color0; // Color for neutral cubes. |
107 | |
108 | QPoint topLeft; |
109 | int cubeSize; |
110 | |
111 | int m_side; |
112 | QList<KCubeWidget *> cubes; |
113 | |
114 | QTimer *animationTimer; |
115 | |
116 | int m_index; |
117 | AnimationType cascadeAnimation; |
118 | AnimationType currentAnimation; |
119 | int animationCount; |
120 | int animationSteps; |
121 | int animationTime; |
122 | |
123 | QTimer * m_highlightTimer; // Timer for highlighted cube. |
124 | int m_highlighted; // Cube that has been highlighted. |
125 | |
126 | QLabel * ; |
127 | |
128 | public: |
129 | /** |
130 | * Starts the animation loop. |
131 | */ |
132 | void startAnimation (bool cascading, int index); |
133 | int killAnimation(); |
134 | |
135 | void (const QString & message); |
136 | void (); |
137 | |
138 | private: |
139 | void (); |
140 | void scatterDots (int step); |
141 | |
142 | private slots: |
143 | void nextAnimationStep(); |
144 | void highlightDone(); // Timeout of the highlighted cube. |
145 | |
146 | bool checkClick (int x, int y); |
147 | }; |
148 | |
149 | #endif // KCUBEBOXWIDGET_H |
150 | |