Added option to build using Qt5

Added code modifications needed to build using Qt 5.
The changes not compatible with Qt 4 are isolated by ifdefs.

The default build still Qt 4. In order to build with Qt 5, you need
to run cmake -DQT5=1.

Some modifications, e.g. the ones regarding QGraphicsItemGroup, don't
need ifdefs because the original code was using APIs marked as obsolete
in Qt 4.