Salome HOME
no message
authorstv <stv@opencascade.com>
Fri, 11 Nov 2005 08:12:57 +0000 (08:12 +0000)
committerstv <stv@opencascade.com>
Fri, 11 Nov 2005 08:12:57 +0000 (08:12 +0000)
src/SUIT/SUIT_Desktop.cxx
src/SUIT/SUIT_Desktop.h
src/SUIT/SUIT_FileDlg.cxx
src/SUIT/SUIT_Session.cxx
src/SUIT/SUIT_Session.h

index 567f23dd18fb438ef3d2323a643dc2bcad67b6f6..25d5da9772c66958019e97f2e8cc80adedade723 100755 (executable)
 #include <qstyle.h>
 
 /*!
- Class: LogoBox
+ Class: SUIT_Desktop::LogoMgr
  Level: Internal
 */
 
-class LogoBox : public QHBox
+class SUIT_Desktop::LogoMgr : public QObject
 {
 public:
-  LogoBox( QWidget* parent = 0, const char* name = 0, WFlags f = 0 ) : QHBox( parent, name, f )
-  {
-    setFrameStyle( Plain | NoFrame );
-    setMargin( 0 ); setSpacing( 2 );
-  }
-  void addSpacing( int spacing )
-  {
-    QApplication::sendPostedEvents( this, QEvent::ChildInserted );
-    ((QHBoxLayout*)layout())->addSpacing( spacing );
-  }
-protected:
-  void drawContents( QPainter* p )
-  {
-    if ( parentWidget()->inherits( "QMenuBar" ) )
-      style().drawControl( QStyle::CE_MenuBarEmptyArea, p, this, contentsRect(), colorGroup() );
-    else
-      QHBox::drawContents( p );
-  }
-};
+  LogoMgr( QMenuBar* );
+  virtual ~LogoMgr();
 
-/*!
- Class: SUIT_Desktop::LogoManager
- Level: Internal
-*/
+  int                    count() const;
+
+  void                   insert( const QString&, const QPixmap&, const int = -1 );
+  void                   remove( const QString& );
+  void                   clear();
+
+  QMenuBar*              menuBar() const;
+
+private:
+  void                   generate();
+  int                    find( const QString& ) const;
+
+private:
+  typedef struct { QString id; QPixmap pix; } LogoInfo;
+  typedef QValueList<LogoInfo>                LogoList;
+
+private:
+  int                    myId;
+  QMenuBar*              myMenus;
+  LogoList               myLogos;
+};
 
-SUIT_Desktop::LogoManager::LogoManager( SUIT_Desktop* desktop)
-: myDesktop( desktop ), myId( 0 ) 
+SUIT_Desktop::LogoMgr::LogoMgr( QMenuBar* mb )
+: QObject( mb ),
+myMenus( mb ),
+myId( 0 )
 {
 } 
 
-void SUIT_Desktop::LogoManager::addLogo( const QString& logoID, const QPixmap& logo )
+SUIT_Desktop::LogoMgr::~LogoMgr()
+{
+}
+
+QMenuBar* SUIT_Desktop::LogoMgr::menuBar() const
+{
+  return myMenus;
+}
+
+int SUIT_Desktop::LogoMgr::count() const
+{
+  return myLogos.count();
+}
+
+void SUIT_Desktop::LogoMgr::insert( const QString& id, const QPixmap& pix, const int index )
 {
-  if ( !myDesktop || logo.isNull() )
+  if ( pix.isNull() )
     return;
-  myLogoMap[ logoID ] = logo;
-  generateLogo();
+
+  LogoInfo* inf = 0;
+
+  int idx = find( id );
+  if ( idx < 0 )
+  {
+    idx = index < (int)myLogos.count() ? index : -1;
+    if ( idx < 0 )
+      inf = &( *myLogos.append( LogoInfo() ) );
+    else
+      inf = &( *myLogos.insert( myLogos.at( idx ), LogoInfo() ) );
+  }
+  else
+    inf = &( *myLogos.at( idx ) );
+
+
+  inf->id = id;
+  inf->pix = pix;
+
+  generate();
 }
 
-void SUIT_Desktop::LogoManager::removeLogo( const QString& logoID )
+void SUIT_Desktop::LogoMgr::remove( const QString& id )
 {
-  if ( !myDesktop || myLogoMap.find( logoID ) == myLogoMap.end() )
+  int idx = find( id );
+  if ( idx < 0 )
     return;
-  myLogoMap.remove( logoID );
-  generateLogo();
+
+  myLogos.remove( myLogos.at( idx ) );
+
+  generate();
 }
 
-void SUIT_Desktop::LogoManager::clearLogo()
+void SUIT_Desktop::LogoMgr::clear()
 {
-  myLogoMap.clear();
-  generateLogo();
+  myLogos.clear();
+  generate();
 }
 
-void SUIT_Desktop::LogoManager::generateLogo()
+void SUIT_Desktop::LogoMgr::generate()
 {
-  if ( !myDesktop ) return;
+  if ( !menuBar() )
+    return;
 
   if ( myId ) 
-    myDesktop->menuBar()->removeItem( myId );
+    menuBar()->removeItem( myId );
+
   myId = 0;
 
-  if ( !myLogoMap.count() )
+  if ( myLogos.isEmpty() )
     return;
 
-  LogoBox* cnt = new LogoBox( myDesktop );
-  
-  QMap<QString, QPixmap>::Iterator it;
-  for ( it = myLogoMap.begin(); it != myLogoMap.end(); ++it ) {
+  class LogoBox : public QHBox
+  {
+  public:
+    LogoBox( QWidget* parent = 0, const char* name = 0, WFlags f = 0 ) : QHBox( parent, name, f ) {};
+
+    void addSpacing( int spacing )
+    {
+      QApplication::sendPostedEvents( this, QEvent::ChildInserted );
+      ((QHBoxLayout*)layout())->addSpacing( spacing );
+    }
+
+  protected:
+    void drawContents( QPainter* p )
+    {
+      if ( parentWidget()->inherits( "QMenuBar" ) )
+        style().drawControl( QStyle::CE_MenuBarEmptyArea, p, this, contentsRect(), colorGroup() );
+      else
+        QHBox::drawContents( p );
+    }
+  };
+
+  LogoBox* cnt = new LogoBox( menuBar() );
+  cnt->setSpacing( 2 );
+
+  for ( LogoList::const_iterator it = myLogos.begin(); it != myLogos.end(); ++it )
+  {
     QLabel* logoLab = new QLabel( cnt );
-    logoLab->setPixmap( *it );
-    logoLab->setAlignment( QLabel::AlignCenter ); 
+    logoLab->setPixmap( (*it).pix );
     logoLab->setScaledContents( false );
+    logoLab->setAlignment( QLabel::AlignCenter ); 
   }
+  QApplication::sendPostedEvents( cnt, QEvent::ChildInserted );
   cnt->addSpacing( 2 );
 
-  myId = myDesktop->menuBar()->insertItem( cnt );
-  QApplication::sendPostedEvents( myDesktop->menuBar()->parentWidget(), QEvent::LayoutHint );
-  QApplication::postEvent( myDesktop->menuBar()->parentWidget(), new QEvent( QEvent::LayoutHint ) );
+  myId = menuBar()->insertItem( cnt );
+
+  QApplication::sendPostedEvents( menuBar()->parentWidget(), QEvent::LayoutHint );
+  QApplication::postEvent( menuBar()->parentWidget(), new QEvent( QEvent::LayoutHint ) );
 }
 
+int SUIT_Desktop::LogoMgr::find( const QString& id ) const
+{
+  int idx = -1;
+  for ( uint i = 0; i < myLogos.count() && idx < 0; i++ )
+  {
+    if ( (*myLogos.at( i ) ).id == id )
+      idx = i;
+  }
+  return idx;
+}
 
 /*!\class SUIT_Desktop
  * Provide desktop management:\n
@@ -115,10 +188,11 @@ void SUIT_Desktop::LogoManager::generateLogo()
   Constructor.
 */
 SUIT_Desktop::SUIT_Desktop()
-: QtxMainWindow(), myLogoMan( this )
+: QtxMainWindow()
 {
   myMenuMgr = new QtxActionMenuMgr( this );
   myToolMgr = new QtxActionToolMgr( this );
+  myLogoMgr = new LogoMgr( menuBar() );
 }
 
 /*!
@@ -186,28 +260,62 @@ QtxActionToolMgr* SUIT_Desktop::toolMgr() const
   return myToolMgr;
 }
 
+/*!
+  Returns the count of the existed logos.
+*/
+int SUIT_Desktop::logoCount() const
+{
+  if ( !myLogoMgr )
+    return 0;
+  else
+    return myLogoMgr->count();
+}
+
+/*!
+  Adds new logo to the menu bar area.
+  Obsolete. Not should be used.
+  Use SUIT_Desktop::logoInsert();
+*/
+void SUIT_Desktop::addLogo( const QString& id, const QPixmap& pix )
+{
+  logoInsert( id, pix );
+}
+
+/*!
+  Removes a logo.
+  Obsolete. Not should be used.
+  Use SUIT_Desktop::logoRemove();
+*/
+void SUIT_Desktop::removeLogo( const QString& id )
+{
+  logoRemove( id );
+}
+
 /*!
   Adds new logo to the menu bar area
 */
-void SUIT_Desktop::addLogo( const QString& logoID, const QPixmap& logo )
+void SUIT_Desktop::logoInsert( const QString& logoID, const QPixmap& logo, const int idx )
 {
-  myLogoMan.addLogo( logoID, logo );
+  if ( myLogoMgr )
+    myLogoMgr->insert( logoID, logo, idx );
 }
 
 /*!
   Removes a logo
 */
-void SUIT_Desktop::removeLogo( const QString& logoID )
+void SUIT_Desktop::logoRemove( const QString& logoID )
 {
-  myLogoMan.removeLogo( logoID );
+  if ( myLogoMgr )
+    myLogoMgr->remove( logoID );
 }
 
 /*!
   Removes all logos 
 */
-void SUIT_Desktop::clearLogo()
+void SUIT_Desktop::logoClear()
 {
-  myLogoMan.clearLogo();
+  if ( myLogoMgr )
+    myLogoMgr->clear();
 }
 
 
index 9eb46cfa0d0f6db95cde4d538c2777e4f96ffa31..52d64c4c9a8417750a9f237d57869378b040cde9 100755 (executable)
@@ -16,22 +16,7 @@ class SUIT_EXPORT SUIT_Desktop : public QtxMainWindow
 {
   Q_OBJECT
 
-  class LogoManager
-  {
-  public:
-    LogoManager( SUIT_Desktop* );
-    void                   addLogo( const QString&, const QPixmap& );
-    void                   removeLogo( const QString& );
-    void                   clearLogo();
-
-  private:
-    void                   generateLogo();
-    
-  private:
-    SUIT_Desktop*          myDesktop;
-    QMap<QString, QPixmap> myLogoMap;
-    int                    myId;
-  };
+  class LogoMgr;
 
 public:
   SUIT_Desktop();
@@ -43,9 +28,14 @@ public:
   virtual SUIT_ViewWindow* activeWindow() const = 0;
   virtual QPtrList<SUIT_ViewWindow> windows() const = 0;
 
-  void                     addLogo( const QString&, const QPixmap& );
-  void                     removeLogo( const QString& );
-  void                     clearLogo();
+  void                     addLogo( const QString&, const QPixmap& ); // Not should be used. Will be removed.
+  void                     removeLogo( const QString& );              // Not should be used. Will be removed.
+
+  int                      logoCount() const;
+
+  void                     logoClear();
+  void                     logoRemove( const QString& );
+  void                     logoInsert( const QString&, const QPixmap&, const int = -1 );
 
 signals:
   void                     activated();
@@ -63,7 +53,7 @@ protected:
 private:
   QtxActionMenuMgr*        myMenuMgr;
   QtxActionToolMgr*        myToolMgr;
-  LogoManager              myLogoMan;
+  LogoMgr*                 myLogoMgr;
 };
 
 #endif
index 7fe3754140544c30e0f75e4cbf0f0af0f70935a5..87f1994d3460326732c49b906a3343ae98501ecd 100755 (executable)
@@ -249,18 +249,23 @@ bool SUIT_FileDlg::acceptData()
   if ( myValidator )
   {
     if ( isOpenDlg() )
-      if ( mode() == ExistingFiles ) {
-       QStringList fileNames = selectedFiles();
-       for ( int i = 0; i < (int)fileNames.count(); i++ ) {
-         if ( !myValidator->canOpen( fileNames[i] ) )
-           return false;
-       }
-       return true;
+    {
+      if ( mode() == ExistingFiles )
+      {
+             QStringList fileNames = selectedFiles();
+             for ( int i = 0; i < (int)fileNames.count(); i++ )
+        {
+               if ( !myValidator->canOpen( fileNames[i] ) )
+                 return false;
+             }
+             return true;
       }
-      else {
-       return myValidator->canOpen( selectedFile() );
+      else
+      {
+             return myValidator->canOpen( selectedFile() );
       }
-    else 
+    }
+    else
       return myValidator->canSave( selectedFile() );
   }
   return true;
@@ -333,9 +338,10 @@ void SUIT_FileDlg::addExtension()
       {
         QString newExt = extList[i].replace( QRegExp( "[\\\\][+]" ),"+" );
         int res = newExt.findRev( '.' );
-        if ( res >= 0 ) 
+        if ( res >= 0 )
           newExt = newExt.mid( res + 1 );
-        if ( newExt.find( QRegExp("[*|?]" ) ) < 0 ) {
+        if ( newExt.find( QRegExp("[*|?]" ) ) < 0 )
+        {
           mySelectedFile.stripWhiteSpace();
           mySelectedFile += mySelectedFile.endsWith(".") ? newExt : QString(".") + newExt;
           break;
index a9db903d08ce360045b6bf2b393e34c502130fda..32dbe57b469e5427de3cc811b448b20a3ef2a290 100755 (executable)
@@ -61,17 +61,18 @@ SUIT_Application* SUIT_Session::startApplication( const QString& name, int args,
   if ( myAppLibs.contains( appName ) )
     libHandle = myAppLibs[appName];
 
+  QString lib;
   if ( !libHandle )
-    libHandle = loadLibrary( name );
+    libHandle = loadLibrary( name, lib );
 
   if ( !libHandle )
   {
     SUIT_MessageBox::warn1( 0, tr( "Error" ),
-                            tr( "Can not find function %1. %2").arg( APP_CREATE_NAME ).arg( lastError() ), tr( "Ok" ) );
+                            tr( "Can not load application library \"%1\": %2").arg( lib ).arg( lastError() ), tr( "Ok" ) );
     return 0;
   }
 
-  if (!myAppLibs.contains(appName) || !myAppLibs[appName]) // jfa 22.06.2005
+  if ( !myAppLibs.contains( appName ) || !myAppLibs[appName] ) // jfa 22.06.2005
     myAppLibs.insert( appName, libHandle );
 
   APP_CREATE_FUNC crtInst = 0;
@@ -85,7 +86,7 @@ SUIT_Application* SUIT_Session::startApplication( const QString& name, int args,
   if ( !crtInst )
   {
     SUIT_MessageBox::warn1( 0, tr( "Error" ),
-                            tr( "Can not find function %1. %2").arg( APP_CREATE_NAME ).arg( lastError() ), tr( "Ok" ) );
+                            tr( "Can not find function \"%1\": %2" ).arg( APP_CREATE_NAME ).arg( lastError() ), tr( "Ok" ) );
     return 0;
   }
 
@@ -100,7 +101,7 @@ SUIT_Application* SUIT_Session::startApplication( const QString& name, int args,
   SUIT_Application* anApp = crtInst();
   if ( !anApp )
   {
-    SUIT_MessageBox::warn1(0, tr( "Error" ), tr( "Can not find function %1. %2").arg( APP_CREATE_NAME ).arg( lastError() ), tr( "Ok" ) );
+    SUIT_MessageBox::warn1( 0, tr( "Error" ), tr( "Can not create application \"%1\": %2").arg( appName ).arg( lastError() ), tr( "Ok" ) );
     return 0;
   }
 
@@ -109,7 +110,7 @@ SUIT_Application* SUIT_Session::startApplication( const QString& name, int args,
   connect( anApp, SIGNAL( applicationClosed( SUIT_Application* ) ),
            this, SLOT( onApplicationClosed( SUIT_Application* ) ) );
   connect( anApp, SIGNAL( activated( SUIT_Application* ) ), 
-          this, SLOT( onApplicationActivated( SUIT_Application* ) ) );
+                this, SLOT( onApplicationActivated( SUIT_Application* ) ) );
 
   myAppList.append( anApp );
 
@@ -127,6 +128,10 @@ SUIT_Application* SUIT_Session::startApplication( const QString& name, int args,
 
   anApp->start();
 
+  // Application can be closed during starting (not started).
+  if ( !myAppList.contains( anApp ) )
+    anApp = 0;
+
   return anApp;
 }
 
@@ -255,10 +260,11 @@ QString SUIT_Session::lastError() const
 /*! Load library to session.
  * \retval Loaded library.
  */
-SUIT_Session::AppLib SUIT_Session::loadLibrary( const QString& name )
+SUIT_Session::AppLib SUIT_Session::loadLibrary( const QString& name, QString& libName )
 {
   QString libFile = SUIT_Tools::library( name );
 
+  libName = libFile;
   if ( libFile.isEmpty() )
     return 0;
 
index 1ec8bd6386060d741070f562febdb9c0562bb98d..01a1e46f8f3c0c31d2719d87e488144840c2d785 100755 (executable)
@@ -72,7 +72,7 @@ private:
 
 private:
   QString                      lastError() const;
-  AppLib                       loadLibrary( const QString& );
+  AppLib                       loadLibrary( const QString&, QString& );
   QString                      applicationName( const QString& ) const;
 
 private: