Sunday, July 22, 2007

Web on canvas and Dashboard widgets

There are days when I do something quite interesting and in my mind I can almost see myself on a stage in tight, tight spandex pants, long hair, perm, cowboy boots yelling angrily "are you ready to roock?!". People cheering, babies laughing, women throwing their bra's on the stage. It's poetic. Then I remember that I'm a computer scientist and I snap right out of it. I go back to the life filled with math equations on napkins, sleepless nights in front of buzzing computers, stacks of books in corners and no spandex pants (although I can deal with the last one just fine). The fact that I hate rock lessens the blow, but it doesn't make it any less disappointing. So in those moments of sadness I blog, yearning attention and approval, so readily available on the internet. Cough, cough...

I was wondering how hard would it be to create a QGraphicsItem that uses QtWebKit to render pages on a canvas. The idea being that combining full blown canvas like QGraphicsView framework with web rendering engine would give us quite a killer combination. So I've sat down today and done it. At first I had to redo some of the rendering code in QtWebKit and once I was finished I had a QWebGraphicsItem that beautifully renders pages. It being a QGraphicsItem all the effects available to graphics items in Qt are available for free to it. So you can animate, scale, rotate, perspective-transform and do a whole bunch of neat effects on it for free. Once I've done that I figured that it's obvious that this is the best way of getting Apple's Dashboard widgets to work. So I've done that too. I quickly hacked up a class that reads-in Apple Dashboard widget bundles and can render them on a QWebGraphicsItem. The compatibility is not 1:1 quite yet, because some of the Dashboard widgets use JavaScript objects that I haven't implemented yet, like AddressBook object. To be honest I'm not 100% sure whether I want to implement them, I think we can get those things done a lot nicer, it's just a question of whether 1:1 compatibility with Apple Dashboard is worth the extra effort needed to make all those JavaScript objects work on KDE.First a screenshot of one Apple Dashboard widget rendered and on top a scaled to half its size KDE homepage:

Now a Dashboard widget with a perspective-transformed dot.kde.org page. Since this is QGraphicsView I can interact with the item while it's transformed so I've selected some text on it.Crackalicious. (no drugs were used while hacking on this, but I did touch myself a little after getting it to work). Furthermore (yes, there's more... what can I say, I'm a giver...) in QtWebKit we have this neat interface that allows you to inject QObject's into the framework as JavaScript objects at run-time, so adding new JavaScript objects is trivial and getting Opera widgets to work would be very, very simple. No spandex pants included though.

Warning: I work on framework/libraries not applications, if you don't like borders, you shouldn't be adding them. It has nothing to do with me. Write a style where you fix that. Much love.

Oh, QtWebKit is in WebKit's svn repository, so you can get access to it. We'll evaluate and review patches I did for QWebGraphicsItem and either fold them in or just leave it as it is and depend on "widgets on canvas" implementation that is coming in Qt 4.4 anyway.

Hey Zack, very impressive work on those opengl plasmoids! I'm curious and as a 3D modeller, would the opengl plasmoid support perhaps collada (an open 3D XML format) with a certain library in the same manner as SVG's are being rendered? I have some wicked ideas for some interesting 3D animated models dancing around the screen exploiting crazy eyecandy like GLSL shaders and normal maps (for usability purposes of course, not just bling graphics hahaha). A possible idea of mine is "think about the OSX dock, only the programs are held by a massive 3D animated normal/specular mapped penguin :)"

I'm hatching a plot to embed .mp4 or H.264 video in a Qt app, and the best solution I seem to be finding is to mind-meld Qt with Helix (as was done in Qtopia, but with a more recent version to get the desired format support). I'm hoping that I'm missing something terribly obvious and you can tell me that QVideoKit is available for download from the svn repositories and it should be going Gold stable in the coming weeks?

It's very cool and I can't wait to try it out. I've downloaded Qt 4.4 for mac, compiled and installed it. Now I want to use QtWebKit to generate something similar like this. But I'm a little bit stuck. Where can I get QtWebKit to view webpages from within my application? Shouln't this be embedded in Qt? Can you help me getting started?