1 /*******************************************************************
3 * This file is part of the KDE project "Bovo"
5 * Bovo 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, or (at your option)
10 * Bovo 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.
15 * You should have received a copy of the GNU General Public License
16 * along with Bovo; see the file COPYING. If not, write to
17 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
20 ********************************************************************/
24 #include <QtCore/QTimer>
25 #include <QtGui/QColor>
26 #include <QtGui/QPainter>
27 #include <QtSvg/QSvgRenderer>
38 Mark::Mark(Scene
* scene
, const Move
& move
, bool animate
, qreal fill
) : QGraphicsSvgItem(),
39 m_scene(scene
), m_row(move
.y()), m_col(move
.x()), m_fill(fill
) {
40 m_sizeShrink
= 1.0/12.0; //1.0/(qrand()%5+7.0);
41 setElementId(QString(move
.player() == X
? "x%1" : "o%1")
42 .arg(QString::number(qrand() % 5 + 1)));
46 m_ticker
= new QTimer(this);
48 connect(m_ticker
, SIGNAL(timeout()), this, SLOT(tick()));
54 setPos(m_scene
->cellCenter(m_col
, m_row
));
59 disconnect(m_ticker
, SIGNAL(timeout()), this, SLOT(tick()));
61 m_ticker
->deleteLater();
65 QRectF
Mark::boundingRect() const {
66 qreal width
= m_scene
->squareSize();
68 qreal margin
= (1.0-m_fill
) * width
/ 2.0;
69 return QRectF( -width
/ 2.0 + margin
,
70 -height
/ 2.0 + margin
,
75 void Mark::killAnimation() {
78 disconnect(m_ticker
, 0, this, 0);
79 m_ticker
->deleteLater();
88 disconnect(m_ticker
, SIGNAL(timeout()), this, SLOT(tick()));
91 m_ticker
= new QTimer(this);
93 connect(m_ticker
, SIGNAL(timeout()), this, SLOT(killTick()));
97 void Mark::killTick() {
100 if (m_opacity
<= 0.1) {
116 void Mark::paint(QPainter
*p
, const QStyleOptionGraphicsItem
*, QWidget
*) {
117 p
->setOpacity(m_opacity
);
118 renderer()->render(p
, elementId(), boundingRect());
121 void Mark::setFill(qreal fill
) {
123 prepareGeometryChange();
126 usi
Mark::col() const {
130 usi
Mark::row() const {
134 } /* namespace gui */