1/*
2 Copyright (C) 2002-2005, Jason Katz-Brown <jasonkb@mit.edu>
3 Copyright 2010 Stefan Majewsky <majewsky@gmx.net>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20#ifndef KOLF_OBSTACLES_H
21#define KOLF_OBSTACLES_H
22
23//NOTE: Only refactored stuff goes into this header.
24
25#include "config.h"
26#include "canvasitem.h"
27#include "overlay.h"
28
29#include <QPen>
30
31class QCheckBox;
32class QGridLayout;
33
34namespace Kolf
35{
36 class LineShape;
37 class RectShape;
38
39 class Bumper : public EllipticalCanvasItem
40 {
41 Q_OBJECT
42 public:
43 Bumper(QGraphicsItem* parent, b2World* world);
44
45 virtual bool collision(Ball* ball);
46 protected:
47 virtual Kolf::Overlay* createOverlay();
48 public Q_SLOTS:
49 void turnBumperOff();
50 };
51
52 class Wall : public QGraphicsLineItem, public CanvasItem
53 {
54 public:
55 Wall(QGraphicsItem* parent, b2World* world);
56
57 virtual void load(KConfigGroup* cfgGroup);
58 virtual void save(KConfigGroup* cfgGroup);
59 void setVisible(bool visible);
60
61 virtual void setLine(const QLineF& line);
62 virtual void moveBy(double dx, double dy);
63 virtual QPointF getPosition() const;
64 protected:
65 virtual Kolf::Overlay* createOverlay();
66 private:
67 Kolf::LineShape* m_shape;
68 };
69
70 class WallOverlay : public Kolf::Overlay
71 {
72 Q_OBJECT
73 public:
74 WallOverlay(Kolf::Wall* wall);
75 virtual void update();
76 private Q_SLOTS:
77 //interface to handles
78 void moveHandle(const QPointF& handleScenePos);
79 private:
80 Kolf::OverlayHandle* m_handle1;
81 Kolf::OverlayHandle* m_handle2;
82 };
83
84 //WARNING: WallIndex and WallFlag have to stay in sync like they are now!
85 enum WallIndex {
86 TopWallIndex = 0,
87 LeftWallIndex = 1,
88 RightWallIndex = 2,
89 BottomWallIndex = 3,
90 RectangleWallCount = 4
91 };
92
93 class RectangleItem : public Tagaro::SpriteObjectItem, public CanvasItem
94 {
95 Q_OBJECT
96 public:
97 RectangleItem(const QString& type, QGraphicsItem* parent, b2World* world);
98 virtual ~RectangleItem();
99
100 bool hasWall(Kolf::WallIndex index) const;
101 bool isWallAllowed(Kolf::WallIndex index) const;
102 void setWall(Kolf::WallIndex index, bool hasWall);
103 void setWallAllowed(Kolf::WallIndex index, bool wallAllowed);
104 virtual void setSize(const QSizeF& size);
105 virtual QPointF getPosition() const;
106 virtual void moveBy(double dx, double dy);
107
108 void setWallColor(const QColor& color);
109 void applyWallStyle(Kolf::Wall* wall, bool adjustPainting = true);
110
111 virtual void load(KConfigGroup* group);
112 virtual void save(KConfigGroup* group);
113
114 virtual Config* config(QWidget* parent);
115 Q_SIGNALS:
116 void wallChanged(Kolf::WallIndex index, bool hasWall, bool wallAllowed);
117 protected:
118 virtual Kolf::Overlay* createOverlay();
119 virtual void updateWallPosition();
120 private:
121 QPen m_wallPen;
122 QVector<bool> m_wallAllowed;
123 QVector<Kolf::Wall*> m_walls;
124 Kolf::RectShape* m_shape;
125 };
126
127 class RectangleOverlay : public Kolf::Overlay
128 {
129 Q_OBJECT
130 public:
131 RectangleOverlay(Kolf::RectangleItem* item);
132 virtual void update();
133 private Q_SLOTS:
134 //interface to handles
135 void moveHandle(const QPointF& handleScenePos);
136 private:
137 QList<Kolf::OverlayHandle*> m_handles;
138 };
139
140 class RectangleConfig : public Config
141 {
142 Q_OBJECT
143 public:
144 RectangleConfig(Kolf::RectangleItem* item, QWidget* parent);
145 protected Q_SLOTS:
146 void setWall(bool hasWall);
147 void wallChanged(Kolf::WallIndex index, bool hasWall, bool wallAllowed);
148 protected:
149 QGridLayout* m_layout;
150 QVector<QCheckBox*> m_wallCheckBoxes;
151 Kolf::RectangleItem* const m_item;
152 };
153
154 class Bridge : public Kolf::RectangleItem
155 {
156 public:
157 Bridge(QGraphicsItem* parent, b2World* world);
158 virtual bool collision(Ball* ball);
159 };
160
161 class Floater : public Kolf::RectangleItem
162 {
163 Q_OBJECT
164 public:
165 Floater(QGraphicsItem* parent, b2World* world);
166 virtual void editModeChanged(bool changed);
167 virtual void moveBy(double dx, double dy);
168
169 QLineF motionLine() const;
170 void setMotionLine(const QLineF& motionLine);
171 int speed() const;
172 virtual void advance(int phase);
173
174 virtual void load(KConfigGroup* group);
175 virtual void save(KConfigGroup* group);
176 public Q_SLOTS:
177 void setSpeed(int speed);
178 protected:
179 virtual Kolf::Overlay* createOverlay();
180 private:
181 void setMlPosition(qreal position);
182
183 QLineF m_motionLine;
184 int m_speed;
185 qreal m_velocity;
186 qreal m_position; //parameter on motion line (see QLineF::pointAt)
187 bool m_moveByMovesMotionLine, m_animated;
188 };
189
190 class FloaterOverlay : public Kolf::RectangleOverlay
191 {
192 Q_OBJECT
193 public:
194 FloaterOverlay(Kolf::Floater* floater);
195 virtual void update();
196 private Q_SLOTS:
197 //interface to handles
198 void moveMotionLineHandle(const QPointF& handleScenePos);
199 private:
200 Kolf::OverlayHandle* m_handle1;
201 Kolf::OverlayHandle* m_handle2;
202 QGraphicsLineItem* m_motionLineItem;
203 };
204
205 class Sign : public Kolf::RectangleItem
206 {
207 Q_OBJECT
208 public:
209 Sign(QGraphicsItem* parent, b2World* world);
210
211 QString text() const;
212 virtual void setSize(const QSizeF& size);
213
214 virtual void load(KConfigGroup* group);
215 virtual void save(KConfigGroup* group);
216 public Q_SLOTS:
217 void setText(const QString& text);
218 private:
219 QString m_text;
220 QGraphicsTextItem* m_textItem;
221 };
222
223 class Windmill : public Kolf::RectangleItem
224 {
225 Q_OBJECT
226 public:
227 Windmill(QGraphicsItem* parent, b2World* world);
228 virtual ~Windmill();
229
230 bool guardAtTop() const;
231 int speed() const;
232 virtual void advance(int phase);
233 virtual void moveBy(double dx, double dy);
234
235 virtual void load(KConfigGroup* group);
236 virtual void save(KConfigGroup* group);
237 public Q_SLOTS:
238 void setGuardAtTop(bool guardAtTop);
239 void setSpeed(int speed);
240 protected:
241 virtual void updateWallPosition();
242 private:
243 Kolf::Wall* m_leftWall;
244 Kolf::Wall* m_rightWall;
245 Kolf::Wall* m_guardWall;
246 bool m_guardAtTop;
247 int m_speed;
248 double m_velocity;
249 };
250}
251
252#endif // KOLF_OBSTACLES_H
253