From 4d148645d284599ffb89aca9313b3a5878570e33 Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 13 Sep 2005 10:14:44 +0000 Subject: [PATCH] Provide logo support for SALOME desktop --- src/SUIT/SUIT_Desktop.cxx | 120 +++++++++++++++++++++++++++++++++++- src/SUIT/SUIT_Desktop.h | 23 +++++++ src/SUIT/SUIT_ResourceMgr.h | 2 +- 3 files changed, 143 insertions(+), 2 deletions(-) diff --git a/src/SUIT/SUIT_Desktop.cxx b/src/SUIT/SUIT_Desktop.cxx index 4ff86a88d..567f23dd1 100755 --- a/src/SUIT/SUIT_Desktop.cxx +++ b/src/SUIT/SUIT_Desktop.cxx @@ -11,6 +11,97 @@ #include #include #include +#include +#include +#include + +/*! + 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::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 @@ -19,11 +110,12 @@ * \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(); +} + + diff --git a/src/SUIT/SUIT_Desktop.h b/src/SUIT/SUIT_Desktop.h index 9cc13b94a..761008ed4 100755 --- a/src/SUIT/SUIT_Desktop.h +++ b/src/SUIT/SUIT_Desktop.h @@ -3,6 +3,7 @@ #include "SUIT.h" +#include #include 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 myLogoMap; + int myId; + }; + public: SUIT_Desktop(); virtual ~SUIT_Desktop(); @@ -24,6 +42,10 @@ public: virtual SUIT_ViewWindow* activeWindow() const = 0; virtual QPtrList 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 diff --git a/src/SUIT/SUIT_ResourceMgr.h b/src/SUIT/SUIT_ResourceMgr.h index 37cbe5991..bff9a4654 100755 --- a/src/SUIT/SUIT_ResourceMgr.h +++ b/src/SUIT/SUIT_ResourceMgr.h @@ -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; -- 2.39.2