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