From e6222e45166bc2276f45e1b23ae6557a04d51c9a Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Wed, 14 May 2014 01:50:19 +0100 Subject: [PATCH 1/2] Stop histogram while playing and add a message. Clean some code --- source/app/HistogramWidget.cpp | 76 ++++++++++++++++---------- source/app/HistogramWidget.h | 60 ++++++++++----------- source/app/PropertiesSidebar.cpp | 79 +++++++++++++++------------ source/app/PropertiesSidebar.h | 9 ++-- source/app/ViewArea.h | 4 +- source/app/plaYUVerApp.cpp | 80 +++++++++++++++------------- source/app/plaYUVerApp.h | 4 +- source/lib/PlaYUVerFrameStatistics.h | 3 ++ 8 files changed, 174 insertions(+), 141 deletions(-) diff --git a/source/app/HistogramWidget.cpp b/source/app/HistogramWidget.cpp index 69c695b..f7ea10d 100755 --- a/source/app/HistogramWidget.cpp +++ b/source/app/HistogramWidget.cpp @@ -29,6 +29,7 @@ #include #include #include "HistogramWidget.h" +#include "TypeDef.h" #include "PlaYUVerFrameStatistics.h" #include "PlaYUVerFrame.h" @@ -46,7 +47,7 @@ const QBrush g_eColorPallet[][3] = Qt::red, // Channel Red Qt::green, // Channel Green Qt::blue, // Channel Blue - },}; + }, }; class HistogramWidgetPrivate { @@ -58,6 +59,7 @@ public: HistogramDataLoading, // The image is being loaded HistogramStarted, // Histogram values calculation started. HistogramCompleted, // Histogram values calculation completed. + HistogramSkipped, // Skip histogram while playing HistogramFailed // Histogram values calculation failed. }; @@ -79,11 +81,11 @@ public: double xmin; double xminOrg; double xmax; - int range; - int clearFlag; // Clear drawing zone with message. + Int range; + Int clearFlag; // Clear drawing zone with message. // Image informations - int imageChannels; + Int imageChannels; Int imageColorSpace; bool sixteenBits; @@ -110,7 +112,7 @@ public: //////////////////////////////////////////////////////////////////////////////// //Constructor without image data -HistogramWidget::HistogramWidget( int width, int height, QWidget *parent ) : +HistogramWidget::HistogramWidget( Int width, Int height, QWidget *parent ) : QWidget( parent ) { setAttribute( Qt::WA_DeleteOnClose ); @@ -143,7 +145,7 @@ HistogramWidget::~HistogramWidget() // Setup Functions //////////////////////////////////////////////////////////////////////////////// -void HistogramWidget::setupWidget( int width, int height, HistogramOptions options ) +Void HistogramWidget::setupWidget( Int width, Int height, HistogramOptions options ) { m_channelType = LumaHistogram; m_scaleType = LogScaleHistogram; @@ -160,7 +162,7 @@ void HistogramWidget::setupWidget( int width, int height, HistogramOptions optio connect( d->blinkTimer, SIGNAL( timeout() ), this, SLOT( slotBlinkTimerDone() ) ); } -void HistogramWidget::setOptions( HistogramOptions options ) +Void HistogramWidget::setOptions( HistogramOptions options ) { d->statisticsVisible = ( bool )( options & ShowStatistics ); d->selectMode = ( bool )( options & SelectMode ); @@ -168,14 +170,14 @@ void HistogramWidget::setOptions( HistogramOptions options ) d->lumaChannel = ( bool )( options & ShowLumaChannel ); } -void HistogramWidget::setHistogramGuideByColor( QColor color ) +Void HistogramWidget::setHistogramGuideByColor( QColor color ) { d->guideVisible = true; d->colorGuide = color; update(); } -void HistogramWidget::reset( void ) +Void HistogramWidget::reset() { d->guideVisible = false; d->clearFlag = HistogramWidgetPrivate::HistogramNone; @@ -197,7 +199,7 @@ void HistogramWidget::reset( void ) // Custom Event Handler //////////////////////////////////////////////////////////////////////////////// -void HistogramWidget::customEvent( QEvent *event ) +Void HistogramWidget::customEvent( QEvent *event ) { if( !event ) { @@ -249,7 +251,7 @@ void HistogramWidget::customEvent( QEvent *event ) unsetCursor(); // Send signals to refresh information if necessary. - // The signals may trigger multiple repaints, avoid this, + // The signals may trigger multiple repaints, aVoid this, // we repaint once afterwards. setUpdatesEnabled( false ); @@ -287,7 +289,7 @@ void HistogramWidget::customEvent( QEvent *event ) // Data Loading Functions //////////////////////////////////////////////////////////////////////////////// -void HistogramWidget::setDataLoading() +Void HistogramWidget::setDataLoading() { if( d->clearFlag != HistogramWidgetPrivate::HistogramDataLoading ) { @@ -301,7 +303,16 @@ void HistogramWidget::setDataLoading() } } -void HistogramWidget::setLoadingFailed() +Void HistogramWidget::setLoadingSkipped() +{ + d->clearFlag = HistogramWidgetPrivate::HistogramSkipped; + d->blinkTimer->stop(); + d->inInitialRepaintWait = false; + update(); + unsetCursor(); +} + +Void HistogramWidget::setLoadingFailed() { d->clearFlag = HistogramWidgetPrivate::HistogramFailed; d->blinkTimer->stop(); @@ -312,7 +323,7 @@ void HistogramWidget::setLoadingFailed() //////////////////////////////////////////////////////////////////////////////// -void HistogramWidget::stopHistogramComputation( void ) +Void HistogramWidget::stopHistogramComputation() { if( m_imageHistogram ) m_imageHistogram->stopCalcHistogramValues(); @@ -327,7 +338,7 @@ void HistogramWidget::stopHistogramComputation( void ) // Update Data Methods //////////////////////////////////////////////////////////////////////////////// -void HistogramWidget::updateData( Pel ***imageData, UInt imageWidth, UInt imageHeight, Int bitsPerChannel, Int pixel_format, UInt chroma_size, Pel ***selData, +Void HistogramWidget::updateData( Pel ***imageData, UInt imageWidth, UInt imageHeight, Int bitsPerChannel, Int pixel_format, UInt chroma_size, Pel ***selData, UInt selWidth, UInt selHeight ) { Int colorSpace = PlaYUVerFrame::isRGBorYUVorGray( pixel_format ); @@ -375,7 +386,7 @@ void HistogramWidget::updateData( Pel ***imageData, UInt imageWidth, UInt imageH m_selectionHistogram = 0L; } -void HistogramWidget::updateData( const PlaYUVerFrame *playuver_frame, const PlaYUVerFrame *playuver_selection ) +Void HistogramWidget::updateData( const PlaYUVerFrame *playuver_frame, const PlaYUVerFrame *playuver_selection ) { d->sixteenBits = false; //d->imageColorSpace = image.getPelFormat(); @@ -409,7 +420,7 @@ void HistogramWidget::updateData( const PlaYUVerFrame *playuver_frame, const Pla } -void HistogramWidget::updateSelectionData( Pel ***selData, UInt selWidth, UInt selHeight, Int bitsPerChannel, Int pixel_format, UInt chroma_size ) +Void HistogramWidget::updateSelectionData( Pel ***selData, UInt selWidth, UInt selHeight, Int bitsPerChannel, Int pixel_format, UInt chroma_size ) { // Remove old histogram data from memory. @@ -420,7 +431,7 @@ void HistogramWidget::updateSelectionData( Pel ***selData, UInt selWidth, UInt s m_selectionHistogram = new PlaYUVerFrameStatistics( selData, selWidth, selHeight, bitsPerChannel, pixel_format, chroma_size, this ); } -void HistogramWidget::updateSelectionData( const PlaYUVerFrame *selection ) +Void HistogramWidget::updateSelectionData( const PlaYUVerFrame *selection ) { // Remove old histogram data from memory. @@ -433,7 +444,7 @@ void HistogramWidget::updateSelectionData( const PlaYUVerFrame *selection ) //////////////////////////////////////////////////////////////////////////////// -void HistogramWidget::slotBlinkTimerDone( void ) +Void HistogramWidget::slotBlinkTimerDone() { d->blinkFlag = !d->blinkFlag; d->inInitialRepaintWait = false; @@ -445,7 +456,7 @@ void HistogramWidget::slotBlinkTimerDone( void ) // Paint Event //////////////////////////////////////////////////////////////////////////////// -void HistogramWidget::paintEvent( QPaintEvent * ) +Void HistogramWidget::paintEvent( QPaintEvent * ) { int maxX = size().width() - 1; int maxY = size().height() - 1; @@ -484,6 +495,17 @@ void HistogramWidget::paintEvent( QPaintEvent * ) return; } + // Histogram computation skipped: + // Draw message. + else if( d->clearFlag == HistogramWidgetPrivate::HistogramSkipped ) + { + QPainter p1( this ); + p1.fillRect( 0, 0, maxX, maxY, Qt::white ); + p1.setPen( Qt::darkGreen ); + p1.drawText( 0, 0, maxX, maxY, Qt::AlignCenter, tr( "Histogram\ncalculation\nskipped." ) ); + //bitBlt(this, 0, 0, &pm); + return; + } // Histogram computation failed: // Draw message. else if( d->clearFlag == HistogramWidgetPrivate::HistogramFailed ) @@ -557,7 +579,7 @@ void HistogramWidget::paintEvent( QPaintEvent * ) // From Qt 4.0, QWidget automatically double-buffers its painting, // so there's no need to write double-buffering code in paintEvent() - // to avoid flicker. + // to aVoid flicker. QPainter p1( this ); Int pallet = d->imageColorSpace; @@ -991,7 +1013,7 @@ void HistogramWidget::paintEvent( QPaintEvent * ) // Mouse Events //////////////////////////////////////////////////////////////////////////////// -void HistogramWidget::mousePressEvent( QMouseEvent * e ) +Void HistogramWidget::mousePressEvent( QMouseEvent * e ) { if( d->selectMode == true && d->clearFlag == HistogramWidgetPrivate::HistogramCompleted ) { @@ -1009,7 +1031,7 @@ void HistogramWidget::mousePressEvent( QMouseEvent * e ) } } -void HistogramWidget::mouseReleaseEvent( QMouseEvent * ) +Void HistogramWidget::mouseReleaseEvent( QMouseEvent * ) { if( d->selectMode == true && d->clearFlag == HistogramWidgetPrivate::HistogramCompleted ) @@ -1027,7 +1049,7 @@ void HistogramWidget::mouseReleaseEvent( QMouseEvent * ) } } -void HistogramWidget::mouseMoveEvent( QMouseEvent * e ) +Void HistogramWidget::mouseMoveEvent( QMouseEvent * e ) { if( d->selectMode == true && d->clearFlag == HistogramWidgetPrivate::HistogramCompleted ) { @@ -1060,12 +1082,12 @@ void HistogramWidget::mouseMoveEvent( QMouseEvent * e ) //////////////////////////////////////////////////////////////////////////////// -void HistogramWidget::notifyValuesChanged() +Void HistogramWidget::notifyValuesChanged() { emit signalIntervalChanged( ( int )( d->xmin * d->range ), d->xmax == 0.0 ? d->range : ( int )( d->xmax * d->range ) ); } -void HistogramWidget::slotMinValueChanged( int min ) +Void HistogramWidget::slotMinValueChanged( int min ) { if( d->selectMode == true && d->clearFlag == HistogramWidgetPrivate::HistogramCompleted ) { @@ -1083,7 +1105,7 @@ void HistogramWidget::slotMinValueChanged( int min ) } } -void HistogramWidget::slotMaxValueChanged( int max ) +Void HistogramWidget::slotMaxValueChanged( int max ) { if( d->selectMode == true && d->clearFlag == HistogramWidgetPrivate::HistogramCompleted ) { diff --git a/source/app/HistogramWidget.h b/source/app/HistogramWidget.h index a7d08fd..b270f74 100755 --- a/source/app/HistogramWidget.h +++ b/source/app/HistogramWidget.h @@ -26,8 +26,11 @@ #ifndef __HISTOGRAMWIDGET_H__ #define __HISTOGRAMWIDGET_H__ +#include "config.h" + #include #include +#include "TypeDef.h" #include "PlaYUVerFrame.h" #include "PlaYUVerFrameStatistics.h" @@ -106,84 +109,79 @@ public : * @param height of the widget * @param parent the histogram widget parent */ - HistogramWidget( int width, int height, QWidget *parent = 0 ); + HistogramWidget( Int width, Int height, QWidget *parent = 0 ); - void setupWidget( int width, int height, + Void setupWidget( Int width, Int height, HistogramOptions options = AllOptions ); ~HistogramWidget(); /** Stop current histogram computations.*/ - void stopHistogramComputation( void ); + Void stopHistogramComputation(); /** Update full image histogram data methods.*/ - void updateData( Pel ***imageData, UInt imageWidth, UInt imageHeight, + Void updateData( Pel ***imageData, UInt imageWidth, UInt imageHeight, Int bitsPerChannel, Int pixel_format, UInt chroma_size, Pel ***selData = 0, UInt selWidth = 0, UInt selHeight = 0); /** Update full image histogram data from SImage.*/ - void updateData( const PlaYUVerFrame *playuver_frame, const PlaYUVerFrame *playuver_selection ); + Void updateData( const PlaYUVerFrame *playuver_frame, const PlaYUVerFrame *playuver_selection ); /** Update image selection histogram data methods.*/ - void updateSelectionData( Pel ***selData, uint selWidth, uint selHeight, + Void updateSelectionData( Pel ***selData, uint selWidth, uint selHeight, Int bitsPerChannel, Int pixel_format, UInt chroma_size ); /** Update image selection histogram data from SImage.*/ - void updateSelectionData( const PlaYUVerFrame *imageSelection ); + Void updateSelectionData( const PlaYUVerFrame *imageSelection ); /** @see @p HistogramOption */ - void setOptions( HistogramOptions options = AllOptions ); - void setDataLoading(); - void setLoadingFailed(); - void setHistogramGuideByColor( QColor color ); + Void setOptions( HistogramOptions options = AllOptions ); + Void setDataLoading(); + Void setLoadingSkipped(); + Void setLoadingFailed(); + Void setHistogramGuideByColor( QColor color ); - void reset(void); + Void reset(); public: /** Channel type to draw */ - int m_channelType; + Int m_channelType; /** Scale to use for drawing */ - int m_scaleType; + Int m_scaleType; /** Color to use for drawing in All Colors Channel mode */ - int m_colorType; + Int m_colorType; /** Using full image or image selection for histogram rendering */ - int m_renderingType; + Int m_renderingType; /** Full image */ PlaYUVerFrameStatistics *m_imageHistogram; /** Histogram area selection */ PlaYUVerFrameStatistics *m_selectionHistogram; - signals: - + Q_SIGNALS: void signalIntervalChanged( int min, int max ); void signalMaximumValueChanged( int ); void signalHistogramComputationDone( bool ); void signalHistogramComputationFailed( void ); -public slots: - +public Q_SLOTS: void slotMinValueChanged( int min ); void slotMaxValueChanged( int max ); protected slots: - void slotBlinkTimerDone( void ); protected: - - void paintEvent( QPaintEvent * ); - void mousePressEvent( QMouseEvent * e ); - void mouseReleaseEvent( QMouseEvent * e ); - void mouseMoveEvent( QMouseEvent * e ); - -private : - - void customEvent( QEvent *event ); - void notifyValuesChanged(); + Void paintEvent( QPaintEvent * ); + Void mousePressEvent( QMouseEvent * e ); + Void mouseReleaseEvent( QMouseEvent * e ); + Void mouseMoveEvent( QMouseEvent * e ); private: + Void customEvent( QEvent *event ); + Void notifyValuesChanged(); +private: HistogramWidgetPrivate* d; }; diff --git a/source/app/PropertiesSidebar.cpp b/source/app/PropertiesSidebar.cpp index bbc9514..4822d61 100755 --- a/source/app/PropertiesSidebar.cpp +++ b/source/app/PropertiesSidebar.cpp @@ -166,13 +166,14 @@ Void StreamPropertiesSideBar::setData( InputStream* pcStream ) // FramePropertiesSideBar //////////////////////////////////////////////////////////////////////////////// -FramePropertiesSideBar::FramePropertiesSideBar( QWidget* parent ) : +FramePropertiesSideBar::FramePropertiesSideBar( QWidget* parent, Bool *pbIsPlaying ) : QWidget( parent ) { // -------------- Variables definition -------------- m_pcFrame = NULL; m_pcFrameSelection = NULL; m_iLastFrameType = -1; + m_pbIsPlaying = pbIsPlaying; // Histogram area ----------------------------------------------------- @@ -470,7 +471,7 @@ Void FramePropertiesSideBar::setData( PlaYUVerFrame* pcFrame ) } setEnabled( true ); m_pcFrame = pcFrame; - slotUpdateDataHistogram(); + updateDataHistogram(); } } @@ -500,14 +501,41 @@ Void FramePropertiesSideBar::setSelection( const QRect &selectionArea ) } } +Void FramePropertiesSideBar::updateDataHistogram() +{ + if( m_pcFrame->isValid() && isVisible() ) + { + if( !(*m_pbIsPlaying) ) + { + // If a selection area is done in Image Editor and if the current + // image is the same in Image Viewer, then compute too the histogram + // for this selection. + // New frame required to separate from the thread + histogramWidget->updateData( new PlaYUVerFrame(m_pcFrame), NULL ); + fullImageButton->hide(); + selectionImageButton->hide(); + } + else + { + histogramWidget->setLoadingSkipped(); + } + histogramWidget->update(); + } + else + { + histogramWidget->setLoadingFailed(); + slotHistogramComputationFailed(); + } +} + Void FramePropertiesSideBar::updateStatistiques() { QString value; - int min = minInterv->value(); - int max = maxInterv->value(); - int channel = histogramWidget->m_channelType; - //int channel = channelCB->currentIndex(); + Int min = minInterv->value(); + Int max = maxInterv->value(); + Int channel = histogramWidget->m_channelType; + //Int channel = channelCB->currentIndex(); if( channel == HistogramWidget::ColorChannelsHistogram ) channel = colorsCB->currentIndex() + 1; @@ -547,26 +575,7 @@ Void FramePropertiesSideBar::stopHistogram() // SLOTS //////////////////////////////////////////////////////////////////////////////// -void FramePropertiesSideBar::slotUpdateDataHistogram() -{ - if( m_pcFrame->isValid() && isVisible() ) - { - // If a selection area is done in Image Editor and if the current - // image is the same in Image Viewer, then compute too the histogram - // for this selection. - // New frame required to separate from the thread - histogramWidget->updateData( new PlaYUVerFrame(m_pcFrame), NULL ); - fullImageButton->hide(); - selectionImageButton->hide(); - } - else - { - histogramWidget->setLoadingFailed(); - slotHistogramComputationFailed(); - } -} - -void FramePropertiesSideBar::slotRefreshOptions( bool /*depth*/) +Void FramePropertiesSideBar::slotRefreshOptions( bool /*depth*/) { if( !isVisible() ) return; @@ -589,13 +598,13 @@ void FramePropertiesSideBar::slotRefreshOptions( bool /*depth*/) } } -void FramePropertiesSideBar::slotHistogramComputationFailed() +Void FramePropertiesSideBar::slotHistogramComputationFailed() { m_pcFrame = NULL; m_pcFrameSelection = NULL; } -void FramePropertiesSideBar::slotChannelChanged( int channel ) +Void FramePropertiesSideBar::slotChannelChanged( Int channel ) { if( PlaYUVerFrame::isRGBorYUVorGray( m_pcFrame->getPelFormat() ) == PlaYUVerFrame::COLOR_YUV ) channel += 1; @@ -633,13 +642,13 @@ void FramePropertiesSideBar::slotChannelChanged( int channel ) updateStatistiques(); } -void FramePropertiesSideBar::slotScaleChanged( int scale ) +Void FramePropertiesSideBar::slotScaleChanged( Int scale ) { histogramWidget->m_scaleType = scale; histogramWidget->update(); } -void FramePropertiesSideBar::slotColorsChanged( int color ) +Void FramePropertiesSideBar::slotColorsChanged( Int color ) { switch( color ) { @@ -658,14 +667,14 @@ void FramePropertiesSideBar::slotColorsChanged( int color ) updateStatistiques(); } -void FramePropertiesSideBar::slotRenderingChanged( int rendering ) +Void FramePropertiesSideBar::slotRenderingChanged( Int rendering ) { histogramWidget->m_renderingType = rendering; histogramWidget->update(); updateStatistiques(); } -void FramePropertiesSideBar::slotMinValueChanged( int min ) +Void FramePropertiesSideBar::slotMinValueChanged( Int min ) { // Called when user changes values of spin box. // Communicate the change to histogram widget. @@ -679,7 +688,7 @@ void FramePropertiesSideBar::slotMinValueChanged( int min ) updateStatistiques(); } -void FramePropertiesSideBar::slotMaxValueChanged( int max ) +Void FramePropertiesSideBar::slotMaxValueChanged( Int max ) { if( max == minInterv->value() - 1 ) minInterv->setValue( max ); @@ -689,7 +698,7 @@ void FramePropertiesSideBar::slotMaxValueChanged( int max ) updateStatistiques(); } -void FramePropertiesSideBar::slotUpdateInterval( int min, int max ) +Void FramePropertiesSideBar::slotUpdateInterval( Int min, Int max ) { // Called when value is set from within histogram widget. // Block signals to prevent slotMinValueChanged and @@ -707,7 +716,7 @@ void FramePropertiesSideBar::slotUpdateInterval( int min, int max ) updateStatistiques(); } -void FramePropertiesSideBar::slotUpdateIntervRange( int range ) +Void FramePropertiesSideBar::slotUpdateIntervRange( Int range ) { maxInterv->blockSignals( true ); maxInterv->setMaximum( range ); diff --git a/source/app/PropertiesSidebar.h b/source/app/PropertiesSidebar.h index aa8e334..08ebc1d 100755 --- a/source/app/PropertiesSidebar.h +++ b/source/app/PropertiesSidebar.h @@ -65,7 +65,7 @@ class FramePropertiesSideBar: public QWidget { Q_OBJECT public: - FramePropertiesSideBar( QWidget* parent ); + FramePropertiesSideBar( QWidget* parent, Bool *pbIsPlaying ); ~FramePropertiesSideBar(); QSize sizeHint() const; @@ -95,11 +95,9 @@ private: PlaYUVerFrame *m_pcFrame; PlaYUVerFrame *m_pcFrameSelection; - + Bool* m_pbIsPlaying; Int m_iLastFrameType; - Bool inLoadingProcess; - QComboBox *channelCB; QComboBox *colorsCB; QComboBox *renderingCB; @@ -133,11 +131,10 @@ private: HistogramWidget *histogramWidget; -private: Void updateStatistiques(); + Void updateDataHistogram(); private Q_SLOTS: - void slotUpdateDataHistogram(); void slotRefreshOptions( bool sixteenBit ); void slotHistogramComputationFailed( void ); void slotChannelChanged( int channel ); diff --git a/source/app/ViewArea.h b/source/app/ViewArea.h index 86a8e20..46d1023 100755 --- a/source/app/ViewArea.h +++ b/source/app/ViewArea.h @@ -108,13 +108,13 @@ public: // QSize sizeHint() const; -signals: +Q_SIGNALS: void selectionChanged( const QRect &rect ); void positionChanged( const QPoint &pos, PlaYUVerFrame *frame ); void moveScroll( QPoint offset ); void zoomFactorChanged( double factor , QPoint center); -public slots: +public Q_SLOTS: void setNormalMode(); void setMaskMode(); void setMaskTool(); diff --git a/source/app/plaYUVerApp.cpp b/source/app/plaYUVerApp.cpp index 5aacfce..e894aed 100644 --- a/source/app/plaYUVerApp.cpp +++ b/source/app/plaYUVerApp.cpp @@ -70,11 +70,11 @@ plaYUVerApp::plaYUVerApp() setUnifiedTitleAndToolBarOnMac( true ); m_bIsPlaying = false; - playingTimer = new QTimer; + m_pcPlayingTimer = new QTimer; #if( QT_VERSION_PLAYUVER == 5 ) - playingTimer->setTimerType( Qt::CoarseTimer ); + m_pcPlayingTimer->setTimerType( Qt::CoarseTimer ); #endif - connect( playingTimer, SIGNAL( timeout() ), this, SLOT( playEvent() ) ); + connect( m_pcPlayingTimer, SIGNAL( timeout() ), this, SLOT( playEvent() ) ); setAcceptDrops( true ); mdiArea->setAcceptDrops( true ); @@ -125,7 +125,7 @@ Void plaYUVerApp::closeEvent( QCloseEvent *event ) if( mayCloseAll ) { - playingTimer->stop(); + m_pcPlayingTimer->stop(); closeAll(); writeSettings(); event->accept(); @@ -172,7 +172,7 @@ Void plaYUVerApp::loadFile( QString fileName ) // ----------------------- File Functions ----------------------- -void plaYUVerApp::open() +Void plaYUVerApp::open() { QString supported = tr( "Supported Files" ); QString formats = InputStream::supportedReadFormats(); @@ -194,19 +194,19 @@ void plaYUVerApp::open() } } -void plaYUVerApp::save() +Void plaYUVerApp::save() { if( m_pcCurrentSubWindow ) m_pcCurrentSubWindow->save(); } -void plaYUVerApp::format() +Void plaYUVerApp::format() { if( m_pcCurrentSubWindow ) m_pcCurrentSubWindow->loadFile( m_pcCurrentSubWindow->currentFile() ); } -void plaYUVerApp::closeActiveWindow() +Void plaYUVerApp::closeActiveWindow() { SubWindowHandle *currSubWindow = activeSubWindow(); if( currSubWindow ) @@ -221,14 +221,14 @@ void plaYUVerApp::closeActiveWindow() mdiArea->closeActiveSubWindow(); } -void plaYUVerApp::closeAll() +Void plaYUVerApp::closeAll() { mdiArea->closeAllSubWindows(); } // ----------------------- Modules Selection -------------------- -void plaYUVerApp::selectModule( QAction *curr_action ) +Void plaYUVerApp::selectModule( QAction *curr_action ) { m_pcFrameProperties->stopHistogram(); SubWindowHandle *interfaceChild = m_pcModulesHandle->toggleSelectedModuleIf(); @@ -247,7 +247,7 @@ void plaYUVerApp::selectModule( QAction *curr_action ) // ----------------------- Update Properties -------------------- -void plaYUVerApp::updateProperties() +Void plaYUVerApp::updateProperties() { updateStreamProperties(); updateFrameProperties(); @@ -278,7 +278,7 @@ Void plaYUVerApp::updateFrameProperties() } } -void plaYUVerApp::updatePropertiesSelectedArea( QRect area ) +Void plaYUVerApp::updatePropertiesSelectedArea( QRect area ) { if( m_pcCurrentSubWindow ) { @@ -322,10 +322,12 @@ Void plaYUVerApp::setTimerStatus() if( status ) { m_cTimer.start(); + m_bIsPlaying = true; } else { - playingTimer->stop(); + m_pcPlayingTimer->stop(); + m_bIsPlaying = false; } } @@ -338,12 +340,13 @@ Void plaYUVerApp::startPlay() qDebug( ) << "Desired frame rate: " << QString::number( 1000 / timeInterval ) << " fps"; - playingTimer->start( timeInterval ); + m_pcPlayingTimer->start( timeInterval ); m_cTimer.start(); + m_bIsPlaying = true; } } -void plaYUVerApp::play() +Void plaYUVerApp::play() { if( !m_pcCurrentSubWindow ) return; @@ -366,13 +369,13 @@ void plaYUVerApp::play() { m_acPlayingSubWindows.append( m_pcCurrentSubWindow ); m_pcCurrentSubWindow->seekAbsoluteEvent( m_acPlayingSubWindows.at( 0 )->getInputStream()->getCurrFrameNum() ); - m_pcCurrentSubWindow->play(); m_pcFrameSlider->setMaximum( getMaxFrameNumber() - 1 ); } + m_pcCurrentSubWindow->play(); } else { - playingTimer->stop(); + m_pcPlayingTimer->stop(); m_acPlayingSubWindows.clear(); m_acPlayingSubWindows.append( m_pcCurrentSubWindow ); m_pcCurrentSubWindow->play(); @@ -382,7 +385,7 @@ void plaYUVerApp::play() startPlay(); } -void plaYUVerApp::pause() +Void plaYUVerApp::pause() { if( m_pcCurrentSubWindow ) { @@ -400,9 +403,10 @@ void plaYUVerApp::pause() updateCurrFrameNum(); } setTimerStatus(); + updateFrameProperties(); } -void plaYUVerApp::stop() +Void plaYUVerApp::stop() { if( m_acPlayingSubWindows.size() > 0 ) { @@ -429,7 +433,7 @@ void plaYUVerApp::stop() } } -void plaYUVerApp::playEvent() +Void plaYUVerApp::playEvent() { UInt time = m_cTimer.elapsed(); m_cTimer.restart(); @@ -483,7 +487,7 @@ Void plaYUVerApp::updateTotalFrameNum( UInt total_frame_num ) m_pcTotalFrameNumLabel->setText( QString( tr( "%1" ) ).arg( total_frame_num ) ); } -void plaYUVerApp::seekEvent( int direction ) +Void plaYUVerApp::seekEvent( int direction ) { if( m_pcCurrentSubWindow ) { @@ -503,7 +507,7 @@ void plaYUVerApp::seekEvent( int direction ) } } -void plaYUVerApp::seekSliderEvent( int new_frame_num ) +Void plaYUVerApp::seekSliderEvent( int new_frame_num ) { if( m_pcCurrentSubWindow ) { @@ -523,7 +527,7 @@ void plaYUVerApp::seekSliderEvent( int new_frame_num ) } } -void plaYUVerApp::lockButtonEvent() +Void plaYUVerApp::lockButtonEvent() { if( !m_arrayActions[VIDEO_LOCK_ACT]->isChecked() ) { @@ -539,7 +543,7 @@ void plaYUVerApp::lockButtonEvent() } } -void plaYUVerApp::videoSelectionButtonEvent() +Void plaYUVerApp::videoSelectionButtonEvent() { DialogSubWindowSelector dialogWindowsSelection( this, mdiArea ); QStringList cWindowListNames; @@ -574,13 +578,13 @@ void plaYUVerApp::videoSelectionButtonEvent() // ----------------------- Zoom Functions ----------------------- -void plaYUVerApp::normalSize() +Void plaYUVerApp::normalSize() { if( activeSubWindow() ) activeSubWindow()->normalSize(); } -void plaYUVerApp::zoomToFit() +Void plaYUVerApp::zoomToFit() { if( activeSubWindow() ) activeSubWindow()->zoomToFit(); @@ -596,7 +600,7 @@ Void plaYUVerApp::zoomToFitAll() } } -void plaYUVerApp::scaleFrame( int ratio ) +Void plaYUVerApp::scaleFrame( Int ratio ) { if( activeSubWindow() ) { @@ -609,7 +613,7 @@ void plaYUVerApp::scaleFrame( int ratio ) // ----------------------- About Functions ----------------------- -void plaYUVerApp::about() +Void plaYUVerApp::about() { QString about_message; about_message.append( "The plaYUVerApp is an open-source raw video player" ); @@ -620,7 +624,7 @@ void plaYUVerApp::about() QMessageBox::about( this, tr( "About plaYUVerApp" ), about_message ); } -void plaYUVerApp::chageSubWindowSelection() +Void plaYUVerApp::chageSubWindowSelection() { SubWindowHandle *new_window = activeSubWindow(); if( activeSubWindow() != m_pcCurrentSubWindow ) @@ -642,7 +646,7 @@ void plaYUVerApp::chageSubWindowSelection() // ----------------------- Status bar Functions ----------------------- -void plaYUVerApp::updatePixelValueStatusBar( const QPoint & pos, PlaYUVerFrame* frame ) +Void plaYUVerApp::updatePixelValueStatusBar( const QPoint & pos, PlaYUVerFrame* frame ) { Pixel sPixelValue; Int iWidth, iHeight; @@ -669,7 +673,7 @@ void plaYUVerApp::updatePixelValueStatusBar( const QPoint & pos, PlaYUVerFrame* // ----------------------- Drag and drop functions ---------------------- -void plaYUVerApp::dragEnterEvent( QDragEnterEvent *event ) +Void plaYUVerApp::dragEnterEvent( QDragEnterEvent *event ) { //setText(tr("")); setBackgroundRole( QPalette::Highlight ); @@ -677,7 +681,7 @@ void plaYUVerApp::dragEnterEvent( QDragEnterEvent *event ) event->acceptProposedAction(); } -void plaYUVerApp::dropEvent( QDropEvent *event ) +Void plaYUVerApp::dropEvent( QDropEvent *event ) { const QMimeData *mimeData = event->mimeData(); @@ -713,19 +717,19 @@ QMdiSubWindow *plaYUVerApp::findSubWindow( const QString &fileName ) return 0; } -void plaYUVerApp::setNavigationTool() +Void plaYUVerApp::setNavigationTool() { m_appTool = NavigationTool; setAllSubWindowTool(); } -void plaYUVerApp::setSelectionTool() +Void plaYUVerApp::setSelectionTool() { m_appTool = NormalSelectionTool; setAllSubWindowTool(); } -void plaYUVerApp::setAllSubWindowTool() +Void plaYUVerApp::setAllSubWindowTool() { foreach( QMdiSubWindow * window, mdiArea->subWindowList() ){ SubWindowHandle *mdiChild = qobject_cast( window); @@ -733,7 +737,7 @@ void plaYUVerApp::setAllSubWindowTool() } } -void plaYUVerApp::setActiveSubWindow( QWidget *window ) +Void plaYUVerApp::setActiveSubWindow( QWidget *window ) { if( !window ) return; @@ -776,7 +780,7 @@ Void plaYUVerApp::updateMenus() m_pcModulesHandle->updateMenus( hasSubWindow ); } -void plaYUVerApp::updateWindowMenu() +Void plaYUVerApp::updateWindowMenu() { m_arrayMenu[WINDOW_MENU]->clear(); m_arrayMenu[WINDOW_MENU]->addAction( m_arrayActions[CLOSE_ACT] ); @@ -1103,7 +1107,7 @@ Void plaYUVerApp::createDockWidgets() addDockWidget( Qt::RightDockWidgetArea, m_arraySideBars[STREAM_SIDEBAR] ); connect( m_arraySideBars[STREAM_SIDEBAR], SIGNAL( visibilityChanged(bool) ), this, SLOT( updateProperties() ) ); - m_pcFrameProperties = new FramePropertiesSideBar( this ); + m_pcFrameProperties = new FramePropertiesSideBar( this, &m_bIsPlaying ); m_arraySideBars[FRAME_SIDEBAR] = new QDockWidget( tr( "Frame Information" ), this ); m_arraySideBars[FRAME_SIDEBAR]->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); m_arraySideBars[FRAME_SIDEBAR]->setWidget( m_pcFrameProperties ); diff --git a/source/app/plaYUVerApp.h b/source/app/plaYUVerApp.h index 5dbdd97..ad70f48 100644 --- a/source/app/plaYUVerApp.h +++ b/source/app/plaYUVerApp.h @@ -113,7 +113,8 @@ private: ModulesHandle *m_pcModulesHandle; QString m_cLastOpenPath; - QTimer *playingTimer; + QTimer *m_pcPlayingTimer; + Bool m_bIsPlaying; QTime m_cTimer; UInt m_uiAveragePlayInterval; @@ -144,7 +145,6 @@ private: SubWindowHandle *activeSubWindow(); QMdiSubWindow *findSubWindow( const QString &fileName ); - Bool m_bIsPlaying; QVector m_acPlayingSubWindows; QSlider *m_pcFrameSlider; QLabel *m_pcCurrFrameNumLabel; diff --git a/source/lib/PlaYUVerFrameStatistics.h b/source/lib/PlaYUVerFrameStatistics.h index de54cfd..d030d2d 100755 --- a/source/lib/PlaYUVerFrameStatistics.h +++ b/source/lib/PlaYUVerFrameStatistics.h @@ -26,7 +26,10 @@ #ifndef __PLAYUVERFRAMESTATISTICS_H_ #define __PLAYUVERFRAMESTATISTICS_H_ +#include "config.h" + #include +#include "TypeDef.h" #include "PlaYUVerFrame.h" class QObject; From 069d18a7e469f525acadf720314f57e0c5efc64f Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Wed, 14 May 2014 02:06:33 +0100 Subject: [PATCH 2/2] Separated module enable/disable code --- source/app/ModulesHandle.cpp | 47 +++++++++++++++++++++--------------- source/app/ModulesHandle.h | 1 + 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/source/app/ModulesHandle.cpp b/source/app/ModulesHandle.cpp index a0b1e0b..fe3bfeb 100644 --- a/source/app/ModulesHandle.cpp +++ b/source/app/ModulesHandle.cpp @@ -62,8 +62,6 @@ void ModulesHandle::selectModule( int index ) SubWindowHandle* ModulesHandle::toggleSelectedModuleIf() { - Bool bShowModulesNewWindow = m_arrayActions[FORCE_NEW_WINDOW_ACT]->isChecked(); - SubWindowHandle* pcSubWindow = qobject_cast( m_pcMdiArea->activeSubWindow() ); SubWindowHandle* interfaceChild = NULL; PlaYUVerModuleIf* currModuleIf = NULL; @@ -76,32 +74,41 @@ SubWindowHandle* ModulesHandle::toggleSelectedModuleIf() if( currModuleIf->m_pcAction->isChecked() ) { - currModuleIf->m_pcDisplaySubWindow = NULL; - if( ( currModuleIf->m_cModuleDef.m_uiModuleRequirements & MODULE_REQUIRES_NEW_WINDOW ) || bShowModulesNewWindow ) - { - QString windowName; - interfaceChild = new SubWindowHandle( m_pcParent ); - windowName.append( pcSubWindow->userFriendlyCurrentFile() ); - windowName.append( " [" ); - windowName.append( currModuleIf->m_cModuleDef.m_pchModuleName ); - windowName.append( "]" ); - interfaceChild->setWindowName( windowName ); - connect( interfaceChild->getViewArea(), SIGNAL( positionChanged(const QPoint &, PlaYUVerFrame *) ), this, - SLOT( updatePixelValueStatusBar(const QPoint &, PlaYUVerFrame *) ) ); - currModuleIf->m_pcDisplaySubWindow = interfaceChild; - currModuleIf->m_pcDisplaySubWindow->setModule( currModuleIf ); - } - currModuleIf->m_pcSubWindow[0] = pcSubWindow; - pcSubWindow->enableModule( currModuleIf ); + enableModuleIf( currModuleIf ); } else { - QCoreApplication::processEvents(); destroyModuleIf( currModuleIf ); } return interfaceChild; } +SubWindowHandle* ModulesHandle::enableModuleIf( PlaYUVerModuleIf *currModuleIf ) +{ + Bool bShowModulesNewWindow = m_arrayActions[FORCE_NEW_WINDOW_ACT]->isChecked(); + SubWindowHandle* pcSubWindow = qobject_cast( m_pcMdiArea->activeSubWindow() ); + SubWindowHandle* interfaceChild = NULL; + + currModuleIf->m_pcDisplaySubWindow = NULL; + if( ( currModuleIf->m_cModuleDef.m_uiModuleRequirements & MODULE_REQUIRES_NEW_WINDOW ) || bShowModulesNewWindow ) + { + QString windowName; + interfaceChild = new SubWindowHandle( m_pcParent ); + windowName.append( pcSubWindow->userFriendlyCurrentFile() ); + windowName.append( " [" ); + windowName.append( currModuleIf->m_cModuleDef.m_pchModuleName ); + windowName.append( "]" ); + interfaceChild->setWindowName( windowName ); + connect( interfaceChild->getViewArea(), SIGNAL( positionChanged(const QPoint &, PlaYUVerFrame *) ), this, + SLOT( updatePixelValueStatusBar(const QPoint &, PlaYUVerFrame *) ) ); + currModuleIf->m_pcDisplaySubWindow = interfaceChild; + currModuleIf->m_pcDisplaySubWindow->setModule( currModuleIf ); + } + currModuleIf->m_pcSubWindow[0] = pcSubWindow; + pcSubWindow->enableModule( currModuleIf ); + return interfaceChild; +} + PlaYUVerFrame* ModulesHandle::applyModuleIf( PlaYUVerModuleIf *pcCurrModuleIf ) { PlaYUVerFrame* processedFrame; diff --git a/source/app/ModulesHandle.h b/source/app/ModulesHandle.h index 8ea628e..6ab5316 100644 --- a/source/app/ModulesHandle.h +++ b/source/app/ModulesHandle.h @@ -79,6 +79,7 @@ private: QVector m_arrayActions; Void appendModule( PlaYUVerModuleIf* ); + SubWindowHandle* enableModuleIf( PlaYUVerModuleIf *currModuleIf ); private Q_SLOTS: void selectModule( int index );