All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TimeSliderWidget.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2010-2013 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.cpp
22 
23  \brief A widget used to alow the user to controle the visualization of temporal data
24 */
25 
26 //Terralib
27 #include "TimePropertiesDialog.h"
28 //#include "TimeSliderEventFilter.h"
29 #include "TimeSliderWidget.h"
30 #include "ui_TimeSliderWidgetForm.h"
31 
32 //QT
33 #include <qgraphicseffect.h>
34 #include <QtGui/QSlider>
35 #include <QMouseEvent>
36 
37 te::qt::widgets::TimeSliderWidget::TimeSliderWidget(QWidget* parent, Qt::WindowFlags f, int minimum, int maximum)
38  : QWidget(parent, f),
39  m_ui(new Ui::TimeSliderWidgetForm)
40 {
41  m_ui->setupUi(this);
42 
43  //Adjusting the slider's range
44  m_ui->m_TemporalHorizontalSlider->setMinimum(minimum);
45  m_ui->m_TemporalHorizontalSlider->setMaximum(maximum);
46 
47  //Adjusting the Timer
48  m_timer.reset(new QTimer(this));
49  connect(m_timer.get(), SIGNAL(timeout()), this, SLOT(play()));
50 
51  //The opacity used to fade the widget if the mouse is not over it
52  QGraphicsOpacityEffect* opacityEffect = new QGraphicsOpacityEffect;
53  opacityEffect->setOpacity(0.3);
54  this->setGraphicsEffect(opacityEffect);
55 
56  ////An event filter used to know when the mouse is over the widget
57  //this->installEventFilter(new te::qt::widgets::TimeSliderEventFilter(this));
58 
59  //Adjusting the icons and the graphic effects
60  m_ui->m_exitToolButton->setIcon(QIcon::fromTheme("system-log-out"));
61  m_ui->m_settingsToolButton->setIcon(QIcon::fromTheme("preferences-system"));
62  m_ui->m_playToolButton->setIcon(QIcon::fromTheme("media-playback-start"));
63  m_ui->m_skipBackwardToolButton->setIcon(QIcon::fromTheme("media-skip-backward"));
64  m_ui->m_skipForwardToolButton->setIcon(QIcon::fromTheme("media-skip-forward"));
65 
66  // connect signal and slots
67  connect(m_ui->m_exitToolButton, SIGNAL(clicked()), this, SLOT(onExitToolButtonnClicked()));
68  connect(m_ui->m_settingsToolButton, SIGNAL(clicked()), this, SLOT(onSettingsToolButtonnClicked()));
69  connect(m_ui->m_playToolButton, SIGNAL(clicked()), this, SLOT(onPlayToolButtonnClicked()));
70  connect(m_ui->m_skipBackwardToolButton, SIGNAL(clicked()), this, SLOT(onSkipBackwardToolButtonnClicked()));
71  connect(m_ui->m_skipForwardToolButton, SIGNAL(clicked()), this, SLOT(onSkipForwardToolButtonnClicked()));
72  connect(m_ui->m_TemporalHorizontalSlider, SIGNAL(valueChanged (int)), this, SLOT(onSliderValueChanged(int)));
73 
74  setAttribute(Qt::WA_DeleteOnClose, true);
75 
76  m_loop = false; //By default, the animation will not be looping.
77  m_state = false; //By default, the amimation state will be false, as in not playing.
78  m_speed = 100; //By default, the animation speed will be 100 miliseconds.
79 }
80 
82 {
83 }
84 
86 {
87  graphicsEffect()->setEnabled(false);
88 }
89 
91 {
92  graphicsEffect()->setEnabled(true);
93 }
94 
96 {
97  this->close();
98 }
99 
101 {
102  std::auto_ptr<te::qt::widgets::TimePropertiesDialog> dlg (new te::qt::widgets::TimePropertiesDialog(this));
103  int res = dlg->exec();
104  if (res == QDialog::Accepted)
105  {
106  m_loop = dlg->isLoopChecked();
107  m_speed = 10000/dlg->getValue();
108  }
109 }
110 
112 {
113  if(!m_state)
114  {
115  //The timer will bradcast a timeout for every step per <m_speed> miliseconds
116  m_timer->start(m_ui->m_TemporalHorizontalSlider->singleStep() * m_speed);
117  m_state = true;
118  m_ui->m_playToolButton->setIcon(QIcon::fromTheme("media-playback-stop"));
119  }
120  else
121  {
122  m_state = false;
123  m_timer->stop();
124  m_ui->m_playToolButton->setIcon(QIcon::fromTheme("media-playback-start"));
125  }
126 }
127 
129 {
130  m_ui->m_TemporalHorizontalSlider->setValue(m_ui->m_TemporalHorizontalSlider->minimum());
131 }
132 
134 {
135  m_ui->m_TemporalHorizontalSlider->setValue(m_ui->m_TemporalHorizontalSlider->maximum());
136 }
137 
139 {
140  int step = m_ui->m_TemporalHorizontalSlider->value() + m_ui->m_TemporalHorizontalSlider->singleStep();
141 
142  m_ui->m_TemporalHorizontalSlider->setValue(step);
143 
144  if(step > m_ui->m_TemporalHorizontalSlider->maximum())
145  {
146  if(m_loop)
147  m_ui->m_TemporalHorizontalSlider->setValue(m_ui->m_TemporalHorizontalSlider->minimum());
148  else
149  {
150  m_timer->stop();
151  m_state = false;
152  m_ui->m_playToolButton->setIcon(QIcon::fromTheme("media-playback-start"));
153  }
154  }
155 }
156 
158 {
159  emit valueCHanged(value);
160 }
std::auto_ptr< QTimer > m_timer
The timer that will control the animation proccesses.
A widget used to alow the user to control the visualization of temporal data.
A dialog used to configure the behaviour of the TimeSliderWidget.
bool m_state
This property holds whether the slider&#39;s animation is running.
int m_speed
The slider&#39;s animation speed in miliseconds.
std::auto_ptr< Ui::TimeSliderWidgetForm > m_ui
The widget form.
A widget used to alow the user to control the visualization of temporal data.
bool m_loop
This property holds whether the slider&#39;s animation is on loop.
TimeSliderWidget(QWidget *parent=0, Qt::WindowFlags f=0, int minimum=0, int maximum=10)
Constructor.