1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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
23 // File: QtxLogoMgr.cxx
24 // Author: Sergey TELKOV
26 #include "QtxLogoMgr.h"
31 #include <QHBoxLayout>
34 #include <QApplication>
38 \class QtxLogoMgr::LogoBox
40 \brief Logo images container.
43 class QtxLogoMgr::LogoBox : public QWidget
48 QMenuBar* menuBar() const;
49 virtual bool eventFilter( QObject*, QEvent* );
50 void setLabels( const QList<QLabel*>& );
53 virtual void customEvent( QEvent* );
57 void updateContents();
60 typedef QPointer<QWidget> WidgetPtr;
63 QMenuBar* myMB; //!< parent menu bar
64 QList<QLabel*> myLabels; //!< list of labels containing logo images
65 WidgetPtr myCornWid; //!< corner widget
72 QtxLogoMgr::LogoBox::LogoBox( QMenuBar* mb )
77 myMB->installEventFilter( this );
85 QMenuBar* QtxLogoMgr::LogoBox::menuBar() const
91 \brief Custom event filter.
92 \param o event receiver object
93 \param e event sent to object
94 \return \c true if further event processing should be stopped
96 bool QtxLogoMgr::LogoBox::eventFilter( QObject* o, QEvent* e )
101 if ( e->type() == QEvent::MenubarUpdated || e->type() == QEvent::Resize )
104 if ( e->type() == QEvent::ChildAdded || e->type() == QEvent::ChildRemoved )
107 QApplication::postEvent( this, new QEvent( QEvent::User ) );
114 \brief Set label widgets (logo containers).
115 \param labs list of labels
117 void QtxLogoMgr::LogoBox::setLabels( const QList<QLabel*>& labs )
119 for ( QList<QLabel*>::iterator it = myLabels.begin(); it != myLabels.end(); ++it )
121 if ( !labs.contains( *it ) )
130 \brief Custom event processing (update logo widget).
131 \param e event (not used)
133 void QtxLogoMgr::LogoBox::customEvent( QEvent* /*e*/ )
139 \brief Update menu bar's corner widget.
141 void QtxLogoMgr::LogoBox::updateCorner()
143 if ( menuBar()->cornerWidget() == this )
146 myCornWid = menuBar()->cornerWidget();
147 myMB->setCornerWidget( this );
152 \brief Update logo manager contents.
154 void QtxLogoMgr::LogoBox::updateContents()
159 QHBoxLayout* base = new QHBoxLayout( this );
160 base->setMargin( 0 );
161 base->setSpacing( 3 );
163 for ( QList<QLabel*>::const_iterator it = myLabels.begin(); it != myLabels.end(); ++it )
164 base->addWidget( *it );
167 base->addWidget( myCornWid );
169 QApplication::sendPostedEvents();
174 \brief Provides a way to install logo pictures to the application main window.
176 The class includes the following functionality:
179 - support static images and animated images (QMovie)
180 - start/stop and pause/resume the animated logos
185 \param mb parent menu bar
187 QtxLogoMgr::QtxLogoMgr( QMenuBar* mb )
190 myBox = new LogoBox( mb );
196 QtxLogoMgr::~QtxLogoMgr()
202 \return parent menu bar
204 QMenuBar* QtxLogoMgr::menuBar() const
206 return myBox->menuBar();
210 \brief Get number of logo images.
211 \return current number of logo images
213 int QtxLogoMgr::count() const
215 return myLogos.count();
219 \brief Insert new logo pixmap to the menu bar area.
220 \param id unique string identifier of the logo
221 \param pix logo pixmap
222 \param index logo position (if < 0, logo is added to the end)
224 void QtxLogoMgr::insert( const QString& id, const QPixmap& pix, const int index )
229 LogoInfo& inf = insert( id, index );
237 \brief Insert new animated logo to the menu bar area.
238 \param id unique string identifier of the logo
239 \param pix logo movie
240 \param index logo position (if < 0, logo is added to the end)
242 void QtxLogoMgr::insert( const QString& id, QMovie* movie, const int index )
247 LogoInfo& inf = insert( id, index );
250 movie->setParent( this );
251 movie->setCacheMode( QMovie::CacheAll );
252 movie->jumpToFrame( 0 );
258 \brief Insert new logo information structure into the logos list.
259 \param id unique string identifier of the logo
260 \param index logo position (if < 0, logo is added to the end)
261 \return logo information object
263 QtxLogoMgr::LogoInfo& QtxLogoMgr::insert( const QString& id, const int index )
269 int idx = find( id );
272 idx = index < (int)myLogos.count() ? index : -1;
275 myLogos.append( empty );
276 idx = myLogos.count() - 1;
279 myLogos.insert( idx, empty );
282 LogoInfo& inf = myLogos[idx];
288 \brief Remove a logo.
289 \param id logo identifier
291 void QtxLogoMgr::remove( const QString& id )
293 int idx = find( id );
297 myLogos.removeAt( idx );
303 \brief Removes all logos.
305 void QtxLogoMgr::clear()
312 \brief Start the animation of movie logo.
314 If \a id is empty, all movie logos animation are started.
316 \param id logo identifier
318 void QtxLogoMgr::startAnimation( const QString& id )
320 QList<QMovie*> movList;
321 movies( id, movList );
323 for ( QList<QMovie*>::iterator it = movList.begin(); it != movList.end(); ++it )
328 \brief Stop the animation of movie logo.
330 If \a id is empty, all movie logos animation are stopped.
332 \param id logo identifier
334 void QtxLogoMgr::stopAnimation( const QString& id )
336 QList<QMovie*> movList;
337 movies( id, movList );
339 for ( QList<QMovie*>::iterator it = movList.begin(); it != movList.end(); ++it )
344 \brief Pause/resume the animation of movie logo.
346 If \a pause is \c true, the animation is paused; otherwise
349 If \a id is empty, the operation is performed for all movis logos.
351 \param pause if \c true, pause animation, otherwise resume it
352 \param id logo identifier
354 void QtxLogoMgr::pauseAnimation( const bool pause, const QString& id )
356 QList<QMovie*> movList;
357 movies( id, movList );
359 for ( QList<QMovie*>::iterator it = movList.begin(); it != movList.end(); ++it )
360 (*it)->setPaused( pause );
364 \brief Regenerate logo manager widget contents.
366 Insert logo to menu bar if it not yet done, layout the widget.
368 void QtxLogoMgr::generate()
373 QList<QLabel*> labels;
374 for ( LogoList::const_iterator it = myLogos.begin(); it != myLogos.end(); ++it )
376 QPixmap pix = (*it).pix;
377 QMovie* mov = (*it).mov;
378 if ( !pix.isNull() && !pix.mask() )
381 QImage img = pix.toImage();
382 if ( img.hasAlphaChannel() )
383 bm = QPixmap::fromImage( img.createAlphaMask() );
385 bm = QPixmap::fromImage( img.createHeuristicMask() );
389 QLabel* logoLab = new QLabel( myBox );
391 logoLab->setMovie( mov );
394 logoLab->setPixmap( (*it).pix );
395 // if ( !pix.mask().isNull() )
396 // logoLab->setMask( pix.mask() );
399 logoLab->setScaledContents( false );
400 logoLab->setAlignment( Qt::AlignCenter );
402 labels.append( logoLab );
405 myBox->setLabels( labels );
409 \brief Search the logo by the specified \a id.
410 \param id logo identifier
411 \return index of logo or -1 if not found
413 int QtxLogoMgr::find( const QString& id ) const
416 for ( int i = 0; i < myLogos.count() && idx < 0; i++ )
418 if ( myLogos.at( i ).id == id )
425 \brief Get movie logos by specified \a id.
427 If \a id is empty, all movie logos are returned.
429 \param id logo identifier
430 \param lst list of movies, which satisfy the \a id
432 void QtxLogoMgr::movies( const QString& id, QList<QMovie*>& lst ) const
435 for ( LogoList::const_iterator it = myLogos.begin(); it != myLogos.end(); ++it )
437 if ( (*it).mov && ( id.isEmpty() || id == (*it).id ) )
438 lst.append( (*it).mov );