From cfb34aeef106836c5ef8b8e9248d3534443bb45d Mon Sep 17 00:00:00 2001 From: stv Date: Fri, 25 Nov 2005 14:28:02 +0000 Subject: [PATCH] no message --- src/Qtx/QtxWorkstack.cxx | 67 ++++++++++++++++++++++++---------------- src/Qtx/QtxWorkstack.h | 11 ++++--- 2 files changed, 47 insertions(+), 31 deletions(-) diff --git a/src/Qtx/QtxWorkstack.cxx b/src/Qtx/QtxWorkstack.cxx index b05f6013c..20cbd0515 100644 --- a/src/Qtx/QtxWorkstack.cxx +++ b/src/Qtx/QtxWorkstack.cxx @@ -2,7 +2,6 @@ // Author: Sergey TELKOV #include "QtxWorkstack.h" -#include "QtxNameDlg.h" #include #include @@ -17,6 +16,7 @@ #include #include #include +#include /*! Class: QtxWorkstack [Public] @@ -27,12 +27,12 @@ QtxWorkstack::QtxWorkstack( QWidget* parent ) : QWidget( parent ), myWin( 0 ), myArea( 0 ), -myWinForAction( 0 ) +myWorkWin( 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 )); - myActionsMap.insert( Rename, new QAction( tr( "Rename" ), 0, this )); + 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 ) ); + myActionsMap.insert( Rename, new QAction( tr( "Rename" ), 0, this ) ); connect( myActionsMap[SplitVertical], SIGNAL( activated() ), this, SLOT( splitVertical() ) ); connect( myActionsMap[SplitHorizontal], SIGNAL( activated() ), this, SLOT( splitHorizontal() ) ); @@ -711,12 +711,14 @@ void QtxWorkstack::splitHorizontal() void QtxWorkstack::renameWindow( QWidget* w ) { - if( !w ) + if ( !w ) return; - QString new_name = QtxNameDlg::getName( ( QWidget* )parent(), w->caption() ); - if( !new_name.isEmpty() ) - w->setCaption( new_name ); + bool ok = false; + QString newName = QInputDialog::getText( tr( "Rename" ), tr( "Enter new name:" ), QLineEdit::Normal, + w->caption(), &ok, topLevelWidget() ); + if ( ok ) + w->setCaption( newName ); } void QtxWorkstack::onRenameActive() @@ -726,7 +728,7 @@ void QtxWorkstack::onRenameActive() void QtxWorkstack::onRename() { - renameWindow( myWinForAction ); + renameWindow( myWorkWin ); } QSplitter* QtxWorkstack::wrapSplitter( QtxWorkstackArea* area ) @@ -795,10 +797,8 @@ void QtxWorkstack::insertWidget( QWidget* wid, QWidget* pWid, QWidget* after ) */ void QtxWorkstack::onCloseWindow() { - //if ( activeWindow() ) - //activeWindow()->close(); - if( myWinForAction ) - myWinForAction->close(); + if ( myWorkWin ) + myWorkWin->close(); } void QtxWorkstack::onDestroyed( QObject* obj ) @@ -851,7 +851,6 @@ void QtxWorkstack::onDeactivated( QtxWorkstackArea* area ) void QtxWorkstack::onContextMenuRequested( QWidget* w, QPoint p ) { - myWinForAction = 0; if ( !activeArea() ) return; @@ -859,7 +858,8 @@ void QtxWorkstack::onContextMenuRequested( QWidget* w, QPoint p ) if ( lst.isEmpty() ) return; - myWinForAction = w; + myWorkWin = w; + QPopupMenu* pm = new QPopupMenu(); if ( lst.count() > 1 ) @@ -869,12 +869,18 @@ void QtxWorkstack::onContextMenuRequested( QWidget* w, QPoint p ) pm->insertSeparator(); } - myActionsMap[Close]->addTo( pm ); - myActionsMap[Rename]->addTo( pm ); - - pm->exec( p ); + if ( w ) + { + myActionsMap[Close]->addTo( pm ); + myActionsMap[Rename]->addTo( pm ); + } + + if ( pm->count() ) + pm->exec( p ); delete pm; + + myWorkWin = 0; } void QtxWorkstack::childEvent( QChildEvent* e ) @@ -1134,7 +1140,7 @@ QtxWorkstackArea::QtxWorkstackArea( QWidget* parent ) connect( myClose, SIGNAL( clicked() ), this, SLOT( onClose() ) ); connect( myBar, SIGNAL( selected( int ) ), this, SLOT( onSelected( int ) ) ); connect( myBar, SIGNAL( dragActiveTab() ), this, SLOT( onDragActiveTab() ) ); - connect( myBar, SIGNAL( contextMenuRequested( QPoint ) ), this, SLOT( onBarRequestContextMenu( QPoint ) ) ); + connect( myBar, SIGNAL( contextMenuRequested( QPoint ) ), this, SLOT( onContextMenuRequested( QPoint ) ) ); updateState(); @@ -1189,16 +1195,23 @@ void QtxWorkstackArea::insertWidget( QWidget* wid, const int idx ) setWidgetActive( wid ); } -void QtxWorkstackArea::onBarRequestContextMenu( QPoint p ) +void QtxWorkstackArea::onContextMenuRequested( QPoint p ) { - const QtxWorkstackTabBar* bar = dynamic_cast( sender() ); - if( bar ) - emit contextMenuRequested( widget( myBar->tabAt( tabAt( p ) )->identifier() ), p ); + const QtxWorkstackTabBar* bar = ::qt_cast( sender() ); + if ( !bar ) + return; + + QWidget* wid = 0; + QTab* tab = myBar->tabAt( tabAt( p ) ); + if ( tab ) + wid = widget( tab->identifier() ); + + emit contextMenuRequested( wid, p ); } void QtxWorkstackArea::onWidgetDestroyed() { - if( sender() ) + if ( sender() ) removeWidget( (QWidget*)sender(), false ); } diff --git a/src/Qtx/QtxWorkstack.h b/src/Qtx/QtxWorkstack.h index 2ac5c444c..14f18e417 100644 --- a/src/Qtx/QtxWorkstack.h +++ b/src/Qtx/QtxWorkstack.h @@ -34,7 +34,8 @@ class QTX_EXPORT QtxWorkstack : public QWidget public: enum { SplitVertical, SplitHorizontal, Close, Rename }; - enum SplitType { + enum SplitType + { SPLIT_STAY, //!< given widget stays in its workarea, others are moved into a new one SPLIT_AT, //!< widgets before a given widget stays in they workarea, others are moved into a new one SPLIT_MOVE //!< given widget is moved into a new workarea, others stay in an old one @@ -110,9 +111,10 @@ private: const int need_pos, const int splitter_pos ); private: - QWidget* myWin, *myWinForAction; + QWidget* myWin; QtxWorkstackArea* myArea; QSplitter* mySplit; + QWidget* myWorkWin; QMap myActionsMap; //!< The map of the actions. Allows to get the QAction object by the key. @@ -167,13 +169,14 @@ private slots: void onWidgetDestroyed(); - void onDragActiveTab(); void onChildDestroyed( QObject* ); void onChildShown( QtxWorkstackChild* ); void onChildHided( QtxWorkstackChild* ); void onChildActivated( QtxWorkstackChild* ); void onChildCaptionChanged( QtxWorkstackChild* ); - void onBarRequestContextMenu( QPoint ); + + void onDragActiveTab(); + void onContextMenuRequested( QPoint ); protected: virtual void customEvent( QCustomEvent* ); -- 2.39.2