diff --git a/Modules/IGTUI/Qmitk/QmitkUpdateTimerWidget.cpp b/Modules/IGTUI/Qmitk/QmitkUpdateTimerWidget.cpp index d48301fde6..41ecfad52d 100644 --- a/Modules/IGTUI/Qmitk/QmitkUpdateTimerWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkUpdateTimerWidget.cpp @@ -1,171 +1,183 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-03-21 19:27:37 +0100 (Sa, 21 Mrz 2009) $ Version: $Revision: 16719 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkUpdateTimerWidget.h" #include #include static unsigned int DEFAULTUPDATEVALUE = 50; // default update value (in msec) for the timer static unsigned int MINIMUMUPDATEVALUE = 10; // smallest value for the update rate spinbox static unsigned int MAXIMUMUPDATEVALUE = 1000; // greatest value for the update rate spinbox static unsigned int UPDATEVALUESTEP = 10; // step size for the update rate spinbox QmitkUpdateTimerWidget::QmitkUpdateTimerWidget(QWidget* parent) : QWidget(parent), m_Controls(NULL) { this->m_UpdateTimer = new QTimer( this ); this->CreateQtPartControl( this ); this->m_Controls->m_StopNavigationBtn->setEnabled( false ); this->SetupUpdateRateSB( MINIMUMUPDATEVALUE, MAXIMUMUPDATEVALUE, UPDATEVALUESTEP ); this->m_UpdateTimer->setInterval( DEFAULTUPDATEVALUE ); this->m_Controls->m_UpdateRateSB->setValue( DEFAULTUPDATEVALUE ); this->DisableWidget(); } QmitkUpdateTimerWidget::~QmitkUpdateTimerWidget() { m_UpdateTimer->stop(); m_UpdateTimer = NULL; m_Controls = NULL; } void QmitkUpdateTimerWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkUpdateTimerWidgetControls; m_Controls->setupUi(parent); this->CreateConnections(); } } void QmitkUpdateTimerWidget::CreateConnections() { connect( (QObject*)(m_Controls->m_StartNavigationBtn), SIGNAL(clicked()), this, SLOT(OnStartTimer()) ); connect( (QObject*)(m_Controls->m_StopNavigationBtn), SIGNAL(clicked()), this, SLOT(OnStopTimer()) ); connect( m_Controls->m_UpdateRateSB, SIGNAL(valueChanged(int)), this, SLOT(OnChangeTimerInterval(int)) ); } unsigned int QmitkUpdateTimerWidget::GetTimerInterval() { return this->m_UpdateTimer->interval(); } void QmitkUpdateTimerWidget::OnChangeTimerInterval( int interval ) { this->SetTimerInterval(interval); this->SetFrameRateLabel(); } void QmitkUpdateTimerWidget::SetTimerInterval( unsigned int msec ) { this->m_UpdateTimer->setInterval( msec ); this->m_Controls->m_UpdateRateSB->setValue( msec ); } void QmitkUpdateTimerWidget::StartTimer() { if(!m_UpdateTimer->isActive()) { this->m_UpdateTimer->start(); this->m_Controls->m_StartNavigationBtn->setEnabled( false ); this->m_Controls->m_StopNavigationBtn->setEnabled( true ); this->m_Controls->m_NavigationStateLbl->setStyleSheet( "QLabel{background-color: #96e066 }" ); this->m_Controls->m_NavigationStateLbl->setText( "Started ... " ); emit Started(); } } void QmitkUpdateTimerWidget::StopTimer() { if(m_UpdateTimer->isActive()) { m_UpdateTimer->stop(); this->m_Controls->m_StopNavigationBtn->setEnabled( false ); this->m_Controls->m_StartNavigationBtn->setEnabled( true ); this->m_Controls->m_NavigationStateLbl->setStyleSheet( "QLabel{background-color: #ffcccc }" ); this->m_Controls->m_NavigationStateLbl->setText( "Stopped ... " ); emit Stopped(); } } QTimer* QmitkUpdateTimerWidget::GetUpdateTimer() { return this->m_UpdateTimer; } void QmitkUpdateTimerWidget::OnStartTimer() { this->StartTimer(); } void QmitkUpdateTimerWidget::OnStopTimer() { this->StopTimer(); } void QmitkUpdateTimerWidget::SetPurposeLabelText( QString text ) { m_Controls->m_StartNavigationBtn->setText( " Start " + text ); m_Controls->m_StopNavigationBtn->setText( " Stop " + text ); } void QmitkUpdateTimerWidget::SetupUpdateRateSB( int min, int max, int step ) { this->m_Controls->m_UpdateRateSB->setRange( min , max ); this->m_Controls->m_UpdateRateSB->setSingleStep( step ); } void QmitkUpdateTimerWidget::SetFrameRateLabel() { float frameRate = floor(1000 / (float) this->GetTimerInterval() + 0.5); // floor rounding can be used because there are no negative values QString frameRateString = QString::number( frameRate, 'g', 4 ); this->m_Controls->m_FrameRateLbl->setText("msec (" + frameRateString + " Hz)"); } void QmitkUpdateTimerWidget::HideFramerateSettings( bool hidden ) { this->m_Controls->m_UpdatesInMsecLbl->setVisible( !hidden ); this->m_Controls->m_UpdateRateSB->setVisible ( !hidden ); this->m_Controls->m_FrameRateLbl->setVisible ( !hidden ); } void QmitkUpdateTimerWidget::EnableWidget() { this->setEnabled( true ); } void QmitkUpdateTimerWidget::DisableWidget() { this->StopTimer(); this->setEnabled( false ); -} \ No newline at end of file +} + + + +void QmitkUpdateTimerWidget::SetIcon( WidgetButtons button, const QIcon& icon ) +{ + switch( button ) + { + case StartButton: m_Controls->m_StartNavigationBtn->setIcon(icon); + + case StopButton: m_Controls->m_StartNavigationBtn->setIcon(icon); + } +} diff --git a/Modules/IGTUI/Qmitk/QmitkUpdateTimerWidget.h b/Modules/IGTUI/Qmitk/QmitkUpdateTimerWidget.h index 9317d02b18..e8442060f0 100644 --- a/Modules/IGTUI/Qmitk/QmitkUpdateTimerWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkUpdateTimerWidget.h @@ -1,130 +1,146 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-03-21 19:27:37 +0100 (Sa, 21 Mrz 2009) $ Version: $Revision: 16719 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef _QmitkUpdateTimerWidget_H_INCLUDED #define _QmitkUpdateTimerWidget_H_INCLUDED #include "ui_QmitkUpdateTimerWidgetControls.h" #include "MitkIGTUIExports.h" /*! \brief QmitkUpdateTimerWidget Widget for setting up and controlling an update timer in an IGT-Pipeline. */ class MitkIGTUI_EXPORT QmitkUpdateTimerWidget : public QWidget { Q_OBJECT // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) public: + + enum WidgetButtons { + + StartButton, + StopButton + }; + /*! \brief default constructor */ QmitkUpdateTimerWidget( QWidget* parent ); /*! \brief default destructor */ virtual ~QmitkUpdateTimerWidget(); /*! \brief This method returns the timer's timeout interval in msec. */ unsigned int GetTimerInterval(); /*! \brief This method sets the timer's timeout interval in msec. */ void SetTimerInterval( unsigned int msec ); /*! \brief This method starts the timer if it is not already active. */ void StartTimer(); /*! \brief This method stops the timer if it is active at the moment. */ void StopTimer(); /*! \brief This method returns this object's timer. */ QTimer* GetUpdateTimer(); /*! \brief This method sets the given QString for the purpose of this update timer e.g. if "Navigation" is given, the start and stop button will be labeled "Start Navigation" and "Stop Navigation". Furthermore the purpose description is used for the timer status label: "Navigation started ... " in this case. */ void SetPurposeLabelText( QString text ); - /* + /*! \brief This method hides the framerate settings spinbox and her labels in the view. */ void HideFramerateSettings( bool hidden ); + /*! + \brief This method sets the icon for a specific button of the widget. + */ + void SetIcon( WidgetButtons button, const QIcon& icon ); + + + + signals: void Started(); void Stopped(); public slots: void EnableWidget(); void DisableWidget(); -private: - /*! - \brief This object's update timer realized by a QTimer - */ - QTimer* m_UpdateTimer; - - /*! - \brief This method is used to set up the update rate spinbox, min and max range are set and also the step size - */ - void SetupUpdateRateSB( int min, int max, int step ); - - /*! - \brief This method is used to set the actual framerate (in Hz) as the framerate label text - */ - void SetFrameRateLabel(); - protected slots: /*! \brief This method is called when the start button is pressed. It starts the timer using StartTimer(). */ void OnStartTimer(); /*! \brief This method is called when the stop button is pressed. It stops the timer using StopTimer(). */ void OnStopTimer(); /*! \brief This method is called when the value in the spinbox is changed. It updates the timer interval using SetTimerInterval( ). */ void OnChangeTimerInterval( int interval ); protected: void CreateConnections(); void CreateQtPartControl( QWidget *parent ); Ui::QmitkUpdateTimerWidgetControls* m_Controls; ///< gui widgets + + +private: + /*! + \brief This object's update timer realized by a QTimer + */ + QTimer* m_UpdateTimer; + + /*! + \brief This method is used to set up the update rate spinbox, min and max range are set and also the step size + */ + void SetupUpdateRateSB( int min, int max, int step ); + + /*! + \brief This method is used to set the actual framerate (in Hz) as the framerate label text + */ + void SetFrameRateLabel(); }; #endif // _QmitkUpdateTimerWidget_H_INCLUDED