1 | /******************************************************************* |
2 | * |
3 | * Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com> |
4 | * |
5 | * This file is part of the KDE project "KLines" |
6 | * |
7 | * KLines 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) |
10 | * any later version. |
11 | * |
12 | * KLines 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. |
16 | * |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with KLines; see the file COPYING. If not, write to |
19 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
20 | * Boston, MA 02110-1301, USA. |
21 | * |
22 | ********************************************************************/ |
23 | #include "ballitem.h" |
24 | #include "renderer.h" |
25 | |
26 | #include <kdebug.h> |
27 | #include <QGraphicsScene> |
28 | #include <KGameRenderer> |
29 | |
30 | BallItem::BallItem( QGraphicsScene* parent ) |
31 | : KGameRenderedItem(KLinesRenderer::renderer() , "" , NULL) |
32 | { |
33 | parent->addItem(this); |
34 | setShapeMode( BoundingRectShape ); |
35 | |
36 | m_color = NumColors; // = uninitialized |
37 | |
38 | m_timeLine.setCurveShape( QTimeLine::LinearCurve ); |
39 | m_timeLine.setLoopCount(0); |
40 | |
41 | connect(&m_timeLine, SIGNAL(frameChanged(int)), SLOT(animFrameChanged(int)) ); |
42 | } |
43 | |
44 | void BallItem::setColor( BallColor c, bool setPix ) |
45 | { |
46 | m_color = c; |
47 | if(setPix) |
48 | setSpriteKey(KLinesRenderer::ballPixmapId(m_color)); |
49 | } |
50 | |
51 | void BallItem::startSelectedAnimation() |
52 | { |
53 | if(m_timeLine.state() == QTimeLine::Running) |
54 | return; |
55 | // it needs to be here rather than in constructor, |
56 | // because if different theme would get selected |
57 | // new settings will be picked up from KLinesRenderer |
58 | m_timeLine.setDuration(KLinesRenderer::animDuration(KLinesRenderer::SelectedAnim)); |
59 | m_timeLine.setFrameRange(0, KLinesRenderer::frameCount(KLinesRenderer::SelectedAnim)-1); |
60 | m_timeLine.start(); |
61 | } |
62 | |
63 | void BallItem::stopAnimation() |
64 | { |
65 | m_timeLine.stop(); |
66 | setSpriteKey(KLinesRenderer::ballPixmapId(m_color)); |
67 | } |
68 | |
69 | |
70 | |
71 | void BallItem::animFrameChanged(int frame) |
72 | { |
73 | setSpriteKey(KLinesRenderer::animationFrameId(KLinesRenderer::SelectedAnim, m_color, frame )); |
74 | } |
75 | |
76 | #include "ballitem.moc" |
77 | |