#include <qstyle.h>
/*!
- Class: LogoBox
+ Class: SUIT_Desktop::LogoMgr
Level: Internal
*/
-class LogoBox : public QHBox
+class SUIT_Desktop::LogoMgr : public QObject
{
public:
- LogoBox( QWidget* parent = 0, const char* name = 0, WFlags f = 0 ) : QHBox( parent, name, f )
- {
- setFrameStyle( Plain | NoFrame );
- setMargin( 0 ); setSpacing( 2 );
- }
- void addSpacing( int spacing )
- {
- QApplication::sendPostedEvents( this, QEvent::ChildInserted );
- ((QHBoxLayout*)layout())->addSpacing( spacing );
- }
-protected:
- void drawContents( QPainter* p )
- {
- if ( parentWidget()->inherits( "QMenuBar" ) )
- style().drawControl( QStyle::CE_MenuBarEmptyArea, p, this, contentsRect(), colorGroup() );
- else
- QHBox::drawContents( p );
- }
-};
+ LogoMgr( QMenuBar* );
+ virtual ~LogoMgr();
-/*!
- Class: SUIT_Desktop::LogoManager
- Level: Internal
-*/
+ int count() const;
+
+ void insert( const QString&, const QPixmap&, const int = -1 );
+ void remove( const QString& );
+ void clear();
+
+ QMenuBar* menuBar() const;
+
+private:
+ void generate();
+ int find( const QString& ) const;
+
+private:
+ typedef struct { QString id; QPixmap pix; } LogoInfo;
+ typedef QValueList<LogoInfo> LogoList;
+
+private:
+ int myId;
+ QMenuBar* myMenus;
+ LogoList myLogos;
+};
-SUIT_Desktop::LogoManager::LogoManager( SUIT_Desktop* desktop)
-: myDesktop( desktop ), myId( 0 )
+SUIT_Desktop::LogoMgr::LogoMgr( QMenuBar* mb )
+: QObject( mb ),
+myMenus( mb ),
+myId( 0 )
{
}
-void SUIT_Desktop::LogoManager::addLogo( const QString& logoID, const QPixmap& logo )
+SUIT_Desktop::LogoMgr::~LogoMgr()
+{
+}
+
+QMenuBar* SUIT_Desktop::LogoMgr::menuBar() const
+{
+ return myMenus;
+}
+
+int SUIT_Desktop::LogoMgr::count() const
+{
+ return myLogos.count();
+}
+
+void SUIT_Desktop::LogoMgr::insert( const QString& id, const QPixmap& pix, const int index )
{
- if ( !myDesktop || logo.isNull() )
+ if ( pix.isNull() )
return;
- myLogoMap[ logoID ] = logo;
- generateLogo();
+
+ LogoInfo* inf = 0;
+
+ int idx = find( id );
+ if ( idx < 0 )
+ {
+ idx = index < (int)myLogos.count() ? index : -1;
+ if ( idx < 0 )
+ inf = &( *myLogos.append( LogoInfo() ) );
+ else
+ inf = &( *myLogos.insert( myLogos.at( idx ), LogoInfo() ) );
+ }
+ else
+ inf = &( *myLogos.at( idx ) );
+
+
+ inf->id = id;
+ inf->pix = pix;
+
+ generate();
}
-void SUIT_Desktop::LogoManager::removeLogo( const QString& logoID )
+void SUIT_Desktop::LogoMgr::remove( const QString& id )
{
- if ( !myDesktop || myLogoMap.find( logoID ) == myLogoMap.end() )
+ int idx = find( id );
+ if ( idx < 0 )
return;
- myLogoMap.remove( logoID );
- generateLogo();
+
+ myLogos.remove( myLogos.at( idx ) );
+
+ generate();
}
-void SUIT_Desktop::LogoManager::clearLogo()
+void SUIT_Desktop::LogoMgr::clear()
{
- myLogoMap.clear();
- generateLogo();
+ myLogos.clear();
+ generate();
}
-void SUIT_Desktop::LogoManager::generateLogo()
+void SUIT_Desktop::LogoMgr::generate()
{
- if ( !myDesktop ) return;
+ if ( !menuBar() )
+ return;
if ( myId )
- myDesktop->menuBar()->removeItem( myId );
+ menuBar()->removeItem( myId );
+
myId = 0;
- if ( !myLogoMap.count() )
+ if ( myLogos.isEmpty() )
return;
- LogoBox* cnt = new LogoBox( myDesktop );
-
- QMap<QString, QPixmap>::Iterator it;
- for ( it = myLogoMap.begin(); it != myLogoMap.end(); ++it ) {
+ class LogoBox : public QHBox
+ {
+ public:
+ LogoBox( QWidget* parent = 0, const char* name = 0, WFlags f = 0 ) : QHBox( parent, name, f ) {};
+
+ void addSpacing( int spacing )
+ {
+ QApplication::sendPostedEvents( this, QEvent::ChildInserted );
+ ((QHBoxLayout*)layout())->addSpacing( spacing );
+ }
+
+ protected:
+ void drawContents( QPainter* p )
+ {
+ if ( parentWidget()->inherits( "QMenuBar" ) )
+ style().drawControl( QStyle::CE_MenuBarEmptyArea, p, this, contentsRect(), colorGroup() );
+ else
+ QHBox::drawContents( p );
+ }
+ };
+
+ LogoBox* cnt = new LogoBox( menuBar() );
+ cnt->setSpacing( 2 );
+
+ for ( LogoList::const_iterator it = myLogos.begin(); it != myLogos.end(); ++it )
+ {
QLabel* logoLab = new QLabel( cnt );
- logoLab->setPixmap( *it );
- logoLab->setAlignment( QLabel::AlignCenter );
+ logoLab->setPixmap( (*it).pix );
logoLab->setScaledContents( false );
+ logoLab->setAlignment( QLabel::AlignCenter );
}
+ QApplication::sendPostedEvents( cnt, QEvent::ChildInserted );
cnt->addSpacing( 2 );
- myId = myDesktop->menuBar()->insertItem( cnt );
- QApplication::sendPostedEvents( myDesktop->menuBar()->parentWidget(), QEvent::LayoutHint );
- QApplication::postEvent( myDesktop->menuBar()->parentWidget(), new QEvent( QEvent::LayoutHint ) );
+ myId = menuBar()->insertItem( cnt );
+
+ QApplication::sendPostedEvents( menuBar()->parentWidget(), QEvent::LayoutHint );
+ QApplication::postEvent( menuBar()->parentWidget(), new QEvent( QEvent::LayoutHint ) );
}
+int SUIT_Desktop::LogoMgr::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;
+}
/*!\class SUIT_Desktop
* Provide desktop management:\n
Constructor.
*/
SUIT_Desktop::SUIT_Desktop()
-: QtxMainWindow(), myLogoMan( this )
+: QtxMainWindow()
{
myMenuMgr = new QtxActionMenuMgr( this );
myToolMgr = new QtxActionToolMgr( this );
+ myLogoMgr = new LogoMgr( menuBar() );
}
/*!
return myToolMgr;
}
+/*!
+ Returns the count of the existed logos.
+*/
+int SUIT_Desktop::logoCount() const
+{
+ if ( !myLogoMgr )
+ return 0;
+ else
+ return myLogoMgr->count();
+}
+
+/*!
+ Adds new logo to the menu bar area.
+ Obsolete. Not should be used.
+ Use SUIT_Desktop::logoInsert();
+*/
+void SUIT_Desktop::addLogo( const QString& id, const QPixmap& pix )
+{
+ logoInsert( id, pix );
+}
+
+/*!
+ Removes a logo.
+ Obsolete. Not should be used.
+ Use SUIT_Desktop::logoRemove();
+*/
+void SUIT_Desktop::removeLogo( const QString& id )
+{
+ logoRemove( id );
+}
+
/*!
Adds new logo to the menu bar area
*/
-void SUIT_Desktop::addLogo( const QString& logoID, const QPixmap& logo )
+void SUIT_Desktop::logoInsert( const QString& logoID, const QPixmap& logo, const int idx )
{
- myLogoMan.addLogo( logoID, logo );
+ if ( myLogoMgr )
+ myLogoMgr->insert( logoID, logo, idx );
}
/*!
Removes a logo
*/
-void SUIT_Desktop::removeLogo( const QString& logoID )
+void SUIT_Desktop::logoRemove( const QString& logoID )
{
- myLogoMan.removeLogo( logoID );
+ if ( myLogoMgr )
+ myLogoMgr->remove( logoID );
}
/*!
Removes all logos
*/
-void SUIT_Desktop::clearLogo()
+void SUIT_Desktop::logoClear()
{
- myLogoMan.clearLogo();
+ if ( myLogoMgr )
+ myLogoMgr->clear();
}
if ( myAppLibs.contains( appName ) )
libHandle = myAppLibs[appName];
+ QString lib;
if ( !libHandle )
- libHandle = loadLibrary( name );
+ libHandle = loadLibrary( name, lib );
if ( !libHandle )
{
SUIT_MessageBox::warn1( 0, tr( "Error" ),
- tr( "Can not find function %1. %2").arg( APP_CREATE_NAME ).arg( lastError() ), tr( "Ok" ) );
+ tr( "Can not load application library \"%1\": %2").arg( lib ).arg( lastError() ), tr( "Ok" ) );
return 0;
}
- if (!myAppLibs.contains(appName) || !myAppLibs[appName]) // jfa 22.06.2005
+ if ( !myAppLibs.contains( appName ) || !myAppLibs[appName] ) // jfa 22.06.2005
myAppLibs.insert( appName, libHandle );
APP_CREATE_FUNC crtInst = 0;
if ( !crtInst )
{
SUIT_MessageBox::warn1( 0, tr( "Error" ),
- tr( "Can not find function %1. %2").arg( APP_CREATE_NAME ).arg( lastError() ), tr( "Ok" ) );
+ tr( "Can not find function \"%1\": %2" ).arg( APP_CREATE_NAME ).arg( lastError() ), tr( "Ok" ) );
return 0;
}
SUIT_Application* anApp = crtInst();
if ( !anApp )
{
- SUIT_MessageBox::warn1(0, tr( "Error" ), tr( "Can not find function %1. %2").arg( APP_CREATE_NAME ).arg( lastError() ), tr( "Ok" ) );
+ SUIT_MessageBox::warn1( 0, tr( "Error" ), tr( "Can not create application \"%1\": %2").arg( appName ).arg( lastError() ), tr( "Ok" ) );
return 0;
}
connect( anApp, SIGNAL( applicationClosed( SUIT_Application* ) ),
this, SLOT( onApplicationClosed( SUIT_Application* ) ) );
connect( anApp, SIGNAL( activated( SUIT_Application* ) ),
- this, SLOT( onApplicationActivated( SUIT_Application* ) ) );
+ this, SLOT( onApplicationActivated( SUIT_Application* ) ) );
myAppList.append( anApp );
anApp->start();
+ // Application can be closed during starting (not started).
+ if ( !myAppList.contains( anApp ) )
+ anApp = 0;
+
return anApp;
}
/*! Load library to session.
* \retval Loaded library.
*/
-SUIT_Session::AppLib SUIT_Session::loadLibrary( const QString& name )
+SUIT_Session::AppLib SUIT_Session::loadLibrary( const QString& name, QString& libName )
{
QString libFile = SUIT_Tools::library( name );
+ libName = libFile;
if ( libFile.isEmpty() )
return 0;