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  protected:
228 
229  /*!
230  \brief it filters the events of interest.
231  */
232  bool eventFilter(QObject*, QEvent*);
233 
234  /*!
235  \brief Update animation time.
236  */
237  void updateTimeTextEdit();
238 
239  /*!
240  \brief Updates the position of the slider with respect to time animation.
241  */
242  void updateSliderPos();
243 
244  /*!
245  \brief Play animation.
246  */
247  void play();
248 
249  /*!
250  \brief Create animations.
251  */
252  void createAnimations();
253 
254  /*!
255  \brief
256  It it gets the animation time on a time instant.
257  /param tinstant The time instant.
258 
259  \return The animation time in miliseconds.
260  */
261  int getAnimationTime(const te::dt::TimeInstant& tinstant);
262 
263  /*!
264  \brief
265  It it gets the animation time instant.
266 
267  \return The animation time instant.
268  */
269  te::dt::TimeInstant getTimeInstant();
270 
271  /*!
272  \brief
273  It Erase trajectory piece.
274  */
275  void erase(const unsigned int& curTime);
276 
277  /*!
278  \brief
279  True to erase trajectory piece perfectly.
280  Note: Perfectly clear implies loss of performance.
281  */
282  void setErasePerfectly(bool b);
283 
284  /*!
285  \brief
286  It corrects the edited date time
287 
288  /param dte DateTimeEdit to be fixed.
289  /param t The edite date time.
290  */
291  QDateTime fixDateTimeEdit(QDateTimeEdit* dte, const QDateTime& t);
292 
293  void loadAnimation(const QString& title);
294 
295  void removeAnimation(const int& ind);
296  //void removeAnimation(const QString& title);
297 
298  //void removeOnPropertieCombo(const QString& title);
299 
300  bool trajectoryAlreadyExists(QPair<QString, QString>& item);
301  bool coverageAlreadyExists(QPair<QString, QString>& item);
302 
303  /*!
304  \brief It initialize a property animation dialog
305  */
306  void initProperty();
307 
308  /*!
309  \brief Show Property
310 
311  \param b true = show, false = hide
312  */
313  void showPropertySection(bool b);
314 
315  /*!
316  \brief Is Setting Changed
317 
318  \return true = changed, false = not changed
319  */
320  bool isSettingChanged();
321 
322  void adjustPropertyDialog(te::qt::widgets::AnimationItem*);
323 
324  QString getDateString(const te::dt::TimeInstant& t);
325 
326 
327  protected slots:
328 
329  /*!
330  \brief it draw on display.
331  \param p Pointer to QPainter.
332  */
333  void onDisplayPaintEvent(QPainter* p);
334 
335  /*!
336  \brief Drag enter event on display.
337  \param e The drag enter event.
338  */
339  void onAnimationDragEnterEvent(QDragEnterEvent* e);
340 
341  void onAnimationDropEvent(QDropEvent*);
342  /*!
343  \brief it opens the configuration window animation.
344  */
345  void onSettingsToolButtonnClicked();
346 
347  /*!
348  \brief Play or pause the animation.
349  */
350  void onPlayToolButtonnClicked();
351 
352  /*!
353  \brief Stop animation.
354  */
355  void onStopToolButtonnClicked();
356 
357  /*!
358  \brief It takes the necessary measures after slider move.
359  \param e The slider value.
360  */
361  void onSliderMoved(int value);
362 
363  /*!
364  \brief It takes the necessary measures after the change of extent.
365  */
366  void onExtentChanged();
367 
368  /*!
369  \brief It takes the necessary measures after the change of extent.
370  */
371  void onSridChanged();
372 
373  /*!
374  \brief It takes the necessary measures after the end of the trajectory.
375  */
376  void onFinishAnimation();
377 
378  /*!
379  \brief It takes the necessary steps after changing the duration.
380  \param v Value of duration in miliseconds.
381  */
382  void onDurationValueChanged(int v);
383 
384  /*!
385  \brief It takes the necessary steps after changing the duration.
386  \param v Value of opacity (0 - 255).
387  */
388  void onOpacityValueChanged(int v);
389 
390  /*!
391  \brief It takes the necessary steps after changing the current time of animation.
392  \param t The new current time.
393  */
394  void onDateTimeEditChanged(const QDateTime& t);
395 
396  void onAutoPanCheckBoxClicked(bool);
397  void onPanFactorValueChanged(double);
398  void onFrontPushButtonClicked(bool b);
399  void onBackPushButtonClicked(bool b);
400 
401  /*!
402  \brief Help button clicked.
403  */
404  void onHelpPushButtonClicked();
405 
406  /*!
407  \brief Draw track check box clicked.
408 
409  \param b True if the button is checked, or false if the button is unchecked
410  */
411  void onDrawTrailCheckBoxClicked(bool b);
412 
413  /*!
414  \brief Forward radio button clicked.
415 
416  \param b True if the button is checked, or false if the button is unchecked
417  */
418  void onForwardRadioButtonClicked(bool b);
419 
420  /*!
421  \brief Backward radio button clicked.
422 
423  \param b True if the button is checked, or false if the button is unchecked
424  */
425  void onBackwardRadioButtonClicked(bool b);
426 
427  /*!
428  \brief Loop check box clicked.
429 
430  \param b True if the button is checked, or false if the button is unchecked
431  */
432  void onLoopCheckBoxClicked(bool b);
433 
434  /*!
435  \brief Forward and then backward check box clicked.
436 
437  \param b True if the button is checked, or false if the button is unchecked
438  */
439  void onGoAndBackCheckBoxClicked(bool b);
440 
441  /*!
442  \brief Apply time interval push button clicked.
443 
444  \param b True if the button is checked, or false if the button is unchecked
445  */
446  void onApplyTimeIntervalPushButtonClicked(bool b);
447 
448  /*!
449  \brief Opacity combo box activated.
450 
451  \param i The index of combo box.
452  */
453  void onAnimationComboBoxActivated(int i);
454 
455  /*!
456  \brief Remove item animation.
457  */
458  void onRemovePushButtonClicked(bool);
459 
460  /*!
461  \brief Remove all animations.
462  */
463  void onRemoveAllPushButtonClicked(bool);
464 
465  /*!
466  \brief Reset initial time button clicked.
467  */
468  void onResetInitialTimePushButtonClicked();
469 
470  /*!
471  \brief Reset final time button clicked.
472  */
473  void onResetFinalTimePushButtonClicked();
474 
475  void onTrajectoryPixmapSizeChanged(int);
476 
477  void onIconRotateCheckBoxClicked(bool);
478 
479  void dropAction();
480 
481  signals:
482 
483  /*!
484  \brief This sign warns that this widget must be destroyed.
485  */
486  void deleteTimeSliderWidget();
487 
488  private:
489 
490  //struct AnimationAuxInfo
491  //{
492  // QString type;
493  // QString title;
494  // unsigned char opacity;
495  // bool drawTrail;
496  // bool autoPan;
497  // QColor forwardColor;
498  // QColor backwardColor;
499  //};
500 
501  bool m_loop; //!< This property holds whether the slider's animation is on loop.
502  int m_duration; //!< The animation's duration time in miliseconds
503  QAbstractAnimation::Direction m_direction; //!< QAbstractAnimation::Forward or QAbstractAnimation::Backward
504  bool m_goAndBack; //!< Forward and then backward direction
505  bool m_comingBack; //!< Flag to indicate that the trend is coming back
506  MapDisplay* m_display; //!< The map display
507  QGraphicsView* m_animationView; //!< The animation graphics view
508  AnimationScene* m_animationScene; //!< The animation scene
509  QParallelAnimationGroup* m_parallelAnimation; //!< The parallel animation
510  te::gm::Envelope m_spatialExtent; //!< Spatial extent.
511  te::dt::TimePeriod m_temporalExtent; //!< Temporal extent.
512  te::dt::TimePeriod m_temporalAnimationExtent; //!< Animation temporal extent. It is used for show animation.
513  int m_currentTime; //!< Current animation time (relative to time duration).
514  bool m_erasePerfectly; //!< flag to erase trajectory piece perfectly (default = false).
515  std::auto_ptr<Ui::TimeSliderWidgetForm> m_ui; //!< The widget form.
516  QDateTime m_oldQDateTime; //!< The old Qt date time.
517  QDateTime m_oldIQDateTime; //!< The old initial Qt date time.
518  QDateTime m_oldFQDateTime; //!< The old final Qt date time.
519  bool m_dateTimeChanged; //!< flag to signal change in animation time.
520  int m_maxSliderValue; //!< The max slider value.
521  bool m_finished; //!< flag to signal animation finish.
522  bool m_paused; //!< flag to signal animation pause.
523  QList<QPair<QString, te::st::TrajectoryDataSetLayer*> > m_trajectoryItemList; //!< List of all trajectory items (title, layer).
524  QList<QPair<QString, QString> > m_coverageItemList; //!< List of all animation items (title, path).
525  Qt::KeyboardModifiers m_dropModifiers; //!< Control pressed to add animation with drag and drop.
526  QList<QUrl> m_dropUrls; //!< Urls to animation with drag and drop.
527  QByteArray m_dropBA; //!< Layer animation with drag and drop.
528  SliderPropertiesDialog* m_spd; //!< Slider Properties Dialog.
529  QList<QString> m_animationIdList; //!< List containing the shadow of m_ui->m_animationComboBox
530  double m_panFactor; //!< the range is between 0.002 and 0.5
531  };
532  } // end namespace widgets
533  } // end namespace qt
534 } // end namespace te
535 
536 #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.