From: vsr Date: Tue, 29 Jan 2008 09:29:35 +0000 (+0000) Subject: Improve study/session closing and module activation mechanism: for light modules... X-Git-Tag: for_M2008_07022008~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=dc86847ef77f773c32a6256e02ae357e411d8edf;p=modules%2Fgui.git Improve study/session closing and module activation mechanism: for light modules no actions like "Load study", "Unload study" and "Shutdown standalone servers" should be proposed. --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index c60c1b53e..2e59728d0 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -655,20 +655,16 @@ void LightApp_Application::onModuleActivation( QAction* a ) bool cancelled = false; while ( !modName.isEmpty() && !activeStudy() && !cancelled ){ LightApp_ModuleDlg aDlg( desktop(), modName, icon ); - int res = aDlg.exec(); + QMap opmap = activateModuleActions(); + for ( QMap::ConstIterator it = opmap.begin(); it != opmap.end(); ++it ) + aDlg.addButton( it.data(), it.key() ); - switch ( res ){ - case 1: - onNewDoc(); - break; - case 2: - onOpenDoc(); - break; - case 3: - //onLoadStudy(); - //break; - case 0: - default: + int res = aDlg.exec(); + if ( res != QDialog::Rejected ) { + // some operation is selected + moduleActionSelected( res ); + } + else { putInfo( tr("INF_CANCELLED") ); myActions[QString()]->setOn( true ); cancelled = true; @@ -2108,6 +2104,39 @@ void LightApp_Application::updateDesktopTitle() { desktop()->setCaption( aTitle ); } +/*! + \brief Get module activation actions + \return map where + - action_id is unique non-zero action identifier + - action_name is action title + \sa moduleActionSelected() +*/ +QMap LightApp_Application::activateModuleActions() const +{ + QMap opmap; + opmap.insert( NewStudyId, tr( "ACTIVATE_MODULE_OP_NEW" ) ); + opmap.insert( OpenStudyId, tr( "ACTIVATE_MODULE_OP_OPEN" ) ); + return opmap; +} + +/*! + \brief Process module activation action. + \param id action identifier + \sa activateModuleActions() +*/ +void LightApp_Application::moduleActionSelected( const int id ) +{ + switch ( id ) { + case NewStudyId: + onNewDoc(); + break; + case OpenStudyId: + onOpenDoc(); + break; + default: + break; + } +} /*! Updates windows after close document */ diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index bdabb3ef8..e83e3c2fd 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -96,6 +96,10 @@ public: #endif PreferencesId, MRUId, UserID }; + +protected: + enum { NewStudyId = 1, OpenStudyId }; + public: LightApp_Application(); virtual ~LightApp_Application(); @@ -200,6 +204,9 @@ protected: virtual void savePreferences(); virtual void updateDesktopTitle(); + virtual QMap activateModuleActions() const; + virtual void moduleActionSelected( const int ); + protected slots: virtual void onDesktopActivated(); diff --git a/src/LightApp/LightApp_ModuleDlg.cxx b/src/LightApp/LightApp_ModuleDlg.cxx index d7777bdaa..3fcaf5112 100644 --- a/src/LightApp/LightApp_ModuleDlg.cxx +++ b/src/LightApp/LightApp_ModuleDlg.cxx @@ -22,18 +22,9 @@ #include -#include #include -#include -#include -#include -#ifndef WIN32 -using namespace std; -#endif - -/*!Default icon*/ -static const char* const default_icon[] = { +static const char* default_icon[] = { "48 48 17 1", ". c None", "# c #161e4c", @@ -101,116 +92,15 @@ static const char* const default_icon[] = { "................................................", "................................................"}; -//============================================================================================================================== -/*! - * LightApp_ModuleDlg::LightApp_ModuleDlg \n - * - * Constructor. - */ -//============================================================================================================================== -LightApp_ModuleDlg::LightApp_ModuleDlg ( QWidget * parent, const QString& component, const QPixmap icon ) - : QDialog ( parent, "ActivateModuleDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) +LightApp_ModuleDlg::LightApp_ModuleDlg( QWidget* parent, + const QString& component, + const QPixmap& icon ) +: SUIT_MsgDlg( parent, tr( "CAPTION" ), tr ( "DESCRIPTION" ).arg( component ), !icon.isNull() ? icon : QPixmap( default_icon ) ) { - QPixmap defaultIcon( ( const char** ) default_icon ); - setCaption( tr( "CAPTION" ) ); - setSizeGripEnabled( TRUE ); - - QGridLayout* ActivateModuleDlgLayout = new QGridLayout( this ); - ActivateModuleDlgLayout->setMargin( 11 ); ActivateModuleDlgLayout->setSpacing( 6 ); - - // Module's name and icon - myComponentFrame = new QFrame( this, "myComponentFrame" ); - myComponentFrame->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Expanding ) ); - myComponentFrame->setMinimumHeight( 100 ); - myComponentFrame->setFrameStyle( QFrame::Box | QFrame::Sunken ); - - QGridLayout* myComponentFrameLayout = new QGridLayout( myComponentFrame ); - myComponentFrameLayout->setMargin( 11 ); myComponentFrameLayout->setSpacing( 6 ); - - // --> icon - myComponentIcon = new QLabel( myComponentFrame, "myComponentIcon" ); - myComponentIcon->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); - myComponentIcon->setPixmap( !icon.isNull() ? icon : defaultIcon ); - myComponentIcon->setScaledContents( false ); - myComponentIcon->setAlignment( AlignCenter ); - // --> name - myComponentLab = new QLabel( component, myComponentFrame, "myComponentLab" ); - QFont fnt = myComponentLab->font(); fnt.setBold( TRUE ); myComponentLab->setFont( fnt ); - myComponentLab->setAlignment( AlignCenter ); - - myComponentFrameLayout->addWidget( myComponentIcon, 0, 0 ); - myComponentFrameLayout->addWidget( myComponentLab, 0, 1 ); - - // Info - QVBoxLayout* infoLayout = new QVBoxLayout(); - infoLayout->setMargin( 0 ); infoLayout->setSpacing( 6 ); - - // --> top line - QFrame* myLine1 = new QFrame( this, "myLine1" ); - myLine1->setFrameStyle( QFrame::HLine | QFrame::Plain ); - // --> info label - myInfoLabel = new QLabel( tr ("ActivateComponent_DESCRIPTION"), this, "myInfoLabel" ); - myInfoLabel->setAlignment( AlignCenter ); - // --> bottom line - QFrame* myLine2 = new QFrame( this, "myLine2" ); - myLine2->setFrameStyle( QFrame::HLine | QFrame::Plain ); - - infoLayout->addStretch(); - infoLayout->addWidget( myLine1 ); - infoLayout->addWidget( myInfoLabel ); - infoLayout->addWidget( myLine2 ); - infoLayout->addStretch(); - - // Buttons - QHBoxLayout* btnLayout = new QHBoxLayout(); - btnLayout->setMargin( 0 ); btnLayout->setSpacing( 6 ); - - // --> New - myNewBtn = new QPushButton( tr( "NEW" ), this, "myNewBtn" ); - myNewBtn->setDefault( true ); myNewBtn->setAutoDefault( true ); - // --> Open - myOpenBtn = new QPushButton( tr( "OPEN" ), this, "myOpenBtn" ); - myOpenBtn->setAutoDefault( true ); - // --> Load - myLoadBtn = new QPushButton( tr( "LOAD" ), this, "myLoadBtn" ); - myLoadBtn->setAutoDefault( true ); - // --> Cancel - myCancelBtn = new QPushButton( tr( "CANCEL" ), this, "myCancelBtn" ); - myCancelBtn->setAutoDefault( true ); - - btnLayout->addWidget( myNewBtn ); - btnLayout->addWidget( myOpenBtn ); - btnLayout->addWidget( myLoadBtn ); - btnLayout->addStretch(); - btnLayout->addSpacing( 70 ); - btnLayout->addStretch(); - btnLayout->addWidget( myCancelBtn ); - - ActivateModuleDlgLayout->addWidget( myComponentFrame, 0, 0 ); - ActivateModuleDlgLayout->addLayout( infoLayout, 0, 1 ); - ActivateModuleDlgLayout->addMultiCellLayout( btnLayout, 1, 1, 0, 1 ); - - // signals and slots connections - connect( myNewBtn, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); - connect( myOpenBtn, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); - connect( myLoadBtn, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); - connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) ); + iconLabel()->setFrameStyle( QFrame::Box | QFrame::Sunken ); + iconLabel()->setMinimumSize( 70, 70 ); } -//============================================================================================================================== -/*! - * LightApp_ModuleDlg::onButtonClicked - * - * Buttons slot - */ -//============================================================================================================================== -void LightApp_ModuleDlg::onButtonClicked() +LightApp_ModuleDlg::~LightApp_ModuleDlg() { - QPushButton* btn = ( QPushButton* )sender(); - if ( btn == myNewBtn ) - done( 1 ); - if ( btn == myOpenBtn ) - done( 2 ); - if ( btn == myLoadBtn ) - done( 3 ); } diff --git a/src/LightApp/LightApp_ModuleDlg.h b/src/LightApp/LightApp_ModuleDlg.h index 9b818344c..0f2dd79a9 100644 --- a/src/LightApp/LightApp_ModuleDlg.h +++ b/src/LightApp/LightApp_ModuleDlg.h @@ -16,49 +16,25 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// SALOME SALOMEGUI : implementation of desktop and GUI kernel +// File : LightApp_ModuleDlg.h +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) // -// File : LightApp_ModuleDlg.h -// Author : Michael ZORIN (mzn) -// Module : SALOME #ifndef LIGHTAPP_MODULEDLG_H #define LIGHTAPP_MODULEDLG_H #include "LightApp.h" -#include -#include -class QFrame; -class QLabel; -class QPushButton; +#include -/*! - \class LightApp_ModuleDlg - Dialog allows to choose action on module activation when there is no document. - It is possible to create new document, to open existing or to cancel module activation -*/ -class LIGHTAPP_EXPORT LightApp_ModuleDlg : public QDialog +class LIGHTAPP_EXPORT LightApp_ModuleDlg : public SUIT_MsgDlg { Q_OBJECT public: - LightApp_ModuleDlg ( QWidget* parent, const QString& component, const QPixmap icon = QPixmap() ) ; - ~LightApp_ModuleDlg ( ) { }; - -private slots: - void onButtonClicked(); - -private: - QFrame* myComponentFrame; - QLabel* myComponentLab; - QLabel* myComponentIcon; - QLabel* myInfoLabel; - QPushButton* myNewBtn; - QPushButton* myOpenBtn; - QPushButton* myLoadBtn; - QPushButton* myCancelBtn; + LightApp_ModuleDlg( QWidget*, const QString&, const QPixmap& = QPixmap() ); + ~LightApp_ModuleDlg(); }; -#endif +#endif // LIGHTAPP_MODULEDLG_H diff --git a/src/LightApp/resources/LightApp_msg_en.po b/src/LightApp/resources/LightApp_msg_en.po index dc4381003..c138bb49f 100644 --- a/src/LightApp/resources/LightApp_msg_en.po +++ b/src/LightApp/resources/LightApp_msg_en.po @@ -335,20 +335,8 @@ msgstr "Hide all" msgid "LightApp_ModuleDlg::CAPTION" msgstr "Activate module" -msgid "LightApp_ModuleDlg::NEW" -msgstr "&New" - -msgid "LightApp_ModuleDlg::OPEN" -msgstr "&Open" - -msgid "LightApp_ModuleDlg::LOAD" -msgstr "&Load" - -msgid "LightApp_ModuleDlg::CANCEL" -msgstr "&Cancel" - -msgid "LightApp_ModuleDlg::ActivateComponent_DESCRIPTION" -msgstr "Create, open or load study." +msgid "LightApp_ModuleDlg::DESCRIPTION" +msgstr "You're activating module %1.
Please, select required action by pressing the corresponding button below." msgid "LightApp_NameDlg::TLT_RENAME" msgstr "Rename" @@ -356,3 +344,9 @@ msgstr "Rename" msgid "LightApp_NameDlg::NAME_LBL" msgstr "Name: " +msgid "LightApp_Application::ACTIVATE_MODULE_OP_OPEN" +msgstr "&Open..." + +msgid "LightApp_Application::ACTIVATE_MODULE_OP_NEW" +msgstr "&New" +