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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
#include <tqbrush.h>
#include <tqcolor.h>
#include <tqcanvas.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqslider.h>
#include <klocale.h>
#include <klibloader.h>
#include <kapplication.h>
#include <kdebug.h>
#include <kconfig.h>
#include "test.h"
K_EXPORT_COMPONENT_FACTORY(libkolftest, TestFactory)
TQObject *TestFactory::createObject (TQObject * /*tqparent*/, const char * /*name*/, const char * /*classname*/, const TQStringList & /*args*/)
{ return new TestObj; }
Test::Test(TQCanvas *canvas)
: TQCanvasEllipse(60, 40, canvas), count(0), m_switchEvery(20)
{
// force to the bottom of other objects
setZ(-100000);
// we want calls to advance() even though we have no velocity
setAnimated(true);
}
void Test::advance(int phase)
{
TQCanvasEllipse::advance(phase);
// phase is either 0 or 1, only calls with 1 should be handled
if (phase == 1)
{
// this makes it so the body is called every
// m_switchEvery times
if (count % m_switchEvery == 0)
{
// random color
const TQColor myColor((TQRgb)(kapp->random() % 0x01000000));
// set the brush, so our tqshape is drawn
// with the random color
setBrush(TQBrush(myColor));
count = 0;
}
count++;
}
}
void Test::save(KConfig *cfg)
{
// save our option from the course
// (courses are represented as KConfig files)
cfg->writeEntry("switchEvery", switchEvery());
}
void Test::load(KConfig *cfg)
{
// load our option
setSwitchEvery(cfg->readNumEntry("switchEvery", 50));
}
TestConfig::TestConfig(Test *test, TQWidget *tqparent)
: Config(tqparent), m_test(test)
{
TQVBoxLayout *tqlayout = new TQVBoxLayout(this, marginHint(), spacingHint());
tqlayout->addStretch();
tqlayout->addWidget(new TQLabel(i18n("Flash speed"), this));
TQHBoxLayout *htqlayout = new TQHBoxLayout(tqlayout, spacingHint());
TQLabel *slow = new TQLabel(i18n("Slow"), this);
htqlayout->addWidget(slow);
TQSlider *slider = new TQSlider(1, 100, 5, 101 - m_test->switchEvery(), Qt::Horizontal, this);
htqlayout->addWidget(slider);
TQLabel *fast = new TQLabel(i18n("Fast"), this);
htqlayout->addWidget(fast);
tqlayout->addStretch();
connect(slider, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(switchEveryChanged(int)));
}
void TestConfig::switchEveryChanged(int news)
{
// update our object
m_test->setSwitchEvery((101 - news));
// tells Kolf the hole was modified
changed();
}
Config *Test::config(TQWidget *tqparent)
{
return new TestConfig(this, tqparent);
}
#include "test.moc"
|