* In this case, it allows the user to zoom in and out of the
* array of tiles.
*/
public void wheelEvent(QWheelEvent event){
// Get the position of the mouse before scaling, in scene coords
QPointF pointBeforeScale = mapToScene(event.pos());
// Scale the view ie. do the zoom
double zoom = this.matrix().m11();
if (event.delta() > 0) {
// Zoom in (if not at limit)
if(zoom < zoomMax)
scale(scaleFactor, scaleFactor);
} else {
// Zoom out (if not at limit)
if(zoom > zoomMin)
scale(1.0 / scaleFactor, 1.0 / scaleFactor);
}
// Get the position after scaling, in scene coords
QPointF pointAfterScale = mapToScene(event.pos());
// Get the offset of how the screen moved
QPointF offset = new QPointF(
pointBeforeScale.x() - pointAfterScale.x(), pointBeforeScale.y() - pointAfterScale.y());
this.horizontalScrollBar().setValue((int) (this.horizontalScrollBar().value()+zoom*offset.x()));
this.verticalScrollBar().setValue((int) (this.verticalScrollBar().value()+zoom*offset.y()));
}