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>
30 QtxLogoMgr::QtxLogoMgr( QMenuBar* mb )
37 QtxLogoMgr::~QtxLogoMgr()
44 QMenuBar* QtxLogoMgr::menuBar() const
50 Returns the count of the existed logos.
52 int QtxLogoMgr::count() const
54 return myLogos.count();
58 Insert new logo to the menu bar area
60 void QtxLogoMgr::insert( const QString& id, const QPixmap& pix, const int index )
70 idx = index < (int)myLogos.count() ? index : -1;
72 inf = &( *myLogos.append( LogoInfo() ) );
74 inf = &( *myLogos.insert( myLogos.at( idx ), LogoInfo() ) );
77 inf = &( *myLogos.at( idx ) );
89 void QtxLogoMgr::remove( const QString& id )
95 myLogos.remove( myLogos.at( idx ) );
103 void QtxLogoMgr::clear()
109 void QtxLogoMgr::generate()
115 menuBar()->removeItem( myId );
119 if ( myLogos.isEmpty() )
122 class LogoBox : public QHBox
125 LogoBox( QWidget* parent = 0, const char* name = 0, WFlags f = 0 ) : QHBox( parent, name, f ) {};
127 void addSpacing( int spacing )
129 QApplication::sendPostedEvents( this, QEvent::ChildInserted );
130 ((QHBoxLayout*)layout())->addSpacing( spacing );
134 void drawContents( QPainter* p )
136 if ( parentWidget()->inherits( "QMenuBar" ) )
137 style().drawControl( QStyle::CE_MenuBarEmptyArea, p, this, contentsRect(), colorGroup() );
139 QHBox::drawContents( p );
143 LogoBox* cnt = new LogoBox( menuBar() );
144 cnt->setSpacing( 3 );
146 for ( LogoList::const_iterator it = myLogos.begin(); it != myLogos.end(); ++it )
148 QPixmap pix = (*it).pix;
151 QImage img = pix.convertToImage();
153 if ( img.hasAlphaBuffer() )
154 bm = img.createAlphaMask();
156 bm = img.createHeuristicMask();
160 QLabel* logoLab = new QLabel( cnt );
161 logoLab->setPixmap( (*it).pix );
162 logoLab->setScaledContents( false );
163 logoLab->setAlignment( QLabel::AlignCenter );
166 logoLab->setMask( *pix.mask() );
169 QApplication::sendPostedEvents( cnt, QEvent::ChildInserted );
170 cnt->addSpacing( 2 );
172 myId = menuBar()->insertItem( cnt );
174 QApplication::sendPostedEvents( menuBar()->parentWidget(), QEvent::LayoutHint );
175 QApplication::postEvent( menuBar()->parentWidget(), new QEvent( QEvent::LayoutHint ) );
178 int QtxLogoMgr::find( const QString& id ) const
181 for ( uint i = 0; i < myLogos.count() && idx < 0; i++ )
183 if ( (*myLogos.at( i ) ).id == id )