MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
QmitkUpdateTimerWidget.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14
15#include <QTimer>
16#include <cmath>
17
18
19static unsigned int DEFAULTUPDATEVALUE = 50; // default update value (in msec) for the timer
20
21static unsigned int MINIMUMUPDATEVALUE = 10; // smallest value for the update rate spinbox
22static unsigned int MAXIMUMUPDATEVALUE = 1000; // greatest value for the update rate spinbox
23static unsigned int UPDATEVALUESTEP = 10; // step size for the update rate spinbox
24
26: QWidget(parent), m_Controls(nullptr)
27{
28 this->m_UpdateTimer = new QTimer( this );
29 this->CreateQtPartControl( this );
30
31 this->m_Controls->m_StopNavigationBtn->setEnabled( false );
32 this->SetupUpdateRateSB( MINIMUMUPDATEVALUE, MAXIMUMUPDATEVALUE, UPDATEVALUESTEP );
33
34 this->m_UpdateTimer->setInterval( DEFAULTUPDATEVALUE );
35 this->m_Controls->m_UpdateRateSB->setValue( DEFAULTUPDATEVALUE );
36
37 this->DisableWidget();
38}
39
41{
42 m_UpdateTimer->stop();
43 m_UpdateTimer = nullptr;
44 m_Controls = nullptr;
45}
46
47
49{
50 if (!m_Controls)
51 {
52 // create GUI widgets
53 m_Controls = new Ui::QmitkUpdateTimerWidgetControls;
54 m_Controls->setupUi(parent);
55 this->CreateConnections();
56 }
57}
58
59
61{
62 connect( (QObject*)(m_Controls->m_StartNavigationBtn), SIGNAL(clicked()), this, SLOT(OnStartTimer()) );
63 connect( (QObject*)(m_Controls->m_StopNavigationBtn), SIGNAL(clicked()), this, SLOT(OnStopTimer()) );
64 connect( m_Controls->m_UpdateRateSB, SIGNAL(valueChanged(int)), this, SLOT(OnChangeTimerInterval(int)) );
65}
66
68{
69 return this->m_UpdateTimer->interval();
70}
71
73{
74 this->SetTimerInterval(interval);
75 this->SetFrameRateLabel();
76}
77
79{
80 this->m_UpdateTimer->setInterval( msec );
81 this->m_Controls->m_UpdateRateSB->setValue( msec );
82}
83
85{
86 if(!m_UpdateTimer->isActive())
87 {
88 this->m_UpdateTimer->start();
89 this->m_Controls->m_StartNavigationBtn->setEnabled( false );
90 this->m_Controls->m_StopNavigationBtn->setEnabled( true );
91 this->m_Controls->m_NavigationStateLbl->setStyleSheet( "QLabel{background-color: #96e066 }" );
92 this->m_Controls->m_NavigationStateLbl->setText( "Started ... " );
93
94 emit Started();
95 }
96}
97
99{
100 if(m_UpdateTimer->isActive())
101 {
102 m_UpdateTimer->stop();
103 this->m_Controls->m_StopNavigationBtn->setEnabled( false );
104 this->m_Controls->m_StartNavigationBtn->setEnabled( true );
105 this->m_Controls->m_NavigationStateLbl->setStyleSheet( "QLabel{background-color: #ffcccc }" );
106 this->m_Controls->m_NavigationStateLbl->setText( "Stopped ... " );
107
108 emit Stopped();
109 }
110}
111
113{
114 return this->m_UpdateTimer;
115}
116
121
123{
124 this->StopTimer();
125}
126
127
129{
130 m_Controls->m_StartNavigationBtn->setText( " Start " + text );
131 m_Controls->m_StopNavigationBtn->setText( " Stop " + text );
132}
133
134
135void QmitkUpdateTimerWidget::SetupUpdateRateSB( int min, int max, int step )
136{
137 this->m_Controls->m_UpdateRateSB->setRange( min , max );
138 this->m_Controls->m_UpdateRateSB->setSingleStep( step );
139}
140
141
142void QmitkUpdateTimerWidget::SetFrameRateLabel()
143{
144 float frameRate = floor(1000 / (float) this->GetTimerInterval() + 0.5); // floor rounding can be used because there are no negative values
145 QString frameRateString = QString::number( frameRate, 'g', 4 );
146 this->m_Controls->m_FrameRateLbl->setText("msec (" + frameRateString + " Hz)");
147}
148
150{
151 this->m_Controls->m_UpdatesInMsecLbl->setVisible( !hidden );
152 this->m_Controls->m_UpdateRateSB->setVisible ( !hidden );
153 this->m_Controls->m_FrameRateLbl->setVisible ( !hidden );
154}
155
156
158{
159 this->setEnabled( true );
160}
161
163{
164 this->StopTimer();
165 this->setEnabled( false );
166}
167
168
169
170void QmitkUpdateTimerWidget::SetIcon( WidgetButtons button, const QIcon& icon )
171{
172 switch( button )
173 {
174 case StartButton:
175 m_Controls->m_StartNavigationBtn->setIcon(icon);
176 break;
177
178 case StopButton: m_Controls->m_StopNavigationBtn->setIcon(icon);
179 break;
180
181 default:
182 break;
183 }
184}
void HideFramerateSettings(bool hidden)
This method hides the framerate settings spinbox and her labels in the view.
void StopTimer()
This method stops the timer if it is active at the moment.
void SetPurposeLabelText(QString text)
This method sets the given QString for the purpose of this update timer e.g. if "Navigation" is given...
QTimer * GetUpdateTimer()
This method returns this object's timer.
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 StartTimer()
This method starts the timer if it is not already active.
QmitkUpdateTimerWidget(QWidget *parent)
default constructor
void CreateQtPartControl(QWidget *parent)
void SetTimerInterval(unsigned int msec)
This method sets the timer's timeout interval in msec.
~QmitkUpdateTimerWidget() override
default destructor
void SetIcon(WidgetButtons button, const QIcon &icon)
This method sets the icon for a specific button of the widget.
void OnStopTimer()
This method is called when the stop button is pressed. It stops the timer using StopTimer().
unsigned int GetTimerInterval()
This method returns the timer's timeout interval in msec.
void OnStartTimer()
This method is called when the start button is pressed. It starts the timer using StartTimer().