summaryrefslogtreecommitdiffstats
path: root/kolf/objects/poolball
diff options
context:
space:
mode:
Diffstat (limited to 'kolf/objects/poolball')
-rw-r--r--kolf/objects/poolball/Makefile.am13
-rw-r--r--kolf/objects/poolball/poolball.cpp86
-rw-r--r--kolf/objects/poolball/poolball.h63
-rw-r--r--kolf/objects/poolball/poolball.plugin1
4 files changed, 163 insertions, 0 deletions
diff --git a/kolf/objects/poolball/Makefile.am b/kolf/objects/poolball/Makefile.am
new file mode 100644
index 00000000..0388f4dd
--- /dev/null
+++ b/kolf/objects/poolball/Makefile.am
@@ -0,0 +1,13 @@
+INCLUDES= $(all_includes)
+lib_LTLIBRARIES = libkolfpoolball.la
+
+libkolfpoolball_la_SOURCES = poolball.cpp
+
+libkolfpoolball_la_LDFLAGS = $(all_libraries) $(LIB_KIO) -lkolf -module -avoid-version
+
+libkolfpoolball_la_METASOURCES = AUTO
+
+noinst_HEADERS = poolball.h
+
+kolf_DATA = poolball.plugin
+kolfdir = $(kde_datadir)/kolf
diff --git a/kolf/objects/poolball/poolball.cpp b/kolf/objects/poolball/poolball.cpp
new file mode 100644
index 00000000..a5ca80ec
--- /dev/null
+++ b/kolf/objects/poolball/poolball.cpp
@@ -0,0 +1,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"
diff --git a/kolf/objects/poolball/poolball.h b/kolf/objects/poolball/poolball.h
new file mode 100644
index 00000000..eeb851b2
--- /dev/null
+++ b/kolf/objects/poolball/poolball.h
@@ -0,0 +1,63 @@
+#ifndef KOLFPOOLBALL_H
+#define KOLFPOOLBALL_H
+
+#include <qcanvas.h>
+#include <qobject.h>
+#include <qpainter.h>
+
+#include <klibloader.h>
+
+#include <kolf/ball.h>
+#include <kolf/canvasitem.h>
+#include <kolf/config.h>
+#include <kolf/object.h>
+
+class StateDB;
+class KConfig;
+
+class PoolBallFactory : KLibFactory { Q_OBJECT public: QObject *createObject(QObject *, const char *, const char *, const QStringList & = QStringList()); };
+
+class PoolBall : public Ball
+{
+public:
+ PoolBall(QCanvas *canvas);
+
+ virtual bool deleteable() const { return true; }
+
+ virtual Config *config(QWidget *parent);
+ virtual void saveState(StateDB *);
+ virtual void save(KConfig *cfg);
+ virtual void loadState(StateDB *);
+ virtual void load(KConfig *cfg);
+ virtual void draw(QPainter &);
+ virtual bool fastAdvance() const { return true; }
+
+ int number() const { return m_number; }
+ void setNumber(int newNumber) { m_number = newNumber; update(); }
+
+private:
+ int m_number;
+};
+
+class PoolBallConfig : public Config
+{
+ Q_OBJECT
+
+public:
+ PoolBallConfig(PoolBall *poolBall, QWidget *parent);
+
+private slots:
+ void numberChanged(int);
+
+private:
+ PoolBall *m_poolBall;
+};
+
+class PoolBallObj : public Object
+{
+public:
+ PoolBallObj() { m_name = i18n("Pool Ball"); m__name = "poolball"; m_author = "Jason Katz-Brown"; }
+ virtual QCanvasItem *newObject(QCanvas *canvas) { return new PoolBall(canvas); }
+};
+
+#endif
diff --git a/kolf/objects/poolball/poolball.plugin b/kolf/objects/poolball/poolball.plugin
new file mode 100644
index 00000000..c305251f
--- /dev/null
+++ b/kolf/objects/poolball/poolball.plugin
@@ -0,0 +1 @@
+Filename=libkolfpoolball