From 769bcead8620f3fa4be5ee5ddc4dce49055226c5 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Wed, 23 Apr 2014 22:49:42 +0100 Subject: [PATCH] Rearrange modules enable/disable code. now the main function is inside ModulesHandle class --- source/app/ModulesHandle.cpp | 58 +++++++++++++++++++++++++++++----- source/app/ModulesHandle.h | 10 ++++-- source/app/PlaYUVerModuleIf.h | 3 +- source/app/SubWindowHandle.cpp | 2 +- source/app/plaYUVerApp.cpp | 36 +++------------------ 5 files changed, 66 insertions(+), 43 deletions(-) diff --git a/source/app/ModulesHandle.cpp b/source/app/ModulesHandle.cpp index 47c49d5..f6e56a2 100644 --- a/source/app/ModulesHandle.cpp +++ b/source/app/ModulesHandle.cpp @@ -25,6 +25,9 @@ #include #include "ModulesHandle.h" +#include "SubWindowHandle.h" + +// List of modules includes #include "FilterFrame.h" namespace plaYUVer @@ -32,20 +35,22 @@ namespace plaYUVer Void ModulesHandle::ModulesList( Bool bCreate ) { + // Register Modules REGISTER_MODULE( FilterFrame ); - } - ModulesHandle::ModulesHandle( QWidget * parent ) { - ModulesList( true ); + m_pcParent = parent; + // configure class - setParent( parent ); + setParent( m_pcParent ); m_uiModulesCount = 0; - m_uiModuleSelected= -1; + m_uiModuleSelected = -1; + + ModulesList( true ); } ModulesHandle::~ModulesHandle() @@ -69,12 +74,51 @@ PlaYUVerModuleIf* ModulesHandle::getSelectedModuleIf() if( m_uiModuleSelected >= 0 ) //if( m_arrayModulesActions.at(m_uiModuleSelected)->isChecked() ) - currModuleIf = m_pcPlaYUVerModules.at( m_uiModuleSelected ); + currModuleIf = m_pcPlaYUVerModules.at( m_uiModuleSelected ); m_uiModuleSelected = -1; return currModuleIf; } +SubWindowHandle* ModulesHandle::toggleSelectedModuleIf( SubWindowHandle* pcSubWindow ) +{ + SubWindowHandle* interfaceChild = NULL; + PlaYUVerModuleIf* currModuleIf = NULL; + + if( m_uiModuleSelected >= 0 ) + //if( m_arrayModulesActions.at(m_uiModuleSelected)->isChecked() ) + currModuleIf = m_pcPlaYUVerModules.at( m_uiModuleSelected ); + m_uiModuleSelected = -1; + + if( currModuleIf->m_pcAction->isChecked() ) + { + if( currModuleIf->m_cModuleDef.m_bRequiresNewWindow ) + { + interfaceChild = new SubWindowHandle( m_pcParent ); + //mdiArea->addSubWindow( interfaceChild ); + + pcSubWindow->setModuleSubWindow( interfaceChild ); + pcSubWindow->enableModule( currModuleIf ); + + interfaceChild->show(); + interfaceChild->zoomToFit(); + connect( interfaceChild->getViewArea(), SIGNAL( positionChanged(const QPoint &, PlaYUVerFrame *) ), this, + SLOT( updatePixelValueStatusBar(const QPoint &, PlaYUVerFrame *) ) ); + } + else + { + pcSubWindow->enableModule( currModuleIf ); + } + currModuleIf->m_pcSubWindow = pcSubWindow; + } + else + { + currModuleIf->m_pcSubWindow->disableModule(); + currModuleIf->m_pcSubWindow = NULL; + } + return interfaceChild; +} + QMenu* ModulesHandle::createMenus( QMenuBar *MainAppMenuBar ) { PlaYUVerModuleIf* currModuleIf; @@ -88,8 +132,6 @@ QMenu* ModulesHandle::createMenus( QMenuBar *MainAppMenuBar ) //m_arrayModulesActions.resize( m_uiModulesCount ); - - for( Int i = 0; i < m_pcPlaYUVerModules.size(); i++ ) { currModuleIf = m_pcPlaYUVerModules.at( i ); diff --git a/source/app/ModulesHandle.h b/source/app/ModulesHandle.h index b859dda..4f5f554 100644 --- a/source/app/ModulesHandle.h +++ b/source/app/ModulesHandle.h @@ -42,9 +42,11 @@ namespace plaYUVer { -class ModulesHandle : public QObject +class SubWindowHandle; + +class ModulesHandle: public QObject { - Q_OBJECT +Q_OBJECT public: ModulesHandle( QWidget * parent = 0 ); ~ModulesHandle(); @@ -52,8 +54,11 @@ public: QMenu* createMenus( QMenuBar *MainAppMenuBar ); Void updateMenus( Bool hasSubWindow ); PlaYUVerModuleIf* getSelectedModuleIf(); + SubWindowHandle* toggleSelectedModuleIf( SubWindowHandle* pcSubWindow ); private: + QWidget *m_pcParent; + UInt m_uiModulesCount; Int m_uiModuleSelected; QMenu* m_pcModulesMenu; @@ -64,6 +69,7 @@ private: Void appendModule( PlaYUVerModuleIf* ); Void ModulesList( Bool bCreate ); + private Q_SLOTS: void selectModule( int index ); }; diff --git a/source/app/PlaYUVerModuleIf.h b/source/app/PlaYUVerModuleIf.h index d52d777..a7d1132 100644 --- a/source/app/PlaYUVerModuleIf.h +++ b/source/app/PlaYUVerModuleIf.h @@ -73,6 +73,7 @@ typedef struct __PlaYUVerModuleDefinition bool m_bRequiresNewWindow; }PlaYUVerModuleDefinition; +class SubWindowHandle; class PlaYUVerModuleIf { @@ -86,7 +87,7 @@ public: } QAction* m_pcAction; - + SubWindowHandle* m_pcSubWindow; PlaYUVerModuleDefinition m_cModuleDef; virtual Void create() {}; diff --git a/source/app/SubWindowHandle.cpp b/source/app/SubWindowHandle.cpp index 5d425d2..4b32fc1 100644 --- a/source/app/SubWindowHandle.cpp +++ b/source/app/SubWindowHandle.cpp @@ -131,7 +131,7 @@ Void SubWindowHandle::disableModule() if( !m_pcCurrentModule ) return; - m_pcCurrentModule->m_pcAction->setCheckable( false ); + m_pcCurrentModule->m_pcAction->setChecked( false ); m_pcCurrentModule->destroy(); m_pcCurrentModule = NULL; refreshFrame(); diff --git a/source/app/plaYUVerApp.cpp b/source/app/plaYUVerApp.cpp index 182ea32..026a981 100644 --- a/source/app/plaYUVerApp.cpp +++ b/source/app/plaYUVerApp.cpp @@ -49,7 +49,6 @@ plaYUVerApp::plaYUVerApp() //mdiArea->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded ); connect( mdiArea, SIGNAL( subWindowActivated(QMdiSubWindow*) ), this, SLOT( chageSubWindowSelection() ) ); - //connect( mdiArea, SIGNAL( subWindowActivated(QMdiSubWindow*) ), this, SLOT( updateMenus() ) ); mapperWindow = new QSignalMapper( this ); connect( mapperWindow, SIGNAL( mapped(QWidget*) ), this, SLOT( setActiveSubWindow(QWidget*) ) ); @@ -221,32 +220,11 @@ void plaYUVerApp::closeAll() void plaYUVerApp::selectModule( QAction *curr_action ) { - //emit curr_action->triggered(); - if( m_pcCurrentSubWindow ) + SubWindowHandle *interfaceChild = m_pcModulesHandle->toggleSelectedModuleIf( m_pcCurrentSubWindow ); + if( interfaceChild ) { - PlaYUVerModuleIf* pcCurrMod = m_pcModulesHandle->getSelectedModuleIf(); - if( pcCurrMod ) - { - if( pcCurrMod->m_cModuleDef.m_bRequiresNewWindow ) - { - SubWindowHandle *interfaceChild = new SubWindowHandle( this ); //createSubWindow(); - mdiArea->addSubWindow( interfaceChild ); - -// connect( interfaceChild->getViewArea(), SIGNAL( positionChanged(const QPoint &, InputStream *) ), this, -// SLOT( updatePixelValueStatusBar(const QPoint &, PlaYUVerFrame *) ) ); - // connect( interfaceChild->getViewArea(), SIGNAL( selectionChanged( QRect ) ), this, - // SLOT( updatePixelValueStatusBar(const QPoint &, PlaYUVerFrame *) ) ); - m_pcCurrentSubWindow->setModuleSubWindow( interfaceChild ); - m_pcCurrentSubWindow->enableModule( pcCurrMod ); - interfaceChild->show(); - interfaceChild->zoomToFit(); - interfaceChild->getViewArea()->setTool( m_appTool ); - } - else - { - m_pcCurrentSubWindow->enableModule( pcCurrMod ); - } - } + mdiArea->addSubWindow( interfaceChild ); + interfaceChild->getViewArea()->setTool( m_appTool ); } return; } @@ -555,12 +533,8 @@ void plaYUVerApp::chageSubWindowSelection() SubWindowHandle *new_window = activeSubWindow(); if( activeSubWindow() != m_pcCurrentSubWindow ) { - if( activeSubWindow() ) + if( activeSubWindow() ) { - if( m_pcCurrentSubWindow ) - { - m_pcCurrentSubWindow->disableModule(); - } m_pcCurrentSubWindow = new_window; m_pcStreamProperties->setData( m_pcCurrentSubWindow->getInputStream() ); m_pcFrameProperties->setData( m_pcCurrentSubWindow->getInputStream()->getCurrFrame() );