1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#include <qbrush.h>
#include <qcolor.h>
#include <qcanvas.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qpainter.h>
#include <klocale.h>
#include <klibloader.h>
#include <kapplication.h>
#include <kdebug.h>
#include <knuminput.h>
#include <kconfig.h>
#include <kolf/statedb.h>
#include <kolf/canvasitem.h>
#include "poolball.h"
K_EXPORT_COMPONENT_FACTORY(libkolfpoolball, PoolBallFactory)
QObject *PoolBallFactory::createObject (QObject *, const char *, const char *, const QStringList &) { return new PoolBallObj; }
PoolBall::PoolBall(QCanvas *canvas)
: Ball(canvas)
{
setBrush(black);
m_number = 1;
}
void PoolBall::save(KConfig *cfg)
{
cfg->writeEntry("number", number());
}
void PoolBall::saveState(StateDB *db)
{
db->setPoint(QPoint(x(), y()));
}
void PoolBall::load(KConfig *cfg)
{
setNumber(cfg->readNumEntry("number", 1));
}
void PoolBall::loadState(StateDB *db)
{
move(db->point().x(), db->point().y());
setVelocity(0, 0);
setState(Stopped);
}
void PoolBall::draw(QPainter &p)
{
// we should draw the number here
Ball::draw(p);
}
PoolBallConfig::PoolBallConfig(PoolBall *poolBall, QWidget *parent)
: Config(parent), m_poolBall(poolBall)
{
QVBoxLayout *layout = new QVBoxLayout(this, marginHint(), spacingHint());
layout->addStretch();
QLabel *num = new QLabel(i18n("Number:"), this);
layout->addWidget(num);
KIntNumInput *slider = new KIntNumInput(m_poolBall->number(), this);
slider->setRange(1, 15);
layout->addWidget(slider);
layout->addStretch();
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(numberChanged(int)));
}
void PoolBallConfig::numberChanged(int newNumber)
{
m_poolBall->setNumber(newNumber);
changed();
}
Config *PoolBall::config(QWidget *parent)
{
return new PoolBallConfig(this, parent);
}
#include "poolball.moc"
|