From 6bae3cf8a391fa15d7b293dce06ee6a7fe4a5237 Mon Sep 17 00:00:00 2001 From: stv Date: Thu, 16 Aug 2007 07:49:42 +0000 Subject: [PATCH] Rearange Window menu --- src/Qtx/QtxWorkstackAction.cxx | 82 +++++++++++++++++++++++++++++++--- src/Qtx/QtxWorkstackAction.h | 14 ++++++ src/STD/STD_TabDesktop.cxx | 5 +++ src/STD/STD_TabDesktop.h | 3 ++ 4 files changed, 98 insertions(+), 6 deletions(-) diff --git a/src/Qtx/QtxWorkstackAction.cxx b/src/Qtx/QtxWorkstackAction.cxx index a1dbcb974..bfc208b94 100644 --- a/src/Qtx/QtxWorkstackAction.cxx +++ b/src/Qtx/QtxWorkstackAction.cxx @@ -26,13 +26,27 @@ #include #include +QtxWorkstackActionFilter::QtxWorkstackActionFilter() +{ +} + +QtxWorkstackActionFilter::~QtxWorkstackActionFilter() +{ +} + +bool QtxWorkstackActionFilter::windowMenu( QWidget*, QStringList& ) +{ + return true; +} + /*! Constructor */ QtxWorkstackAction::QtxWorkstackAction( QtxWorkstack* ws, QObject* parent, const char* name ) : QtxAction( tr( "Controls windows into workstack" ), tr( "Workstack management" ), 0, parent, name ), myFlags( Standard ), -myWorkstack( ws ) +myWorkstack( ws ), +myFilter( 0 ) { myItem.insert( VSplit, new QtxAction( tr( "Split the active window on two vertical parts" ), tr( "Split vertically" ), 0, this, 0, false ) ); @@ -253,6 +267,15 @@ void QtxWorkstackAction::perform( const int type ) } } +void QtxWorkstackAction::setActionFilter( QtxWorkstackActionFilter* f ) +{ + if ( myFilter == f ) + return; + + delete myFilter; + myFilter = f; +} + /*! SLOT: called just before the popup menu is displayed, updates popup */ @@ -381,13 +404,60 @@ void QtxWorkstackAction::fillPopup( QPopupMenu* pm, const int idx ) int param = 0; pm->setCheckable( true ); - for ( QWidgetListIt it( wList ); it.current(); ++it ) + for ( QWidgetListIt it( wList ); it.current(); ++it, param++ ) { - int id = pm->insertItem( it.current()->caption(), this, SLOT( onItemActivated( int ) ), 0, -1, index++ ); - pm->setItemParameter( id, param++ ); - pm->setItemChecked( id, it.current() == ws->activeWindow() ); - lst.append( id ); + QStringList menus; + if ( myFilter && !myFilter->windowMenu( it.current(), menus ) ) + continue; + + QPopupMenu* popup = pm; + for ( QStringList::const_iterator menuIt = menus.begin(); menuIt != menus.end(); ++menuIt ) + { + QString menu = *menuIt; + QPopupMenu* subMenu = findPopup( menu, popup ); + if ( !subMenu ) + { + subMenu = new QPopupMenu( popup ); + if ( popup == pm ) + lst.append( popup->insertItem( menu, subMenu, -1, index++ ) ); + else + popup->insertItem( menu, subMenu ); + } + popup = subMenu; + } + + int id = -1; + if ( popup == pm ) + { + id = popup->insertItem( it.current()->caption(), this, SLOT( onItemActivated( int ) ), 0, -1, index++ ); + lst.append( id ); + } + else + id = popup->insertItem( it.current()->caption(), this, SLOT( onItemActivated( int ) ) ); + + popup->setItemParameter( id, param ); + popup->setItemChecked( id, it.current() == ws->activeWindow() ); + } +} + +QPopupMenu* QtxWorkstackAction::findPopup( const QString& name, QPopupMenu* pm ) const +{ + if ( !pm ) + return 0; + + QPopupMenu* res = 0; + for ( uint i = 0; i < pm->count() && !res; i++ ) + { + QMenuData* md = 0; + int id = pm->idAt( i ); + QMenuItem* item = pm->findItem( id, &md ); + if ( !item || md != pm || !item->popup() ) + continue; + + if ( pm->text( id ) == name ) + res = item->popup(); } + return res; } /*! diff --git a/src/Qtx/QtxWorkstackAction.h b/src/Qtx/QtxWorkstackAction.h index 650184d24..189fd99a8 100644 --- a/src/Qtx/QtxWorkstackAction.h +++ b/src/Qtx/QtxWorkstackAction.h @@ -30,6 +30,15 @@ class QtxWorkstack; #pragma warning( disable:4251 ) #endif +class QTX_EXPORT QtxWorkstackActionFilter +{ +public: + QtxWorkstackActionFilter(); + virtual ~QtxWorkstackActionFilter(); + + virtual bool windowMenu( QWidget*, QStringList& ); +}; + class QTX_EXPORT QtxWorkstackAction : public QtxAction { Q_OBJECT @@ -67,6 +76,8 @@ public: void perform( const int ); + void setActionFilter( QtxWorkstackActionFilter* ); + private slots: void onAboutToShow(); void onItemActivated( int ); @@ -79,6 +90,8 @@ private: int clearPopup( QPopupMenu* ); void fillPopup( QPopupMenu*, const int ); + QPopupMenu* findPopup( const QString&, QPopupMenu* ) const; + private: typedef QMap MenuMap; typedef QMap ItemMap; @@ -88,6 +101,7 @@ private: ItemMap myItem; int myFlags; QtxWorkstack* myWorkstack; + QtxWorkstackActionFilter* myFilter; }; #ifdef WIN32 diff --git a/src/STD/STD_TabDesktop.cxx b/src/STD/STD_TabDesktop.cxx index 645188035..24b033501 100644 --- a/src/STD/STD_TabDesktop.cxx +++ b/src/STD/STD_TabDesktop.cxx @@ -140,6 +140,11 @@ QtxWorkstack* STD_TabDesktop::workstack() const return myWorkstack; } +void STD_TabDesktop::setActionFilter( QtxWorkstackActionFilter* f ) +{ + myWorkstackAction->setActionFilter( f ); +} + /*!Emit window activated.*/ void STD_TabDesktop::onWindowActivated( QWidget* w ) { diff --git a/src/STD/STD_TabDesktop.h b/src/STD/STD_TabDesktop.h index aa63db065..dc65597a0 100644 --- a/src/STD/STD_TabDesktop.h +++ b/src/STD/STD_TabDesktop.h @@ -28,6 +28,7 @@ class QPopupMenu; class QWorkspace; class QtxWorkstack; class QtxWorkstackAction; +class QtxWorkstackActionFilter; #if defined WNT #pragma warning( disable: 4251 ) @@ -55,6 +56,8 @@ public: QtxWorkstack* workstack() const; + void setActionFilter( QtxWorkstackActionFilter* ); + private slots: void onWindowActivated( QWidget* ); -- 2.39.2