qmapview.cpp
Go to the documentation of this file.
1 #include "qmapview.h"
2 #include "qmapview.moc"
3 
4 
5 #include <QDebug>
6 #include <QGraphicsScene>
7 #include <QWheelEvent>
8 
9 #include <math.h>
10 
12 {
13  setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
14 
15  setCacheMode(CacheBackground);
16  setRenderHint(QPainter::Antialiasing);
17  setTransformationAnchor(AnchorUnderMouse);
18  setResizeAnchor(AnchorViewCenter);
19 
20  scale(0.8, 0.8);
21  setMinimumSize(400, 400);
22  setWindowTitle(tr("QMapView"));
23 }
24 
25 void QMapView::keyPressEvent(QKeyEvent *event)
26 {
27  switch (event->key()) {
28  case Qt::Key_Up:
29  break;
30  case Qt::Key_Down:
31  break;
32  case Qt::Key_Left:
33  break;
34  case Qt::Key_Right:
35  break;
36  case Qt::Key_Plus:
37  scaleView(1.2);
38  break;
39  case Qt::Key_Minus:
40  scaleView(1 / 1.2);
41  break;
42  case Qt::Key_Space:
43  default:
44  QGraphicsView::keyPressEvent(event);
45  }
46 }
47 
48 
49 void QMapView::wheelEvent(QWheelEvent *event)
50 {
51  scaleView(pow((double)2, -event->delta() / 240.0));
52 }
53 
54 
55 void QMapView::scaleView(qreal scaleFactor)
56 {
57  qreal factor = matrix().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
58  if (factor < 0.07 || factor > 100)
59  return;
60 
61  scale(scaleFactor, scaleFactor);
62 }
QMapView()
Definition: qmapview.cpp:11
void wheelEvent(QWheelEvent *event)
Definition: qmapview.cpp:49
#define tr(v)
Definition: egsl_macros.h:12
void keyPressEvent(QKeyEvent *event)
Definition: qmapview.cpp:25
void scaleView(qreal scaleFactor)
Definition: qmapview.cpp:55


csm
Author(s): Andrea Censi
autogenerated on Tue May 11 2021 02:18:23