PDA

View Full Version : QPropertyAnimations in Qt Script



Scorp2us
30th June 2009, 06:43
So I can't get this to work. The xScale factor should be animated. It works in C++ but not QtScript. You will need qt-master and the latest bindings generator (4.6 branch)
The only message I get is "QPropertyAnimation::updateState: Changing state of an animation without target"

http://pastebin.com/m51cee344
or

function GraphicsItemPropertyProxy (item, parent)
{
//QObject.call(parent);
this.item = item;
this._xScale = 1;
}

GraphicsItemPropertyProxy.prototype = new QObject();
GraphicsItemPropertyProxy.__defineGetter__("xScale", function() { return this._xScale; });
GraphicsItemPropertyProxy.__defineSetter__("xScale",
function(v) {
print("setting xScale to", v);
this._xScale = v;
this.updateTransform();
return v;
}
);
GraphicsItemPropertyProxy.prototype.updateTransfor m=function() {
print("updateTransform()");
this.item.setTransform(new QTransform().translate(0,0)
.rotate(0, Qt.ZAxis)
.rotate(0, Qt.YAxis)
.rotate(0, Qt.XAxis)
.scale(this._xScale, 5)
.translate(0, 0));
}

function AffineTextItem(text, font, brush, parent)
{
QGraphicsItem.call(this, parent);
var fm = new QFontMetrics(font);

this.path = new QPainterPath();
this.brush=brush;
this.path.addText(0,fm.ascent(), this.font, text);
this.br = fm.boundingRect(text).adjusted(0,0,0, fm.ascent());
this.boundingRect = function() { return this.br; };
}

AffineTextItem.prototype = new QGraphicsItem();

AffineTextItem.prototype.paint = function (painter, options, widget)
{
if (this.opacity()==0)
return;
painter.fillPath(this.path, this.brush);
}


var scene = new QGraphicsScene();
scene.setSceneRect(0,0, 900, 500);


var item = new AffineTextItem("this is text", new QFont("Arial", 25), new QColor(255,0,0));
item.setOpacity(0.75);
scene.addItem(item);
var proxy = new GraphicsItemPropertyProxy(item);
var animX = new QPropertyAnimation(proxy, "xScale");
animX.startValue = 50.0;
animX.endValue = 10.0;
animX.duration = 5000.0;
animX.loopCount = -1;

var view = new QGraphicsView(scene);
view.renderHints = (QPainter.Antialiasing | QPainter.SmoothPixmapTransform | QPainter.TextAntialiasing);

var blueGradient = new QLinearGradient (0,0,0,1080);
blueGradient.setColorAt(0, new QColor(0,255,0));
blueGradient.setColorAt(1, new QColor(0,0,255));

view.backgroundBrush = new QBrush(blueGradient);
animX.start();
view.resize(960, 540);
view.show();
QCoreApplication.exec();

Scorp2us
1st July 2009, 15:48
I am now offering $20 via PayPal for a working QtScript solution.

To qualify, you must use the GraphicsItemPropertyProxy technique from the script (lines 1-26) and the general approach of lines 57-75.

From what I can tell the QPropertyAnimation is not accepting the item passed in because d->target is null. It is my understanding that javascript objects are interchangeable with QObjects, so this should work.