From: stv Date: Thu, 17 May 2007 13:08:39 +0000 (+0000) Subject: no message X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1c1b4d01ec2a8d341b60cb76628a03f7e1f7e3b3;p=modules%2Fgui.git no message --- diff --git a/src/Qtx/QtxLogoMgr.cxx b/src/Qtx/QtxLogoMgr.cxx index 2103eccae..cd2783d86 100644 --- a/src/Qtx/QtxLogoMgr.cxx +++ b/src/Qtx/QtxLogoMgr.cxx @@ -18,23 +18,130 @@ // #include "QtxLogoMgr.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include + +/*! + class: LogoBox [internal] +*/ + +class QtxLogoMgr::LogoBox : public QWidget +{ +public: + LogoBox( QMenuBar* ); + + QMenuBar* menuBar() const; + virtual bool eventFilter( QObject*, QEvent* ); + void setLabels( const QList& ); + +protected: + virtual void customEvent( QEvent* ); + +private: + void updateCorner(); + void updateContents(); + +private: + typedef QPointer WidgetPtr; + +private: + QMenuBar* myMB; + QList myLabels; + WidgetPtr myCornWid; +}; + +QtxLogoMgr::LogoBox::LogoBox( QMenuBar* mb ) +: QWidget( mb ), +myMB( mb ), +myCornWid( 0 ) +{ + myMB->installEventFilter( this ); + updateCorner(); +} + +QMenuBar* QtxLogoMgr::LogoBox::menuBar() const +{ + return myMB; +} + +bool QtxLogoMgr::LogoBox::eventFilter( QObject* o, QEvent* e ) +{ + if ( o != menuBar() ) + return false; + + if ( e->type() == QEvent::MenubarUpdated ) + updateCorner(); + + if ( e->type() == QEvent::ChildAdded || e->type() == QEvent::ChildRemoved ) + { + updateCorner(); + QApplication::postEvent( this, new QEvent( QEvent::User ) ); + } + + return false; +} + +void QtxLogoMgr::LogoBox::setLabels( const QList& labs ) +{ + for ( QList::iterator it = myLabels.begin(); it != myLabels.end(); ++it ) + { + if ( !labs.contains( *it ) ) + delete *it; + } + + myLabels = labs; + updateContents(); +} + +void QtxLogoMgr::LogoBox::customEvent( QEvent* ) +{ + updateCorner(); +} + +void QtxLogoMgr::LogoBox::updateCorner() +{ + if ( menuBar()->cornerWidget() == this ) + return; + + myCornWid = menuBar()->cornerWidget(); + myMB->setCornerWidget( this ); + updateContents(); +} + +void QtxLogoMgr::LogoBox::updateContents() +{ + if ( layout() ) + delete layout(); + + QHBoxLayout* base = new QHBoxLayout( this ); + base->setMargin( 0 ); + base->setSpacing( 3 ); + + if ( myCornWid ) + base->addWidget( myCornWid ); + + for ( QList::const_iterator it = myLabels.begin(); it != myLabels.end(); ++it ) + base->addWidget( *it ); + + QApplication::sendPostedEvents(); +} + +/*! + class: QtxLogoMgr [public] +*/ /*! Constructor */ QtxLogoMgr::QtxLogoMgr( QMenuBar* mb ) -: QObject( mb ), -myMenus( mb ), -myId( 0 ) +: QObject( mb ) { + myBox = new LogoBox( mb ); } /*! @@ -49,7 +156,7 @@ QtxLogoMgr::~QtxLogoMgr() */ QMenuBar* QtxLogoMgr::menuBar() const { - return myMenus; + return myBox->menuBar(); } /*! @@ -61,32 +168,63 @@ int QtxLogoMgr::count() const } /*! - Insert new logo to the menu bar area + Insert new logo pixmap to the menu bar area */ void QtxLogoMgr::insert( const QString& id, const QPixmap& pix, const int index ) { if ( pix.isNull() ) return; - LogoInfo* inf = 0; + LogoInfo& inf = insert( id, index ); + + inf.pix = pix; + + generate(); +} + +/*! + Insert new logo movie to the menu bar area +*/ +void QtxLogoMgr::insert( const QString& id, QMovie* movie, const int index ) +{ + if ( !movie ) + return; + + LogoInfo& inf = insert( id, index ); + + inf.mov = movie; + movie->setParent( this ); + movie->setCacheMode( QMovie::CacheAll ); + movie->jumpToFrame( 0 ); + + generate(); +} + +/*! + Insert new logo information structure into the logos list +*/ +QtxLogoMgr::LogoInfo& QtxLogoMgr::insert( const QString& id, const int index ) +{ + LogoInfo empty; + empty.id = id; + empty.mov = 0; int idx = find( id ); if ( idx < 0 ) { idx = index < (int)myLogos.count() ? index : -1; if ( idx < 0 ) - inf = &( *myLogos.append( LogoInfo() ) ); + { + myLogos.append( empty ); + idx = myLogos.count() - 1; + } else - inf = &( *myLogos.insert( myLogos.at( idx ), LogoInfo() ) ); + myLogos.insert( idx, empty ); } - else - inf = &( *myLogos.at( idx ) ); + LogoInfo& inf = myLogos[idx]; - inf->id = id; - inf->pix = pix; - - generate(); + return inf; } /*! @@ -98,7 +236,7 @@ void QtxLogoMgr::remove( const QString& id ) if ( idx < 0 ) return; - myLogos.remove( myLogos.at( idx ) ); + myLogos.removeAt( idx ); generate(); } @@ -113,75 +251,82 @@ void QtxLogoMgr::clear() } /*! - Inserts logo to menu bar + Start the animation for specified movie or for all movies if id is empty. */ -void QtxLogoMgr::generate() +void QtxLogoMgr::startAnimation( const QString& id ) { - if ( !menuBar() ) - return; - - if ( myId ) - menuBar()->removeItem( myId ); + QList movList; + movies( id, movList ); - myId = 0; + for ( QList::iterator it = movList.begin(); it != movList.end(); ++it ) + (*it)->start(); +} - if ( myLogos.isEmpty() ) - return; +/*! + Stop the animation for specified movie or for all movies if id is empty. +*/ +void QtxLogoMgr::stopAnimation( const QString& id ) +{ + QList movList; + movies( id, movList ); - class LogoBox : public QHBox - { - public: - LogoBox( QWidget* parent = 0, const char* name = 0, WFlags f = 0 ) : QHBox( parent, name, f ) {}; + for ( QList::iterator it = movList.begin(); it != movList.end(); ++it ) + (*it)->stop(); +} - void addSpacing( int spacing ) - { - QApplication::sendPostedEvents( this, QEvent::ChildInserted ); - ((QHBoxLayout*)layout())->addSpacing( spacing ); - } +/*! + Pause/Continue the animation for specified movie or for all movies if id is empty. +*/ +void QtxLogoMgr::pauseAnimation( const bool pause, const QString& id ) +{ + QList movList; + movies( id, movList ); - protected: - void drawContents( QPainter* p ) - { - if ( parentWidget()->inherits( "QMenuBar" ) ) - style().drawControl( QStyle::CE_MenuBarEmptyArea, p, this, contentsRect(), colorGroup() ); - else - QHBox::drawContents( p ); - } - }; + for ( QList::iterator it = movList.begin(); it != movList.end(); ++it ) + (*it)->setPaused( pause ); +} - LogoBox* cnt = new LogoBox( menuBar() ); - cnt->setSpacing( 3 ); +/*! + Inserts logo to menu bar +*/ +void QtxLogoMgr::generate() +{ + if ( !menuBar() ) + return; + QList labels; for ( LogoList::const_iterator it = myLogos.begin(); it != myLogos.end(); ++it ) { QPixmap pix = (*it).pix; - if ( !pix.mask() ) + QMovie* mov = (*it).mov; + if ( !pix.isNull() && !pix.mask() ) { - QImage img = pix.convertToImage(); QBitmap bm; - if ( img.hasAlphaBuffer() ) - bm = img.createAlphaMask(); + QImage img = pix.toImage(); + if ( img.hasAlphaChannel() ) + bm = QPixmap::fromImage( img.createAlphaMask() ); else - bm = img.createHeuristicMask(); + bm = QPixmap::fromImage( img.createHeuristicMask() ); pix.setMask( bm ); } - QLabel* logoLab = new QLabel( cnt ); - logoLab->setPixmap( (*it).pix ); + QLabel* logoLab = new QLabel( myBox ); + if ( mov ) + logoLab->setMovie( mov ); + else + { + logoLab->setPixmap( (*it).pix ); +// if ( !pix.mask().isNull() ) +// logoLab->setMask( pix.mask() ); + } + logoLab->setScaledContents( false ); - logoLab->setAlignment( QLabel::AlignCenter ); + logoLab->setAlignment( Qt::AlignCenter ); - if ( pix.mask() ) - logoLab->setMask( *pix.mask() ); + labels.append( logoLab ); } - 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 ) ); + myBox->setLabels( labels ); } /*! @@ -193,8 +338,22 @@ int QtxLogoMgr::find( const QString& id ) const int idx = -1; for ( uint i = 0; i < myLogos.count() && idx < 0; i++ ) { - if ( (*myLogos.at( i ) ).id == id ) + if ( myLogos.at( i ).id == id ) idx = i; } return idx; } + +/*! + \return list of movies according to specified id + \param id - logo id +*/ +void QtxLogoMgr::movies( const QString& id, QList& lst ) const +{ + lst.clear(); + for ( LogoList::const_iterator it = myLogos.begin(); it != myLogos.end(); ++it ) + { + if ( (*it).mov && ( id.isEmpty() || id == (*it).id ) ) + lst.append( (*it).mov ); + } +} diff --git a/src/Qtx/QtxLogoMgr.h b/src/Qtx/QtxLogoMgr.h index 7e0615c82..93e848ca8 100644 --- a/src/Qtx/QtxLogoMgr.h +++ b/src/Qtx/QtxLogoMgr.h @@ -23,8 +23,9 @@ class QMenuBar; -#include -#include +#include +#include +#include #ifdef WIN32 #pragma warning( disable : 4251 ) @@ -34,29 +35,37 @@ class QTX_EXPORT QtxLogoMgr : public QObject { Q_OBJECT + class LogoBox; + public: QtxLogoMgr( QMenuBar* ); virtual ~QtxLogoMgr(); int count() const; + void insert( const QString&, QMovie*, const int = -1 ); void insert( const QString&, const QPixmap&, const int = -1 ); void remove( const QString& ); void clear(); + void startAnimation( const QString& = QString() ); + void stopAnimation( const QString& = QString() ); + void pauseAnimation( const bool, const QString& = QString() ); + QMenuBar* menuBar() const; private: - void generate(); - int find( const QString& ) const; + typedef struct { QString id; QPixmap pix; QMovie* mov; } LogoInfo; + typedef QList LogoList; private: - typedef struct { QString id; QPixmap pix; } LogoInfo; - typedef QValueList LogoList; + void generate(); + int find( const QString& ) const; + LogoInfo& insert( const QString&, const int ); + void movies( const QString&, QList& ) const; private: - int myId; - QMenuBar* myMenus; + LogoBox* myBox; LogoList myLogos; }; diff --git a/src/SUIT/SUIT_Desktop.cxx b/src/SUIT/SUIT_Desktop.cxx index 11bb07b53..e16680033 100755 --- a/src/SUIT/SUIT_Desktop.cxx +++ b/src/SUIT/SUIT_Desktop.cxx @@ -20,7 +20,7 @@ #include "SUIT_ViewWindow.h" -//#include +#include #include #include @@ -53,7 +53,7 @@ SUIT_Desktop::SUIT_Desktop() { myMenuMgr = new QtxActionMenuMgr( this ); myToolMgr = new QtxActionToolMgr( this ); - myLogoMgr = 0;//new QtxLogoMgr( menuBar() ); + myLogoMgr = new QtxLogoMgr( menuBar() ); } /*! @@ -139,40 +139,52 @@ QtxActionToolMgr* SUIT_Desktop::toolMgr() const return myToolMgr; } +/*! + Gets logo manager. +*/ +QtxLogoMgr* SUIT_Desktop::logoMgr() const +{ + return myLogoMgr; +} + /*! Returns the count of the existed logos. */ int SUIT_Desktop::logoCount() const { return 0; -/* + if ( !myLogoMgr ) return 0; else return myLogoMgr->count(); -*/ } /*! Adds new logo to the menu bar area */ -void SUIT_Desktop::logoInsert( const QString& /*logoID*/, const QPixmap& /*logo*/, const int /*idx*/ ) +void SUIT_Desktop::logoInsert( const QString& logoID, QMovie* logo, const int idx ) { -/* if ( myLogoMgr ) myLogoMgr->insert( logoID, logo, idx ); +} + +/*! + Adds new logo to the menu bar area */ +void SUIT_Desktop::logoInsert( const QString& logoID, const QPixmap& logo, const int idx ) +{ + if ( myLogoMgr ) + myLogoMgr->insert( logoID, logo, idx ); } /*! Removes a logo */ -void SUIT_Desktop::logoRemove( const QString& /*logoID*/ ) +void SUIT_Desktop::logoRemove( const QString& logoID ) { -/* if ( myLogoMgr ) myLogoMgr->remove( logoID ); -*/ } /*! @@ -180,10 +192,8 @@ void SUIT_Desktop::logoRemove( const QString& /*logoID*/ ) */ void SUIT_Desktop::logoClear() { -/* if ( myLogoMgr ) myLogoMgr->clear(); -*/ } /*! diff --git a/src/SUIT/SUIT_Desktop.h b/src/SUIT/SUIT_Desktop.h index ba3b057e6..c38c38128 100755 --- a/src/SUIT/SUIT_Desktop.h +++ b/src/SUIT/SUIT_Desktop.h @@ -26,11 +26,14 @@ #include +class QMovie; + class QtxLogoMgr; -class SUIT_ViewWindow; class QtxActionMenuMgr; class QtxActionToolMgr; +class SUIT_ViewWindow; + /*! \class SUIT_Desktop Provides standard desktop: main window with @@ -50,6 +53,7 @@ public: QtxActionMenuMgr* menuMgr() const; QtxActionToolMgr* toolMgr() const; + QtxLogoMgr* logoMgr() const; virtual SUIT_ViewWindow* activeWindow() const = 0; virtual QList windows() const = 0; @@ -58,6 +62,7 @@ public: void logoClear(); void logoRemove( const QString& ); + void logoInsert( const QString&, QMovie*, const int = -1 ); void logoInsert( const QString&, const QPixmap&, const int = -1 ); void emitActivated();