summaryrefslogtreecommitdiffstats
path: root/kjsembed/docs/examples/eventhandling
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit90825e2392b2d70e43c7a25b8a3752299a933894 (patch)
treee33aa27f02b74604afbfd0ea4f1cfca8833d882a /kjsembed/docs/examples/eventhandling
downloadtdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz
tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.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/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kjsembed/docs/examples/eventhandling')
-rw-r--r--kjsembed/docs/examples/eventhandling/jsboard.js89
-rw-r--r--kjsembed/docs/examples/eventhandling/mousetrack.js21
-rw-r--r--kjsembed/docs/examples/eventhandling/scribble.js34
3 files changed, 144 insertions, 0 deletions
diff --git a/kjsembed/docs/examples/eventhandling/jsboard.js b/kjsembed/docs/examples/eventhandling/jsboard.js
new file mode 100644
index 00000000..91e9a0f2
--- /dev/null
+++ b/kjsembed/docs/examples/eventhandling/jsboard.js
@@ -0,0 +1,89 @@
+#!/usr/bin/env kjscmd
+
+// Globals
+var frame = new QFrame(this);
+var labels = new Array();
+var startPos = new Point(0,0);
+var lastPos = new Point(0,0);
+
+frame.resize(300,300);
+frame.paletteBackgroundColor = "blue";
+
+var target = new Target(frame,"Target");
+for( var idx = 0; idx < 3; ++idx)
+ labels[idx] = new Block(frame, "Label " + idx);
+
+frame.show();
+application.exec();
+
+function Target( parent, text)
+{
+ var x = Math.floor( Math.random() * parent.width );
+ var y = Math.floor( Math.random() * parent.height );
+ var w = 100;
+ var h = 100;
+
+ this.label = new QLabel(parent);
+ this.text = text;
+ this.label.paletteBackgroundColor = "green";
+ this.label.geometry = new Rect(x,y,w,h);
+
+ this.checkInside = function( objectRect )
+ {
+ return this.label.geometry.contains(objectRect);
+ }
+
+}
+
+function Block(parent,text)
+{
+ this.label = new QLabel(parent);
+ var x = Math.floor( Math.random() * parent.width );
+ var y = Math.floor( Math.random() * parent.height );
+ var w = 25;
+ var h = 25;
+ this.label.text = text;
+ this.label.geometry = new Rect(x,y,w,h);
+ this.label.frameShape = QFrame.WinPanel;
+ this.label.frameShadow = QFrame.Plain;
+ this.label.paletteBackgroundColor = "white";
+ this.label.setMouseTracking(true);
+ this.label.adjustSize();
+
+ // Event handlers
+ this.label.mousePressEvent = function(ev)
+ {
+ //println("Press: " + this.text);
+ startPos = this.pos;
+ lastPos = ev.globalPos;
+ println("Start: " + startPos.x() + "," + startPos.y());
+
+ }
+
+ this.label.mouseReleaseEvent = function(ev)
+ {
+ if( target.checkInside(this.geometry) )
+ alert( "You got " + this.text + " on target!" );
+ else
+ {
+ println("Reset: " + startPos.x() + "," + startPos.y());
+ this.pos = startPos;
+ }
+ }
+
+ this.label.mouseMoveEvent = function(ev)
+ {
+ if( ev.state == 1)
+ {
+ var xDelta = ev.globalX - lastPos.x();
+ var yDelta = ev.globalY - lastPos.y();
+ this.move( this.x + xDelta, this.y + yDelta );
+ lastPos = ev.globalPos;
+ }
+ }
+}
+
+
+
+
+
diff --git a/kjsembed/docs/examples/eventhandling/mousetrack.js b/kjsembed/docs/examples/eventhandling/mousetrack.js
new file mode 100644
index 00000000..9c970c42
--- /dev/null
+++ b/kjsembed/docs/examples/eventhandling/mousetrack.js
@@ -0,0 +1,21 @@
+#!/usr/bin/env kjscmd
+
+//
+// The standard 'scribble' application coded using kjsembed
+//
+
+
+var mousetrack = new QWidget(this);
+mousetrack.setMouseTracking(true);
+x=0;
+y=0;
+
+mousetrack.mouseMoveEvent = function(ev)
+{
+ this.drawLine(x,y,ev.x,ev.y);
+ x = ev.x;
+ y = ev.y;
+}
+
+mousetrack.show();
+application.exec();
diff --git a/kjsembed/docs/examples/eventhandling/scribble.js b/kjsembed/docs/examples/eventhandling/scribble.js
new file mode 100644
index 00000000..0ffcdb07
--- /dev/null
+++ b/kjsembed/docs/examples/eventhandling/scribble.js
@@ -0,0 +1,34 @@
+#!/usr/bin/env kjscmd
+
+//
+// The standard 'scribble' application coded using kjsembed
+//
+
+
+var scribble = new QWidget(this);
+scribble.line=false;
+var x=0;
+var y=0;
+
+scribble.mousePressEvent = function(ev)
+{
+ if ( ev.button == 2 ) {
+ this.drawText(ev.x,ev.y,'KJSEmbed!');
+ }
+ else {
+ x = ev.x;
+ y = ev.y;
+ line=true;
+ }
+}
+
+scribble.mouseReleaseEvent = function(ev)
+{
+ if ( line )
+ this.drawLine(x,y,ev.x,ev.y);
+ line = false;
+}
+
+scribble.show();
+application.exec();
+