September 22, 2009

Displaying html with animated gifs

When consulting for Hyves, we wanted a light-weight widget that displays html and animated gifs (for smileys) for the chat client and for tooltips. The option to use Qt/WebKit was out since we intended to create numerous instances of this widget (it consumed lots of memory) and the rendering was not as fast we would like. QLabel does not support animated gifs, so that was not an option either.

Instead of writing a basic html parser, layouter and renderer, I thought I can somehow trick QTextDocument into displaying animated gifs. You can see the basic idea in this kb but to get it working with animations wasn’t easy. One good thing about adding the feature to QTextDocument is that you can set it on QTextBrowser and QTextEdit.

Without further ado, get the code here. Label is a richtext label that does not support links or selection. TextBrowser is a browser that supports selection and links. TextEdit is an editor with support for undo/redo.

P.S. Thanks to Hyves for making it possible to actually publish this code; they released most of their code as GPL.

September 18, 2009

Non-selectable QWebView

There are situations where you don’t want text to be selected and images to be dragged in your QWebView (See my previous post). Qt does not provide support out of the box, but this is fairly straightforward to do. I wrote a quick hack to demonstrate, get it here.

September 16, 2009

KDocker 4.0 released

Almost a year back, I was looking for a maintainer for kdocker. I had practically given up, when out of the blue John contacted me to be the new maintainer. What more, he had already ported it Qt4! That made handing over maintainership to him a no-brainer :)

Also, KDocker is now moved from sourceforge to launchpad. Once I regain access to sourceforge, I will update the sourceforge page.

Read the release announcement here. If you are interested in helping  out with translating the app, please contact John.

September 12, 2009

Side effects of using QtWebKit for desktop apps

Integrating the web into desktop apps is now incredibly easy thanks to Qt WebKit.  Qt WebKit also allows us to embed any Qt widget inside the html. This feature makes it extremely tempting to develop full blown desktop applications using Qt WebKit – your interface is entirely designed using html/css (instead of .ui) and you as a C++ developer decide what parts are best done in Qt/C++ and embed them into the html page.

The above scheme works very well (for the most part). However, there are a lot of features that make our applications feel native, that we take for granted in desktop apps when using Qt/C++ but not so when using Qt WebKit. So here is a list of short comings that you should know about.

1. Focus handling - Tab focus  doesn’t work at all when navigating from html into a c++ plugin and vice versa.

2. Keyboard accelerators - In html, you can specify accelerator using ‘accesskey’. They don’t seem to work in QtWebKit. They do work in google chrome, so must be something to do with the Qt port.

3. Text can be selected and images can be dragged – Your main ui is html, what did you expect :) ?

4. Plugins will get deleted if you hide them – If you hide your C++ plugin/widget using ‘display: none’, Qt/WebKit will delete it. In your traditional Qt program, all your data is part of the widget – now it’s all gone. To prevent this, you have to write all your widgets to use the model-view paradigm. An alternative is to use ‘visibility: hidden’ which won’t delete the plugin but the plugin will continue to hog space in the layout. Side note: In Qt 4.4.x, plugins weren’t deleted (aka leak). Starting Qt 4.5.x, they were deleted – we found this problem when our app starting crashing gloriously when we moved to Qt 4.5.x.

5. Fluid layouts - When the windows resizes, UI elements inside are expected to reposition and resize nicely; the window must have a nice minimum size – that is all done by QLayout does. This is really hard to get right when using html. You will most likely end up writing js layouting code.

6. Moving data back and forth is slow – Passing Qt types from C++ to JS works very well using QJson. Converting complex types like a QPixmap to html img is really really slow, since you have to convert in into png first. Also, using this method crashes Asus laptops/Windows, probably some graphics card issue, nevertheless your app has to deal with it.

8. RTL – Qt will layout your widgets automatically when your app is run in a RTL environment. With HTML, you will have to provide an alternate html file, do your own RTL detection, implement sizing fixes to elements for different languages and so on.

9. Translations – Qt provides you linguist, lrelease, lupdate. When using HTML, you will have to roll out your own translation framework (this is an awful lot of work).

10. Misc – There are other minor problems depending on your Qt version - the default fonts of html and qt didn’t match. There was a time when a 12pt font of Qt and 12 pt font of webkit don’t match (this seems to be fixed now). Displaying plugins inside divs had some artifacts.

Note that the above is not a case against using Qt/WebKit for developing desktop apps since they can all be worked around. It’s more for you to know what you will be up against if you decide to go down this road.

Update 1: Added note on rtl and translations

September 11, 2009

Hyves Photo Uploader 1.2: Do More

Late last year, I blogged about the beta release of Hyves Desktop. In about half-a-year, the application has grown much more than just helping folks upload images to Hyves. It now has some very interesting features to help you spice up your photos. Here is a short video demo showing off some of them:

You can download the app for free from http://hyves.nl/hyvesdesktop/download (but you need to have joined Hyves (for free again) before you can download it).

A lot of work has gone into this 1.2 release from the Hyves Desktop team: Arend, Boud, Girish, Markus and self. We’ve also designed the application in a unique way – the main screen’s ui is in html/js, with each core functionality coded in C++ and integrated into the app as a Qt/Webkit plugin.

We can already see how popular the pimping and effects features are, by the sheer number of photos in Hyves tagged gepimpt. Keep em coming, folks.

September 4, 2009

We are hiring!

It’s been a year and a half since my good friend Roopesh and I started this company, ForwardBias Technologies.  Starting our own business has been nothing short of exhilarating and fabulous.  Estimating turnover, pricing, talking to customers, deciding company vision/direction is all very very thrilling!

Since inception, we have been focusing our energies on Qt consulting. We have managed to carve a nice niche for ourselves in “high end” Qt consulting market – we have developed paint engines (yes, plural!), custom styles, a really cool full blown webkit application (which we will blog about shortly), hacked on koffice (for only a short while, unfortunately) and a lot more. I think I can safely say that our customers are enthralled with our work – every one of them has offered us more work.

And, we are also working on our hush-hush product in parallel. And despite me saying it’s all very exciting and fun, we are also getting a wee bit exhausted with all the action. It’s just two of us and we need more people!

So, am very happy to say, we are hiring! We have spoken our hearts out in that page and what we would like to repeat is that this is a company made for developers by developers and we are looking for fearless programmers – our customers and product requires one to constantly learn new things on the job and become good at it very fast.

And of course, some bonus points if you are already know KDE/Qt development.