From 92d97413fe179696a11a1a6fff7306d4d913b30f Mon Sep 17 00:00:00 2001 From: stv Date: Thu, 24 Nov 2005 10:08:05 +0000 Subject: [PATCH] New class added and used: QtxLogoMgr --- src/SUIT/SUIT_Desktop.cxx | 174 +------------------------------------- src/SUIT/SUIT_Desktop.h | 5 +- 2 files changed, 4 insertions(+), 175 deletions(-) diff --git a/src/SUIT/SUIT_Desktop.cxx b/src/SUIT/SUIT_Desktop.cxx index 3d41900db..f40ba81b8 100755 --- a/src/SUIT/SUIT_Desktop.cxx +++ b/src/SUIT/SUIT_Desktop.cxx @@ -3,179 +3,10 @@ #include "SUIT_Tools.h" #include "SUIT_ViewWindow.h" +#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include - -/*! - Class: SUIT_Desktop::LogoMgr - Level: Internal -*/ - -class SUIT_Desktop::LogoMgr : public QObject -{ -public: - LogoMgr( QMenuBar* ); - virtual ~LogoMgr(); - - 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 LogoList; - -private: - int myId; - QMenuBar* myMenus; - LogoList myLogos; -}; - -SUIT_Desktop::LogoMgr::LogoMgr( QMenuBar* mb ) -: QObject( mb ), -myMenus( mb ), -myId( 0 ) -{ -} - -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 ( pix.isNull() ) - return; - - 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::LogoMgr::remove( const QString& id ) -{ - int idx = find( id ); - if ( idx < 0 ) - return; - - myLogos.remove( myLogos.at( idx ) ); - - generate(); -} - -void SUIT_Desktop::LogoMgr::clear() -{ - myLogos.clear(); - generate(); -} - -void SUIT_Desktop::LogoMgr::generate() -{ - if ( !menuBar() ) - return; - - if ( myId ) - menuBar()->removeItem( myId ); - - myId = 0; - - if ( myLogos.isEmpty() ) - return; - - 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).pix ); - logoLab->setScaledContents( false ); - logoLab->setAlignment( QLabel::AlignCenter ); - } - QApplication::sendPostedEvents( cnt, QEvent::ChildInserted ); - cnt->addSpacing( 2 ); - - 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 * \li menu manager @@ -183,7 +14,6 @@ int SUIT_Desktop::LogoMgr::find( const QString& id ) const * \li windows */ - /*! Constructor. */ @@ -192,7 +22,7 @@ SUIT_Desktop::SUIT_Desktop() { myMenuMgr = new QtxActionMenuMgr( this ); myToolMgr = new QtxActionToolMgr( this ); - myLogoMgr = new LogoMgr( menuBar() ); + myLogoMgr = new QtxLogoMgr( menuBar() ); } /*! diff --git a/src/SUIT/SUIT_Desktop.h b/src/SUIT/SUIT_Desktop.h index 52d64c4c9..9d79964c9 100755 --- a/src/SUIT/SUIT_Desktop.h +++ b/src/SUIT/SUIT_Desktop.h @@ -8,6 +8,7 @@ #include class QPopupMenu; +class QtxLogoMgr; class SUIT_ViewWindow; class QtxActionMenuMgr; class QtxActionToolMgr; @@ -16,8 +17,6 @@ class SUIT_EXPORT SUIT_Desktop : public QtxMainWindow { Q_OBJECT - class LogoMgr; - public: SUIT_Desktop(); virtual ~SUIT_Desktop(); @@ -53,7 +52,7 @@ protected: private: QtxActionMenuMgr* myMenuMgr; QtxActionToolMgr* myToolMgr; - LogoMgr* myLogoMgr; + QtxLogoMgr* myLogoMgr; }; #endif -- 2.39.2