2 Copyright (C) 2002-2005, Jason Katz-Brown <jasonkb@mit.edu>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef KOLF_CANVASITEM_H
20 #define KOLF_CANVASITEM_H
24 #include <QGraphicsView>
25 #include <QGraphicsRectItem>
37 CanvasItem() { game
= 0; }
38 virtual ~CanvasItem() {}
40 * load your settings from the KConfigGroup, which represents a course.
42 virtual void load(KConfigGroup
*) {}
44 * load a point if you wish. Rarely necessary.
46 virtual void loadState(StateDB
* /*db*/) {}
48 * returns a bool that is true if your item needs to load after other items
50 virtual bool loadLast() const { return false; }
52 * called if the item is made by user while editing, with the item that was selected on the hole;
54 virtual void selectedItem(QGraphicsItem
* /*item*/) {}
56 * called after the item is moved the very first time by the game
58 virtual void firstMove(int /*x*/, int /*y*/) {}
60 * used for resizing, also moves the item appropriately
62 virtual void resize(double /*resize factor*/) { kDebug(12007) << "Warning, empty resize used\n"; }
66 virtual void save(KConfigGroup
*cfg
);
68 * save a point if you wish. Rarely necessary.
70 virtual void saveState(StateDB
* /*db*/) {}
72 * called for information when shot started
74 virtual void shotStarted() {}
76 * called right before any items are saved.
78 virtual void aboutToSave() {}
80 * called right after all items are saved.
82 virtual void savingDone() {}
84 * called when the edit mode has been changed.
86 virtual void editModeChanged(bool /*editing*/) {}
88 * the item should delete any other objects it's created.
89 * DO NOT DO THIS KIND OF STUFF IN THE DESTRUCTOR!
91 virtual void aboutToDie() {}
93 * returns the object to get rid of when the delete button is pressed on this item. Some sub-objects will return something other than this.
95 virtual CanvasItem
*itemToDelete() { return this; }
97 * called when user presses delete key while editing. This is very rarely reimplemented, and generally shouldn't be.
99 virtual void aboutToDelete() {}
101 * returns whether this item should be able to be deleted by user while editing.
103 virtual bool deleteable() const { return true; }
105 * returns whether this item should get doAdvance called -- it is called in sync with ball advancing (which is twice as fast as the advance() calling rate)
107 virtual bool fastAdvance() const { return false; }
109 * called when all items have had their chance at a doAdvance
111 virtual void fastAdvanceDone() {}
113 * called if fastAdvance is enabled
115 virtual void doAdvance() {}
117 * if all items of this type of item (based on data()) that are "colliding" (ie, in the same spot) with ball should get collision() called.
119 virtual bool terrainCollisions() const { return false; }
121 * returns whether or not this item lifts items on top of it.
123 virtual bool vStrut() const { return false; }
125 * show extra item info
127 virtual void showInfo() {}
129 * hide extra item info
131 virtual void hideInfo() {}
133 * update your Z value (this is called by various things when perhaps the value should change) if this is called by a vStrut, it will pass 'this'.
135 virtual void updateZ(QGraphicsRectItem
* /*vStrut*/ = 0) {}
137 * clean up for prettyness
139 virtual void clean() {}
141 * scale factor changed (game->scaleFactor(), the world matrix is game->worldMatrix())
142 * NOTE: not used in Kolf 1.1, which comes with KDE 3.1.
144 virtual void scaleChanged() {}
146 * returns whether this item can be moved by others (if you want to move an item, you should honor this!)
148 virtual bool canBeMovedByOthers() const { return false; }
150 * returns a Config that can be used to configure this item by the user.
151 * The default implementation returns one that says 'No configuration options'.
153 virtual Config
*config(QWidget
*parent
) { return new DefaultConfig(parent
); }
155 * returns other items that should be moveable (besides this one of course).
157 virtual QList
<QGraphicsItem
*> moveableItems() const { return QList
<QGraphicsItem
*>(); }
159 * returns whether this can be moved by the user while editing.
161 virtual bool moveable() const { return true; }
163 void setId(int newId
) { id
= newId
; }
164 int curId() const { return id
; }
167 * call to play sound (ie, playSound("wall") plays kdedir/share/apps/kolf/sounds/wall.wav).
168 * optionally, specify vol to be between 0-1, for no sound to full volume, respectively.
170 void playSound(const QString
&file
, double vol
= 1);
173 * called on ball's collision. Return if terrain collidingItems should be processed.
175 virtual bool collision(Ball
* /*ball*/, long int /*id*/) { return false; }
178 * reimplement if you want extra items to have access to the game object.
179 * playSound() relies on having this.
181 virtual void setGame(KolfGame
*game
) { this->game
= game
; }
184 * returns whether this is a corner resizer
186 virtual bool cornerResize() const { return false; }
188 QString
name() const { return m_name
; }
189 void setName(const QString
&newname
) { m_name
= newname
; }
190 virtual void setSize(double /*width*/, double /*height*/) {;}
192 virtual void updateBaseResizeInfo() {}
195 * custom animation code
197 void setAnimated(bool animated
) { this->animated
=animated
; }
198 void setVelocity(double xv
, double yv
) { setXVelocity(xv
); setYVelocity(yv
); }
199 void setXVelocity(double xVelocity
) { this->xVelocity
=xVelocity
; }
200 void setYVelocity(double yVelocity
) { this->yVelocity
=yVelocity
; }
201 double getXVelocity() { return xVelocity
; }
202 double getYVelocity() { return yVelocity
; }
203 virtual void moveBy(double , double) { kDebug(12007) << "Warning, empty moveBy used";} //needed so that float can call the own custom moveBy()s of everything on it
207 * pointer to main KolfGame
212 * returns the highest vertical strut the item is on
214 QGraphicsRectItem
*onVStrut();
217 * custom animation code