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
|
#!/usr/bin/env kjscmd5
function scribble() {
frame = new QWidget("QFrame", this);
frame.startX = 0;
frame.startY = 0;
frame.endX = 0;
frame.endY = 0;
frame.onMouseButtonPressEvent = function ( ev ) {
println('Start');
this.startX = ev.x;
this.startY = ev.y;
}
frame.onMouseButtonReleaseEvent = function ( ev ) {
println('End');
this.endX = ev.x;
this.endY = ev.y;
this.update();
}
frame.onPaintEvent = function ( ev ) {
println('Paint');
var p = new QPainter();
p.begin( this );
p.drawLine( this.startX, this.startY, this.endX, this.endY );
p.end();
}
return frame;
}
frame = scribble();
frame.show();
exec();
|