From 4cd0019dafda14d1f063e5d6f851316915a2b6db Mon Sep 17 00:00:00 2001 From: stv Date: Fri, 18 May 2007 05:53:29 +0000 Subject: [PATCH] *** empty log message *** --- src/Qtx/QtxLogoMgr.cxx | 433 +++++++++++++++++++++++++++++++++++++++ src/Qtx/QtxLogoMgr.h | 77 +++++++ src/Qtx/QtxMRUAction.cxx | 163 ++++++++------- 3 files changed, 595 insertions(+), 78 deletions(-) create mode 100644 src/Qtx/QtxLogoMgr.cxx create mode 100644 src/Qtx/QtxLogoMgr.h diff --git a/src/Qtx/QtxLogoMgr.cxx b/src/Qtx/QtxLogoMgr.cxx new file mode 100644 index 000000000..47a8d5628 --- /dev/null +++ b/src/Qtx/QtxLogoMgr.cxx @@ -0,0 +1,433 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#include "QtxLogoMgr.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +/*! + \class QtxLogoMgr::LogoBox + \internal + \brief Logo images container. +*/ + +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; //!< parent menu bar + QList myLabels; //!< list of labels containing logo images + WidgetPtr myCornWid; //!< corner widget +}; + +/*! + \brief Constructor. + \param mb menu bar +*/ +QtxLogoMgr::LogoBox::LogoBox( QMenuBar* mb ) +: QWidget( mb ), + myMB( mb ), + myCornWid( 0 ) +{ + myMB->installEventFilter( this ); + updateCorner(); +} + +/*! + \brief Get menu bar. + \return menu bar +*/ +QMenuBar* QtxLogoMgr::LogoBox::menuBar() const +{ + return myMB; +} + +/*! + \brief Custom event filter. + \param o event receiver object + \param e event sent to object + \return \c true if further event processing should be stopped +*/ +bool QtxLogoMgr::LogoBox::eventFilter( QObject* o, QEvent* e ) +{ + if ( o != menuBar() ) + return false; + + if ( e->type() == QEvent::MenubarUpdated || e->type() == QEvent::Resize ) + updateCorner(); + + if ( e->type() == QEvent::ChildAdded || e->type() == QEvent::ChildRemoved ) + { + updateCorner(); + QApplication::postEvent( this, new QEvent( QEvent::User ) ); + } + + return false; +} + +/*! + \brief Set label widgets (logo containers). + \param labs list of labels +*/ +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(); +} + +/*! + \brief Custom event processing (update logo widget). + \param e event (not used) +*/ +void QtxLogoMgr::LogoBox::customEvent( QEvent* /*e*/ ) +{ + updateCorner(); +} + +/*! + \brief Update menu bar's corner widget. +*/ +void QtxLogoMgr::LogoBox::updateCorner() +{ + if ( menuBar()->cornerWidget() == this ) + return; + + myCornWid = menuBar()->cornerWidget(); + myMB->setCornerWidget( this ); + updateContents(); +} + +/*! + \brief Update logo manager contents. +*/ +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 + \brief Provides a way to install logo pictures to the application main window. + + The class includes the following functionality: + - add the logo image + - remove logo image + - support static images and animated images (QMovie) + - start/stop and pause/resume the animated logos +*/ + +/*! + \brief Constructor. + \param mb parent menu bar +*/ +QtxLogoMgr::QtxLogoMgr( QMenuBar* mb ) +: QObject( mb ) +{ + myBox = new LogoBox( mb ); +} + +/*! + \brief Destructor. +*/ +QtxLogoMgr::~QtxLogoMgr() +{ +} + +/*! + \brief Get menu bar. + \return parent menu bar +*/ +QMenuBar* QtxLogoMgr::menuBar() const +{ + return myBox->menuBar(); +} + +/*! + \brief Get number of logo images. + \return current number of logo images +*/ +int QtxLogoMgr::count() const +{ + return myLogos.count(); +} + +/*! + \brief Insert new logo pixmap to the menu bar area. + \param id unique string identifier of the logo + \param pix logo pixmap + \param index logo position (if < 0, logo is added to the end) +*/ +void QtxLogoMgr::insert( const QString& id, const QPixmap& pix, const int index ) +{ + if ( pix.isNull() ) + return; + + LogoInfo& inf = insert( id, index ); + + inf.pix = pix; + + generate(); +} + +/*! + \brief Insert new animated logo to the menu bar area. + \param id unique string identifier of the logo + \param pix logo movie + \param index logo position (if < 0, logo is added to the end) +*/ +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(); +} + +/*! + \brief Insert new logo information structure into the logos list. + \param id unique string identifier of the logo + \param index logo position (if < 0, logo is added to the end) + \return logo information object +*/ +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 ) + { + myLogos.append( empty ); + idx = myLogos.count() - 1; + } + else + myLogos.insert( idx, empty ); + } + + LogoInfo& inf = myLogos[idx]; + + return inf; +} + +/*! + \brief Remove a logo. + \param id logo identifier +*/ +void QtxLogoMgr::remove( const QString& id ) +{ + int idx = find( id ); + if ( idx < 0 ) + return; + + myLogos.removeAt( idx ); + + generate(); +} + +/*! + \brief Removes all logos. +*/ +void QtxLogoMgr::clear() +{ + myLogos.clear(); + generate(); +} + +/*! + \brief Start the animation of movie logo. + + If \a id is empty, all movie logos animation are started. + + \param id logo identifier +*/ +void QtxLogoMgr::startAnimation( const QString& id ) +{ + QList movList; + movies( id, movList ); + + for ( QList::iterator it = movList.begin(); it != movList.end(); ++it ) + (*it)->start(); +} + +/*! + \brief Stop the animation of movie logo. + + If \a id is empty, all movie logos animation are stopped. + + \param id logo identifier +*/ +void QtxLogoMgr::stopAnimation( const QString& id ) +{ + QList movList; + movies( id, movList ); + + for ( QList::iterator it = movList.begin(); it != movList.end(); ++it ) + (*it)->stop(); +} + +/*! + \brief Pause/resume the animation of movie logo. + + If \a pause is \c true, the animation is paused; otherwise + it is resumed. + + If \a id is empty, the operation is performed for all movis logos. + + \param pause if \c true, pause animation, otherwise resume it + \param id logo identifier +*/ +void QtxLogoMgr::pauseAnimation( const bool pause, const QString& id ) +{ + QList movList; + movies( id, movList ); + + for ( QList::iterator it = movList.begin(); it != movList.end(); ++it ) + (*it)->setPaused( pause ); +} + +/*! + \brief Regenerate logo manager widget contents. + + Insert logo to menu bar if it not yet done, layout the widget. +*/ +void QtxLogoMgr::generate() +{ + if ( !menuBar() ) + return; + + QList labels; + for ( LogoList::const_iterator it = myLogos.begin(); it != myLogos.end(); ++it ) + { + QPixmap pix = (*it).pix; + QMovie* mov = (*it).mov; + if ( !pix.isNull() && !pix.mask() ) + { + QBitmap bm; + QImage img = pix.toImage(); + if ( img.hasAlphaChannel() ) + bm = QPixmap::fromImage( img.createAlphaMask() ); + else + bm = QPixmap::fromImage( img.createHeuristicMask() ); + pix.setMask( bm ); + } + + 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( Qt::AlignCenter ); + + labels.append( logoLab ); + } + + myBox->setLabels( labels ); +} + +/*! + \brief Search the logo by the specified \a id. + \param id logo identifier + \return index of logo or -1 if not found +*/ +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 ) + idx = i; + } + return idx; +} + +/*! + \brief Get movie logos by specified \a id. + + If \a id is empty, all movie logos are returned. + + \param id logo identifier + \param lst list of movies, which satisfy the \a 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 new file mode 100644 index 000000000..ff43fddaa --- /dev/null +++ b/src/Qtx/QtxLogoMgr.h @@ -0,0 +1,77 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#ifndef QTX_LOGOMGR_H +#define QTX_LOGOMGR_H + +#include "Qtx.h" + +#include +#include +#include + +class QMenuBar; +class QMovie; + +#ifdef WIN32 +#pragma warning( disable : 4251 ) +#endif + +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: + typedef struct { QString id; QPixmap pix; QMovie* mov; } LogoInfo; + typedef QList LogoList; + +private: + void generate(); + int find( const QString& ) const; + LogoInfo& insert( const QString&, const int ); + void movies( const QString&, QList& ) const; + +private: + LogoBox* myBox; + LogoList myLogos; +}; + +#ifdef WIN32 +#pragma warning( default : 4251 ) +#endif + +#endif diff --git a/src/Qtx/QtxMRUAction.cxx b/src/Qtx/QtxMRUAction.cxx index 9f8821243..6f1b81844 100755 --- a/src/Qtx/QtxMRUAction.cxx +++ b/src/Qtx/QtxMRUAction.cxx @@ -27,42 +27,45 @@ #include /*! - Name: QtxMRUAction [public] - Desc: Constructs an MRU action with given parent and name. + \class QtxMRUAction + \brief Menu action which provides most recent used items support. */ +/*! + \brief Constructor. + \param parent parent object +*/ QtxMRUAction::QtxMRUAction( QObject* parent ) : QtxAction( "Most Recently Used", "Most Recently Used", 0, parent ), -myVisCount( 5 ), -myInsertMode( MoveFirst ) + myVisCount( 5 ), + myInsertMode( MoveFirst ) { setMenu( new QMenu( 0 ) ); connect( menu(), SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); } /*! - Name: QtxMRUAction [public] - Desc: This constructor creates an action with the following properties: the - description text, the menu text and. It is a child of given parent and - named specified name. + \brief Constructor. + \param description (tooltip) text + \param menuText menu text + \param parent parent object */ - QtxMRUAction::QtxMRUAction( const QString& text, const QString& menuText, QObject* parent ) : QtxAction( text, menuText, 0, parent ), -myVisCount( 5 ), -myInsertMode( MoveFirst ) + myVisCount( 5 ), + myInsertMode( MoveFirst ) { setMenu( new QMenu( 0 ) ); connect( menu(), SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); } /*! - Name: QtxMRUAction [public] - Desc: This constructor creates an action with the following properties: the - description text, the menu text, the icon or iconset icon and keyboard - accelerator. It is a child of given parent and named specified name. + \brief Constructor. + \param description (tooltip) text + \param icon action icon + \param menuText menu text + \param parent parent object */ - QtxMRUAction::QtxMRUAction( const QString& text, const QIcon& icon, const QString& menuText, QObject* parent ) : QtxAction( text, icon, menuText, 0, parent ), @@ -74,75 +77,69 @@ myInsertMode( MoveFirst ) } /*! - Name: ~QtxMRUAction [public] - Desc: This destructor removes all added popup items. + \brief Destructor. */ - QtxMRUAction::~QtxMRUAction() { delete menu(); } /*! - Name: insertMode [public] - Desc: Returns the insert mode. + \brief Get items insertion policy. + \return insertion policy (QtxMRUAction::InsertionMode) */ - int QtxMRUAction::insertMode() const { return myInsertMode; } /*! - Name: setInsertMode [public] - Desc: Returns the insert mode. Can be following values: - MoveFirst - place the specified link to the first position in any case - MoveLast - place the specified link to the last position in any case - AddFirst - if inserted link doesn't exist then add to the first position - AddLast - if inserted link doesn't exist then add to the lase position + \brief Set items insertion policy. + \param mode insertion policy (QtxMRUAction::InsertionMode) */ - void QtxMRUAction::setInsertMode( const int mode ) { myInsertMode = mode; } /*! - Name: count [public] - Desc: Returns the number of links. + \brief Get number of MRU items. + \return number of MRU items */ - int QtxMRUAction::count() const { return myLinks.count(); } /*! - Name: isEmpty [public] - Desc: Returns 'true' if there is no links. + \brief Check if the MRU items list is empty. + \return \c true if there are no MRU items */ - bool QtxMRUAction::isEmpty() const { return myLinks.isEmpty(); } /*! - Name: visibleCount [public] - Desc: Returns the number of first links which will be added to popup menu. - If 'visibleCount' less than 1 then all links will be used. + \brief Get number of visible MRU items. + \return visible MRU items number + \sa setVisibleCount() */ - int QtxMRUAction::visibleCount() const { return myVisCount; } /*! - Name: setVisibleCount [public] - Desc: Sets the number of links which will be used in popup menu. -*/ + \brief Set number of visible MRU items. + + This method sets the maximum number of MRU items + to be displayed in the popup menu (5 by default). + If \a num < 1, then all MRU items will be displayed. + + \param num visible MRU items number +*/ void QtxMRUAction::setVisibleCount( int num ) { if ( myVisCount == num ) @@ -152,10 +149,12 @@ void QtxMRUAction::setVisibleCount( int num ) } /*! - Name: insert [public] - Desc: Insert the link according to the insert mode. -*/ + \brief Insert MRU item. + + The item is inserted according to the current insertion policy. + \param link MRU item to be added +*/ void QtxMRUAction::insert( const QString& link ) { if ( myLinks.contains( link ) && ( insertMode() == AddFirst || insertMode() == AddLast ) ) @@ -177,10 +176,12 @@ void QtxMRUAction::insert( const QString& link ) } /*! - Name: remove [public] - Desc: Removes link with specified index. -*/ + \brief Remove MRU item. + + Does nothing if \a idx is out of range. + \param idx MRU item index +*/ void QtxMRUAction::remove( const int idx ) { if ( idx < 0 || idx >= (int)myLinks.count() ) @@ -190,20 +191,22 @@ void QtxMRUAction::remove( const int idx ) } /*! - Name: remove [public] - Desc: Removes specified link. -*/ + \brief Remove MRU item. + Does nothing if there is no speicified item in the list. + + \param link MRU item to be removed +*/ void QtxMRUAction::remove( const QString& link ) { myLinks.removeAll( link ); } /*! - Name: item [public] - Desc: Returns the link with specified index. + \brief Get MRU item + \param idx MRU item index + \return MRU item or null QString if \a idx is out of range */ - QString QtxMRUAction::item( const int idx ) const { QString res; @@ -213,31 +216,31 @@ QString QtxMRUAction::item( const int idx ) const } /*! - Name: find [public] - Desc: Find specified link. If link exists then returns index otherwise -1 returned. + \brief Get MRU item index. + \param link MRU item + \return MRU item index or -1 if item is not found */ - int QtxMRUAction::find( const QString& link ) const { return myLinks.indexOf( link ); } /*! - Name: contains [public] - Desc: Returns 'true' if given link exist. + \brief Check if MRU item is in the list. + \param link MRU item + \return \c true if specified item is already added to the list */ - bool QtxMRUAction::contains( const QString& link ) const { return myLinks.contains( link ); } /*! - Name: loadLinks [public] - Desc: Load the MRU links from specified resource manager section. - If parameter 'clear' is 'true' then link list will be cleared first. + \brief Load the MRU items from specified resources section. + \param resMgr resources manager + \param section resources section + \param clear if \c true, previous MRU items list is cleared */ - void QtxMRUAction::loadLinks( QtxResourceMgr* resMgr, const QString& section, const bool clear ) { if ( !resMgr || section.isEmpty() ) @@ -268,11 +271,11 @@ void QtxMRUAction::loadLinks( QtxResourceMgr* resMgr, const QString& section, co } /*! - Name: saveLinks [public] - Desc: Save the MRU links into specified resource manager section. - If parameter 'clear' is 'true' then section will be cleared first. + \brief Save the MRU items to specified resources section. + \param resMgr resources manager + \param section resources section + \param clear if \c true, the resources section is first cleared */ - void QtxMRUAction::saveLinks( QtxResourceMgr* resMgr, const QString& section, const bool clear ) const { if ( !resMgr || section.isEmpty() ) @@ -312,21 +315,21 @@ void QtxMRUAction::saveLinks( QtxResourceMgr* resMgr, const QString& section, co } /*! - Name: onAboutToShow [private slots] - Desc: Enable or disable sub menu item according to number of MRU links - in sub popup when parent popup is shown. + \brief Prepare MRU items popup menu. + + This method is called when the parent menu is shown. + Enables or disables sub menu item according to the number of MRU items. */ - void QtxMRUAction::onAboutToShow() { updateMenu(); } /*! - Name: onActivated [private slot] - Desc: Process popup item activation and emit signal activated with selected MRU link. -*/ + \brief Called when any MRU item is selected by the user. + Emits signal activated(const QString&) passing selected MRU item as parameter. +*/ void QtxMRUAction::onActivated() { QAction* a = ::qobject_cast( sender() ); @@ -339,10 +342,8 @@ void QtxMRUAction::onActivated() } /*! - Name: updateMenu [private] - Desc: Updates the popup menu which contains MRU link items. + \brief Update MRU items popup menu. */ - void QtxMRUAction::updateMenu() { QMenu* pm = menu(); @@ -355,3 +356,9 @@ void QtxMRUAction::updateMenu() for ( QStringList::const_iterator it = myLinks.begin(); it != myLinks.end() && count > 0; ++it, count-- ) pm->addAction( *it, this, SLOT( onActivated() ) ); } + +/*! + \fn void QtxMRUAction::activated( const QString& link ); + \brief Emitted when user selects any MRU item in the menu. + \param link selected MRU item +*/ -- 2.39.2