1 /*******************************************************************
3 * Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com>
5 * This file is part of the KDE project "KReversi"
7 * KReversi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * KReversi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with KReversi; see the file COPYING. If not, write to
19 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
22 ********************************************************************/
23 #ifndef KREVERSI_CHIP_H
24 #define KREVERSI_CHIP_H
26 #include <QGraphicsPixmapItem>
27 #include "commondefs.h"
30 class KReversiChipFrameSet
;
32 class KReversiChip
: public QGraphicsPixmapItem
35 KReversiChip( ChipColor color
, const KReversiChipFrameSet
*frameSet
, QGraphicsScene
*scene
);
36 void setFrameSet( const KReversiChipFrameSet
*frameSet
);
37 void setColor( ChipColor color
);
38 void setRowCol( int row
, int col
) { m_row
= row
; m_col
= col
; }
40 int row() const { return m_row
; }
41 int col() const { return m_col
; }
42 ChipColor
color() const { return m_color
; }
44 * Called during animation
45 * NOTE: it doesn't change the color of the chip when
46 * animation finishes - you've to do it yourself
47 * @return whether the animation sequence is finished
51 * Toggles showing of little marker on top of the chip.
52 * It is used to indicate last-made move
54 void showLastMoveMarker(bool show
);
56 enum { Type
= UserType
+ 1 };
57 virtual int type() const { return Type
; }
60 const KReversiChipFrameSet
* m_frameSet
;
62 * Current animation frame
70 * This class will load and hold a chip animation frameset.
71 * As all chips share the same frames it's good to
72 * put them in a single storage class like this,
73 * so any chip can retrieve any frame any time :).
75 * This class is based on a number of assumptions which
76 * reflect the current chips.svgz pixmap format.
78 * 1. Animation sequence goes from black to white colored chips
79 * 2a. as a consequence of 1: frame(0) is black chip
80 * 2b. as a consequence of 1: frame(frameCount()) is white chip
81 * But 2a and 2b shouldn't matter, because there's chipPixmap()
82 * 3. The svg image contains 4 cols and 3 rows of chip pixmaps, i.e 12 frames
84 class KReversiChipFrameSet
87 KReversiChipFrameSet();
88 ~KReversiChipFrameSet();
90 * Prepare to render chips (from svg elements) pixmap with prefix chipsPrefix, which
91 * contains chip's animation sequence.
92 * The chips frames are extracted from it and put into
94 * Supposes that this pixmap represents an animation sequence
95 * going from black to white.
96 * @param chipsPrefixa svg prefix element ids containing whole animation sequence
97 * @param chipSize if not equal to 0 then chips will be scaled to chipSize x chipSize each
98 * else chips will be loaded unscaled
100 void switchChipSet( const QString
& chipsPrefix
, int chipSize
= 0 );
102 * Retruns a pixmap which corresponds to frame with number frameNo.
103 * It takes the chip color into account. This means that
104 * based on the assumption No. 1 (see class description), while frameNo
105 * increases it will return
106 * frames from black to white if chip color == Black and
107 * from white to black if chip color == White.
108 * It allows this class to hide all this pixmap-format assumtion tricks
109 * from KReversiChip which can simply increase frameNo and be happy :)
111 QPixmap
frame( ChipColor color
, int frameNo
) const;
113 * Returns a pixmap with a chip of corresponding color
115 QPixmap
chipPixmap(ChipColor color
) const;
117 * Returns number of frames in animation
119 int frameCount() const { return m_frames
.count(); }
121 * Sets chip pixmap size to size.
122 * I.e. re-renders svg image so that each individual chip
123 * pixmap in m_frames will have size passed as a parameter to this function
125 void setChipSize( int newSize
);
127 * Returns default chip size
129 int defaultChipSize() const { return m_frames
.at(0).width(); }
131 QList
<QPixmap
> m_frames
;
132 QString m_currentChipsPrefix
;