qmapview.cpp
Go to the documentation of this file.
00001 #include "qmapview.h"
00002 #include "qmapview.moc"
00003 
00004 
00005 #include <QDebug>
00006 #include <QGraphicsScene>
00007 #include <QWheelEvent>
00008 
00009 #include <math.h>
00010 
00011 QMapView::QMapView()
00012 {
00013         setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
00014         
00015          setCacheMode(CacheBackground);
00016          setRenderHint(QPainter::Antialiasing);
00017          setTransformationAnchor(AnchorUnderMouse);
00018          setResizeAnchor(AnchorViewCenter);
00019 
00020          scale(0.8, 0.8);
00021          setMinimumSize(400, 400);
00022          setWindowTitle(tr("QMapView"));
00023 }
00024 
00025 void QMapView::keyPressEvent(QKeyEvent *event)
00026 {
00027          switch (event->key()) {
00028          case Qt::Key_Up:
00029                   break;
00030          case Qt::Key_Down:
00031                   break;
00032          case Qt::Key_Left:
00033                   break;
00034          case Qt::Key_Right:
00035                   break;
00036          case Qt::Key_Plus:
00037                   scaleView(1.2);
00038                   break;
00039          case Qt::Key_Minus:
00040                   scaleView(1 / 1.2);
00041                   break;
00042          case Qt::Key_Space:
00043          default:
00044                   QGraphicsView::keyPressEvent(event);
00045          }
00046 }
00047 
00048 
00049 void QMapView::wheelEvent(QWheelEvent *event)
00050 {
00051          scaleView(pow((double)2, -event->delta() / 240.0));
00052 }
00053 
00054 
00055 void QMapView::scaleView(qreal scaleFactor)
00056 {
00057          qreal factor = matrix().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
00058          if (factor < 0.07 || factor > 100)
00059                   return;
00060 
00061          scale(scaleFactor, scaleFactor);
00062 }


csm
Author(s): Andrea Censi
autogenerated on Mon Jan 16 2017 03:48:29