From 5f3ab1306d8f0a557ad55f06a0e5f0eb6671903a Mon Sep 17 00:00:00 2001 From: Luis Lucas Date: Sat, 12 Apr 2014 23:42:25 +0100 Subject: [PATCH] Add tools menu with 2 options: Navigation and Selection Tools. --- source/app/TypeDef.h | 5 ++++ source/app/ViewArea.cpp | 3 +-- source/app/ViewArea.h | 11 +++----- source/app/plaYUVerApp.cpp | 54 +++++++++++++++++++++++++++++++++++--- source/app/plaYUVerApp.h | 18 ++++++++++--- 5 files changed, 73 insertions(+), 18 deletions(-) diff --git a/source/app/TypeDef.h b/source/app/TypeDef.h index 8f34ee7..a69d9b6 100644 --- a/source/app/TypeDef.h +++ b/source/app/TypeDef.h @@ -154,6 +154,11 @@ typedef struct __pixel_definition }; }Pixel; +enum eTool +{ + NavigationTool, NormalSelectionTool, BlockSelectionTool, MaskTool, EraserTool +}; + } // NAMESPACE #endif // __TYPEDEF_H__ diff --git a/source/app/ViewArea.cpp b/source/app/ViewArea.cpp index 2cea3ad..7fd5ac6 100755 --- a/source/app/ViewArea.cpp +++ b/source/app/ViewArea.cpp @@ -165,7 +165,7 @@ void ViewArea::setMaskColor( const QColor &color ) update(); } -void ViewArea::setTool( Tool tool ) +void ViewArea::setTool( eTool tool ) { m_tool = tool; } @@ -874,5 +874,4 @@ InputStream* ViewArea::getInputStream() return m_pStream; } - } // NameSpace plaYUVer diff --git a/source/app/ViewArea.h b/source/app/ViewArea.h index b708280..8a48d9a 100755 --- a/source/app/ViewArea.h +++ b/source/app/ViewArea.h @@ -53,16 +53,10 @@ public: NormalMode, MaskMode, }; - enum Tool - { - NavigationTool, NormalSelectionTool, BlockSelectionTool, MaskTool, EraserTool - }; - ViewArea( QWidget *parent = 0 ); void setImage( const QPixmap &pixmap ); void setMode( ViewMode mode ); - void setTool( Tool tool ); void setMaskColor( const QColor &color = QColor() ); /** @@ -94,7 +88,7 @@ public: { return m_mode; } - Tool tool() const + enum eTool tool() const { return m_tool; } @@ -108,6 +102,7 @@ public: Void zoomChangeEvent(Double factor, QPoint center); Double getZoomFactor(); + void setTool( enum eTool tool ); // QSize sizeHint() const; @@ -158,7 +153,7 @@ private: QPoint m_lastWindowPos; GridManager m_grid; ViewMode m_mode; - Tool m_tool; + enum eTool m_tool; QColor m_maskColor; double m_zoomFactor; int m_xOffset; diff --git a/source/app/plaYUVerApp.cpp b/source/app/plaYUVerApp.cpp index 8c2e667..f5fda60 100644 --- a/source/app/plaYUVerApp.cpp +++ b/source/app/plaYUVerApp.cpp @@ -161,6 +161,7 @@ void plaYUVerApp::open() connect( interfaceChild->getViewArea(), SIGNAL( positionChanged(const QPoint &, InputStream *) ), this, SLOT( updatePixelValueStatusBar(const QPoint &, InputStream *) ) ); interfaceChild->zoomToFit(); + interfaceChild->getViewArea()->setTool( m_appTool ); } else { @@ -557,13 +558,33 @@ QMdiSubWindow *plaYUVerApp::findSubWindow( const QString &fileName ) QString canonicalFilePath = QFileInfo( fileName ).canonicalFilePath(); foreach( QMdiSubWindow * window, mdiArea->subWindowList() ){ - SubWindowHandle *mdiChild = qobject_cast( window); - if( mdiChild->currentFile() == canonicalFilePath ) - return window; -} + SubWindowHandle *mdiChild = qobject_cast( window); + if( mdiChild->currentFile() == canonicalFilePath ) + return window; + } return 0; } +void plaYUVerApp::setNavigationTool( ) +{ + m_appTool = NavigationTool; + setAllSubWindowTool( ); +} + +void plaYUVerApp::setSelectionTool( ) +{ + m_appTool = NormalSelectionTool; + setAllSubWindowTool( ); +} + +void plaYUVerApp::setAllSubWindowTool( ) +{ + foreach( QMdiSubWindow * window, mdiArea->subWindowList() ){ + SubWindowHandle *mdiChild = qobject_cast( window); + mdiChild->getViewArea()->setTool( m_appTool ); + } +} + void plaYUVerApp::setActiveSubWindow( QWidget *window ) { if( !window ) @@ -599,6 +620,9 @@ Void plaYUVerApp::updateMenus() m_pcFrameSlider->setValue( 0 ); } + actionNavigationTool->setEnabled( hasSubWindow ); + actionSelectionTool->setEnabled( hasSubWindow ); + m_pcModulesHandle->updateMenus( hasSubWindow ); } @@ -763,6 +787,24 @@ Void plaYUVerApp::createActions() m_pcFrameSlider->setEnabled( false ); connect( m_pcFrameSlider, SIGNAL( sliderMoved(int) ), this, SLOT( seekSliderEvent(int) ) ); + // ------------ Tools ------------ + actionGroupTools = new QActionGroup( this ); + actionGroupTools->setExclusive(true); + + m_appTool = NavigationTool; + + actionNavigationTool = new QAction( tr( "&Navigation Tool" ), this ); + actionNavigationTool->setCheckable( true ); + actionNavigationTool->setChecked( true ); + actionGroupTools->addAction( actionNavigationTool ); + connect( actionNavigationTool, SIGNAL( triggered() ), this, SLOT( setNavigationTool() ) ); + + actionSelectionTool = new QAction( "&Selection Tool", this ); + actionSelectionTool->setCheckable( true ); + actionSelectionTool->setChecked( false ); + actionGroupTools->addAction( actionSelectionTool ); + connect( actionSelectionTool, SIGNAL( triggered() ), this, SLOT( setSelectionTool() ) ); + // ------------ Window ------------ actionTile = new QAction( tr( "&Tile" ), this ); @@ -839,6 +881,10 @@ Void plaYUVerApp::createMenus() QMenu* modules_menu = m_pcModulesHandle->createMenus( menuBar() ); connect( modules_menu, SIGNAL( triggered(QAction *) ), this, SLOT( selectModule(QAction *) ) ); + m_arrayMenu[TOOLS_MENU] = menuBar()->addMenu( tr( "Tools" ) ); + m_arrayMenu[TOOLS_MENU]->addAction( actionNavigationTool ); + m_arrayMenu[TOOLS_MENU]->addAction( actionSelectionTool ); + m_arrayMenu[WINDOW_MENU] = menuBar()->addMenu( tr( "&Window" ) ); updateWindowMenu(); connect( m_arrayMenu[WINDOW_MENU], SIGNAL( aboutToShow() ), this, SLOT( updateWindowMenu() ) ); diff --git a/source/app/plaYUVerApp.h b/source/app/plaYUVerApp.h index f3c0c79..2fd1ee9 100644 --- a/source/app/plaYUVerApp.h +++ b/source/app/plaYUVerApp.h @@ -98,6 +98,10 @@ private Q_SLOTS: void updatePixelValueStatusBar(const QPoint & pos, InputStream* stream); + void setAllSubWindowTool( ); + void setNavigationTool( ); + void setSelectionTool( ); + private: QMdiArea *mdiArea; SubWindowHandle *m_pcCurrentSubWindow; @@ -138,16 +142,16 @@ private: /** * Array of menus for the main app * @param position description: - * 0 - Window - * 1 - File - * 2 - View - * 3 - Help + * 0 - File + * 1 - View + * 2 - ... */ enum MAIN_APP_MENU_LIST { FILE_MENU = 0, VIEW_MENU, VIDEO_MENU, + TOOLS_MENU, WINDOW_MENU, ABOUT_MENU, TOTAL_MENUS, @@ -213,6 +217,12 @@ private: QAction *actionAbout; QAction *actionAboutQt; + // Tools Actions; + QActionGroup *actionGroupTools; + QAction *actionNavigationTool; + QAction *actionSelectionTool; + enum eTool m_appTool; + }; } // NAMESPACE