2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
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.
14 #include <boost/shared_ptr.hpp>
15 #include "clickablecanvas.h"
16 #include "indexconverter.h"
17 #include "namedsprite_utils.h"
18 #include "pixmaploader.h"
20 class AnimationManager
;
25 * @class PiecePool <piecepool.h>
26 * @brief The class representing a crazyhouse-like piece pool.
28 * PiecePool is a canvas item attached to a Board that keeps a
29 * stack of pieces and lets you drop them on the board, notifying
32 class PiecePool
: public ClickableCanvas
33 , private IndexConverter
{
38 /** displayed m_sprites */
39 std::vector
<NamedSprite
> m_sprites
;
44 /** true if flipped */
47 /** size if a square */
50 /** the width of the pool (ie how many pieces) */
53 /** loader class, to load pieces */
54 PixmapLoader m_loader
;
56 /** the piece that is being dragged, if any */
57 NamedSprite m_dragged
;
59 /** the index of the piece being dragged */
62 AnimationManager
* m_anim_manager
;
64 /** internal function, resizes the grid vector to hold x pieces */
67 /** removes the drag putting it back together with his friends in the pool.
68 if fadeOff is true the current drag will fade off while a new piece will
69 fade in the pool, while if fadeOff is false the fade off is not done.
70 fadeOff will typically be false if the piece sprite has been used in the
71 board and we don't want a clone that is fading off */
72 void cancelDragging(bool fadeOff
= true);
74 /** takes the named sprite */
75 NamedSprite
takeSpriteAt(int i
);
77 /** converts an index to the upper left point of the corresponding square */
78 virtual QPoint
toReal(int i
) const;
80 /** finds to which index corresponds the point p, or -1 if corresponds to none */
81 virtual int toLogical(const QPoint
& p
) const;
83 friend class GraphicalSystem
;
84 friend class ChessTable
;
86 /** Constructor, requires the board the pool will be attached to */
87 PiecePool(const IColor
* pool
, ChessBoard
* b
, AnimationManager
*, KGameCanvasAbstract
* parent
);
90 /** returns the sprite loader */
91 PixmapLoader
* loader() { return &m_loader
; }
93 /** returns the sprite loader */
94 const PixmapLoader
* loader() const { return &m_loader
; }
96 /** Load a sprite using the sprite loader */
97 QPixmap
loadSprite(const QString
& id
);
99 /** returns the flipped value */
100 bool flipped() const { return m_flipped
; }
102 /** returns the number of pieces in the pool */
105 /** removes all the pieces */
108 /** adds a sprite to the pool */
109 void insertSprite(int index
, const NamedSprite
& sprite
);
111 /** \return the sprite at the given index. */
112 NamedSprite
getSprite(int index
);
114 /** removes the sprite at the given index from the pool. */
115 void removeSprite(int index
);
117 /** removes the sprite at the given index from the pool and returns it. */
118 NamedSprite
takeSprite(int index
);
122 /** sets the width of the grid (the fill will stay the same, and the
123 grid height will be recalculated) */
124 void setGridWidth(int w
);
126 /** the rect that will be covered by the pool */
127 virtual QRect
boardRect();
129 /** flips and moves the pieces in the pool at the same time */
130 void flipAndMoveBy(QPoint p
);
132 /** mouse release event */
133 virtual void onMouseRelease(const QPoint
& pos
, int button
);
135 /** mouse press event */
136 virtual void onMousePress(const QPoint
& pos
, int button
);
138 /** mouse move event */
139 virtual void onMouseMove(const QPoint
& pos
, int button
);
141 /** resize event (new_size is the new size of a SQUARE) */
142 virtual void onResize(int new_size
, bool force_reload
= false);
144 /** changed settings handler */
145 virtual void settingsChanged();
147 virtual const IndexConverter
* converter() const;