From dd8e26b3e8cfb300875eb97edb58caf722c94a6c Mon Sep 17 00:00:00 2001 From: stv Date: Thu, 31 Aug 2006 13:38:38 +0000 Subject: [PATCH] Improovement of messages in status bar for module. --- src/CAM/CAM_Module.cxx | 47 +++++++++++++++++++++++++++++------ src/CAM/CAM_Module.h | 11 +++++++- src/SUIT/SUIT_Application.cxx | 23 +++++++++++++++-- src/SUIT/SUIT_Application.h | 10 +++++--- 4 files changed, 78 insertions(+), 13 deletions(-) diff --git a/src/CAM/CAM_Module.cxx b/src/CAM/CAM_Module.cxx index 9b37b3347..5e08436f6 100755 --- a/src/CAM/CAM_Module.cxx +++ b/src/CAM/CAM_Module.cxx @@ -87,10 +87,13 @@ CAM_Module::~CAM_Module() void CAM_Module::initialize( CAM_Application* app ) { myApp = app; - if (myApp) { + if ( myApp ) + { SUIT_Session* aSession = SUIT_Session::session(); - connect(aSession, SIGNAL( applicationClosed( SUIT_Application* ) ), - this, SLOT( onApplicationClosed( SUIT_Application* ) )); + connect( aSession, SIGNAL( applicationClosed( SUIT_Application* ) ), + this, SLOT( onApplicationClosed( SUIT_Application* ) ) ); + + connect( myApp, SIGNAL( infoChanged( QString ) ), this, SLOT( onInfoChanged( QString ) ) ); } } @@ -167,10 +170,40 @@ void CAM_Module::studyChanged( SUIT_Study* , SUIT_Study* ) { } +/*!Return true if module is active.*/ +bool CAM_Module::isActiveModule() const +{ + return application() ? application()->activeModule() == this : false; +} + +/*! + Put the message into the status bar of the desktop. Message will be displayed + during specified \amscec milliseconds. If parameter \amsec is negative then + message will be persistently displayed when module is active. +*/ +void CAM_Module::putInfo( const QString& msg, const int msec ) +{ + if ( application() ) + application()->putInfo( msg, msec ); + + if ( msec < 0 ) + myInfo = msg; +} + +/*! + Restore persistently displayed info string when previos information status string erasing + if module is active. +*/ +void CAM_Module::onInfoChanged( QString txt ) +{ + if ( txt.isEmpty() && isActiveModule() && !myInfo.isEmpty() && application() ) + application()->putInfo( myInfo ); +} + /*!Public slot, nullify application pointer if the application was closed.*/ void CAM_Module::onApplicationClosed( SUIT_Application* theApp ) { - if (myApp == theApp) + if ( myApp == theApp ) myApp = NULL; } @@ -640,10 +673,10 @@ void CAM_Module::connectToStudy( CAM_Study* camStudy ) CAM_DataModel* dm = it.current()->dataModel(); if( it.current() == this && !camStudy->containsDataModel( dm ) ) { - if( prev ) - camStudy->insertDataModel( it.current()->dataModel(), prev ); + if ( prev ) + camStudy->insertDataModel( it.current()->dataModel(), prev ); else - camStudy->insertDataModel( it.current()->dataModel(), 0 ); + camStudy->insertDataModel( it.current()->dataModel(), 0 ); } prev = dm; } diff --git a/src/CAM/CAM_Module.h b/src/CAM/CAM_Module.h index 3409905e7..df9282a41 100755 --- a/src/CAM/CAM_Module.h +++ b/src/CAM/CAM_Module.h @@ -64,6 +64,10 @@ public: virtual void contextMenuPopup( const QString&, QPopupMenu*, QString& title ) {}; virtual void updateCommandsStatus() {}; + virtual void putInfo( const QString&, const int = -1 ); + + bool isActiveModule() const; + /** @name Set Menu Shown*/ //@{ virtual void setMenuShown( const bool ); @@ -89,6 +93,9 @@ public slots: virtual void onApplicationClosed( SUIT_Application* ); +private slots: + void onInfoChanged( QString ); + protected: virtual CAM_DataModel* createDataModel(); @@ -136,6 +143,7 @@ private: CAM_Application* myApp; QString myName; QPixmap myIcon; + QString myInfo; CAM_DataModel* myDataModel; QMap myActionMap; @@ -146,7 +154,8 @@ private: #pragma warning( default: 4251 ) #endif -extern "C" { +extern "C" +{ typedef CAM_Module* (*GET_MODULE_FUNC)(); } diff --git a/src/SUIT/SUIT_Application.cxx b/src/SUIT/SUIT_Application.cxx index a4a21d862..bbe68030d 100755 --- a/src/SUIT/SUIT_Application.cxx +++ b/src/SUIT/SUIT_Application.cxx @@ -168,7 +168,7 @@ SUIT_ResourceMgr* SUIT_Application::resourceMgr() const \param msg - text of message \param msec - time in milliseconds, after that the status label will be cleared */ -void SUIT_Application::putInfo ( const QString& msg, const int msec ) +void SUIT_Application::putInfo( const QString& msg, const int msec ) { if ( !desktop() ) return; @@ -180,9 +180,28 @@ void SUIT_Application::putInfo ( const QString& msg, const int msec ) myStatusLabel->show(); } + QString prev = myStatusLabel->text(); + myStatusLabel->setText( msg ); if ( msec != -1 ) - QTimer::singleShot( msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec, myStatusLabel, SLOT( clear() ) ); + QTimer::singleShot( msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec, this, SLOT( onInfoClear() ) ); + + if ( prev != msg ) + emit infoChanged( msg ); +} + +/*! + Clear the information label in status bar after delay. +*/ +void SUIT_Application::onInfoClear() +{ + if ( !myStatusLabel ) + return; + + bool changed = !myStatusLabel->text().isEmpty(); + myStatusLabel->clear(); + if ( changed ) + emit infoChanged( QString::null ); } /*! diff --git a/src/SUIT/SUIT_Application.h b/src/SUIT/SUIT_Application.h index 05e269137..0bf48847e 100755 --- a/src/SUIT/SUIT_Application.h +++ b/src/SUIT/SUIT_Application.h @@ -25,14 +25,14 @@ #include #include +class QLabel; +class QString; class QAction; +class QIconSet; class SUIT_Desktop; class SUIT_Convertor; class SUIT_ViewModel; class SUIT_ResourceMgr; -class QString; -class QIconSet; -class QLabel; #ifdef WIN32 #pragma warning ( disable:4251 ) @@ -112,6 +112,10 @@ public: signals: void applicationClosed( SUIT_Application* ); void activated( SUIT_Application* ); + void infoChanged( QString ); + +private slots: + void onInfoClear(); protected: SUIT_Application* startApplication( int, char** ) const; -- 2.39.2