Docklets in TOra
11/30/2008Dockable windows are a great interface feature for advanced users. They let you quickly select a file, connect to a database or jump to a method declaration. They require no more screen real estate than needed and most can be configured to minimize on use, that way leaving the most room on the screen for code.
They're popular, too. Netbeans and Eclipse use dockable windows nearly to the exclusion of all other types. KDevelop has had them and even my beloved Emacs has advanced syntax and window support with the ECB package.
Dockable windows are also convenient because rather
My Netbeans setup. The window is opened from the left now but will close when I click away.
than developers trying desperately hard to make sure the most used features are readily accessible, the user can simply move around the docks as they prefer.
Qt has some support for dockable windows using QDockWidget. Windows can be stacked together or tabbed. The can be drag 'n dropped by the title bar to another dock area or floated on top of the main window. It gets a few things right like helpful animations that show you where the widget will go when the mouse button is released.
QDockWidget is unfortunately more limited than it is useful. Windows are docked and included in the main window layout or they're floating. There's no support for minimizing a QDockWidget. Calling hide() then show() on a dock widget will lose the size of the window. So if the user had resized it, the window can't spring back to the previous size. There's some support for this but the state of the entire QMainWindow must be saved and restored together. One also can't simply restore the geometry manually since QDockWidget helpfully ignores QWidget properties.
QDockWidget also includes a default title widget that is sufficient for most uses, but titleBarWidget() returns 0 unless a custom widget has been set. There seems to be no way to connect to the close or float buttons it provides and no way to customize what they do for another purpose.
Also, the two modes dock widgets offer are lacking. Either they are shown in the main window, and thereby pushing the code editor out of the way or floating and blocking code instead. At first I'd tried to override the focusOutEvent method to hide the dock after it's used. However, after much setting of properties and Googling, it appears QDockWidget doesn't get focus events. It may be possible to do this in the child widget. Of course, that means every dock widget in TOra must provide it's own event handling.
I think it was around this time I tried out my new heavy bag.
TOra with two docklets enabled.
I'm calling my dockable windows "docklets," and I've added a new abstract base class toDocklet that manages windows and enforces a common set of features. There's also a class toDockbar, a subclass of QToolBar, that manages showing and hiding docklets.
Much of what I wanted to do has been stymied by the limited functionality of QDockWidget. I did manage to write a couple useful docklets, however. One, "Connections" reuses the toConnectionModel class to show the recent connections. I'd like to make this a QTreeView eventually and move a lot of features from the project manager there. I've also created "Directory" which shows the current directory. It updates to select the current file whenever toWorksheet signals a file has been opened.
These are already useful and there are many more docklets that could also be useful. I'm just deeply annoyed by the toolkit now and I'd like feedback before continuing. It could be that I've been spoiled by other tools and what I have now might be good enough. But I also don't want to commit to a feature that is going to force a lot of custom work.