1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: QtxLogoMgr.cxx
23 // Author: Sergey TELKOV
25 #include "QtxLogoMgr.h"
30 #include <QHBoxLayout>
33 #include <QApplication>
37 \class QtxLogoMgr::LogoBox
39 \brief Logo images container.
42 class QtxLogoMgr::LogoBox : public QWidget
47 QMenuBar* menuBar() const;
48 virtual bool eventFilter( QObject*, QEvent* );
49 void setLabels( const QList<QLabel*>& );
52 virtual void customEvent( QEvent* );
56 void updateContents();
59 typedef QPointer<QWidget> WidgetPtr;
62 QMenuBar* myMB; //!< parent menu bar
63 QList<QLabel*> myLabels; //!< list of labels containing logo images
64 WidgetPtr myCornWid; //!< corner widget
71 QtxLogoMgr::LogoBox::LogoBox( QMenuBar* mb )
76 myMB->installEventFilter( this );
84 QMenuBar* QtxLogoMgr::LogoBox::menuBar() const
90 \brief Custom event filter.
91 \param o event receiver object
92 \param e event sent to object
93 \return \c true if further event processing should be stopped
95 bool QtxLogoMgr::LogoBox::eventFilter( QObject* o, QEvent* e )
100 if ( e->type() == QEvent::MenubarUpdated || e->type() == QEvent::Resize )
103 if ( e->type() == QEvent::ChildAdded || e->type() == QEvent::ChildRemoved )
106 QApplication::postEvent( this, new QEvent( QEvent::User ) );
113 \brief Set label widgets (logo containers).
114 \param labs list of labels
116 void QtxLogoMgr::LogoBox::setLabels( const QList<QLabel*>& labs )
118 for ( QList<QLabel*>::iterator it = myLabels.begin(); it != myLabels.end(); ++it )
120 if ( !labs.contains( *it ) )
129 \brief Custom event processing (update logo widget).
130 \param e event (not used)
132 void QtxLogoMgr::LogoBox::customEvent( QEvent* /*e*/ )
138 \brief Update menu bar's corner widget.
140 void QtxLogoMgr::LogoBox::updateCorner()
142 if ( menuBar()->cornerWidget() == this )
145 myCornWid = menuBar()->cornerWidget();
146 myMB->setCornerWidget( this );
151 \brief Update logo manager contents.
153 void QtxLogoMgr::LogoBox::updateContents()
158 QHBoxLayout* base = new QHBoxLayout( this );
159 base->setMargin( 0 );
160 base->setSpacing( 3 );
162 for ( QList<QLabel*>::const_iterator it = myLabels.begin(); it != myLabels.end(); ++it )
163 base->addWidget( *it );
166 base->addWidget( myCornWid );
168 QApplication::sendPostedEvents();
173 \brief Provides a way to install logo pictures to the application main window.
175 The class includes the following functionality:
178 - support static images and animated images (QMovie)
179 - start/stop and pause/resume the animated logos
184 \param mb parent menu bar
186 QtxLogoMgr::QtxLogoMgr( QMenuBar* mb )
189 myBox = new LogoBox( mb );
195 QtxLogoMgr::~QtxLogoMgr()
201 \return parent menu bar
203 QMenuBar* QtxLogoMgr::menuBar() const
205 return myBox->menuBar();
209 \brief Get number of logo images.
210 \return current number of logo images
212 int QtxLogoMgr::count() const
214 return myLogos.count();
218 \brief Insert new logo pixmap to the menu bar area.
219 \param id unique string identifier of the logo
220 \param pix logo pixmap
221 \param index logo position (if < 0, logo is added to the end)
223 void QtxLogoMgr::insert( const QString& id, const QPixmap& pix, const int index )
228 LogoInfo& inf = insert( id, index );
236 \brief Insert new animated logo to the menu bar area.
237 \param id unique string identifier of the logo
238 \param pix logo movie
239 \param index logo position (if < 0, logo is added to the end)
241 void QtxLogoMgr::insert( const QString& id, QMovie* movie, const int index )
246 LogoInfo& inf = insert( id, index );
249 movie->setParent( this );
250 movie->setCacheMode( QMovie::CacheAll );
251 movie->jumpToFrame( 0 );
257 \brief Insert new logo information structure into the logos list.
258 \param id unique string identifier of the logo
259 \param index logo position (if < 0, logo is added to the end)
260 \return logo information object
262 QtxLogoMgr::LogoInfo& QtxLogoMgr::insert( const QString& id, const int index )
268 int idx = find( id );
271 idx = index < (int)myLogos.count() ? index : -1;
274 myLogos.append( empty );
275 idx = myLogos.count() - 1;
278 myLogos.insert( idx, empty );
281 LogoInfo& inf = myLogos[idx];
287 \brief Remove a logo.
288 \param id logo identifier
290 void QtxLogoMgr::remove( const QString& id )
292 int idx = find( id );
296 myLogos.removeAt( idx );
302 \brief Removes all logos.
304 void QtxLogoMgr::clear()
311 \brief Start the animation of movie logo.
313 If \a id is empty, all movie logos animation are started.
315 \param id logo identifier
317 void QtxLogoMgr::startAnimation( const QString& id )
319 QList<QMovie*> movList;
320 movies( id, movList );
322 for ( QList<QMovie*>::iterator it = movList.begin(); it != movList.end(); ++it )
327 \brief Stop the animation of movie logo.
329 If \a id is empty, all movie logos animation are stopped.
331 \param id logo identifier
333 void QtxLogoMgr::stopAnimation( const QString& id )
335 QList<QMovie*> movList;
336 movies( id, movList );
338 for ( QList<QMovie*>::iterator it = movList.begin(); it != movList.end(); ++it )
343 \brief Pause/resume the animation of movie logo.
345 If \a pause is \c true, the animation is paused; otherwise
348 If \a id is empty, the operation is performed for all movis logos.
350 \param pause if \c true, pause animation, otherwise resume it
351 \param id logo identifier
353 void QtxLogoMgr::pauseAnimation( const bool pause, const QString& id )
355 QList<QMovie*> movList;
356 movies( id, movList );
358 for ( QList<QMovie*>::iterator it = movList.begin(); it != movList.end(); ++it )
359 (*it)->setPaused( pause );
363 \brief Regenerate logo manager widget contents.
365 Insert logo to menu bar if it not yet done, layout the widget.
367 void QtxLogoMgr::generate()
372 QList<QLabel*> labels;
373 for ( LogoList::const_iterator it = myLogos.begin(); it != myLogos.end(); ++it )
375 QPixmap pix = (*it).pix;
376 QMovie* mov = (*it).mov;
377 if ( !pix.isNull() && !pix.mask() )
380 QImage img = pix.toImage();
381 if ( img.hasAlphaChannel() )
382 bm = QPixmap::fromImage( img.createAlphaMask() );
384 bm = QPixmap::fromImage( img.createHeuristicMask() );
388 QLabel* logoLab = new QLabel( myBox );
390 logoLab->setMovie( mov );
393 logoLab->setPixmap( (*it).pix );
394 // if ( !pix.mask().isNull() )
395 // logoLab->setMask( pix.mask() );
398 logoLab->setScaledContents( false );
399 logoLab->setAlignment( Qt::AlignCenter );
401 labels.append( logoLab );
404 myBox->setLabels( labels );
408 \brief Search the logo by the specified \a id.
409 \param id logo identifier
410 \return index of logo or -1 if not found
412 int QtxLogoMgr::find( const QString& id ) const
415 for ( int i = 0; i < myLogos.count() && idx < 0; i++ )
417 if ( myLogos.at( i ).id == id )
424 \brief Get movie logos by specified \a id.
426 If \a id is empty, all movie logos are returned.
428 \param id logo identifier
429 \param lst list of movies, which satisfy the \a id
431 void QtxLogoMgr::movies( const QString& id, QList<QMovie*>& lst ) const
434 for ( LogoList::const_iterator it = myLogos.begin(); it != myLogos.end(); ++it )
436 if ( (*it).mov && ( id.isEmpty() || id == (*it).id ) )
437 lst.append( (*it).mov );