X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FLightApp%2FLightApp_ModuleDlg.cxx;h=d37b18cc8fce2f9b564b46ef05b0c958d0cec885;hb=2e434280853b85c5e5b0b4c5b068b5932842a548;hp=3fcaf5112f92afd917c0de0239b47d625c736f25;hpb=f830c97c748d8f8a6a7eccc8e3a58e19066a1181;p=modules%2Fgui.git diff --git a/src/LightApp/LightApp_ModuleDlg.cxx b/src/LightApp/LightApp_ModuleDlg.cxx index 3fcaf5112..d37b18cc8 100644 --- a/src/LightApp/LightApp_ModuleDlg.cxx +++ b/src/LightApp/LightApp_ModuleDlg.cxx @@ -1,30 +1,40 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// File : LightApp_ModuleDlg.cxx -// Author : Michael Zorin (mzn) -// Module : LightApp -#include +// File : LightApp_ModuleDlg.cxx +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// +#include "LightApp_ModuleDlg.h" -#include +#include +#include +#include +#include -static const char* default_icon[] = { +/*! + \brief Pixmap used as default icon for the module. + \internal +*/ +static const char* const default_icon[] = { "48 48 17 1", ". c None", "# c #161e4c", @@ -92,15 +102,169 @@ static const char* default_icon[] = { "................................................", "................................................"}; +/*! + \class LightApp_ModuleDlg + \brief A dialog box allowing to select study operation to be performed + on the module activating. + + The dialog box is shown when the user tries to activate any module + while there is no opened study. The dialog box proposes user to select + one of the possible operations which should be done before module activating, + for example, create new study or open study from the file. + The available operations are assigned by adding the buttons with the unique + identifier to the dialog box. When the user clicks any operation button, + the dialog box sets its identifier as the return code and closes. + + The typical usage of the dialog box: + \code + LightApp_ModuleDlg dlg( desktop() ); + dlg.addButton( "New study", NewStudyId ); + dlg.addButton( "Open study...", OpenStudyId ); + int ret = dlg.exec(); + switch( ret ) { + case NewStudyId: + // create new study + createNewStudy(); + break; + case OpenStudyId: + // open study from the file + // ... show dialog box to choose the file + QString fileName = QFileDialog::getOpenFileName( desktop(), "Open File" ); + if ( !fileName.isEmpty() ) + openStudy( fileName ); + break; + default: + // operation is cancelled + break; + } + \endcode + + \sa addButton() +*/ + +/*! + \brief Constructor. + \param parent parent widget + \param component module name + \param icon module icon +*/ 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 ) ) + const QString& component, + const QPixmap& icon ) +: QDialog ( parent ) { - iconLabel()->setFrameStyle( QFrame::Box | QFrame::Sunken ); - iconLabel()->setMinimumSize( 70, 70 ); + setModal( true ); + + QPixmap defaultIcon( default_icon ); + setWindowTitle( tr( "CAPTION" ) ); + + // icon + QLabel* iconLab = new QLabel( this ); + iconLab->setFrameStyle( QFrame::Box | QFrame::Sunken ); + iconLab->setMinimumSize( 70, 70 ); + iconLab->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + iconLab->setPixmap( !icon.isNull() ? icon : defaultIcon ); + iconLab->setScaledContents( false ); + iconLab->setAlignment( Qt::AlignCenter ); + + // info message + QLabel* infoLab = new QLabel( tr ( "DESCRIPTION" ).arg( component ), this ); + infoLab->setTextFormat( Qt::RichText ); + infoLab->setAlignment( Qt::AlignCenter ); + + // Buttons + myButtonLayout = new QHBoxLayout(); + myButtonLayout->setMargin( 0 ); + myButtonLayout->setSpacing( 6 ); + + // + QPushButton* cancelBtn = new QPushButton( tr( "CANCEL" ), this ); + cancelBtn->setAutoDefault( true ); + + myButtonLayout->addSpacing( 70 ); + myButtonLayout->addStretch(); + myButtonLayout->addWidget( cancelBtn ); + + QGridLayout* layout = new QGridLayout( this ); + layout->setMargin( 11 ); + layout->setSpacing( 6 ); + + layout->addWidget( iconLab, 0, 0 ); + layout->addWidget( infoLab, 0, 1 ); + layout->addLayout( myButtonLayout, 1, 0, 1, 2 ); + + // signals and slots connections + connect( cancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) ); } +/*! + \brief Destructor. +*/ LightApp_ModuleDlg::~LightApp_ModuleDlg() { } + +/*! + \brief Add operation button to the dialog box. + + If the parameter \a id is equal to -1, then the + button identifier is generated automatically. + + \param button button text + \param id button identifier + \return button identifier +*/ +int LightApp_ModuleDlg::addButton( const QString& button, const int id ) +{ + static int lastId = 0; + int bid = id == -1 ? --lastId : id; + + QPushButton* b = findButton( bid ); + if ( b ) { + myButtons.remove( b ); + delete b; + } + + QPushButton* newButton = new QPushButton( button, this ); + newButton->setAutoDefault( true ); + + if ( myButtons.empty() ) { + newButton->setDefault( true ); + newButton->setFocus(); + } + + myButtons.insert( newButton, bid ); + myButtonLayout->insertWidget( myButtonLayout->count()-3, newButton ); + connect( newButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); + + return bid; +} + +/*! + \brief Search button with the specified identifier. + \param id button identifier + \return button or 0 if \a id is invalid +*/ +QPushButton* LightApp_ModuleDlg::findButton( const int id ) const +{ + QPushButton* btn = 0; + for ( ButtonMap::ConstIterator it = myButtons.begin(); + it != myButtons.end() && !btn; ++it ) { + if ( it.value() == id ) + btn = it.key(); + } + return btn; +} + +/*! + \brief Called when any dialog button (except \c Cancel) + is clicked. + + Closes the dialog and sets its result code to the identifier + of the button clicked by the user. +*/ +void LightApp_ModuleDlg::accept() +{ + QPushButton* btn = ( QPushButton* )sender(); + done( myButtons[ btn ] ); +}