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_LANDSCAPE_H
21#define KOLF_LANDSCAPE_H
22
23//NOTE: Only refactored stuff goes into this header.
24
25#include "canvasitem.h"
26#include "config.h"
27#include "overlay.h"
28
29namespace Kolf
30{
31 class LandscapeItem : public EllipticalCanvasItem
32 {
33 Q_OBJECT
34 public:
35 LandscapeItem(const QString& type, QGraphicsItem* parent, b2World* world);
36
37 bool isBlinkEnabled() const;
38 int blinkInterval() const;
39 virtual void advance(int phase);
40
41 virtual void load(KConfigGroup* group);
42 virtual void save(KConfigGroup* group);
43
44 virtual Config* config(QWidget* parent);
45 public Q_SLOTS:
46 void setBlinkEnabled(bool blinkEnabled);
47 void setBlinkInterval(int blinkInterval);
48 protected:
49 virtual Kolf::Overlay* createOverlay();
50 private:
51 bool m_blinkEnabled;
52 int m_blinkInterval, m_blinkFrame;
53 };
54
55 class LandscapeOverlay : public Kolf::Overlay
56 {
57 Q_OBJECT
58 public:
59 LandscapeOverlay(Kolf::LandscapeItem* item);
60 virtual void update();
61 private Q_SLOTS:
62 //interface to handles
63 void moveHandle(const QPointF& handleScenePos);
64 private:
65 QList<Kolf::OverlayHandle*> m_handles;
66 };
67
68 class LandscapeConfig : public Config
69 {
70 Q_OBJECT
71 public:
72 LandscapeConfig(Kolf::LandscapeItem* item, QWidget* parent);
73 Q_SIGNALS:
74 void blinkIntervalChanged(int blinkInterval);
75 public Q_SLOTS:
76 void setBlinkInterval(int sliderValue);
77 };
78
79 class Puddle : public Kolf::LandscapeItem
80 {
81 public:
82 Puddle(QGraphicsItem* parent, b2World* world);
83 virtual bool collision(Ball* ball);
84 };
85
86 class Sand : public Kolf::LandscapeItem
87 {
88 public:
89 Sand(QGraphicsItem* parent, b2World* world);
90 virtual bool collision(Ball* ball);
91 };
92
93 enum SlopeType
94 {
95 VerticalSlope = 0,
96 HorizontalSlope,
97 DiagonalSlope,
98 CrossDiagonalSlope,
99 EllipticSlope
100 };
101
102 class Slope : public Tagaro::SpriteObjectItem, public CanvasItem
103 {
104 Q_OBJECT
105 public:
106 Slope(QGraphicsItem* parent, b2World* world);
107
108 double grade() const;
109 bool isReversed() const;
110 Kolf::SlopeType slopeType() const;
111 bool isStuckOnGround() const;
112
113 virtual QPainterPath shape() const;
114 virtual void setSize(const QSizeF& size);
115 virtual QPointF getPosition() const;
116 virtual void moveBy(double dx, double dy);
117
118 virtual void load(KConfigGroup* group);
119 virtual void save(KConfigGroup* group);
120
121 virtual bool collision(Ball* ball);
122 virtual bool terrainCollisions() const;
123 virtual QList<QGraphicsItem*> infoItems() const;
124 virtual Config* config(QWidget* parent);
125 public Q_SLOTS:
126 void setGrade(double grade);
127 void setReversed(bool reversed);
128 void setSlopeType(int type);
129 void setStuckOnGround(bool stuckOnGround);
130 protected:
131 virtual Kolf::Overlay* createOverlay();
132 private:
133 void updateAppearance();
134 void updateInfo();
135
136 double m_grade;
137 bool m_reversed, m_stuckOnGround;
138 Kolf::SlopeType m_type;
139
140 QGraphicsSimpleTextItem* m_gradeItem;
141 QList<ArrowItem*> m_arrows;
142 };
143
144 class SlopeConfig : public Config
145 {
146 public:
147 SlopeConfig(Kolf::Slope* slope, QWidget* parent);
148 };
149
150 class SlopeOverlay : public Kolf::Overlay
151 {
152 Q_OBJECT
153 public:
154 SlopeOverlay(Kolf::Slope* slope);
155 virtual void update();
156 private Q_SLOTS:
157 //interface to handles
158 void moveHandle(const QPointF& handleScenePos);
159 private:
160 QList<Kolf::OverlayHandle*> m_handles;
161 };
162}
163
164#endif // KOLF_LANDSCAPE_H
165