TimeSliderWidget.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20  /*!
21  \file terralib/qt/widgets/slider/TimeSliderWidget.h
22 
23  \brief A widget used to alow the user to control the visualization of temporal data
24 */
25 
26 #ifndef __TERRALIB_QT_WIDGETS_INTERNAL_TIMESLIDERWIDGET_H
27 #define __TERRALIB_QT_WIDGETS_INTERNAL_TIMESLIDERWIDGET_H
28 
29 //TerraLib
30 #include "../Config.h"
31 #include "../../../geometry.h"
32 #include "../../../datatype.h"
33 #include "../InterfaceController.h"
34 #include "SliderPropertiesDialog.h"
35 // Qt
36 #include <QWidget>
37 #include <QAbstractAnimation>
38 #include <QDateTime>
39 #include <QUrl>
40 
41 //STL
42 #include <memory>
43 
44 namespace Ui { class TimeSliderWidgetForm; }
45 
46 class QGraphicsView;
47 class QParallelAnimationGroup;
48 class QGraphicsItem;
49 class QDateTimeEdit;
50 
51 namespace te
52 {
53  namespace dt
54  {
55  class TimePeriod;
56  class TimeInstant;
57  }
58  namespace gm
59  {
60  class Envelope;
61  }
62  namespace st
63  {
64  class TrajectoryDataSet;
65  class TrajectoryDataSetLayer;
66  }
67 
68  namespace qt
69  {
70  namespace widgets
71  {
72  class MapDisplay;
73  class Animation;
74  class AnimationItem;
75  class TrajectoryItem;
76  class ImageItem;
77  class AnimationScene;
78 
79  /*!
80  \class TimeSliderWidget
81 
82  \brief A wdiget used to control the visualization of temporal data
83  */
85  {
86  Q_OBJECT
87 
88  friend class SliderPropertiesDialog;
89  public:
90 
91  /*!
92  \brief Constructor
93 
94  It constructs a Time Slider Widget
95  */
96  TimeSliderWidget(MapDisplay* d, QWidget* parent = 0, Qt::WindowFlags f = 0);
97 
98  /*!
99  \brief Destructor
100 
101  It destructs a Time Slider Widget
102  */
103  ~TimeSliderWidget();
104 
105  /*!
106  \brief This method is used to set current layer
107 
108  */
109  virtual void layerSelected(te::map::AbstractLayerPtr layer);
110 
111  /*!
112  \brief This method is used to add a new layer
113 
114  */
115  virtual void layerAdded(te::map::AbstractLayerPtr layer);
116 
117  /*!
118  \brief This method is used to remove a layer
119 
120  */
121  virtual void layerRemoved(te::map::AbstractLayerPtr layer);
122 
123  void addTemporalImages(const QString& filePath);
124 
125  /*!
126  \brief This method is used to load a temporal image data.
127  NOTE: It should be edited to enter with new types of temporal images.
128 
129  Param path The folder that has temporal images and the control file.
130  */
131  te::qt::widgets::ImageItem* loadImageData(const QString& path);
132  /*!
133  \brief This method is used to find out the type of temporal image has the folder.
134  NOTE: It should be edited to enter with new types of temporal images.
135  NOTE: You must find a way to discover its kind.
136 
137  \param path The folder that has temporal images and the control file.
138  \return The temporal image type.
139  */
140  QString getTemporalImageType(const QString& path);
141 
142  /*!
143  \brief Add trajectory to animation scene.
144 
145  \param title The trajectory title.
146  \param pixmapFile The trajectory icon.
147  \param poinstFile The trajectory points.
148  */
149  void addTrajectory(te::st::TrajectoryDataSetLayer* tl, const QString& pixmapFile);
150 
151  /*!
152  \brief It calculates the spatial extent.
153  */
154  void calculateAllSpatialExtent();
155 
156  /*!
157  \brief It calculates the temporal extent.
158  */
159  void calculateAllTemporalExtent();
160 
161  /*!
162  \brief Change direction.
163  */
164  void changeDirection();
165 
166  /*!
167  \brief Sets the mode of animation.
168  \param t True if the animation goes back and forth
169  */
170  void setGoAndBack(bool t);
171 
172  /*!
173  \brief Sets the animation direction.
174  \param direction The animation direction.
175  */
176  void setDirection(const QAbstractAnimation::Direction& direction);
177 
178  /*!
179  \brief Sets the animation duration.
180  \param duration The animation duration in miliseconds.
181  */
182  void setDuration(const unsigned int& duration);
183 
184  /*!
185  \brief create new pixmap.
186  */
187  void createNewPixmap();
188 
189  /*!
190  \brief Set transformation matrix and draw current animation.
191  */
192  void draw();
193 
194  /*!
195  \brief It emits, indirectly, a sign for this widget is destroyed.
196  */
197  void deleteMe();
198 
199  /*!
200  \brief It puts graphic item to front.
201 
202  \param item The graphic item.
203  */
204  void putToFront(AnimationItem* item);
205 
206  /*!
207  \brief It puts graphic item to back.
208 
209  \param item The graphic item.
210  */
211  void putToBack(AnimationItem* item);
212 
213  /*!
214  \brief It gets the initial time.
215 
216  \return The initial time.
217  */
218  te::dt::TimeInstant getInitialTime();
219 
220  /*!
221  \brief It gets the final time.
222 
223  \return The final time.
224  */
225  te::dt::TimeInstant getFinalTime();
226 
227  void showWidget(const bool& b);
228 
229  protected:
230 
231  /*!
232  \brief it filters the events of interest.
233  */
234  bool eventFilter(QObject*, QEvent*);
235 
236  /*!
237  \brief Update animation time.
238  */
239  void updateTimeTextEdit();
240 
241  /*!
242  \brief Updates the position of the slider with respect to time animation.
243  */
244  void updateSliderPos();
245 
246  /*!
247  \brief Play animation.
248  */
249  void play();
250 
251  /*!
252  \brief Create animations.
253  */
254  void createAnimations();
255 
256  /*!
257  \brief
258  It it gets the animation time on a time instant.
259  /param tinstant The time instant.
260 
261  \return The animation time in miliseconds.
262  */
263  int getAnimationTime(const te::dt::TimeInstant& tinstant);
264 
265  /*!
266  \brief
267  It it gets the animation time instant.
268 
269  \return The animation time instant.
270  */
271  te::dt::TimeInstant getTimeInstant();
272 
273  /*!
274  \brief
275  It Erase trajectory piece.
276  */
277  void erase(const unsigned int& curTime);
278 
279  /*!
280  \brief
281  True to erase trajectory piece perfectly.
282  Note: Perfectly clear implies loss of performance.
283  */
284  void setErasePerfectly(bool b);
285 
286  /*!
287  \brief
288  It corrects the edited date time
289 
290  /param dte DateTimeEdit to be fixed.
291  /param t The edite date time.
292  */
293  QDateTime fixDateTimeEdit(QDateTimeEdit* dte, const QDateTime& t);
294 
295  void loadAnimation(const QString& title);
296 
297  void removeAnimation(const int& ind);
298  //void removeAnimation(const QString& title);
299 
300  //void removeOnPropertieCombo(const QString& title);
301 
302  bool trajectoryAlreadyExists(QPair<QString, QString>& item);
303  bool coverageAlreadyExists(QPair<QString, QString>& item);
304 
305  /*!
306  \brief It initialize a property animation dialog
307  */
308  void initProperty();
309 
310  /*!
311  \brief Show Property
312 
313  \param b true = show, false = hide
314  */
315  void showPropertySection(bool b);
316 
317  /*!
318  \brief Is Setting Changed
319 
320  \return true = changed, false = not changed
321  */
322  bool isSettingChanged();
323 
324  void adjustPropertyDialog(te::qt::widgets::AnimationItem*);
325 
326  QString getDateString(const te::dt::TimeInstant& t);
327 
328 
329  protected slots:
330 
331  /*!
332  \brief it draw on display.
333  \param p Pointer to QPainter.
334  */
335  void onDisplayPaintEvent(QPainter* p);
336 
337  /*!
338  \brief Drag enter event on display.
339  \param e The drag enter event.
340  */
341  void onAnimationDragEnterEvent(QDragEnterEvent* e);
342 
343  void onAnimationDropEvent(QDropEvent*);
344  /*!
345  \brief it opens the configuration window animation.
346  */
347  void onSettingsToolButtonnClicked();
348 
349  /*!
350  \brief Play or pause the animation.
351  */
352  void onPlayToolButtonnClicked();
353 
354  /*!
355  \brief Stop animation.
356  */
357  void onStopToolButtonnClicked();
358 
359  /*!
360  \brief It takes the necessary measures after slider move.
361  \param e The slider value.
362  */
363  void onSliderMoved(int value);
364 
365  /*!
366  \brief It takes the necessary measures after the change of extent.
367  */
368  void onExtentChanged();
369 
370  /*!
371  \brief It takes the necessary measures after the change of extent.
372  */
373  void onSridChanged();
374 
375  /*!
376  \brief It takes the necessary measures after the end of the trajectory.
377  */
378  void onFinishAnimation();
379 
380  /*!
381  \brief It takes the necessary steps after changing the duration.
382  \param v Value of duration in miliseconds.
383  */
384  void onDurationValueChanged(int v);
385 
386  /*!
387  \brief It takes the necessary steps after changing the duration.
388  \param v Value of opacity (0 - 255).
389  */
390  void onOpacityValueChanged(int v);
391 
392  /*!
393  \brief It takes the necessary steps after changing the current time of animation.
394  \param t The new current time.
395  */
396  void onDateTimeEditChanged(const QDateTime& t);
397 
398  void onAutoPanCheckBoxClicked(bool);
399  void onPanFactorValueChanged(double);
400  void onFrontPushButtonClicked(bool b);
401  void onBackPushButtonClicked(bool b);
402 
403  /*!
404  \brief Help button clicked.
405  */
406  void onHelpPushButtonClicked();
407 
408  /*!
409  \brief Draw track check box clicked.
410 
411  \param b True if the button is checked, or false if the button is unchecked
412  */
413  void onDrawTrailCheckBoxClicked(bool b);
414 
415  /*!
416  \brief Forward radio button clicked.
417 
418  \param b True if the button is checked, or false if the button is unchecked
419  */
420  void onForwardRadioButtonClicked(bool b);
421 
422  /*!
423  \brief Backward radio button clicked.
424 
425  \param b True if the button is checked, or false if the button is unchecked
426  */
427  void onBackwardRadioButtonClicked(bool b);
428 
429  /*!
430  \brief Loop check box clicked.
431 
432  \param b True if the button is checked, or false if the button is unchecked
433  */
434  void onLoopCheckBoxClicked(bool b);
435 
436  /*!
437  \brief Forward and then backward check box clicked.
438 
439  \param b True if the button is checked, or false if the button is unchecked
440  */
441  void onGoAndBackCheckBoxClicked(bool b);
442 
443  /*!
444  \brief Apply time interval push button clicked.
445 
446  \param b True if the button is checked, or false if the button is unchecked
447  */
448  void onApplyTimeIntervalPushButtonClicked(bool b);
449 
450  /*!
451  \brief Opacity combo box activated.
452 
453  \param i The index of combo box.
454  */
455  void onAnimationComboBoxActivated(int i);
456 
457  /*!
458  \brief Remove item animation.
459  */
460  void onRemovePushButtonClicked(bool);
461 
462  /*!
463  \brief Remove all animations.
464  */
465  void onRemoveAllPushButtonClicked(bool);
466 
467  /*!
468  \brief Reset initial time button clicked.
469  */
470  void onResetInitialTimePushButtonClicked();
471 
472  /*!
473  \brief Reset final time button clicked.
474  */
475  void onResetFinalTimePushButtonClicked();
476 
477  void onTrajectoryPixmapSizeChanged(int);
478 
479  void onIconRotateCheckBoxClicked(bool);
480 
481  void dropAction();
482 
483  signals:
484 
485  /*!
486  \brief This sign warns that this widget must be destroyed.
487  */
488  void deleteTimeSliderWidget();
489 
490  private:
491 
492  //struct AnimationAuxInfo
493  //{
494  // QString type;
495  // QString title;
496  // unsigned char opacity;
497  // bool drawTrail;
498  // bool autoPan;
499  // QColor forwardColor;
500  // QColor backwardColor;
501  //};
502 
503  bool m_loop; //!< This property holds whether the slider's animation is on loop.
504  int m_duration; //!< The animation's duration time in miliseconds
505  QAbstractAnimation::Direction m_direction; //!< QAbstractAnimation::Forward or QAbstractAnimation::Backward
506  bool m_goAndBack; //!< Forward and then backward direction
507  bool m_comingBack; //!< Flag to indicate that the trend is coming back
508  MapDisplay* m_display; //!< The map display
509  QGraphicsView* m_animationView; //!< The animation graphics view
510  AnimationScene* m_animationScene; //!< The animation scene
511  QParallelAnimationGroup* m_parallelAnimation; //!< The parallel animation
512  te::gm::Envelope m_spatialExtent; //!< Spatial extent.
513  te::dt::TimePeriod m_temporalExtent; //!< Temporal extent.
514  te::dt::TimePeriod m_temporalAnimationExtent; //!< Animation temporal extent. It is used for show animation.
515  int m_currentTime; //!< Current animation time (relative to time duration).
516  bool m_erasePerfectly; //!< flag to erase trajectory piece perfectly (default = false).
517  std::auto_ptr<Ui::TimeSliderWidgetForm> m_ui; //!< The widget form.
518  QDateTime m_oldQDateTime; //!< The old Qt date time.
519  QDateTime m_oldIQDateTime; //!< The old initial Qt date time.
520  QDateTime m_oldFQDateTime; //!< The old final Qt date time.
521  bool m_dateTimeChanged; //!< flag to signal change in animation time.
522  int m_maxSliderValue; //!< The max slider value.
523  bool m_finished; //!< flag to signal animation finish.
524  bool m_paused; //!< flag to signal animation pause.
525  QList<QPair<QString, te::st::TrajectoryDataSetLayer*> > m_trajectoryItemList; //!< List of all trajectory items (title, layer).
526  QList<QPair<QString, QString> > m_coverageItemList; //!< List of all animation items (title, path).
527  Qt::KeyboardModifiers m_dropModifiers; //!< Control pressed to add animation with drag and drop.
528  QList<QUrl> m_dropUrls; //!< Urls to animation with drag and drop.
529  QByteArray m_dropBA; //!< Layer animation with drag and drop.
530  SliderPropertiesDialog* m_spd; //!< Slider Properties Dialog.
531  QList<QString> m_animationIdList; //!< List containing the shadow of m_ui->m_animationComboBox
532  double m_panFactor; //!< the range is between 0.002 and 0.5
533  };
534  } // end namespace widgets
535  } // end namespace qt
536 } // end namespace te
537 
538 #endif // __TERRALIB_QT_WIDGETS_INTERNAL_TIMESLIDERWIDGET_H
QList< QPair< QString, te::st::TrajectoryDataSetLayer * > > m_trajectoryItemList
List of all trajectory items (title, layer).
Qt::KeyboardModifiers m_dropModifiers
Control pressed to add animation with drag and drop.
QParallelAnimationGroup * m_parallelAnimation
The parallel animation.
te::dt::TimePeriod m_temporalAnimationExtent
Animation temporal extent. It is used for show animation.
std::auto_ptr< Ui::TimeSliderWidgetForm > m_ui
The widget form.
te::gm::Envelope m_spatialExtent
Spatial extent.
QAbstractAnimation::Direction m_direction
QAbstractAnimation::Forward or QAbstractAnimation::Backward.
bool m_goAndBack
Forward and then backward direction.
QGraphicsView * m_animationView
The animation graphics view.
A virtual class for non modal interfaces.
int m_maxSliderValue
The max slider value.
A widget to control the display of a set of layers.
Definition: MapDisplay.h:66
QList< QUrl > m_dropUrls
Urls to animation with drag and drop.
A class to represent time instant.
Definition: TimeInstant.h:55
te::dt::TimePeriod m_temporalExtent
Temporal extent.
QByteArray m_dropBA
Layer animation with drag and drop.
SliderPropertiesDialog * m_spd
Slider Properties Dialog.
bool m_paused
flag to signal animation pause.
bool m_comingBack
Flag to indicate that the trend is coming back.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
URI C++ Library.
int m_currentTime
Current animation time (relative to time duration).
bool m_finished
flag to signal animation finish.
QDateTime m_oldIQDateTime
The old initial Qt date time.
QList< QPair< QString, QString > > m_coverageItemList
List of all animation items (title, path).
MapDisplay * m_display
The map display.
A class to represent time period.
Definition: TimePeriod.h:54
AnimationScene * m_animationScene
The animation scene.
bool m_loop
This property holds whether the slider's animation is on loop.
A layer with reference to a dataset that contains trajectories.
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63
An abstract class for Animation Item.
Definition: AnimationItem.h:62
double m_panFactor
the range is between 0.002 and 0.5
This class allows to add multiple trajectories and temporal image.
A dialog used to configure the behaviour of the SliderSliderWidget.
QDateTime m_oldFQDateTime
The old final Qt date time.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
QList< QString > m_animationIdList
List containing the shadow of m_ui->m_animationComboBox.
QDateTime m_oldQDateTime
The old Qt date time.
bool m_dateTimeChanged
flag to signal change in animation time.
A wdiget used to control the visualization of temporal data.
bool m_erasePerfectly
flag to erase trajectory piece perfectly (default = false).
int m_duration
The animation's duration time in miliseconds.