From: mzn Date: Fri, 8 Jul 2005 08:53:02 +0000 (+0000) Subject: Improvement(Add keyboard shortcuts to make ?Split vertical / Split horizontal / Close... X-Git-Tag: V3_0_1~81 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c9cb36e8408975a5dca04c3e22b45a692615b7d3;p=modules%2Fgui.git Improvement(Add keyboard shortcuts to make ?Split vertical / Split horizontal / Close? on the current viewer). --- diff --git a/src/Qtx/QtxWorkstack.cxx b/src/Qtx/QtxWorkstack.cxx index 128baae7f..9169b4612 100644 --- a/src/Qtx/QtxWorkstack.cxx +++ b/src/Qtx/QtxWorkstack.cxx @@ -4,6 +4,7 @@ #include "QtxWorkstack.h" #include +#include #include #include #include @@ -27,6 +28,14 @@ QtxWorkstack::QtxWorkstack( QWidget* parent ) myWin( 0 ), myArea( 0 ) { + myActionsMap.insert( SplitVertical, new QAction( tr( "Split vertically" ), 0, this )); + myActionsMap.insert( SplitHorizontal, new QAction( tr( "Split horizontally" ), 0, this )); + myActionsMap.insert( Close, new QAction( tr( "Close" ), 0, this )); + + connect( myActionsMap[SplitVertical], SIGNAL( activated() ), this, SLOT( splitVertical() ) ); + connect( myActionsMap[SplitHorizontal], SIGNAL( activated() ), this, SLOT( splitHorizontal() ) ); + connect( myActionsMap[Close], SIGNAL( activated() ), this, SLOT( onCloseWindow() ) ); + QVBoxLayout* base = new QVBoxLayout( this ); mySplit = new QSplitter( this ); mySplit->setChildrenCollapsible( false ); @@ -365,6 +374,21 @@ void QtxWorkstack::SetRelativePosition (QWidget* wid, } } + +void QtxWorkstack::setAccel( const int id, const int accel ) +{ + if (!myActionsMap.contains(id)) + return; + myActionsMap[id]->setAccel(accel); +} + +int QtxWorkstack::accel (const int id) const +{ + if (!myActionsMap.contains(id)) + return 0; + return myActionsMap[id]->accel(); +} + static int positionSimple (QIntList& szList, const int nb, const int splitter_size, const int item_ind, const int item_rel_pos, const int need_pos, const int splitter_pos) @@ -632,6 +656,12 @@ void QtxWorkstack::splitHorizontal() split( Qt::Horizontal ); } +void QtxWorkstack::onCloseWindow() +{ + if ( activeWindow() ) + activeWindow()->close(); +} + QSplitter* QtxWorkstack::wrapSplitter( QtxWorkstackArea* area ) { if ( !area ) @@ -693,23 +723,6 @@ void QtxWorkstack::insertWidget( QWidget* wid, QWidget* pWid, QWidget* after ) itr.current()->reparent( pWid, QPoint( 0, 0 ), map.contains( itr.current() ) ? map[itr.current()] : false ); } -void QtxWorkstack::onPopupActivated( int id ) -{ - switch ( id ) - { - case SplitVertical: - splitVertical(); - break; - case SplitHorizontal: - splitHorizontal(); - break; - case Close: - if ( activeWindow() ) - activeWindow()->close(); - break; - } -} - void QtxWorkstack::onDestroyed( QObject* obj ) { QtxWorkstackArea* area = (QtxWorkstackArea*)obj; @@ -768,16 +781,15 @@ void QtxWorkstack::onContextMenuRequested( QPoint p ) return; QPopupMenu* pm = new QPopupMenu(); - connect( pm, SIGNAL( activated( int ) ), this, SLOT( onPopupActivated( int ) ) ); - + if ( lst.count() > 1 ) { - pm->insertItem( tr( "Split vertically" ), SplitVertical ); - pm->insertItem( tr( "Split horizontally" ), SplitHorizontal ); + myActionsMap[SplitVertical]->addTo( pm ); + myActionsMap[SplitHorizontal]->addTo( pm ); pm->insertSeparator(); } - pm->insertItem( tr( "Close" ), Close ); - + myActionsMap[Close]->addTo( pm ); + pm->exec( p ); delete pm; diff --git a/src/Qtx/QtxWorkstack.h b/src/Qtx/QtxWorkstack.h index d0eebbb13..a48854bbb 100644 --- a/src/Qtx/QtxWorkstack.h +++ b/src/Qtx/QtxWorkstack.h @@ -11,6 +11,7 @@ #include #include +class QAction; class QTabBar; class QPainter; class QSplitter; @@ -25,9 +26,7 @@ class QtxWorkstackTabBar; class QTX_EXPORT QtxWorkstack : public QWidget { Q_OBJECT - - enum { SplitVertical, SplitHorizontal, Close }; - + public: QtxWorkstack( QWidget* = 0 ); @@ -40,6 +39,8 @@ public: void split( const int ); + enum { SplitVertical, SplitHorizontal, Close }; + // begin: jfa 06.07.2005 enum SplitType { SPLIT_STAY, //!< given widget stays in its workarea, others are moved into a new one @@ -96,19 +97,36 @@ public: void SetRelativePosition( QWidget* wid, const Qt::Orientation o, const double pos ); // end: jfa 06.07.2005 + /*! + * \brief Sets the action's accelerator key to accel. + * \param id - the key of the action in the actions map. + * \param accel - action's accelerator key. + */ + void setAccel( const int id, const int accel ); + + /*! + * \brief Returns the action's accelerator key. + * \param id - the key of the action in the actions map. + * \retval int - action's accelerator key. + */ + int accel (const int id) const; + signals: void windowActivated( QWidget* ); public slots: void splitVertical(); void splitHorizontal(); - + private slots: - void onPopupActivated( int ); void onDestroyed( QObject* ); void onWindowActivated( QWidget* ); void onContextMenuRequested( QPoint ); void onDeactivated( QtxWorkstackArea* ); + /*! + * \brief Closes the active window. + */ + void onCloseWindow(); protected: virtual void childEvent( QChildEvent* ); @@ -163,6 +181,8 @@ private: QtxWorkstackArea* myArea; QSplitter* mySplit; + QMap myActionsMap; //!< The map of the actions. Allows to get the QAction object by the key. + friend class QtxWorkstackArea; friend class QtxWorkstackDrag; }; @@ -347,6 +367,7 @@ private: int myTab; QtxWorkstackArea* myArea; QPainter* myPainter; + }; #endif diff --git a/src/Qtx/QtxWorkstackAction.cxx b/src/Qtx/QtxWorkstackAction.cxx index 80c0e26af..82058dabf 100644 --- a/src/Qtx/QtxWorkstackAction.cxx +++ b/src/Qtx/QtxWorkstackAction.cxx @@ -168,6 +168,12 @@ void QtxWorkstackAction::onAboutToShow() if ( !obj || !obj->inherits( "QPopupMenu" ) ) return; + QtxWorkstack* ws = workstack(); + if ( ws ) + { + myItem[VSplit]->setAccel(ws->accel(QtxWorkstack::SplitVertical)); + myItem[HSplit]->setAccel(ws->accel(QtxWorkstack::SplitHorizontal)); + } updatePopup( (QPopupMenu*)obj ); } diff --git a/src/STD/STD_TabDesktop.cxx b/src/STD/STD_TabDesktop.cxx index 0e144b8cd..d2039af15 100644 --- a/src/STD/STD_TabDesktop.cxx +++ b/src/STD/STD_TabDesktop.cxx @@ -28,6 +28,10 @@ myWorkstackAction( 0 ) myWorkstack = new QtxWorkstack( base ); + myWorkstack->setAccel(QtxWorkstack::SplitVertical, SHIFT + Key_V); + myWorkstack->setAccel(QtxWorkstack::SplitHorizontal, SHIFT + Key_H); + myWorkstack->setAccel(QtxWorkstack::Close, SHIFT + Key_C); + connect( myWorkstack, SIGNAL( windowActivated( QWidget* ) ), this, SLOT( onWindowActivated( QWidget* ) ) );