Friday, December 17, 2010

Code updated after comment received from "mich", now code looks much better.
---------------------

Now that I have some free time and no work to do, I thought to play with QML and created simple demo that implement views and changes view on swipe event.

As of now I don't have latest QML installed, therefor I am not able to use GestureArea QML element to detect swipe gesture and decided to implement my own swipe detection code in QML.

In demo, view is quite simple just showing colored rectangle and string. My intention for demo was to create reusable view element and to change view from one to another.

My view code is as below, I am calling it as screen in code and named QML file as Screen.qml. Mainly screen element maintain states to hide and show view and animate the transition. In real world it might required lots of other property and function but my implementation have only few.

Friday, December 10, 2010

Recently I was working on Audiobook Reader application for maemo. For this application I have created one custom item delegate for QListView which contains two clickable item and generate signal accordingly.

For application I was using some different mechanism to create button inside custom item delegate, but now I found better way to create custom item delegate with QPushButton. So thought to share code.

Following is code for custom item delegate derived from QItemDelegate.

Update: I have uploaded following code to gitorous, Please visit this link if you want a working sample code.

Sunday, December 5, 2010

So after long time I found enough time to complete my Audiobook Reader application. This application was in extra-devel repository for long time but there were few problem with it, now finally I worked on those bugs and I am satisfied enough to share information about it.

Now days almost all novels are available in audio format and I am huge fan of those audio book. Previously I was using n900's music player to hear those audio books. But music player dose not preserve last playing position and this create problem when phone restart.

So I created this Audiobook Reader application.Key features are listed below.

You can add multiple audiobook.

It support both individual audio file which contain whole book, or can add folder which contain books audio file.

You can bookmark position in audiobook and can resume from same position.

It remember bookmark for all audiobook.This mean you can play multiple audiobook simultaneously.

Following are snaps from application.

Above snaps is of Book list view. This view list currently added books,

Add Audio button is used to add single audio file which contain whole book content.

Add Folder button is used to add folder, which contain multiple audio file for book. Note that you need to select folder which contain audio files, not the individual files.

Pokemon icon is used to start playing individual audio book.

Cross mark icon is used to remove this book from book list.

In above snaps are from Reading view.This view list currently played book's title, track name and artist's name.

> button is used to play book

|| button is used to pause book

x button is used to stop book, it will put reading position to beginning.

<)) button is used to increase/ decrease volume

Currently you can download this application to your n900 from extra-devel repository.

Monday, November 29, 2010

Recently I was playing with Qt and found QPainterPath class. While reading documentation, I thought how can I use QPainterPath class and I created following prototype application in result.

QPainterPath can contain many different kind of shapes and we can draw all those shape using drawPath API of QPainter. But I used it to animate an object on curve path instead of just drawing, QPainterPath has some intresting API using which curve animation is quite easy.

In my sample app, I want to animate dot on curve as shown in below pic.

To achieve this, I first created a curved QPainterPath like following,

Now that, I have progress of dot on curve path at certain point in terms of percentage.QPainterPath has API pointAtPercent(), that can be used to get point on curve path at progress value and can draw Dot object at that point like below.

I have created custom widget just to show how it can be done with custom widget, but you can apply same animation of any widget. I have uploaded video that shows output with QPushButton at end of post.

Thats all,following is video for custom animation with timer.

Following is video for animation using QPropertyAnimation with QPushButton

In Plug-in loader code, We are creating plug-in object and if plug-in creation is successfully, we are connecting signal workDone() with some slot. Above code will work fine, because SampleWorker has defined workDone signal.

But problem here is, workDone signal is not part of Worker interface, it is defined in implemented plug-in. If plug-in defines required signal than all works well but we are not forcing plug-in to abide with interface.

Proper solution to this problem could be to create plug-in that return Factory, This factory then creates and returns proper object which is derived from Interface or base class that has defined required method and signals.

Here plug-in loader code is loading plug-in implementing WorkerFactory interface and asking it to create object that implements Worker interface which define all required method and signals. Now we can connect required signal slots with this worker object.

Sunday, November 21, 2010

Like I have already told in my past few posts that currently I am working on porting my application to Symbian. Another problem while developing for Symbian is, there are different SDK for different version of Symbian and you need to setup all those SDK to support different symbian version and also Symbian SDK are currently supported only on windows platform.

But now, both problems are solved by new Nokia Qt SDK by adding remote compiler feature in its latest release.

Compiling is one part of development, but we also need to test our application on device and as individual developer its quite hard to get hold on different device. This problem is also solved by Forum Nokia from quite some time by Remote Device Access portal.

Remote Device Access allows you to use device remotely for testing purpose. Its has almost all latest device to test with. Thought it might not be possible to test all use case remotely but most use case can be tested remotely.

I am putting some snaps that show how to setup Nokia Qt SDK with remote compiler feature and how to access Remote Device Access portal.

So, you will see welcome screen after starting Nokia Qt SDK installation like below.

After agreeing license agreement, you need to select type of installation. As shown in figure you need to select Custom as type of installation.

After selecting custom for type of installation,select Experimental to enable remote compiler feature.

Saturday, November 13, 2010

Recently I started to port my game to Symbian platform,
In my previous post I showed how to make graphics work with different resolution.But if you are using images in application, you need to use SVG image to make sure that images looks good in all resoltion.

When I started to replace my game images with SVG image, I need to make changes in my sprite class.With normal images I was drawing only certain portion of image from Sprite sheet like code in this post, but I could not make that thing work with SVG. Then to make my sprite class work I made following changes.

In following code, I am using SVG file which contain each frame with unique id and in code on next frame I am rendering SVG element with id for particular frame.

Saturday, October 23, 2010

Till now I have created few Qt games for Maemo 5 (N900) device, and now I wanted to run same games on Symbian device which support Qt.

First problem I encounter doing so is different screen size from N900, in my current game implementation I have hard coded screen size and coordination of game object.

After playing with graphics framework from some time, I created a small prototype application that shows two rectangle one on top left other on bottom right corner and can run on different Symbian device and N900 as well. So first thing I did is to remove all hard coded coordinate and implemented resize event, then scaled all graphics item which are added to graphics scene.

Following is my prototype code.

In below code, I have added QGraphicsView as QMainWindow's central widget and also reimplemented resizeEvent of QMainWindow.

Thursday, October 21, 2010

In 4.6 Qt introduced new State machine framework. Framework looks quite easy to use and extensible for complex use-case.
To explore Qt's State machine framework I thought to use it with sprite animation, as a complex sprite also holds many state and maintaining sprite state and transition from one state to another can become pain if not done properly.

So following is my sample code for prince sprite which use QStateMachine to maintain sprite's state and transition from one state to another. From somewhere in Internet I found sprite sheet for Prince of Persia, to make it easy for sample code I created another simple version of original sprite sheet.

In above code I have create different state object for different sprite state, like for StandingState or Attack state.
This state classes are derived from QState class and listen to QTimer's timeout signal to change frame according to animation.

Sunday, October 3, 2010

In continuation of my previous post of long press gesture in Qt, I created another simple gesture class to detect swipe gesture.

In my implementation, I am storing initial coordinate on mouse press event and comparing initial coordinate with coordinate on mouse release event.In this code I have not considered speed of swipe but we can easily measure speed of swipe by measuring time difference between two event.

Sunday, September 26, 2010

Recently while working on Qt project I required to recognize Tap and Hold (Long Press) gesture. Qt introduced new gesture handler library in 4.6 but some how it was not working on my machine and I needed to create my own solution. I already have created one custom solution for detecting Tap and Hold for iOS and I tried to port same thing to Qt as well.

Following is my code to detect Tap and Hold for Qt. In code I am starting timer on mouse press event, if timer expire then we have Tap and Hold event. If user release mouse while timer is still active then Tap and Hold is canceled.

Wednesday, September 15, 2010

Recently in one of my Qt project I required to use priority queue and found that Qt framework dose not provide such container. Then I decided to write one my self.

Following is simple version of my actual implementation.

In code Queue class implement simple priority queue. Internally I am using QQueue as storage and created one helper structure which holds data and its priority. Actual work is done inside enqueue method, which check priority of item being inserted with other stored items and insert item at appropriate index.

Friday, September 10, 2010

Today my application for Qt Ambassador was accepted by Qt ambassador program. I had submitted crazy chickens game for Qt ambassador program which is now accepted and soon this game will be showcased in Qt Ambassador showcase.

If you also want to become Qt Ambassador then visit this link for more information.

Wednesday, September 1, 2010

Sometime when using private implementation pattern in Qt, we might want to connect private class's method to signal.

I have seen some code that in such case create slot in public class that call private class's method and connect slot in public class to actual signal but this approach break primary purpose of hiding implementation details from user and also adds unnecessary code.

But using Q_PRIVATE_SLOT macro, we can easily connect private class method to signal. I created following test code to demonstrate usage of Q_PRIVATE_SLOT. Hope this will helps.

In following code I am trying to connection private class's timeOut slot to timer's timeout signal.

Tuesday, August 24, 2010

Recently I started to learn Qt' graphics view and I decided to put my learning in to some action and as output I created this game called crazy chickens. Its classic egg catcher game.

Goal of game is to catch eggs before they touch the ground. You get four chances if you let egg fall on ground. Speed of game increase as you catch more eggs. To make Motu(the fat boy) catch egg in to basket you need to touch hen which produced the egg. Game dose not take gravity into account so speed of egg remain constant till it fall to ground.

I already uploaded this game to maemo's extra-devel repository, so if you want to try the game enable extra-devel repository. I am also planning to promote this game to extra-testing repository soon so this game should be available in extra-testing repository as well.

Sunday, August 22, 2010

Recently while working on some code, I required to create nested function. Well in most case you can avoid use of nested function but in my case, in one function I required to use same code repeatedly and that piece of code was not going to be used else where so I wanted to keep that code inside original function only and I also wanted to remove redundant code. So I thought to create nested function.

By standard C++ dose not support use of nested function, some compiler allows it but that depends on compiler being used. So there is one work around by using you can achieve nested function in C++.

By using local class and overloading function operator we can simulate nested function. Following is my sample code to achieve nested function.

Friday, August 20, 2010

If you are facing segmentation fault in Maemo device than there are some tools available to retrieve core dump files from the device. These tools are in the sp‐rich‐core package. sp‐rich‐core will produce a core dump file and also additional information about process, most of /proc data, last lines from syslog, df, ifconfig output and much more. All of such information is added to a
rich core dump package (.rcore) and then, it is compressed in .lzo file.

The core dumps by default are saved on directory /media/mmc1/core‐dumps on device.

To uncompressed core dump you need to use rich-core-extract tool. The package sp‐rich‐core‐postproc provides the rich‐core‐extract utility, which extracts the information from a rich core dump file that GDB can read.

To install this tool type following

apt-get install sp-rich-core sp-rich-core-postproc

Now to uncompress lzo file and to get core dump file use following command.

Monday, August 16, 2010

Now a days I started to learn Qt's Graphics view. Initially I was struggling with it but once I started programming with it I found that its quite easy and powerful. What I like most about it is, while creating custom item we can perform paint opration with items local coordinate and need not worry about scene coordinate.

While creating custom graphics item, Your class needs to be derived from QGraphicsItem or QGraphicsObject. If your object needs to use signal/slot than derive your class from QGraphicsObject else derive it from QGraphicsItem and override paint and boundingRect methods.

For test application I tried to create sprite with custom graphics item that shows rolling ball animation. Following is code for my custom graphics item.