]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
PAL10635 - IMPROVEMENT: renaming of windows
authorasl <asl@opencascade.com>
Fri, 25 Nov 2005 09:50:09 +0000 (09:50 +0000)
committerasl <asl@opencascade.com>
Fri, 25 Nov 2005 09:50:09 +0000 (09:50 +0000)
src/LightApp/LightApp_Application.cxx
src/LightApp/LightApp_Application.h
src/LightApp/resources/LightApp_msg_en.po
src/Qtx/Makefile.in
src/Qtx/QtxNameDlg.cxx [new file with mode: 0644]
src/Qtx/QtxNameDlg.h [new file with mode: 0644]
src/Qtx/QtxWorkstack.cxx
src/Qtx/QtxWorkstack.h

index d716f89ea11ce4004e56fbfd2a32a1fb43240d9f..e21e2027b0f14163b24bb328506f7250aaa86d28 100644 (file)
@@ -61,6 +61,8 @@
 #include <SUPERVGraph_ViewFrame.h>
 #include <SUPERVGraph_ViewManager.h>
 
+#include <QtxWorkstack.h>
+
 #include <qdir.h>
 #include <qimage.h>
 #include <qstring.h>
@@ -455,6 +457,14 @@ void LightApp_Application::createActions()
     createMenu( a, newWinMenu, -1 );
   }
 
+  STD_TabDesktop* tab_desk = dynamic_cast<STD_TabDesktop*>( 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 );
index ff42be4ff88fe7061222377ca557e7ff9a2b765a..c6f3e8eda03108d1e22c801485db5fc405647c03 100644 (file)
@@ -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();
index 964625e91c6da6ed7b60a94c85d8a083785aede0..eb18204a2e0cce7e4bdb0b0f258b189db4211c35 100644 (file)
@@ -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"
 
index d433050d16ab40e85048a14adc0d97a3eb2bec49..04f2941ecb3cb22e5b41ba4dd41bd6f78f4b5493 100755 (executable)
@@ -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 (file)
index 0000000..28e4fcb
--- /dev/null
@@ -0,0 +1,96 @@
+//  File   : QtxNameDlg.cxx\r
+//  Author : Vadim SANDLER\r
+//  $Header$\r
+\r
+#include "QtxNameDlg.h"\r
+\r
+#include <qlayout.h>\r
+#include <qgroupbox.h>\r
+#include <qlabel.h>\r
+#include <qlineedit.h>\r
+#include <qpushbutton.h>\r
+\r
+#ifndef WIN32\r
+using namespace std;\r
+#endif\r
+\r
+/*!\r
+  Constructor\r
+*/\r
+QtxNameDlg::QtxNameDlg( QWidget* parent )\r
+: QtxDialog( parent ? parent : NULL,//application()->desktop(), \r
+            "QtxNameDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )\r
+{\r
+  setCaption( tr("TLT_RENAME") );\r
+  setSizeGripEnabled( TRUE );\r
+\r
+  clearButtonFlags( Help );\r
+  setButtonFlags( OKCancel );\r
+\r
+  QHBoxLayout* topLayout = new QHBoxLayout( mainFrame(), 0, 5 );\r
+\r
+  /***************************************************************/\r
+  QLabel* TextLabel = new QLabel( mainFrame(), "TextLabel1" );\r
+  TextLabel->setText( tr( "NAME_LBL" ) );\r
+  topLayout->addWidget( TextLabel );\r
+  \r
+  myLineEdit = new QLineEdit( mainFrame(), "LineEdit1" );\r
+  myLineEdit->setMinimumSize( 250, 0 );\r
+  topLayout->addWidget( myLineEdit );\r
\r
+  /* Move widget on the botton right corner of main widget */\r
+  setAlignment( Qt::AlignCenter );\r
+\r
+  QPushButton* btn = dynamic_cast<QPushButton*>( button( OK ) );\r
+  if( btn )\r
+    btn->setAutoDefault( true );\r
+\r
+  setFocusProxy( myLineEdit );\r
+}\r
+\r
+/*!\r
+  Destructor\r
+*/\r
+QtxNameDlg::~QtxNameDlg()\r
+{\r
+}\r
+\r
+/*!\r
+  Sets name\r
+*/\r
+void QtxNameDlg::setName( const QString& name )\r
+{\r
+  myLineEdit->setText( name );\r
+  myLineEdit->end(false);\r
+  myLineEdit->home(true);\r
+}\r
+\r
+/*!\r
+  Returns name entered by user\r
+*/\r
+QString QtxNameDlg::name()\r
+{\r
+  return myLineEdit->text();\r
+}\r
+\r
+void QtxNameDlg::accept()\r
+{\r
+  if ( name().stripWhiteSpace().isEmpty() )\r
+    return;\r
+  QDialog::accept();\r
+}\r
+\r
+/*!\r
+  Creates modal <Rename> dialog and returns name entered [ static ]\r
+*/\r
+QString QtxNameDlg::getName( QWidget* parent, const QString& oldName )\r
+{\r
+  QString n;\r
+  QtxNameDlg* dlg = new QtxNameDlg( parent );\r
+  if ( !oldName.isNull() )\r
+    dlg->setName( oldName );\r
+  if ( dlg->exec() == QDialog::Accepted ) \r
+    n = dlg->name();\r
+  delete dlg;\r
+  return n;\r
+}\r
diff --git a/src/Qtx/QtxNameDlg.h b/src/Qtx/QtxNameDlg.h
new file mode 100644 (file)
index 0000000..a6a8193
--- /dev/null
@@ -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 <Rename> 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
index d48823096c25d10a0fb12e9460e7fe7bd4399e00..b05f6013c1bd4fc88dffabadd4404ee7af711e46 100644 (file)
@@ -2,6 +2,7 @@
 // Author:    Sergey TELKOV
 
 #include "QtxWorkstack.h"
+#include "QtxNameDlg.h"
 
 #include <qstyle.h>
 #include <qimage.h>
 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<const QtxWorkstackTabBar*>( sender() );
+  if( bar )
+    emit contextMenuRequested( widget( myBar->tabAt( tabAt( p ) )->identifier() ), p );
+}
+
 void QtxWorkstackArea::onWidgetDestroyed()
 {
   if( sender() )
index a201ad2ff2662c574db9240db0967d0f974ffea5..2ac5c444c49acbe8ae9e0b4ac2bf8d98ba94fb62 100644 (file)
@@ -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* );