Tuesday, July 8, 2008

A new Location Bar

This past weekend I have been hacking on a replacement for one of the classes in Arora. ExLineEdit was the the base class for the location bar and the search widgets and was a big hack that only allowed for one widget on either side of the text. The new class is cleaner in every way and allows for any number of widgets on either side.

The location bar, search widget, and toolbar search were based on ExLineEdit. Unfortunately when first creating this classes I couldn't find a good solution to add side widgets and ended up with a solution that worked, but it was a hack where I put a QLineEdit inside of a widget and did a lot of painting and event handling myself. When originally developing the demo browser I tried to not have any hacks. If Qt didn't support a feature I didn't either. This made life a lot easier and the code cleaner. The one place I didn't follow that was with the Location Bar because a web browser absolutely must have the website icon in the location bar. Unable to find a good solution I ended up writing a class that was inflexible, had a horrible API, plays badly with new styles and I have been unhappy with it ever sense.

Now that things have settled down I took another look at the problem and was able to find an elegant solution for Qt 4.4 and made a patch for QLineEdit for an even cleaner solution in 4.5. Beyond the technical solution to the bug I made a new subclass of QLineEdit called LineEdit that added a few functions to put widgets inside of the line edit on the left or right hand side. This new class is the base class for the new LocationBar class and search widgets. The side widgets are automatically handled by a layout so they can be shown and hidden whenever you want.

Before merging this class into Arora I wrote autotests and a manualtest. Below is the manual test for the line edit class where you can see multiple widgets on either side of the line edit.


From the users perspective the only thing that should be different is that the completer will now line up under the location bar rather then slightly offset as it has been, but under the covers the code is much cleaner and more maintainable.

Having the ability to add widgets and show/hide them on the fly in a clean way will be very useful for Arora in the future. There are many extensions that people have talked about writing such as the FireFox3 bookmark star, a Go! button, rss feeds, and more. With the ability to add widget easily all of these features will be easy to make. With a good set of core classes Arora should do well.

The new LineEdit, LocationBar, updated search widgets, manualtests and autotests have been merged into Arora this evening. Enjoy!

No comments: