Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "QmitkUpdateTimerWidget.h"
00019
00020 #include <QTimer>
00021 #include <math.h>
00022
00023
00024 static unsigned int DEFAULTUPDATEVALUE = 50;
00025
00026 static unsigned int MINIMUMUPDATEVALUE = 10;
00027 static unsigned int MAXIMUMUPDATEVALUE = 1000;
00028 static unsigned int UPDATEVALUESTEP = 10;
00029
00030 QmitkUpdateTimerWidget::QmitkUpdateTimerWidget(QWidget* parent)
00031 : QWidget(parent), m_Controls(NULL)
00032 {
00033 this->m_UpdateTimer = new QTimer( this );
00034 this->CreateQtPartControl( this );
00035
00036 this->m_Controls->m_StopNavigationBtn->setEnabled( false );
00037 this->SetupUpdateRateSB( MINIMUMUPDATEVALUE, MAXIMUMUPDATEVALUE, UPDATEVALUESTEP );
00038
00039 this->m_UpdateTimer->setInterval( DEFAULTUPDATEVALUE );
00040 this->m_Controls->m_UpdateRateSB->setValue( DEFAULTUPDATEVALUE );
00041
00042 this->DisableWidget();
00043 }
00044
00045 QmitkUpdateTimerWidget::~QmitkUpdateTimerWidget()
00046 {
00047 m_UpdateTimer->stop();
00048 m_UpdateTimer = NULL;
00049 m_Controls = NULL;
00050 }
00051
00052
00053 void QmitkUpdateTimerWidget::CreateQtPartControl(QWidget *parent)
00054 {
00055 if (!m_Controls)
00056 {
00057
00058 m_Controls = new Ui::QmitkUpdateTimerWidgetControls;
00059 m_Controls->setupUi(parent);
00060 this->CreateConnections();
00061 }
00062 }
00063
00064
00065 void QmitkUpdateTimerWidget::CreateConnections()
00066 {
00067 connect( (QObject*)(m_Controls->m_StartNavigationBtn), SIGNAL(clicked()), this, SLOT(OnStartTimer()) );
00068 connect( (QObject*)(m_Controls->m_StopNavigationBtn), SIGNAL(clicked()), this, SLOT(OnStopTimer()) );
00069 connect( m_Controls->m_UpdateRateSB, SIGNAL(valueChanged(int)), this, SLOT(OnChangeTimerInterval(int)) );
00070 }
00071
00072 unsigned int QmitkUpdateTimerWidget::GetTimerInterval()
00073 {
00074 return this->m_UpdateTimer->interval();
00075 }
00076
00077 void QmitkUpdateTimerWidget::OnChangeTimerInterval( int interval )
00078 {
00079 this->SetTimerInterval(interval);
00080 this->SetFrameRateLabel();
00081 }
00082
00083 void QmitkUpdateTimerWidget::SetTimerInterval( unsigned int msec )
00084 {
00085 this->m_UpdateTimer->setInterval( msec );
00086 this->m_Controls->m_UpdateRateSB->setValue( msec );
00087 }
00088
00089 void QmitkUpdateTimerWidget::StartTimer()
00090 {
00091 if(!m_UpdateTimer->isActive())
00092 {
00093 this->m_UpdateTimer->start();
00094 this->m_Controls->m_StartNavigationBtn->setEnabled( false );
00095 this->m_Controls->m_StopNavigationBtn->setEnabled( true );
00096 this->m_Controls->m_NavigationStateLbl->setStyleSheet( "QLabel{background-color: #96e066 }" );
00097 this->m_Controls->m_NavigationStateLbl->setText( "Started ... " );
00098
00099 emit Started();
00100 }
00101 }
00102
00103 void QmitkUpdateTimerWidget::StopTimer()
00104 {
00105 if(m_UpdateTimer->isActive())
00106 {
00107 m_UpdateTimer->stop();
00108 this->m_Controls->m_StopNavigationBtn->setEnabled( false );
00109 this->m_Controls->m_StartNavigationBtn->setEnabled( true );
00110 this->m_Controls->m_NavigationStateLbl->setStyleSheet( "QLabel{background-color: #ffcccc }" );
00111 this->m_Controls->m_NavigationStateLbl->setText( "Stopped ... " );
00112
00113 emit Stopped();
00114 }
00115 }
00116
00117 QTimer* QmitkUpdateTimerWidget::GetUpdateTimer()
00118 {
00119 return this->m_UpdateTimer;
00120 }
00121
00122 void QmitkUpdateTimerWidget::OnStartTimer()
00123 {
00124 this->StartTimer();
00125 }
00126
00127 void QmitkUpdateTimerWidget::OnStopTimer()
00128 {
00129 this->StopTimer();
00130 }
00131
00132
00133 void QmitkUpdateTimerWidget::SetPurposeLabelText( QString text )
00134 {
00135 m_Controls->m_StartNavigationBtn->setText( " Start " + text );
00136 m_Controls->m_StopNavigationBtn->setText( " Stop " + text );
00137 }
00138
00139
00140 void QmitkUpdateTimerWidget::SetupUpdateRateSB( int min, int max, int step )
00141 {
00142 this->m_Controls->m_UpdateRateSB->setRange( min , max );
00143 this->m_Controls->m_UpdateRateSB->setSingleStep( step );
00144 }
00145
00146
00147 void QmitkUpdateTimerWidget::SetFrameRateLabel()
00148 {
00149 float frameRate = floor(1000 / (float) this->GetTimerInterval() + 0.5);
00150 QString frameRateString = QString::number( frameRate, 'g', 4 );
00151 this->m_Controls->m_FrameRateLbl->setText("msec (" + frameRateString + " Hz)");
00152 }
00153
00154 void QmitkUpdateTimerWidget::HideFramerateSettings( bool hidden )
00155 {
00156 this->m_Controls->m_UpdatesInMsecLbl->setVisible( !hidden );
00157 this->m_Controls->m_UpdateRateSB->setVisible ( !hidden );
00158 this->m_Controls->m_FrameRateLbl->setVisible ( !hidden );
00159 }
00160
00161
00162 void QmitkUpdateTimerWidget::EnableWidget()
00163 {
00164 this->setEnabled( true );
00165 }
00166
00167 void QmitkUpdateTimerWidget::DisableWidget()
00168 {
00169 this->StopTimer();
00170 this->setEnabled( false );
00171 }