1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 #include "QtxLogoMgr.h"
28 #include <qapplication.h>
33 QtxLogoMgr::QtxLogoMgr( QMenuBar* mb )
43 QtxLogoMgr::~QtxLogoMgr()
50 QMenuBar* QtxLogoMgr::menuBar() const
56 Returns the count of the existed logos.
58 int QtxLogoMgr::count() const
60 return myLogos.count();
64 Insert new logo to the menu bar area
66 void QtxLogoMgr::insert( const QString& id, const QPixmap& pix, const int index )
76 idx = index < (int)myLogos.count() ? index : -1;
78 inf = &( *myLogos.append( LogoInfo() ) );
80 inf = &( *myLogos.insert( myLogos.at( idx ), LogoInfo() ) );
83 inf = &( *myLogos.at( idx ) );
95 void QtxLogoMgr::remove( const QString& id )
101 myLogos.remove( myLogos.at( idx ) );
109 void QtxLogoMgr::clear()
116 Inserts logo to menu bar
118 void QtxLogoMgr::generate()
124 menuBar()->removeItem( myId );
128 if ( myLogos.isEmpty() )
131 class LogoBox : public QHBox
134 LogoBox( QWidget* parent = 0, const char* name = 0, WFlags f = 0 ) : QHBox( parent, name, f ) {};
136 void addSpacing( int spacing )
138 QApplication::sendPostedEvents( this, QEvent::ChildInserted );
139 ((QHBoxLayout*)layout())->addSpacing( spacing );
143 void drawContents( QPainter* p )
145 if ( parentWidget()->inherits( "QMenuBar" ) )
146 style().drawControl( QStyle::CE_MenuBarEmptyArea, p, this, contentsRect(), colorGroup() );
148 QHBox::drawContents( p );
152 LogoBox* cnt = new LogoBox( menuBar() );
153 cnt->setSpacing( 3 );
155 for ( LogoList::const_iterator it = myLogos.begin(); it != myLogos.end(); ++it )
157 QPixmap pix = (*it).pix;
160 QImage img = pix.convertToImage();
162 if ( img.hasAlphaBuffer() )
163 bm = img.createAlphaMask();
165 bm = img.createHeuristicMask();
169 QLabel* logoLab = new QLabel( cnt );
170 logoLab->setPixmap( (*it).pix );
171 logoLab->setScaledContents( false );
172 logoLab->setAlignment( QLabel::AlignCenter );
175 logoLab->setMask( *pix.mask() );
178 QApplication::sendPostedEvents( cnt, QEvent::ChildInserted );
179 cnt->addSpacing( 2 );
181 myId = menuBar()->insertItem( cnt );
183 QApplication::sendPostedEvents( menuBar()->parentWidget(), QEvent::LayoutHint );
184 QApplication::postEvent( menuBar()->parentWidget(), new QEvent( QEvent::LayoutHint ) );
188 \return index of found logo
191 int QtxLogoMgr::find( const QString& id ) const
194 for ( uint i = 0; i < myLogos.count() && idx < 0; i++ )
196 if ( (*myLogos.at( i ) ).id == id )