by Viranch Mehta - 4 April 2013 - $ cat /home/viranch/life.logKDE Games gets QtQuick support!
Since my last year's GSoC with porting KBreakout to QtQuick, I have been working on adding support for QtQuick to KDE Games libraries. After a few months efforts and careful reviews by David, Albert and Ian (thanks to them!) it has been finally pushed to master.
With the QtQuick support, libkdegames has two crucial additions for QML:
A declarative view (KgDeclarativeView) with added bindings to KDE's convenience functions (eg, i18n() etc.) and register KDE specific paths to QML plugins; this is done with help of KDeclarative in kdelibs.
A QML component for showing game's UI elements from the its SVG files, similar to what KGameRenderer provides. Just do a "import org.kde.games.core 0.1 as KgCore" and KgCore.KgItem component can be used to display elements from SVGs.
One important thing to remember here is that only the central game areas are shown in QML, rest of the parts like the main window, toolbars, menus, status bars, etc. remain as it is.
KgDeclarativeView is simply a wrapper over QDeclarativeView with support for what KDeclarative provides. There is absolutely nothing more that has been written in its code, so it can be treated just like an usual QDeclarativeView.
For rendering of theme SVGs and retrieving a given element from it, we have KgImageProvider, which is a subclass of QDeclarativeImageProvider. The game UI elements are requested via the QML Image element (KgCore.KgItem acts as a wrapper for this), which in turn uses KgImageProvider as its image provider, triggering rendering requests when theme changes, size of the game window changes, etc. KgImageProvider is supplied the game's KgThemeProvider objects (one image provider for each theme provider (yes we can haz multiple theme providers!)). The image provider uses this theme provider to discover path to the SVG file for currently selected game theme and render the requested element from it, and return the QImage. One advantage here is we get rid of KGameRenderer altogether as asynchronous loading and caching capabilities are already provided by QDeclarativeImageProvider!
One challenge with showing elements from SVG was, the image element goes invisible once new rendering request is triggered and becomes visible when rendering is complete, showing the newly rendered image. This caused a little noticeable flickers when window was re-sized or the theme was changed. This was tackled by having two image elements, one of them always invisible for triggering rendering requests, while the other is always visible. Whenever the invisible image's rendering request is complete (indicated by the status property of QML image element) the visible image is updated with the newly rendered image. This way we have no flicker at all, images are updated only when their rendering is complete.
So how do we use the QtQuick support in our games?Full blog