Fix alpha setting in Designer's "Edit Palette" window
[qt-netbsd.git] / demos / sub-attaq / boat_p.h
blob692702b5d6e5b22f693d40b0dd1bc84d0c3f7a88
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the examples of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
42 #ifndef BOAT_P_H
43 #define BOAT_P_H
46 // W A R N I N G
47 // -------------
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
53 // We mean it.
56 //Own
57 #include "bomb.h"
58 #include "graphicsscene.h"
60 // Qt
61 #include <QtGui/QKeyEventTransition>
63 static const int MAX_BOMB = 5;
66 //These transtion test if we have to stop the boat (i.e current speed is 1)
67 class KeyStopTransition : public QKeyEventTransition
69 public:
70 KeyStopTransition(Boat *boat, QEvent::Type type, int key)
71 : QKeyEventTransition(boat, type, key)
73 this->boat = boat;
74 this->key = key;
76 protected:
77 virtual bool eventTest(QEvent *event)
79 Q_UNUSED(event);
80 if (!QKeyEventTransition::eventTest(event))
81 return false;
82 if (boat->currentSpeed() == 1)
83 return true;
84 else
85 return false;
87 private:
88 Boat * boat;
89 int key;
92 //These transtion test if we have to move the boat (i.e current speed was 0 or another value)
93 class KeyMoveTransition : public QKeyEventTransition
95 public:
96 KeyMoveTransition(Boat *boat, QEvent::Type type, int key)
97 : QKeyEventTransition(boat, type, key)
99 this->boat = boat;
100 this->key = key;
102 protected:
103 virtual bool eventTest(QEvent *event)
105 Q_UNUSED(event);
106 if (!QKeyEventTransition::eventTest(event))
107 return false;
108 if (boat->currentSpeed() >= 0)
109 return true;
110 else
111 return false;
114 void onTransition(QEvent *)
116 //We decrease the speed if needed
117 if (key == Qt::Key_Left && boat->currentDirection() == Boat::Right)
118 boat->setCurrentSpeed(boat->currentSpeed() - 1);
119 else if (key == Qt::Key_Right && boat->currentDirection() == Boat::Left)
120 boat->setCurrentSpeed(boat->currentSpeed() - 1);
121 else if (boat->currentSpeed() < 3)
122 boat->setCurrentSpeed(boat->currentSpeed() + 1);
123 boat->updateBoatMovement();
125 private:
126 Boat * boat;
127 int key;
130 //This transition trigger the bombs launch
131 class KeyLaunchTransition : public QKeyEventTransition
133 public:
134 KeyLaunchTransition(Boat *boat, QEvent::Type type, int key)
135 : QKeyEventTransition(boat, type, key)
137 this->boat = boat;
138 this->key = key;
140 protected:
141 virtual bool eventTest(QEvent *event)
143 Q_UNUSED(event);
144 if (!QKeyEventTransition::eventTest(event))
145 return false;
146 //We have enough bomb?
147 if (boat->bombsLaunched() < MAX_BOMB)
148 return true;
149 else
150 return false;
152 private:
153 Boat * boat;
154 int key;
157 //This state is describing when the boat is moving right
158 class MoveStateRight : public QState
160 public:
161 MoveStateRight(Boat *boat,QState *parent = 0) : QState(parent)
163 this->boat = boat;
165 protected:
166 void onEntry(QEvent *)
168 boat->setCurrentDirection(Boat::Right);
169 boat->updateBoatMovement();
171 private:
172 Boat * boat;
175 //This state is describing when the boat is moving left
176 class MoveStateLeft : public QState
178 public:
179 MoveStateLeft(Boat *boat,QState *parent = 0) : QState(parent)
181 this->boat = boat;
183 protected:
184 void onEntry(QEvent *)
186 boat->setCurrentDirection(Boat::Left);
187 boat->updateBoatMovement();
189 private:
190 Boat * boat;
193 //This state is describing when the boat is in a stand by position
194 class StopState : public QState
196 public:
197 StopState(Boat *boat,QState *parent = 0) : QState(parent)
199 this->boat = boat;
201 protected:
202 void onEntry(QEvent *)
204 boat->setCurrentSpeed(0);
205 boat->setCurrentDirection(Boat::None);
206 boat->updateBoatMovement();
208 private:
209 Boat * boat;
212 //This state is describing the launch of the torpedo on the right
213 class LaunchStateRight : public QState
215 public:
216 LaunchStateRight(Boat *boat,QState *parent = 0) : QState(parent)
218 this->boat = boat;
220 protected:
221 void onEntry(QEvent *)
223 Bomb *b = new Bomb();
224 b->setPos(boat->x()+boat->size().width(),boat->y());
225 GraphicsScene *scene = static_cast<GraphicsScene *>(boat->scene());
226 scene->addItem(b);
227 b->launch(Bomb::Right);
228 boat->setBombsLaunched(boat->bombsLaunched() + 1);
230 private:
231 Boat * boat;
234 //This state is describing the launch of the torpedo on the left
235 class LaunchStateLeft : public QState
237 public:
238 LaunchStateLeft(Boat *boat,QState *parent = 0) : QState(parent)
240 this->boat = boat;
242 protected:
243 void onEntry(QEvent *)
245 Bomb *b = new Bomb();
246 b->setPos(boat->x() - b->size().width(), boat->y());
247 GraphicsScene *scene = static_cast<GraphicsScene *>(boat->scene());
248 scene->addItem(b);
249 b->launch(Bomb::Left);
250 boat->setBombsLaunched(boat->bombsLaunched() + 1);
252 private:
253 Boat * boat;
256 #endif // BOAT_P_H