QtScript is also good for tiny things

Here's a quick example of why it's nice to have a script interpreter embedded in Qt: Plasma's KRunner has a calculator which used code borrowed from the KDE 3.x minicli. The old code started up the bc command line calculator then displayed the result - not exactly an efficient way to do things. I've just committed a change that makes it use QtScript and the code is trivial:


Plasma Scripting

I've made some decent progress in the scripting support for plasma today with the addition of the ability to access QPainter, QTimer and QFont from scripts. I've also improved a few other bits of the code. The result is that I've now been able to reimplement a functioning version of the plasma analog clock applet in Javascript. There's obviously more to be done, but I think this shows that things are progressing pretty well and along the right lines. The clock looks just like the C++ one (except I turned on the standard background so it can be distinguished as being the js one).


Back from Glasgow

Well, I'm back from Glasgow and have now almost recovered. The conference was great, and I'd like to thank all the organising team for their efforts. For me things were quite productive, with some nice steps forward in my QtScript code (my bindings are now dynamically loaded plugins for example) and lots of useful discussions about topics from improving the library facilities for scripts. I also managed to make a start on a plasma applet container that lets you write applets in Javascript.

Isn't it nice to be able to blog again :-)


Animating Widgets

Qt 4 includes a useful class called QTimeLine that can form the basis of animations, it's used in QGraphicsView but is also more generally applicable. I did a bit of hacking this weekend and wrote a class that illustrates how it can be used to create a fairly general mechanism for animating QWidgets. The code as it stands needs some work, but it can animate the properties of any QWidgets. You basically say widget X has propery P which should vary from A to B. For example:


QtScript 105

I've done a bit more stuff with QtScript in order to keep up with the changes in the Qt snapshots. The API has changed a bit to make things more consistent, and I've updated the demo code I had to work with the new version. The changes to support the new API were pretty simple, and basically amount to using factory methods on QScriptEngine to create your script values. The cast operator qscript_cast has also been renamed and is now qscriptvalue_cast, but it works as before.


QtScript 104

So far, I've only accessed QObjects, slots and UI files, we need to do better to be able to do anything useful as the Qt 4 API has a lot of methods that aren't accessible that way. To do this, we'll use Javascript prototypes. A prototype is basically the object we can consider an instance to be 'cloned' from (philosophy people can think of it as the platonic ideal of the object) - from a purely implementation point of view, it's enough to know that it's the first place the interpreter will look for something that isn't implemented directly by an object.


QtScript 103

Now we can create widgets and load .ui files, we can take the time to fix a few other things. Initially, we could create widgets, but we couldn't specify their parents. Handling this is quite a small change:


QtScript 102

I've done a bit of tidying up of the QtScript code I was working on, so here's another version. Now, as well as being able to create individual widgets, you can load UI files from Designer. I've also cleaned up the API for calling exec().

The new code looks like this:


QtScript 101

As you might have read in Kent's blog post yesterday, the latest Qt 4.3 snapshots just gained a javascript interpreter. I had a bit of a play with it yesterday and it's pretty neat. Unfortunately it doesn't expose any fun objects by default, so I decided to make it possible to create QWidgets.

The result is a tiny demo that gives you the ability to create instances of any QWidget that Designer supports. The glue code itself is tiny:


Yet another CMake Blog

Since everyone else is blogging on build systems today, I thought I'd join in. Overall CMake seems to be working out ok, but like anything else, it is not without its problems. One problem I had with it was fixed in the new release this weekend though - you no longer need to write:

IF something
  do stuff
ELSE something
  do other stuff
ENDIF something

I don't understand why it was written like that in the first place, but hey it's fixed so lets move on.