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::BoundingRectViewportUpdate);
23  setResizeAnchor(QGraphicsView::NoAnchor);
24 }
25 
27 {
28 }
29 
31 {
32  QCoreApplication::sendEvent(m_display, (QEvent*)e);
33 }
34 
36 {
37  QCoreApplication::sendEvent(m_display, (QEvent*)e);
38 }
39 
41 {
42  QCoreApplication::sendEvent(m_display, (QEvent*)e);
43 }
44 
46 {
47  QCoreApplication::sendEvent(m_display, (QEvent*)e);
48 }
49 
51 {
52  QCoreApplication::sendEvent(m_display, (QEvent*)e);
53 }
54 
56 {
57  QCoreApplication::sendEvent(m_display, (QEvent*)e);
58 }
59 
61 {
62  QCoreApplication::sendEvent(m_display, (QEvent*)e);
63 }
64 
66 {
67  QCoreApplication::sendEvent(m_display, (QEvent*)e);
68 }
69 
71 {
72  QGraphicsScene* scene = this->scene();
73  if(scene)
74  {
75  QRectF r = scene->sceneRect();
76  fitInView(r);
77  }
78 }
79 
81 {
82  emit animationDragEnterEvent(e);
83 }
84 
86 {
87  m_dragDropAccepted = false;
88  e->setAccepted(m_dragDropAccepted);
89 }
90 
92 {
93  e->setAccepted(m_dragDropAccepted);
94 }
95 
97 {
98  if(m_dragDropAccepted)
99  emit animationDropEvent(e);
100 }
101 
103 {
104  setMatrix();
105  QGraphicsView::paintEvent(e);
106 }
107 
109 {
110  int w = m_display->getDisplayPixmap()->width();
111  int h = m_display->getDisplayPixmap()->height();
112  te::qt::widgets::Canvas canvas(w, h);
113  te::gm::Envelope e = m_display->getExtent();
114  canvas.calcAspectRatio(e.m_llx, e.m_lly, e.m_urx, e.m_ury);
115  canvas.setWindow(e.m_llx, e.m_lly, e.m_urx, e.m_ury);
116  QMatrix matrix = canvas.getMatrix();
117 
118  QList<QGraphicsItem*> list = scene()->items();
119  QList<QGraphicsItem*>::iterator it;
120  for(it = list.begin(); it != list.end(); ++it)
121  {
122  AnimationItem* ai = dynamic_cast<AnimationItem*>(*it);
123  ai->m_matrix = matrix;
124  }
125  QGraphicsView::setMatrix(matrix);
126 
127  QRectF sceneRec = scene()->sceneRect(); // The scene rect is already on display projection
128  if (sceneRec != sceneRect())
129  updateSceneRect(sceneRec);
130 
131  // ensure the paint event
132  // set bigger box to ensure paint event
133  QRectF newRec(sceneRec.x() - 10 * sceneRec.width(), sceneRec.y() - 10 * sceneRec.height(), 30 * sceneRec.width(), 30 * sceneRec.height());
134  QRectF dispExt(e.m_llx, e.m_lly, e.getWidth(), e.getHeight());
135  QRectF srec(e.m_llx - 10 * e.getWidth(), e.m_lly - 10 * e.getHeight(), 30 * e.getWidth(), 30 * e.getHeight());
136  if (dispExt.contains(sceneRec))
137  fitInView(srec);
138  else
139  fitInView(newRec);
140 }
void mousePressEvent(QMouseEvent *)
void dragLeaveEvent(QDragLeaveEvent *)
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.
Definition: Envelope.h:346
double getWidth() const
It returns the envelope width.
Definition: Envelope.h:443
A widget to control the display of a set of layers.
Definition: MapDisplay.h:66
QMatrix getMatrix()
It returns the matrix.
Definition: Canvas.cpp:2123
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).
Definition: Canvas.cpp:147
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
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.
Definition: Envelope.h:51
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...
Definition: Canvas.cpp:160
void resizeEvent(QResizeEvent *)
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
A canvas built on top of Qt.
Definition: Canvas.h:54
void mouseReleaseEvent(QMouseEvent *)
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
An abstract class for Animation Item.
Definition: AnimationItem.h:62
void mouseMoveEvent(QMouseEvent *)
QMatrix m_matrix
The display transformation matrix.
double getHeight() const
It returns the envelope height.
Definition: Envelope.h:448
void mouseDoubleClickEvent(QMouseEvent *)
virtual ~AnimationView()
Destructor It destructs a AnimationView.
void paintEvent(QPaintEvent *)