1 #include "SUIT_Desktop.h"
3 #include "SUIT_Tools.h"
4 #include "SUIT_ViewWindow.h"
6 #include <QtxActionMenuMgr.h>
7 #include <QtxActionToolMgr.h>
11 #include <qdockarea.h>
12 #include <qstatusbar.h>
13 #include <qapplication.h>
19 Class: SUIT_Desktop::LogoMgr
23 class SUIT_Desktop::LogoMgr : public QObject
31 void insert( const QString&, const QPixmap&, const int = -1 );
32 void remove( const QString& );
35 QMenuBar* menuBar() const;
39 int find( const QString& ) const;
42 typedef struct { QString id; QPixmap pix; } LogoInfo;
43 typedef QValueList<LogoInfo> LogoList;
51 SUIT_Desktop::LogoMgr::LogoMgr( QMenuBar* mb )
58 SUIT_Desktop::LogoMgr::~LogoMgr()
62 QMenuBar* SUIT_Desktop::LogoMgr::menuBar() const
67 int SUIT_Desktop::LogoMgr::count() const
69 return myLogos.count();
72 void SUIT_Desktop::LogoMgr::insert( const QString& id, const QPixmap& pix, const int index )
82 idx = index < (int)myLogos.count() ? index : -1;
84 inf = &( *myLogos.append( LogoInfo() ) );
86 inf = &( *myLogos.insert( myLogos.at( idx ), LogoInfo() ) );
89 inf = &( *myLogos.at( idx ) );
98 void SUIT_Desktop::LogoMgr::remove( const QString& id )
100 int idx = find( id );
104 myLogos.remove( myLogos.at( idx ) );
109 void SUIT_Desktop::LogoMgr::clear()
115 void SUIT_Desktop::LogoMgr::generate()
121 menuBar()->removeItem( myId );
125 if ( myLogos.isEmpty() )
128 class LogoBox : public QHBox
131 LogoBox( QWidget* parent = 0, const char* name = 0, WFlags f = 0 ) : QHBox( parent, name, f ) {};
133 void addSpacing( int spacing )
135 QApplication::sendPostedEvents( this, QEvent::ChildInserted );
136 ((QHBoxLayout*)layout())->addSpacing( spacing );
140 void drawContents( QPainter* p )
142 if ( parentWidget()->inherits( "QMenuBar" ) )
143 style().drawControl( QStyle::CE_MenuBarEmptyArea, p, this, contentsRect(), colorGroup() );
145 QHBox::drawContents( p );
149 LogoBox* cnt = new LogoBox( menuBar() );
150 cnt->setSpacing( 2 );
152 for ( LogoList::const_iterator it = myLogos.begin(); it != myLogos.end(); ++it )
154 QLabel* logoLab = new QLabel( cnt );
155 logoLab->setPixmap( (*it).pix );
156 logoLab->setScaledContents( false );
157 logoLab->setAlignment( QLabel::AlignCenter );
159 QApplication::sendPostedEvents( cnt, QEvent::ChildInserted );
160 cnt->addSpacing( 2 );
162 myId = menuBar()->insertItem( cnt );
164 QApplication::sendPostedEvents( menuBar()->parentWidget(), QEvent::LayoutHint );
165 QApplication::postEvent( menuBar()->parentWidget(), new QEvent( QEvent::LayoutHint ) );
168 int SUIT_Desktop::LogoMgr::find( const QString& id ) const
171 for ( uint i = 0; i < myLogos.count() && idx < 0; i++ )
173 if ( (*myLogos.at( i ) ).id == id )
179 /*!\class SUIT_Desktop
180 * Provide desktop management:\n
190 SUIT_Desktop::SUIT_Desktop()
193 myMenuMgr = new QtxActionMenuMgr( this );
194 myToolMgr = new QtxActionToolMgr( this );
195 myLogoMgr = new LogoMgr( menuBar() );
201 SUIT_Desktop::~SUIT_Desktop()
208 bool SUIT_Desktop::event( QEvent* e )
215 case QEvent::WindowActivate:
218 case QEvent::WindowDeactivate:
223 return QMainWindow::event( e );
229 void SUIT_Desktop::closeEvent( QCloseEvent* e )
231 emit closing( this, e );
238 void SUIT_Desktop::childEvent( QChildEvent* e )
240 if ( e->type() == QEvent::ChildInserted && parentArea() &&
241 e->child()->isWidgetType() && e->child()->inherits( "SUIT_ViewWindow" ) )
242 ((QWidget*)e->child())->reparent( parentArea(), QPoint( 0, 0 ), true );
244 QtxMainWindow::childEvent( e );
250 QtxActionMenuMgr* SUIT_Desktop::menuMgr() const
258 QtxActionToolMgr* SUIT_Desktop::toolMgr() const
264 Returns the count of the existed logos.
266 int SUIT_Desktop::logoCount() const
271 return myLogoMgr->count();
275 Adds new logo to the menu bar area.
276 Obsolete. Not should be used.
277 Use SUIT_Desktop::logoInsert();
279 void SUIT_Desktop::addLogo( const QString& id, const QPixmap& pix )
281 logoInsert( id, pix );
286 Obsolete. Not should be used.
287 Use SUIT_Desktop::logoRemove();
289 void SUIT_Desktop::removeLogo( const QString& id )
295 Adds new logo to the menu bar area
297 void SUIT_Desktop::logoInsert( const QString& logoID, const QPixmap& logo, const int idx )
300 myLogoMgr->insert( logoID, logo, idx );
306 void SUIT_Desktop::logoRemove( const QString& logoID )
309 myLogoMgr->remove( logoID );
315 void SUIT_Desktop::logoClear()