Salome HOME
Provide logo support for SALOME desktop
authorvsr <vsr@opencascade.com>
Tue, 13 Sep 2005 10:14:44 +0000 (10:14 +0000)
committervsr <vsr@opencascade.com>
Tue, 13 Sep 2005 10:14:44 +0000 (10:14 +0000)
src/SUIT/SUIT_Desktop.cxx
src/SUIT/SUIT_Desktop.h
src/SUIT/SUIT_ResourceMgr.h

index 4ff86a88def98bdcfa28206b20a92f33feee1ce8..567f23dd18fb438ef3d2323a643dc2bcad67b6f6 100755 (executable)
 #include <qdockarea.h>
 #include <qstatusbar.h>
 #include <qapplication.h>
+#include <qhbox.h>
+#include <qlabel.h>
+#include <qstyle.h>
+
+/*!
+ Class: LogoBox
+ Level: Internal
+*/
+
+class LogoBox : public QHBox
+{
+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 );
+  }
+};
+
+/*!
+ Class: SUIT_Desktop::LogoManager
+ Level: Internal
+*/
+
+SUIT_Desktop::LogoManager::LogoManager( SUIT_Desktop* desktop)
+: myDesktop( desktop ), myId( 0 ) 
+{
+} 
+
+void SUIT_Desktop::LogoManager::addLogo( const QString& logoID, const QPixmap& logo )
+{
+  if ( !myDesktop || logo.isNull() )
+    return;
+  myLogoMap[ logoID ] = logo;
+  generateLogo();
+}
+
+void SUIT_Desktop::LogoManager::removeLogo( const QString& logoID )
+{
+  if ( !myDesktop || myLogoMap.find( logoID ) == myLogoMap.end() )
+    return;
+  myLogoMap.remove( logoID );
+  generateLogo();
+}
+
+void SUIT_Desktop::LogoManager::clearLogo()
+{
+  myLogoMap.clear();
+  generateLogo();
+}
+
+void SUIT_Desktop::LogoManager::generateLogo()
+{
+  if ( !myDesktop ) return;
+
+  if ( myId ) 
+    myDesktop->menuBar()->removeItem( myId );
+  myId = 0;
+
+  if ( !myLogoMap.count() )
+    return;
+
+  LogoBox* cnt = new LogoBox( myDesktop );
+  
+  QMap<QString, QPixmap>::Iterator it;
+  for ( it = myLogoMap.begin(); it != myLogoMap.end(); ++it ) {
+    QLabel* logoLab = new QLabel( cnt );
+    logoLab->setPixmap( *it );
+    logoLab->setAlignment( QLabel::AlignCenter ); 
+    logoLab->setScaledContents( false );
+  }
+  cnt->addSpacing( 2 );
+
+  myId = myDesktop->menuBar()->insertItem( cnt );
+  QApplication::sendPostedEvents( myDesktop->menuBar()->parentWidget(), QEvent::LayoutHint );
+  QApplication::postEvent( myDesktop->menuBar()->parentWidget(), new QEvent( QEvent::LayoutHint ) );
+}
+
 
 /*!\class SUIT_Desktop
  * Provide desktop management:\n
  * \li windows
  */
 
+
 /*!
   Constructor.
 */
 SUIT_Desktop::SUIT_Desktop()
-: QtxMainWindow()
+: QtxMainWindow(), myLogoMan( this )
 {
   myMenuMgr = new QtxActionMenuMgr( this );
   myToolMgr = new QtxActionToolMgr( this );
@@ -93,3 +185,29 @@ QtxActionToolMgr* SUIT_Desktop::toolMgr() const
 {
   return myToolMgr;
 }
+
+/*!
+  Adds new logo to the menu bar area
+*/
+void SUIT_Desktop::addLogo( const QString& logoID, const QPixmap& logo )
+{
+  myLogoMan.addLogo( logoID, logo );
+}
+
+/*!
+  Removes a logo
+*/
+void SUIT_Desktop::removeLogo( const QString& logoID )
+{
+  myLogoMan.removeLogo( logoID );
+}
+
+/*!
+  Removes all logos 
+*/
+void SUIT_Desktop::clearLogo()
+{
+  myLogoMan.clearLogo();
+}
+
+
index 9cc13b94a01dd3f043ac6e14e06c8ea494499e2f..761008ed4acdeee3c914ede3b4ebb8d74a13641a 100755 (executable)
@@ -3,6 +3,7 @@
 
 #include "SUIT.h"
 
+#include <qmap.h>
 #include <QtxMainWindow.h>
 
 class QPopupMenu;
@@ -14,6 +15,23 @@ 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;
+  };
+
 public:
   SUIT_Desktop();
   virtual ~SUIT_Desktop();
@@ -24,6 +42,10 @@ 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();
+
 signals:
   void                     activated();
   void                     deactivated();
@@ -40,6 +62,7 @@ protected:
 private:
   QtxActionMenuMgr*        myMenuMgr;
   QtxActionToolMgr*        myToolMgr;
+  LogoManager              myLogoMan;
 };
 
 #endif
index 37cbe5991467ee8f4965ae897d1569b511bd9081..bff9a465448ffb03425869dbcbefe049c25a18ae 100755 (executable)
@@ -11,7 +11,7 @@ public:
   SUIT_ResourceMgr( const QString&, const QString& = QString::null );
   virtual ~SUIT_ResourceMgr();
 
-  QString         version() const;
+  virtual QString version() const;
   void            setVersion( const QString& );
 
   QString         loadDoc( const QString&, const QString& ) const;