diff --git a/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.cpp b/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.cpp index 3b5e69c077..c7c6670457 100644 --- a/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.cpp @@ -1,327 +1,337 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-12 19:14:45 +0200 (Di, 12 Mai 2009) $ Version: $Revision: 1.12 $ 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 "QmitkIGTPlayerWidget.h" //mitk headers #include "mitkTrackingTypes.h" #include #include #include #include #include #include #include //qt headers #include #include #include QmitkIGTPlayerWidget::QmitkIGTPlayerWidget(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f), m_Player(NULL), m_StartTime(-1.0) { m_Controls = NULL; CreateQtPartControl(this); CreateConnections(); this->ResetLCDNumbers(); } QmitkIGTPlayerWidget::~QmitkIGTPlayerWidget() { m_PlayingTimer->stop(); m_Player = NULL; m_PlayingTimer = NULL; } void QmitkIGTPlayerWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkIGTPlayerWidgetControls; m_Controls->setupUi(parent); m_PlayingTimer = new QTimer(this); // initialize update timer } } void QmitkIGTPlayerWidget::CreateConnections() { if ( m_Controls ) { connect( (QObject*)(m_Controls->m_pbLoadDir), SIGNAL(clicked()), this, SLOT(OnSelectPressed()) ); // open file dialog - connect( (QObject*)(m_Controls->m_leInputFile), SIGNAL(editingFinished()), this, SLOT(UpdateInputFileName()) ); // for manual file name input - connect( (QObject*) (m_Controls->m_cbPointSetMode), SIGNAL(clicked(bool)), this, SLOT(OnChangeWidgetView(bool)) ); // widget view switcher connect( (QObject*)(m_Controls->m_pbPlay), SIGNAL(clicked(bool)), this, SLOT(OnPlayButtonClicked(bool)) ); // play button connect( (QObject*)(m_PlayingTimer), SIGNAL(timeout()), this, SLOT(OnPlaying()) ); // update timer connect( (QObject*) (m_Controls->m_pbBegin), SIGNAL(clicked()), this, SLOT(OnGoToBegin()) ); // reset player and go to begin connect( (QObject*) (m_Controls->m_pbEnd), SIGNAL(clicked()), this, SLOT(OnGoToEnd()) ); // reset player } } bool QmitkIGTPlayerWidget::CheckInputFileValid() { QFile file(m_CmpFilename); if(!file.exists()) { QMessageBox::warning(NULL, "IGTPlayer: Error", "No valid input file was loaded. Please load input file first!"); return false; } return true; } +unsigned int QmitkIGTPlayerWidget::GetNumberOfTools() +{ + unsigned int result = 0; + + if(m_Player.IsNotNull()) + result = m_Player->GetNumberOfOutputs(); + + return result; +} + + void QmitkIGTPlayerWidget::SetUpdateRate(unsigned int msecs) { m_PlayingTimer->setInterval((int) msecs); } void QmitkIGTPlayerWidget::OnPlayButtonClicked(bool checked) { if(CheckInputFileValid()) // no playing possible without valid input file { if(checked) // play { if(m_Player.IsNull()) // start play { m_Player = mitk::NavigationDataPlayer::New(); m_Player->SetFileName(m_CmpFilename.toStdString()); m_Player->StartPlaying(); m_PlayingTimer->start(100); emit PlayingStarted(); } else // resume play { m_Player->Resume(); m_PlayingTimer->start(100); emit PlayingResumed(); } } else // pause { m_Player->Pause(); m_PlayingTimer->stop(); emit PlayingPaused(); } } else m_Controls->m_pbPlay->setChecked(false); // uncheck play button if file unvalid } QTimer* QmitkIGTPlayerWidget::GetPlayingTimer() { return m_PlayingTimer; } void QmitkIGTPlayerWidget::OnStopPlaying() { this->StopPlaying(); } void QmitkIGTPlayerWidget::StopPlaying() { m_PlayingTimer->stop(); emit PlayingStopped(); if(m_Player.IsNotNull()) m_Player->StopPlaying(); m_Player = NULL; m_StartTime = -1; // set starttime back - + this->ResetLCDNumbers(); m_Controls->m_pbPlay->setChecked(false); // set play button unchecked } void QmitkIGTPlayerWidget::OnPlaying() { if(m_Player.IsNull()) return; if(m_StartTime < 0) m_StartTime = m_Player->GetOutput()->GetTimeStamp(); // get playback start time if(!m_Player->IsAtEnd()) { m_Player->Update(); // update player int msc = (int) (m_Player->GetOutput()->GetTimeStamp() - m_StartTime); // calculation for playing time display int ms = msc % 1000; msc = (msc - ms) / 1000; int s = msc % 60; int min = (msc-s) / 60; // set lcd numbers m_Controls->m_lcdNrMsec->display(ms); m_Controls->m_lcdNrSec->display(s); m_Controls->m_lcdNrMin->display(min); emit PlayerUpdated(); // player successfully updated } else this->StopPlaying(); // if player is at EOF } const std::vector QmitkIGTPlayerWidget::GetNavigationDatas() { std::vector navDatas; if(m_Player.IsNotNull()) { for(unsigned int i=0; i < m_Player->GetNumberOfOutputs(); ++i) { navDatas.push_back(m_Player->GetOutput(i)); } } return navDatas; } -void QmitkIGTPlayerWidget::UpdateInputFileName() +void QmitkIGTPlayerWidget::SetInputFileName(const QString& inputFileName) { - this->OnGoToEnd(); /// stops playing and resets lcd numbers QString oldName = m_CmpFilename; m_CmpFilename.clear(); - m_CmpFilename = m_Controls->m_leInputFile->text(); + m_CmpFilename = inputFileName; + QFile file(m_CmpFilename); if(m_CmpFilename.isEmpty() || !file.exists()) { QMessageBox::warning(NULL, "Warning", QString("Please enter valid path! Using previous path again.")); m_CmpFilename=oldName; m_Controls->m_leInputFile->setText(m_CmpFilename); } } void QmitkIGTPlayerWidget::SetPlayer( mitk::NavigationDataPlayer::Pointer player ) { if(player.IsNotNull()) m_Player = player; } void QmitkIGTPlayerWidget::OnSelectPressed() { this->OnGoToEnd(); /// stops playing and resets lcd numbers QString oldName = m_CmpFilename; m_CmpFilename.clear(); m_CmpFilename = QFileDialog::getOpenFileName(this, "Load tracking data", QDir::currentPath(),"XML files (*.xml)"); if (m_CmpFilename.isEmpty())//if something went wrong or user pressed cancel in the save dialog { m_CmpFilename=oldName; } + m_Controls->m_leInputFile->setText(m_CmpFilename); } void QmitkIGTPlayerWidget::OnGoToEnd() { this->StopPlaying(); // reset lcd numbers this->ResetLCDNumbers(); } void QmitkIGTPlayerWidget::OnGoToBegin() { // stop player manual so no PlayingStopped() m_PlayingTimer->stop(); if(m_Player.IsNotNull()) m_Player->StopPlaying(); m_Player = NULL; // set player to NULL so it can be initialized again if playback is called afterwards m_StartTime = -1; // set starttime back //reset view elements m_Controls->m_pbPlay->setChecked(false); this->ResetLCDNumbers(); } void QmitkIGTPlayerWidget::SetWidgetViewToNormalPlayback() { m_Controls->m_lblResolution->setHidden(true); m_Controls->m_sbResolution->setHidden(true); m_Controls->m_hsPlaybackPosition->setHidden(true); m_Controls->m_pbFrameBackward->setHidden(true); m_Controls->m_pbFastBackward->setHidden(true); m_Controls->m_pbFrameForward->setHidden(true); m_Controls->m_pbFastForward->setHidden(true); m_Controls->m_lblSample->setHidden(true); m_Controls->m_lcdNrSample->setHidden(true); } void QmitkIGTPlayerWidget::SetWidgetViewToPointSetPlayback() { m_Controls->m_lblResolution->setVisible(true); m_Controls->m_sbResolution->setVisible(true); m_Controls->m_hsPlaybackPosition->setHidden(false); m_Controls->m_pbFrameBackward->setVisible(true); m_Controls->m_pbFastBackward->setVisible(true); m_Controls->m_pbFrameForward->setVisible(true); m_Controls->m_pbFastForward->setVisible(true); m_Controls->m_lblSample->setVisible(true); m_Controls->m_lcdNrSample->setVisible(true); } void QmitkIGTPlayerWidget::OnChangeWidgetView(bool pointSetPlaybackView) { if(pointSetPlaybackView) this->SetWidgetViewToPointSetPlayback(); else this->SetWidgetViewToNormalPlayback(); } void QmitkIGTPlayerWidget::ResetLCDNumbers() { m_Controls->m_lcdNrMin->display(QString("00")); m_Controls->m_lcdNrSec->display(QString("00")); m_Controls->m_lcdNrMsec->display(QString("000")); } \ No newline at end of file diff --git a/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.h b/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.h index a39f01e5e6..2ad8ee890c 100644 --- a/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.h @@ -1,198 +1,204 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-12 19:14:45 +0200 (Di, 12 Mai 2009) $ Version: $Revision: 1.12 $ 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 QmitkIGTPlayerWidget_H #define QmitkIGTPlayerWidget_H //QT headers #include //mitk headers #include "MitkIGTUIExports.h" #include "mitkNavigationTool.h" #include "mitkNavigationDataPlayer.h" #include //ui header #include "ui_QmitkIGTPlayerWidgetControls.h" /** Documentation: * \brief GUI to access the IGT Player. * User must specify the file name where the input xml-file is located. The NavigationDatas from the xml-file can be * played in normal mode or in PointSet mode. * * In normal mode the player updates the NavigationDatas every 100ms (can be changed in SetUpdateRate()) and returns * them when GetNavigationDatas() is called. * In PointSet mode the player generates a PointSet with all NavigationDatas from the xml-file. So the playback is * performed on this ND PointSet. * * \ingroup IGTUI */ class MitkIGTUI_EXPORT QmitkIGTPlayerWidget : public QWidget { Q_OBJECT public: static const std::string VIEW_ID; /*! \brief default constructor */ QmitkIGTPlayerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); /*! \brief default deconstructor */ ~QmitkIGTPlayerWidget(); /*! \brief Sets the player for this player widget */ void SetPlayer(mitk::NavigationDataPlayer::Pointer player); /*! \brief Returns the playing timer of this widget */ QTimer* GetPlayingTimer(); /*! \brief Returns the current playback NavigationDatas from the xml-file */ const std::vector GetNavigationDatas(); /*! \brief Sets the widget's look for the normal playback */ void SetWidgetViewToNormalPlayback(); /*! \brief Sets the widget's look for the PointSet playback */ void SetWidgetViewToPointSetPlayback(); + /*! \brief Sets the update rate of this widget's playing timer */ void SetUpdateRate(unsigned int msecs); + /*! + \brief Returns the number of different tools from the current playing stream. + * + * Retuns 0 if playback file is invalid. + */ + unsigned int GetNumberOfTools(); + + /*! + \brief Stops the playback + */ + void StopPlaying(); + + + signals: /*! \brief This signal is emitted when the player starts the playback */ void PlayingStarted(); /*! \brief This signal is emitted when the player resumes after a pause */ void PlayingResumed(); /*! \brief This signal is emitted when the player stops */ void PlayingStopped(); /*! \brief This signal is emitted when the player is paused */ void PlayingPaused(); /*! \brief This signal is emitted when the player reaches the end of the playback */ void PlayingEnded(); /*! \brief This signal is emitted every time the player updated the NavigationDatas */ void PlayerUpdated(); + protected slots: /*! \brief Starts or pauses the playback */ void OnPlayButtonClicked(bool toggled); /*! \brief Updates the playback data */ void OnPlaying(); /*! \brief Stops the playback */ void OnStopPlaying(); /*! \brief Updates the input filename */ - void UpdateInputFileName(); + void SetInputFileName(const QString& inputFileName); /*! \brief Opens file open dialog for searching the input file */ void OnSelectPressed(); /*! \brief Stops the playback */ void OnGoToEnd(); /*! \brief Stops the playback and resets the player to the beginning */ void OnGoToBegin(); /*! \brief Switches between the normal playback view and the PointSet playback view */ void OnChangeWidgetView(bool pointSetPlaybackView); protected: /// \brief Creation of the connections virtual void CreateConnections(); virtual void CreateQtPartControl(QWidget *parent); - /*! - \brief Sets the filename of the input file - */ - void SetInputFileName(); - - /*! - \brief Stops the playback - */ - void StopPlaying(); - /*! \brief Checks if an imput file with the set filename exists */ bool CheckInputFileValid(); /*! \brief Sets all LCD numbers to 0 */ void ResetLCDNumbers(); Ui::QmitkIGTPlayerWidgetControls* m_Controls; mitk::NavigationDataPlayer::Pointer m_Player; ///< plays NDs from a XML file QString m_CmpFilename; ///< filename of the input file QTimer* m_PlayingTimer; ///< update timer mitk::NavigationData::TimeStampType m_StartTime; ///< start time of playback needed for time display }; #endif \ No newline at end of file diff --git a/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidgetControls.ui b/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidgetControls.ui index e1bc8891bd..a00ad31878 100644 --- a/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidgetControls.ui +++ b/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidgetControls.ui @@ -1,456 +1,459 @@ QmitkIGTPlayerWidgetControls 0 0 398 689 Form - + Settings true false Input File 150 0 + + true + 90 16777215 50 false Select false false Playback in PointSet Mode Qt::Horizontal 40 20 Resolution 1 : Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 1 10 - + Player true background-color: rgb(60, 60, 60); color: rgb(250, 250, 250); 3 QLCDNumber::Flat 0 min background-color: rgb(60, 60, 60); color: rgb(250, 250, 250); 2 QLCDNumber::Flat 0 sec background-color: rgb(60, 60, 60); color: rgb(250, 250, 250); 3 QLCDNumber::Flat 0 msec Qt::Horizontal 40 20 Sample background-color: rgb(60, 60, 60); color: rgb(250, 250, 250); 8 QLCDNumber::Flat color: rgb(170, 0, 0); 0 100 5 Qt::Horizontal false false QSlider::NoTicks 0 0 :/IGTUI/firstframe.png:/IGTUI/firstframe.png 0 0 :/IGTUI/fastbackward.png:/IGTUI/fastbackward.png 20 16 0 0 0 0 :/IGTUI/previousframe.png:/IGTUI/previousframe.png 0 0 Play at normal speed :/IGTUI/play.png :/IGTUI/pause.png:/IGTUI/play.png 16 16 true false 0 0 :/IGTUI/nextframe.png:/IGTUI/nextframe.png 0 0 :/IGTUI/fastforward.png:/IGTUI/fastforward.png 20 16 0 0 :/IGTUI/stop.png:/IGTUI/stop.png Qt::Vertical 20 40