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 HintItem::HintItem(Scene
* scene
, const Move
& hint
, bool animate
, qreal fill
)
39 : QGraphicsSvgItem(), m_scene(scene
), m_row(hint
.y()),
40 m_col(hint
.x()), m_fill(fill
) {
41 m_sizeShrink
= 1.0/(qrand()%5+7.0);
42 setElementId(QString(hint
.player() == X
? "x%1" : "o%1")
43 .arg(QString::number(qrand() % 5 + 1)));
48 m_ticker
= new QTimer(this);
50 connect(m_ticker
, SIGNAL(timeout()), this, SLOT(tick()));
56 setPos(m_scene
->cellCenter(m_col
, m_row
));
59 HintItem::~HintItem() {
61 disconnect(m_ticker
, 0, this, 0);
63 m_ticker
->deleteLater();
67 QRectF
HintItem::boundingRect() const {
68 qreal width
= m_scene
->squareSize();
70 qreal margin
= (1.0-m_fill
) * width
/ 2.0;
71 return QRectF( -width
/ 2.0 + margin
,
72 -height
/ 2.0 + margin
,
78 void HintItem::killAnimation() {
81 disconnect(m_ticker
, 0, this, 0);
87 void HintItem::kill() {
88 connect(m_ticker
, SIGNAL(timeout()), this, SLOT(killTick()));
92 void HintItem::killTick() {
95 if (m_opacity
<= 0.05) {
101 void HintItem::tick() {
106 if (m_tickUp
&& m_tick
> 5) {
108 } else if (m_tickUp
) {
118 // HintItem::setEnabled(enabled) {
119 // m_enabled = enabled;
122 void HintItem::paint(QPainter
*p
, const QStyleOptionGraphicsItem
*, QWidget
*) {
123 p
->setOpacity(m_opacity
);
124 renderer()->render(p
, elementId(), boundingRect());
127 void HintItem::setFill(qreal fill
) {
131 } /* namespace gui */
133 #include "hintitem.moc"