diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | c90c389a8a8d9d8661e9772ec4144c5cf2039f23 (patch) | |
tree | 6d8391395bce9eaea4ad78958617edb20c6a7573 /kolf/objects/test | |
download | tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.tar.gz tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kolf/objects/test')
-rw-r--r-- | kolf/objects/test/Makefile.am | 13 | ||||
-rw-r--r-- | kolf/objects/test/test.cpp | 104 | ||||
-rw-r--r-- | kolf/objects/test/test.h | 56 | ||||
-rw-r--r-- | kolf/objects/test/test.plugin | 1 |
4 files changed, 174 insertions, 0 deletions
diff --git a/kolf/objects/test/Makefile.am b/kolf/objects/test/Makefile.am new file mode 100644 index 00000000..4e9bb33f --- /dev/null +++ b/kolf/objects/test/Makefile.am @@ -0,0 +1,13 @@ +INCLUDES= $(all_includes) +lib_LTLIBRARIES = libkolftest.la + +libkolftest_la_SOURCES = test.cpp + +libkolftest_la_LDFLAGS = $(all_libraries) $(LIB_KIO) -lkolf -module -avoid-version + +libkolftest_la_METASOURCES = AUTO + +noinst_HEADERS = test.h + +kolf_DATA = test.plugin +kolfdir = $(kde_datadir)/kolf diff --git a/kolf/objects/test/test.cpp b/kolf/objects/test/test.cpp new file mode 100644 index 00000000..2c3d564f --- /dev/null +++ b/kolf/objects/test/test.cpp @@ -0,0 +1,104 @@ +#include <qbrush.h> +#include <qcolor.h> +#include <qcanvas.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qslider.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) +QObject *TestFactory::createObject (QObject * /*parent*/, const char * /*name*/, const char * /*classname*/, const QStringList & /*args*/) +{ return new TestObj; } + +Test::Test(QCanvas *canvas) + : QCanvasEllipse(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) +{ + QCanvasEllipse::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 QColor myColor((QRgb)(kapp->random() % 0x01000000)); + + // set the brush, so our shape is drawn + // with the random color + setBrush(QBrush(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, QWidget *parent) + : Config(parent), m_test(test) +{ + QVBoxLayout *layout = new QVBoxLayout(this, marginHint(), spacingHint()); + + layout->addStretch(); + + layout->addWidget(new QLabel(i18n("Flash speed"), this)); + + QHBoxLayout *hlayout = new QHBoxLayout(layout, spacingHint()); + QLabel *slow = new QLabel(i18n("Slow"), this); + hlayout->addWidget(slow); + QSlider *slider = new QSlider(1, 100, 5, 101 - m_test->switchEvery(), Qt::Horizontal, this); + hlayout->addWidget(slider); + QLabel *fast = new QLabel(i18n("Fast"), this); + hlayout->addWidget(fast); + + layout->addStretch(); + + connect(slider, SIGNAL(valueChanged(int)), this, 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(QWidget *parent) +{ + return new TestConfig(this, parent); +} + +#include "test.moc" diff --git a/kolf/objects/test/test.h b/kolf/objects/test/test.h new file mode 100644 index 00000000..3086a578 --- /dev/null +++ b/kolf/objects/test/test.h @@ -0,0 +1,56 @@ +#ifndef KOLFTEST_H +#define KOLFTEST_H + +#include <qcanvas.h> +#include <qobject.h> + +#include <klibloader.h> + +#include <kolf/canvasitem.h> +#include <kolf/object.h> + +class KConfig; + +class TestFactory : KLibFactory { Q_OBJECT public: QObject *createObject(QObject *, const char *, const char *, const QStringList & = QStringList()); }; + +class Test : public QCanvasEllipse, public CanvasItem +{ +public: + Test(QCanvas *canvas); + + virtual Config *config(QWidget *parent); + virtual void save(KConfig *cfg); + virtual void load(KConfig *cfg); + + virtual void advance(int phase); + + int switchEvery() const { return m_switchEvery / 2; } + void setSwitchEvery(int news) { m_switchEvery = news * 2; } + +private: + int count; + int m_switchEvery; +}; + +class TestConfig : public Config +{ + Q_OBJECT + +public: + TestConfig(Test *test, QWidget *parent); + +private slots: + void switchEveryChanged(int news); + +private: + Test *m_test; +}; + +class TestObj : public Object +{ +public: + TestObj() { m_name = i18n("Flash"); m__name = "flash"; m_author = "Jason Katz-Brown"; } + virtual QCanvasItem *newObject(QCanvas *canvas) { return new Test(canvas); } +}; + +#endif diff --git a/kolf/objects/test/test.plugin b/kolf/objects/test/test.plugin new file mode 100644 index 00000000..c58bec40 --- /dev/null +++ b/kolf/objects/test/test.plugin @@ -0,0 +1 @@ +Filename=libkolftest |