All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 PixmapItem;
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  te::qt::widgets::PixmapItem* getMetadata(const QString& path);
126 
127  te::qt::widgets::PixmapItem* getGoesMetadata(const QString& path);
128  te::dt::TimeInstant getGoesTime(const QString& file);
129 
130  te::qt::widgets::PixmapItem* getHidroMetadata(const QString& path);
131  te::qt::widgets::PixmapItem* getHidroCtlParameters(const QString& path);
132  void setHidroLUT(te::qt::widgets::PixmapItem* pi);
133  te::dt::TimeInstant getHidroTime(const QString& file);
134 
135  te::qt::widgets::PixmapItem* getEtaMetadata(const QString& path);
136  te::qt::widgets::PixmapItem* getEtaCtlParameters(const QString& path);
137  void setEtaLUT(te::qt::widgets::PixmapItem* pi);
138  te::dt::TimeInstant getEtaTime(const QString& file);
139 
140  te::qt::widgets::PixmapItem* getTemporalImageMetadata(const QString& path);
141  te::qt::widgets::PixmapItem* getTemporalImageCtlParameters(const QString& path);
142  te::dt::TimeInstant getTemporalImageTime(const QString& file);
143 
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 calculateSpatialExtent();
158 
159  /*!
160  \brief It calculates the temporal extent.
161  */
162  void calculateTemporalExtent();
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 It configures automatic pan over a animation path.
189  It toggles auto pan state.
190  \param title The animation title.
191  */
192  void setAutomaticPan(const QString& title);
193 
194  /*!
195  \brief create new pixmap.
196  */
197  void createNewPixmap();
198 
199  /*!
200  \brief Set transformation matrix and draw current animation.
201  */
202  void draw();
203 
204  /*!
205  \brief It emits, indirectly, a sign for this widget is destroyed.
206  */
207  void deleteMe();
208 
209  /*!
210  \brief It puts graphic item to front.
211 
212  \param item The graphic item.
213  */
214  void putToFront(AnimationItem* item);
215 
216  /*!
217  \brief It puts graphic item to back.
218 
219  \param item The graphic item.
220  */
221  void putToBack(AnimationItem* item);
222 
223  /*!
224  \brief It gets the initial time.
225 
226  \return The initial time.
227  */
228  te::dt::TimeInstant getInitialTime();
229 
230  /*!
231  \brief It gets the final time.
232 
233  \return The final time.
234  */
235  te::dt::TimeInstant getFinalTime();
236 
237  protected:
238 
239  /*!
240  \brief it filters the events of interest.
241  */
242  bool eventFilter(QObject*, QEvent*);
243 
244  /*!
245  \brief Update animation time.
246  */
247  void updateTimeTextEdit();
248 
249  /*!
250  \brief Updates the position of the slider with respect to time animation.
251  */
252  void updateSliderPos();
253 
254  /*!
255  \brief Play animation.
256  */
257  void play();
258 
259  /*!
260  \brief Create animations.
261  */
262  void createAnimations();
263 
264  /*!
265  \brief
266  It it gets the animation time on a time instant.
267  /param tinstant The time instant.
268 
269  \return The animation time in miliseconds.
270  */
271  int getAnimationTime(const te::dt::TimeInstant& tinstant);
272 
273  /*!
274  \brief
275  It it gets the animation time instant.
276 
277  \return The animation time instant.
278  */
279  te::dt::TimeInstant getTimeInstant();
280 
281  /*!
282  \brief
283  It Erase trajectory piece.
284  */
285  void erase(const unsigned int& curTime);
286 
287  /*!
288  \brief
289  True to erase trajectory piece perfectly.
290  Note: Perfectly clear implies loss of performance.
291  */
292  void setErasePerfectly(bool b);
293 
294  /*!
295  \brief
296  It corrects the edited date time
297 
298  /param dte DateTimeEdit to be fixed.
299  /param t The edite date time.
300  */
301  QDateTime fixDateTimeEdit(QDateTimeEdit* dte, const QDateTime& t);
302 
303  /*!
304  \brief
305  Draw the pixmap item.
306 
307  /param pi The pixmap item.
308  /param dwrect The rect of map display in world coordinates.
309  /param painter The painter.
310  */
311  void drawPixmapItem(PixmapItem* pi, const QRectF& dwrect, QPainter* painter);
312 
314 
315  void loadAnimation(const QString& title);
316 
317  void removeAnimation(const QString& title);
318 
319  void removeOnPropertieCombo(const QString& title);
320 
321  /*!
322  \brief
323  Draw the trajectory icon.
324 
325  /param t The trajectory item.
326  /param pos The top left position in device coordinates.
327  /param painter The painter.
328  */
329  void drawTrajectoryIcon(const TrajectoryItem* t, const QPoint& pos, QPainter* painter);
330 
331  bool trajectoryAlreadyExists(QPair<QString, te::st::TrajectoryDataSetLayer*>& item);
332  bool coverageAlreadyExists(QPair<QString, QString>& item);
333 
334  /*!
335  \brief It initialize a property animation dialog
336  */
337  void initProperty();
338 
339  /*!
340  \brief Show Property
341 
342  \param b true = show, false = hide
343  */
344  void showPropertySection(bool b);
345 
346  /*!
347  \brief Is Setting Changed
348 
349  \return true = changed, false = not changed
350  */
351  bool isSettingChanged();
352 
353  /*!
354  \brief Remove animation item from the opacity combo box and trajectory color combo box.
355 
356  \param ai The item to be removed.
357  */
358  //void removeComboItem(te::qt::widgets::AnimationItem* ai);
359 
360  //void getAuxInfo(te::qt::widgets::AnimationItem* ai, int index = -1);
361 
362  //void setAuxInfo(te::qt::widgets::AnimationItem* ai, int index = -1);
363 
364  void adjustTrajectoryGroupBox(te::qt::widgets::AnimationItem*);
365 
366  QString getDateString(const te::dt::TimeInstant& t);
367 
368 
369  protected slots:
370 
371  /*!
372  \brief it draw on display.
373  \param p Pointer to QPainter.
374  */
375  void onDisplayPaintEvent(QPainter* p);
376 
377  /*!
378  \brief Drag enter event on display.
379  \param e The drag enter event.
380  */
381  void onAnimationDragEnterEvent(QDragEnterEvent* e);
382 
383  void onAnimationDropEvent(QDropEvent*);
384  /*!
385  \brief it opens the configuration window animation.
386  */
387  void onSettingsToolButtonnClicked();
388 
389  /*!
390  \brief Play or pause the animation.
391  */
392  void onPlayToolButtonnClicked();
393 
394  /*!
395  \brief Stop animation.
396  */
397  void onStopToolButtonnClicked();
398 
399  /*!
400  \brief It takes the necessary measures after slider move.
401  \param e The slider value.
402  */
403  void onSliderMoved(int value);
404 
405  /*!
406  \brief It takes the necessary measures after the change of extent.
407  */
408  void onExtentChanged();
409 
410  /*!
411  \brief It takes the necessary measures after the change of extent.
412  */
413  void onSridChanged();
414 
415  /*!
416  \brief It takes the necessary measures after the end of the trajectory.
417  */
418  void onFinishAnimation();
419 
420  /*!
421  \brief It takes the necessary steps after changing the duration.
422  \param v Value of duration in miliseconds.
423  */
424  void onDurationValueChanged(int v);
425 
426  /*!
427  \brief It takes the necessary steps after changing the duration.
428  \param v Value of opacity (0 - 255).
429  */
430  void onOpacityValueChanged(int v);
431 
432  /*!
433  \brief It takes the necessary steps after changing the current time of animation.
434  \param t The new current time.
435  */
436  void onDateTimeEditChanged(const QDateTime& t);
437 
438  void onAutoPanCheckBoxClicked(bool);
439  void onPanFactorValueChanged(double);
440  void onFrontPushButtonClicked(bool b);
441  void onBackPushButtonClicked(bool b);
442 
443  /*!
444  \brief Help button clicked.
445  */
446  void onHelpPushButtonClicked();
447 
448  /*!
449  \brief Draw track check box clicked.
450 
451  \param b True if the button is checked, or false if the button is unchecked
452  */
453  void onDrawTrailCheckBoxClicked(bool b);
454 
455  /*!
456  \brief Apply animation items push button clicked. It Sets the visibility of animations.
457 
458  \param b True if the button is checked, or false if the button is unchecked
459  */
460  //void onApplyAnimationItemPushButtonClicked(bool);
461 
462  /*!
463  \brief Forward radio button clicked.
464 
465  \param b True if the button is checked, or false if the button is unchecked
466  */
467  void onForwardRadioButtonClicked(bool b);
468 
469  /*!
470  \brief Backward radio button clicked.
471 
472  \param b True if the button is checked, or false if the button is unchecked
473  */
474  void onBackwardRadioButtonClicked(bool b);
475 
476  /*!
477  \brief Loop check box clicked.
478 
479  \param b True if the button is checked, or false if the button is unchecked
480  */
481  void onLoopCheckBoxClicked(bool b);
482 
483  /*!
484  \brief Forward and then backward check box clicked.
485 
486  \param b True if the button is checked, or false if the button is unchecked
487  */
488  void onGoAndBackCheckBoxClicked(bool b);
489 
490  /*!
491  \brief Apply time interval push button clicked.
492 
493  \param b True if the button is checked, or false if the button is unchecked
494  */
495  void onApplyTimeIntervalPushButtonClicked(bool b);
496 
497  /*!
498  \brief Trajectory color combo box activated.
499 
500  \param i The index of combo box.
501  */
502  //void onTrajectoryColorComboBoxActivated(int i);
503 
504  /*!
505  \brief Opacity combo box activated.
506 
507  \param i The index of combo box.
508  */
509  void onAnimationComboBoxActivated(int i);
510 
511  /*!
512  \brief Remove item animation.
513  */
514  void onRemovePushButtonClicked(bool);
515 
516  /*!
517  \brief Remove all animations.
518  */
519  void onRemoveAllPushButtonClicked(bool);
520 
521  /*!
522  \brief Reset initial time button clicked.
523  */
524  void onResetInitialTimePushButtonClicked();
525 
526  /*!
527  \brief Reset final time button clicked.
528  */
529  void onResetFinalTimePushButtonClicked();
530 
531  void onWidthValueChanged(int);
532 
533  void onHeightValueChanged(int);
534 
535  void dropAction();
536 
537  signals:
538 
539  /*!
540  \brief This sign warns that this widget must be destroyed.
541  */
542  void deleteTimeSliderWidget();
543 
544  private:
545 
546  //struct AnimationAuxInfo
547  //{
548  // QString type;
549  // QString title;
550  // unsigned char opacity;
551  // bool drawTrail;
552  // bool autoPan;
553  // QColor forwardColor;
554  // QColor backwardColor;
555  //};
556 
557  bool m_loop; //!< This property holds whether the slider's animation is on loop.
558  int m_duration; //!< The animation's duration time in miliseconds
559  QAbstractAnimation::Direction m_direction; //!< QAbstractAnimation::Forward or QAbstractAnimation::Backward
560  bool m_goAndBack; //!< Forward and then backward direction
561  bool m_comingBack; //!< Flag to indicate that the trend is coming back
562  MapDisplay* m_display; //!< The map display
563  QGraphicsView* m_animationView; //!< The animation graphics view
564  AnimationScene* m_animationScene; //!< The animation scene
565  QParallelAnimationGroup* m_parallelAnimation; //!< The parallel animation
566  te::gm::Envelope m_spatialExtent; //!< Spatial extent.
567  te::dt::TimePeriod m_temporalExtent; //!< Temporal extent.
568  te::dt::TimePeriod m_temporalAnimationExtent; //!< Animation temporal extent. It is used for show animation.
569  int m_currentTime; //!< Current animation time (relative to time duration).
570  bool m_erasePerfectly; //!< flag to erase trajectory piece perfectly (default = false).
571  std::auto_ptr<Ui::TimeSliderWidgetForm> m_ui; //!< The widget form.
572  QDateTime m_oldQDateTime; //!< The old Qt date time.
573  QDateTime m_oldIQDateTime; //!< The old initial Qt date time.
574  QDateTime m_oldFQDateTime; //!< The old final Qt date time.
576  int m_maxSliderValue; //!< The max slider value.
578  bool m_paused;
579  QList<QPair<QString, te::st::TrajectoryDataSetLayer*> > m_trajectoryItemList; //!< List of all trajectory items (title, layer).
580  QList<QPair<QString, QString> > m_coverageItemList; //!< List of all animation items (title, path).
581  Qt::KeyboardModifiers m_dropModifiers; //!< Control pressed to add animation with drag and drop.
582  QList<QUrl> m_dropUrls; //!< Urls to animation with drag and drop.
583  QByteArray m_dropBA; //!< Layer animation with drag and drop.
584  SliderPropertiesDialog* m_spd; //!< Slider Properties Dialog.
585  //QMap<int, AnimationAuxInfo> m_auxInfo; //!< animation auxiliar information
586  };
587  } // end namespace widgets
588  } // end namespace qt
589 } // end namespace te
590 
591 #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.
QIcon getImage(int type)
QAbstractAnimation::Direction m_direction
QAbstractAnimation::Forward or QAbstractAnimation::Backward.
bool m_goAndBack
Forward and then backward direction.
This class is a dialog for the Trajectory Icon Item.
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_comingBack
Flag to indicate that the trend is coming back.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
int m_currentTime
Current animation time (relative to time duration).
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:66
This class is a dialog for the Pixmap Item.
Definition: AnimationItem.h:57
This class is a dialog for the Animation.
A dialog used to configure the behaviour of the SliderSliderWidget.
QDateTime m_oldFQDateTime
The old final Qt date time.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
QDateTime m_oldQDateTime
The old Qt date 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.