1 #include "QtxLogoMgr.h"
10 #include <qapplication.h>
12 QtxLogoMgr::QtxLogoMgr( QMenuBar* mb )
19 QtxLogoMgr::~QtxLogoMgr()
26 QMenuBar* QtxLogoMgr::menuBar() const
32 Returns the count of the existed logos.
34 int QtxLogoMgr::count() const
36 return myLogos.count();
40 Insert new logo to the menu bar area
42 void QtxLogoMgr::insert( const QString& id, const QPixmap& pix, const int index )
52 idx = index < (int)myLogos.count() ? index : -1;
54 inf = &( *myLogos.append( LogoInfo() ) );
56 inf = &( *myLogos.insert( myLogos.at( idx ), LogoInfo() ) );
59 inf = &( *myLogos.at( idx ) );
71 void QtxLogoMgr::remove( const QString& id )
77 myLogos.remove( myLogos.at( idx ) );
85 void QtxLogoMgr::clear()
91 void QtxLogoMgr::generate()
97 menuBar()->removeItem( myId );
101 if ( myLogos.isEmpty() )
104 class LogoBox : public QHBox
107 LogoBox( QWidget* parent = 0, const char* name = 0, WFlags f = 0 ) : QHBox( parent, name, f ) {};
109 void addSpacing( int spacing )
111 QApplication::sendPostedEvents( this, QEvent::ChildInserted );
112 ((QHBoxLayout*)layout())->addSpacing( spacing );
116 void drawContents( QPainter* p )
118 if ( parentWidget()->inherits( "QMenuBar" ) )
119 style().drawControl( QStyle::CE_MenuBarEmptyArea, p, this, contentsRect(), colorGroup() );
121 QHBox::drawContents( p );
125 LogoBox* cnt = new LogoBox( menuBar() );
126 cnt->setSpacing( 3 );
128 for ( LogoList::const_iterator it = myLogos.begin(); it != myLogos.end(); ++it )
130 QPixmap pix = (*it).pix;
133 QImage img = pix.convertToImage();
135 if ( img.hasAlphaBuffer() )
136 bm = img.createAlphaMask();
138 bm = img.createHeuristicMask();
142 QLabel* logoLab = new QLabel( cnt );
143 logoLab->setPixmap( (*it).pix );
144 logoLab->setScaledContents( false );
145 logoLab->setAlignment( QLabel::AlignCenter );
148 logoLab->setMask( *pix.mask() );
151 QApplication::sendPostedEvents( cnt, QEvent::ChildInserted );
152 cnt->addSpacing( 2 );
154 myId = menuBar()->insertItem( cnt );
156 QApplication::sendPostedEvents( menuBar()->parentWidget(), QEvent::LayoutHint );
157 QApplication::postEvent( menuBar()->parentWidget(), new QEvent( QEvent::LayoutHint ) );
160 int QtxLogoMgr::find( const QString& id ) const
163 for ( uint i = 0; i < myLogos.count() && idx < 0; i++ )
165 if ( (*myLogos.at( i ) ).id == id )