From: asl Date: Fri, 25 Nov 2005 09:50:09 +0000 (+0000) Subject: PAL10635 - IMPROVEMENT: renaming of windows X-Git-Tag: BR_3_1_0_deb~30 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=746396c4a7c45448601a5ef7c8ffcaa09048e5ed;p=modules%2Fgui.git PAL10635 - IMPROVEMENT: renaming of windows --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index d716f89ea..e21e2027b 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -61,6 +61,8 @@ #include #include +#include + #include #include #include @@ -455,6 +457,14 @@ void LightApp_Application::createActions() createMenu( a, newWinMenu, -1 ); } + STD_TabDesktop* tab_desk = dynamic_cast( desk ); + if( tab_desk ) + { + QAction* a = createAction( RenameId, tr( "TOT_RENAME" ), QIconSet(), tr( "MEN_RENAME" ), tr( "PRP_RENAME" ), + 0, desk, false, tab_desk->workstack(), SLOT( onRenameActive() ) ); + createMenu( a, windowMenu, -1 ); + } + connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) ); int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 ); diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index ff42be4ff..c6f3e8eda 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -45,7 +45,7 @@ public: typedef enum { WT_ObjectBrowser, WT_PyConsole, WT_LogWindow, WT_User } WindowTypes; enum { NewGLViewId = STD_Application::UserID, NewPlot2dId, NewOCCViewId, NewVTKViewId, - PreferencesId, MRUId, UserID }; + PreferencesId, MRUId, RenameId, UserID }; public: LightApp_Application(); virtual ~LightApp_Application(); diff --git a/src/LightApp/resources/LightApp_msg_en.po b/src/LightApp/resources/LightApp_msg_en.po index 964625e91..eb18204a2 100644 --- a/src/LightApp/resources/LightApp_msg_en.po +++ b/src/LightApp/resources/LightApp_msg_en.po @@ -32,6 +32,15 @@ msgstr "GNU LGPL" msgid "LightApp_Application::ACTIVATING_MODULE" msgstr "Trying to activate module \"%1\"" +msgid "LightApp_Application::TOT_RENAME" +msgstr "Rename" + +msgid "LightApp_Application::MEN_RENAME" +msgstr "Rename" + +msgid "LightApp_Application::PRP_RENAME" +msgstr "Rename active window" + msgid "LightApp_Application::TOT_DESK_PREFERENCES" msgstr "Preferences" diff --git a/src/Qtx/Makefile.in b/src/Qtx/Makefile.in index d433050d1..04f2941ec 100755 --- a/src/Qtx/Makefile.in +++ b/src/Qtx/Makefile.in @@ -48,7 +48,8 @@ EXPORT_HEADERS= Qtx.h \ QtxWorkstack.h \ QtxResourceEdit.h \ QtxListView.h \ - QtxDirListEditor.h + QtxDirListEditor.h \ + QtxNameDlg.h # .po files to transform in .qm @@ -95,7 +96,8 @@ LIB_SRC= \ QtxResourceEdit.cxx \ QtxWorkstack.cxx \ QtxListView.cxx \ - QtxDirListEditor.cxx + QtxDirListEditor.cxx \ + QtxNameDlg.cxx LIB_MOC = \ QtxAction.h \ @@ -127,7 +129,8 @@ LIB_MOC = \ QtxWorkstack.h \ QtxListView.h \ QtxListResourceEdit.h \ - QtxDirListEditor.h + QtxDirListEditor.h \ + QtxNameDlg.h RESOURCES_FILES = \ diff --git a/src/Qtx/QtxNameDlg.cxx b/src/Qtx/QtxNameDlg.cxx new file mode 100644 index 000000000..28e4fcb04 --- /dev/null +++ b/src/Qtx/QtxNameDlg.cxx @@ -0,0 +1,96 @@ +// File : QtxNameDlg.cxx +// Author : Vadim SANDLER +// $Header$ + +#include "QtxNameDlg.h" + +#include +#include +#include +#include +#include + +#ifndef WIN32 +using namespace std; +#endif + +/*! + Constructor +*/ +QtxNameDlg::QtxNameDlg( QWidget* parent ) +: QtxDialog( parent ? parent : NULL,//application()->desktop(), + "QtxNameDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) +{ + setCaption( tr("TLT_RENAME") ); + setSizeGripEnabled( TRUE ); + + clearButtonFlags( Help ); + setButtonFlags( OKCancel ); + + QHBoxLayout* topLayout = new QHBoxLayout( mainFrame(), 0, 5 ); + + /***************************************************************/ + QLabel* TextLabel = new QLabel( mainFrame(), "TextLabel1" ); + TextLabel->setText( tr( "NAME_LBL" ) ); + topLayout->addWidget( TextLabel ); + + myLineEdit = new QLineEdit( mainFrame(), "LineEdit1" ); + myLineEdit->setMinimumSize( 250, 0 ); + topLayout->addWidget( myLineEdit ); + + /* Move widget on the botton right corner of main widget */ + setAlignment( Qt::AlignCenter ); + + QPushButton* btn = dynamic_cast( button( OK ) ); + if( btn ) + btn->setAutoDefault( true ); + + setFocusProxy( myLineEdit ); +} + +/*! + Destructor +*/ +QtxNameDlg::~QtxNameDlg() +{ +} + +/*! + Sets name +*/ +void QtxNameDlg::setName( const QString& name ) +{ + myLineEdit->setText( name ); + myLineEdit->end(false); + myLineEdit->home(true); +} + +/*! + Returns name entered by user +*/ +QString QtxNameDlg::name() +{ + return myLineEdit->text(); +} + +void QtxNameDlg::accept() +{ + if ( name().stripWhiteSpace().isEmpty() ) + return; + QDialog::accept(); +} + +/*! + Creates modal dialog and returns name entered [ static ] +*/ +QString QtxNameDlg::getName( QWidget* parent, const QString& oldName ) +{ + QString n; + QtxNameDlg* dlg = new QtxNameDlg( parent ); + if ( !oldName.isNull() ) + dlg->setName( oldName ); + if ( dlg->exec() == QDialog::Accepted ) + n = dlg->name(); + delete dlg; + return n; +} diff --git a/src/Qtx/QtxNameDlg.h b/src/Qtx/QtxNameDlg.h new file mode 100644 index 000000000..a6a81938b --- /dev/null +++ b/src/Qtx/QtxNameDlg.h @@ -0,0 +1,47 @@ +// SALOME SalomeApp : implementation of desktop and GUI kernel +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : QtxNameDlg.h +// Author : Vadim SANDLER +// Module : SALOME +// $Header$ + +#ifndef QTX_NAMEDLG_H +#define QTX_NAMEDLG_H + +#include "Qtx.h" +#include "QtxDialog.h" + +class QLineEdit; +class QPushButton; + +//================================================================================= +// class : QtxNameDlg +/*! purpose : Common dialog box class*/ +//================================================================================= +class QTX_EXPORT QtxNameDlg : public QtxDialog +{ + Q_OBJECT + +public: + QtxNameDlg( QWidget* parent = 0 ); + ~QtxNameDlg(); + + void setName( const QString& name ); + QString name(); + + static QString getName( QWidget* parent = 0, const QString& oldName = QString::null ); + +protected slots: + void accept(); + +private: + QPushButton* myButtonOk; + QPushButton* myButtonCancel; + QLineEdit* myLineEdit; +}; + +#endif // QTX_NAMEDLG_H diff --git a/src/Qtx/QtxWorkstack.cxx b/src/Qtx/QtxWorkstack.cxx index d48823096..b05f6013c 100644 --- a/src/Qtx/QtxWorkstack.cxx +++ b/src/Qtx/QtxWorkstack.cxx @@ -2,6 +2,7 @@ // Author: Sergey TELKOV #include "QtxWorkstack.h" +#include "QtxNameDlg.h" #include #include @@ -25,15 +26,18 @@ QtxWorkstack::QtxWorkstack( QWidget* parent ) : QWidget( parent ), myWin( 0 ), -myArea( 0 ) +myArea( 0 ), +myWinForAction( 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( 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() ) ); connect( myActionsMap[Close], SIGNAL( activated() ), this, SLOT( onCloseWindow() ) ); + connect( myActionsMap[Rename], SIGNAL( activated() ), this, SLOT( onRename() ) ); QVBoxLayout* base = new QVBoxLayout( this ); mySplit = new QSplitter( this ); @@ -705,6 +709,26 @@ void QtxWorkstack::splitHorizontal() split( Qt::Vertical ); } +void QtxWorkstack::renameWindow( QWidget* w ) +{ + if( !w ) + return; + + QString new_name = QtxNameDlg::getName( ( QWidget* )parent(), w->caption() ); + if( !new_name.isEmpty() ) + w->setCaption( new_name ); +} + +void QtxWorkstack::onRenameActive() +{ + renameWindow( activeWindow() ); +} + +void QtxWorkstack::onRename() +{ + renameWindow( myWinForAction ); +} + QSplitter* QtxWorkstack::wrapSplitter( QtxWorkstackArea* area ) { if ( !area ) @@ -771,8 +795,10 @@ void QtxWorkstack::insertWidget( QWidget* wid, QWidget* pWid, QWidget* after ) */ void QtxWorkstack::onCloseWindow() { - if ( activeWindow() ) - activeWindow()->close(); + //if ( activeWindow() ) + //activeWindow()->close(); + if( myWinForAction ) + myWinForAction->close(); } void QtxWorkstack::onDestroyed( QObject* obj ) @@ -823,8 +849,9 @@ void QtxWorkstack::onDeactivated( QtxWorkstackArea* area ) QApplication::postEvent( this, new QCustomEvent( QEvent::User ) ); } -void QtxWorkstack::onContextMenuRequested( QPoint p ) +void QtxWorkstack::onContextMenuRequested( QWidget* w, QPoint p ) { + myWinForAction = 0; if ( !activeArea() ) return; @@ -832,6 +859,7 @@ void QtxWorkstack::onContextMenuRequested( QPoint p ) if ( lst.isEmpty() ) return; + myWinForAction = w; QPopupMenu* pm = new QPopupMenu(); if ( lst.count() > 1 ) @@ -840,7 +868,9 @@ void QtxWorkstack::onContextMenuRequested( QPoint p ) myActionsMap[SplitHorizontal]->addTo( pm ); pm->insertSeparator(); } + myActionsMap[Close]->addTo( pm ); + myActionsMap[Rename]->addTo( pm ); pm->exec( p ); @@ -960,7 +990,8 @@ QtxWorkstackArea* QtxWorkstack::createArea( QWidget* parent ) const connect( area, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); connect( area, SIGNAL( activated( QWidget* ) ), this, SLOT( onWindowActivated( QWidget* ) ) ); - connect( area, SIGNAL( contextMenuRequested( QPoint ) ), this, SLOT( onContextMenuRequested( QPoint ) ) ); + connect( area, SIGNAL( contextMenuRequested( QWidget*, QPoint ) ), + this, SLOT( onContextMenuRequested( QWidget*, QPoint ) ) ); connect( area, SIGNAL( deactivated( QtxWorkstackArea* ) ), this, SLOT( onDeactivated( QtxWorkstackArea* ) ) ); return area; @@ -1103,7 +1134,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, SIGNAL( contextMenuRequested( QPoint ) ) ); + connect( myBar, SIGNAL( contextMenuRequested( QPoint ) ), this, SLOT( onBarRequestContextMenu( QPoint ) ) ); updateState(); @@ -1158,6 +1189,13 @@ void QtxWorkstackArea::insertWidget( QWidget* wid, const int idx ) setWidgetActive( wid ); } +void QtxWorkstackArea::onBarRequestContextMenu( QPoint p ) +{ + const QtxWorkstackTabBar* bar = dynamic_cast( sender() ); + if( bar ) + emit contextMenuRequested( widget( myBar->tabAt( tabAt( p ) )->identifier() ), p ); +} + void QtxWorkstackArea::onWidgetDestroyed() { if( sender() ) diff --git a/src/Qtx/QtxWorkstack.h b/src/Qtx/QtxWorkstack.h index a201ad2ff..2ac5c444c 100644 --- a/src/Qtx/QtxWorkstack.h +++ b/src/Qtx/QtxWorkstack.h @@ -32,7 +32,7 @@ class QTX_EXPORT QtxWorkstack : public QWidget Q_OBJECT public: - enum { SplitVertical, SplitHorizontal, Close }; + enum { SplitVertical, SplitHorizontal, Close, Rename }; enum SplitType { SPLIT_STAY, //!< given widget stays in its workarea, others are moved into a new one @@ -68,12 +68,14 @@ signals: public slots: void splitVertical(); void splitHorizontal(); + void onRenameActive(); private slots: + void onRename(); void onCloseWindow(); void onDestroyed( QObject* ); void onWindowActivated( QWidget* ); - void onContextMenuRequested( QPoint ); + void onContextMenuRequested( QWidget*, QPoint ); void onDeactivated( QtxWorkstackArea* ); protected: @@ -87,6 +89,7 @@ private: QSplitter* wrapSplitter( QtxWorkstackArea* ); void insertWidget( QWidget*, QWidget*, QWidget* ); + void renameWindow( QWidget* ); QtxWorkstackArea* areaAt( const QPoint& ) const; @@ -107,7 +110,7 @@ private: const int need_pos, const int splitter_pos ); private: - QWidget* myWin; + QWidget* myWin, *myWinForAction; QtxWorkstackArea* myArea; QSplitter* mySplit; @@ -151,7 +154,7 @@ public: signals: void activated( QWidget* ); - void contextMenuRequested( QPoint ); + void contextMenuRequested( QWidget*, QPoint ); void deactivated( QtxWorkstackArea* ); public slots: @@ -170,6 +173,7 @@ private slots: void onChildHided( QtxWorkstackChild* ); void onChildActivated( QtxWorkstackChild* ); void onChildCaptionChanged( QtxWorkstackChild* ); + void onBarRequestContextMenu( QPoint ); protected: virtual void customEvent( QCustomEvent* );