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 KCUBEWIDGET_H
23#define KCUBEWIDGET_H
24
25#include <QFrame>
26#include "ai_globals.h"
27
28enum SVGElement {Neutral, Player1, Player2, Pip, BlinkLight, BlinkDark,
29 FirstElement = Neutral, LastElement = BlinkDark};
30
31class QMouseEvent;
32class QPaintEvent;
33
34/**
35*
36*/
37class KCubeWidget : public QFrame
38{
39 Q_OBJECT
40
41public:
42 /** constructs a new KCubeWidget*/
43 explicit KCubeWidget (QWidget * parent = 0);
44 virtual ~KCubeWidget();
45
46 Player owner() { return m_owner; }
47 int value() { return m_value; }
48
49 void setOwner (Player newOwner);
50 void setValue (int newValue);
51 void setPixmaps (QList<QPixmap> * ptr);
52
53 /**
54 * sets the coordinates of the Cube in a Cubebox;
55 * needed for identification when clicked.
56 */
57 void setCoordinates (int row, int col, int limit);
58
59 /** enables or disables possibility to click a cube*/
60 static void enableClicks(bool flag);
61
62 void setLight() { blinking = Light; update(); }
63 void setDark() { blinking = Dark; update(); }
64 void setNeutral() { blinking = None; update(); }
65 bool isNeutral() { return (blinking == None); }
66
67 void shrink (qreal scale);
68 void expand (qreal scale);
69 void migrateDot (int rowDiff, int colDiff, int step, Player player);
70
71public slots:
72 /** resets the Cube to default values */
73 virtual void reset();
74 /** shows changed colors*/
75 virtual void updateColors();
76
77signals:
78 void clicked (int row, int column);
79
80protected:
81 /** checks, if mouseclick was inside this cube*/
82 virtual void mouseReleaseEvent(QMouseEvent*);
83
84 /** refreshes the contents of the Cube */
85 virtual void paintEvent(QPaintEvent*);
86
87private:
88 int m_row;
89 int m_col;
90 int m_limit;
91 Player m_owner;
92 int m_value;
93
94 QList<QPixmap> * pixmaps;
95 enum Blink {None, Light, Dark};
96 Blink blinking;
97
98 static bool _clicksAllowed;
99 int migrating;
100 qreal m_rowDiff;
101 qreal m_colDiff;
102 Player m_player;
103 qreal m_scale;
104 qreal m_opacity;
105};
106
107#endif // KCUBEWIDGET_H
108