AnimationView.cpp
Go to the documentation of this file.
1 #include "AnimationView.h"
2 #include "AnimationScene.h"
3 #include "AnimationItem.h"
4 #include "../canvas/MapDisplay.h"
5 #include "../canvas/Canvas.h"
6 
7 //QT
8 #include <QtCore/QEvent>
9 #include <QtCore/QCoreApplication>
10 #include <QtGui/QMouseEvent>
11 //#include <QtWidgets/QGridLayout>
12 
14  : QGraphicsView(parent),
15  m_display(parent),
16  m_dragDropAccepted(false)
17 {
18  setMouseTracking(true);
19  setAcceptDrops(true);
20  setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
21  setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
22  setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
23  setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing);
24  setResizeAnchor(QGraphicsView::NoAnchor);
25  setCacheMode(QGraphicsView::CacheBackground);
26  setUpdatesEnabled(true);
27 }
28 
30 
32 {
33  QCoreApplication::sendEvent(m_display, (QEvent*)e);
34 }
35 
37 {
38  QCoreApplication::sendEvent(m_display, (QEvent*)e);
39 }
40 
42 {
43  QCoreApplication::sendEvent(m_display, (QEvent*)e);
44 }
45 
47 {
48  QCoreApplication::sendEvent(m_display, (QEvent*)e);
49 }
50 
52 {
53  QCoreApplication::sendEvent(m_display, (QEvent*)e);
54 }
55 
57 {
58  QCoreApplication::sendEvent(m_display, (QEvent*)e);
59 }
60 
62 {
63  QCoreApplication::sendEvent(m_display, (QEvent*)e);
64 }
65 
67 {
68  QCoreApplication::sendEvent(m_display, (QEvent*)e);
69 }
70 
72 {
73  QGraphicsScene* scene = this->scene();
74  if(scene)
75  {
76  QRectF r = scene->sceneRect();
77  fitInView(r);
78  }
79 }
80 
82 {
84 }
85 
87 {
88  m_dragDropAccepted = false;
89  e->setAccepted(m_dragDropAccepted);
90 }
91 
93 {
94  e->setAccepted(m_dragDropAccepted);
95 }
96 
98 {
100  emit animationDropEvent(e);
101 }
102 
104 {
105  setMatrix();
106 
107  // The following code ensures continuous animation.
108  // Without this, when we give great zooms, it is observed the loss of a few frames of animation.
109  QRectF sceneRec = scene()->sceneRect(); // The scene rect is already on display projection
110  if (sceneRec != sceneRect())
111  updateSceneRect(sceneRec);
112 
113  // if the projection is different, increase the scene rect
114  if (m_sameSRID == false)
115  {
116  QPointF c = sceneRec.center();
117  sceneRec = QRectF(0, 0, sceneRec.width() * 50, sceneRec.height() * 50);
118  sceneRec.moveCenter(c);
119  }
120  fitInView(sceneRec);
121  QGraphicsView::paintEvent(e);
122  update();
123 }
124 
126 {
127  m_sameSRID = true;
128  int w = m_display->getDisplayPixmap()->width();
129  int h = m_display->getDisplayPixmap()->height();
130  te::qt::widgets::Canvas canvas(w, h);
132  canvas.calcAspectRatio(e.m_llx, e.m_lly, e.m_urx, e.m_ury);
133  canvas.setWindow(e.m_llx, e.m_lly, e.m_urx, e.m_ury);
134  QMatrix matrix = canvas.getMatrix();
135 
136  QList<QGraphicsItem*> list = scene()->items();
137  QList<QGraphicsItem*>::iterator it;
138  for(it = list.begin(); it != list.end(); ++it)
139  {
140  AnimationItem* ai = dynamic_cast<AnimationItem*>(*it);
141  ai->m_matrix = matrix;
142  if (ai->m_SRID != m_display->getSRID())
143  m_sameSRID = false;
144  }
145 
146  if (rect() != m_display->getDisplayPixmap()->rect())
147  resize(m_display->getDisplayPixmap()->rect().size());
148  if (matrix != QGraphicsView::matrix())
149  QGraphicsView::setMatrix(matrix);
150 }
void mousePressEvent(QMouseEvent *)
void dragLeaveEvent(QDragLeaveEvent *)
void animationDragEnterEvent(QDragEnterEvent *)
void dragEnterEvent(QDragEnterEvent *)
AnimationView(te::qt::widgets::MapDisplay *md)
Constructor It constructs a AnimationView.
void dragMoveEvent(QDragMoveEvent *)
void keyReleaseEvent(QKeyEvent *)
double m_urx
Upper right corner x-coordinate.
A widget to control the display of a set of layers.
QMatrix getMatrix()
It returns the matrix.
void setWindow(const double &llx, const double &lly, const double &urx, const double &ury)
It sets the world (or window) coordinates area (supposing a cartesian reference system).
double m_llx
Lower left corner x-coordinate.
void animationDropEvent(QDropEvent *)
This file defines a class for a Animation Scene.
This file defines a class for a Animation Item.
An Envelope defines a 2D rectangular region.
void calcAspectRatio(double &llx, double &lly, double &urx, double &ury, const te::map::AlignType hAlign=te::map::Center, const te::map::AlignType vAlign=te::map::Center)
It calculates the best aspect ratio for world (or window) coordinates area (supposing a cartesian ref...
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
void resizeEvent(QResizeEvent *)
double m_lly
Lower left corner y-coordinate.
void mouseReleaseEvent(QMouseEvent *)
double m_ury
Upper right corner y-coordinate.
An abstract class for Animation Item.
Definition: AnimationItem.h:64
void mouseMoveEvent(QMouseEvent *)
QMatrix m_matrix
The display transformation matrix.
void mouseDoubleClickEvent(QMouseEvent *)
int m_SRID
The input route srid.
virtual ~AnimationView()
Destructor It destructs a AnimationView.
void paintEvent(QPaintEvent *)
virtual QPixmap * getDisplayPixmap() const
It returns the map display pixmap.