Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkUpdateTimerWidget.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "QmitkUpdateTimerWidget.h"
18 
19 #include <QTimer>
20 #include <math.h>
21 
22 
23 static unsigned int DEFAULTUPDATEVALUE = 50; // default update value (in msec) for the timer
24 
25 static unsigned int MINIMUMUPDATEVALUE = 10; // smallest value for the update rate spinbox
26 static unsigned int MAXIMUMUPDATEVALUE = 1000; // greatest value for the update rate spinbox
27 static unsigned int UPDATEVALUESTEP = 10; // step size for the update rate spinbox
28 
30 : QWidget(parent), m_Controls(nullptr)
31 {
32  this->m_UpdateTimer = new QTimer( this );
33  this->CreateQtPartControl( this );
34 
35  this->m_Controls->m_StopNavigationBtn->setEnabled( false );
36  this->SetupUpdateRateSB( MINIMUMUPDATEVALUE, MAXIMUMUPDATEVALUE, UPDATEVALUESTEP );
37 
38  this->m_UpdateTimer->setInterval( DEFAULTUPDATEVALUE );
39  this->m_Controls->m_UpdateRateSB->setValue( DEFAULTUPDATEVALUE );
40 
41  this->DisableWidget();
42 }
43 
45 {
46  m_UpdateTimer->stop();
47  m_UpdateTimer = nullptr;
48  m_Controls = nullptr;
49 }
50 
51 
53 {
54  if (!m_Controls)
55  {
56  // create GUI widgets
57  m_Controls = new Ui::QmitkUpdateTimerWidgetControls;
58  m_Controls->setupUi(parent);
59  this->CreateConnections();
60  }
61 }
62 
63 
65 {
66  connect( (QObject*)(m_Controls->m_StartNavigationBtn), SIGNAL(clicked()), this, SLOT(OnStartTimer()) );
67  connect( (QObject*)(m_Controls->m_StopNavigationBtn), SIGNAL(clicked()), this, SLOT(OnStopTimer()) );
68  connect( m_Controls->m_UpdateRateSB, SIGNAL(valueChanged(int)), this, SLOT(OnChangeTimerInterval(int)) );
69 }
70 
72 {
73  return this->m_UpdateTimer->interval();
74 }
75 
77 {
78  this->SetTimerInterval(interval);
79  this->SetFrameRateLabel();
80 }
81 
83 {
84  this->m_UpdateTimer->setInterval( msec );
85  this->m_Controls->m_UpdateRateSB->setValue( msec );
86 }
87 
89 {
90  if(!m_UpdateTimer->isActive())
91  {
92  this->m_UpdateTimer->start();
93  this->m_Controls->m_StartNavigationBtn->setEnabled( false );
94  this->m_Controls->m_StopNavigationBtn->setEnabled( true );
95  this->m_Controls->m_NavigationStateLbl->setStyleSheet( "QLabel{background-color: #96e066 }" );
96  this->m_Controls->m_NavigationStateLbl->setText( "Started ... " );
97 
98  emit Started();
99  }
100 }
101 
103 {
104  if(m_UpdateTimer->isActive())
105  {
106  m_UpdateTimer->stop();
107  this->m_Controls->m_StopNavigationBtn->setEnabled( false );
108  this->m_Controls->m_StartNavigationBtn->setEnabled( true );
109  this->m_Controls->m_NavigationStateLbl->setStyleSheet( "QLabel{background-color: #ffcccc }" );
110  this->m_Controls->m_NavigationStateLbl->setText( "Stopped ... " );
111 
112  emit Stopped();
113  }
114 }
115 
117 {
118  return this->m_UpdateTimer;
119 }
120 
122 {
123  this->StartTimer();
124 }
125 
127 {
128  this->StopTimer();
129 }
130 
131 
133 {
134  m_Controls->m_StartNavigationBtn->setText( " Start " + text );
135  m_Controls->m_StopNavigationBtn->setText( " Stop " + text );
136 }
137 
138 
139 void QmitkUpdateTimerWidget::SetupUpdateRateSB( int min, int max, int step )
140 {
141  this->m_Controls->m_UpdateRateSB->setRange( min , max );
142  this->m_Controls->m_UpdateRateSB->setSingleStep( step );
143 }
144 
145 
146 void QmitkUpdateTimerWidget::SetFrameRateLabel()
147 {
148  float frameRate = floor(1000 / (float) this->GetTimerInterval() + 0.5); // floor rounding can be used because there are no negative values
149  QString frameRateString = QString::number( frameRate, 'g', 4 );
150  this->m_Controls->m_FrameRateLbl->setText("msec (" + frameRateString + " Hz)");
151 }
152 
154 {
155  this->m_Controls->m_UpdatesInMsecLbl->setVisible( !hidden );
156  this->m_Controls->m_UpdateRateSB->setVisible ( !hidden );
157  this->m_Controls->m_FrameRateLbl->setVisible ( !hidden );
158 }
159 
160 
162 {
163  this->setEnabled( true );
164 }
165 
167 {
168  this->StopTimer();
169  this->setEnabled( false );
170 }
171 
172 
173 
174 void QmitkUpdateTimerWidget::SetIcon( WidgetButtons button, const QIcon& icon )
175 {
176  switch( button )
177  {
178  case StartButton:
179  m_Controls->m_StartNavigationBtn->setIcon(icon);
180  break;
181 
182  case StopButton: m_Controls->m_StopNavigationBtn->setIcon(icon);
183  break;
184 
185  default:
186  break;
187  }
188 }
static unsigned int DEFAULTUPDATEVALUE
void OnStartTimer()
This method is called when the start button is pressed. It starts the timer using StartTimer()...
void SetTimerInterval(unsigned int msec)
This method sets the timer's timeout interval in msec.
void StopTimer()
This method stops the timer if it is active at the moment.
void OnChangeTimerInterval(int interval)
This method is called when the value in the spinbox is changed. It updates the timer interval using S...
Ui::QmitkUpdateTimerWidgetControls * m_Controls
gui widgets
void SetIcon(WidgetButtons button, const QIcon &icon)
This method sets the icon for a specific button of the widget.
static unsigned int UPDATEVALUESTEP
QmitkUpdateTimerWidget(QWidget *parent)
default constructor
static unsigned int MAXIMUMUPDATEVALUE
void OnStopTimer()
This method is called when the stop button is pressed. It stops the timer using StopTimer().
virtual ~QmitkUpdateTimerWidget()
default destructor
QTimer * GetUpdateTimer()
This method returns this object's timer.
void SetPurposeLabelText(QString text)
This method sets the given QString for the purpose of this update timer e.g. if "Navigation" is given...
void HideFramerateSettings(bool hidden)
This method hides the framerate settings spinbox and her labels in the view.
unsigned int GetTimerInterval()
This method returns the timer's timeout interval in msec.
void CreateQtPartControl(QWidget *parent)
static T max(T x, T y)
Definition: svm.cpp:70
void StartTimer()
This method starts the timer if it is not already active.
static T min(T x, T y)
Definition: svm.cpp:67
static unsigned int MINIMUMUPDATEVALUE