Allrighty. In the last two posts (here and here) we laid the foundations for a rudimentary QML view framework. This time we add some simple context sensitivity to the UI and finalize the amazing KittyApp. Oh yeah, about that neat performance trick I promised in the first post – well I’m breaking my promise. I’ll write about it in a separate post.
Something about bindings (pros can skip this)
Back to the subject at hand
So let’s add some context sensitivity. First up the navigation buttons. Here are the relevant bits inside NavigationButton.qml:
And this is how they’re instantiated:
Switching the view title works in a similar way, but there’s a catch. Let’s see the code first:
To support both normal views and ViewLoader (if you don’t remember what this was about, go read the previous post) views, the properties that contribute to the context need to be bound to the properties of the loaded views. Like this:
So the text property is bound to the currently active view’s viewTitle property – couldn’t be simpler. The small complication is caused by our use of ViewLoader. Binding directly to the item property of the loader causes the declarative engine to print warnings during construction of the ViewLoaders and unloading of the views (remember the keepLoaded property). This is because before loading and after unloading the item property is null and thus doesn’t have the viewTitle property and declarative engine spits out a warning about it. Now this doesn’t have any adverse effects on the functionality, but it’s pretty annoying to have a buttload (amount of properties * amount of loadable views = buttload) of warnings when you start up and then some more when ever you switch away from a view that won’t be kept loaded. All the useful logging plus real warnings and errors get buried in the mess.
Problem solved (let me know if you find a better way to solve this). I’m not saying you have to do this. It all depends how pedantic and annoyed by warnings you are. If you often find yourself organizing the icons on your desktop or unmatched HTML tags give you hives and emotional discomfort, you probably have to do it.
Here’s the code (BTW the kitty, the sheep and the rainbow are shamelessly taken from openclipart.org – I assume it’s ok) and here’s the sis file you can install to your Symbian (preferably S^3) device. Before you can run it, you need to install the Qt which ships with the QtSDK 1.1 TP. Note that for some reason the damn font files won’t unload. Luckily this whole font mess is solved in the upcoming Qt 4.7.2 release). So for now you need to reboot after running KittyApp, if you want uninstall it (can’t figure out why someone would want to do that though).