Back to index

salome-gui  6.5.0
SalomeApp_LoadStudiesDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "SalomeApp_LoadStudiesDlg.h"
00021 
00022 #include <QLabel>
00023 #include <QHBoxLayout>
00024 #include <QVBoxLayout>
00025 #include <QListWidget>
00026 #include <QPushButton>
00027 #include <QStringList>
00028 
00029 #define SPACING_SIZE             6
00030 #define MARGIN_SIZE             11
00031 #define MIN_LISTBOX_WIDTH      150
00032 #define MIN_LISTBOX_HEIGHT     100
00033 
00045 SalomeApp_LoadStudiesDlg::SalomeApp_LoadStudiesDlg( QWidget* parent, const QStringList& studies )
00046 : QDialog( parent )
00047 {
00048   setModal( true );
00049 
00050   setWindowTitle( tr("DLG_LOAD_STUDY_CAPTION") );
00051   setSizeGripEnabled( true );
00052 
00053   QVBoxLayout* topLayout = new QVBoxLayout( this );
00054   topLayout->setMargin( MARGIN_SIZE );
00055   topLayout->setSpacing( SPACING_SIZE );
00056   
00057   QLabel* lab = new QLabel( tr( "MEN_STUDIES_CHOICE" ), this );
00058   
00059   myButtonOk = new QPushButton( tr( "BUT_OK" ), this );
00060   myButtonOk->setAutoDefault( true );
00061   myButtonOk->setDefault( true );
00062     
00063   QPushButton* buttonCancel = new QPushButton( tr( "BUT_CANCEL" ), this );
00064   
00065   QHBoxLayout* btnLayout = new QHBoxLayout;
00066   btnLayout->setSpacing( SPACING_SIZE );
00067   btnLayout->setMargin( 0 );
00068   btnLayout->addWidget( myButtonOk );
00069   btnLayout->addStretch();
00070   btnLayout->addWidget( buttonCancel );
00071 
00072   myList = new QListWidget( this );
00073   myList->setMinimumSize( MIN_LISTBOX_WIDTH, MIN_LISTBOX_HEIGHT );
00074   myList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, 
00075                                                QSizePolicy::Expanding ) );
00076   myList->setSelectionMode( QAbstractItemView::SingleSelection );
00077 
00078   topLayout->addWidget( lab );
00079   topLayout->addWidget( myList );
00080   topLayout->addLayout( btnLayout );
00081   
00082   connect( myButtonOk,   SIGNAL( clicked() ), this, SLOT( accept() ) );
00083   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
00084   connect( myList,       SIGNAL( itemDoubleClicked( QListWidgetItem* ) ),
00085                                               this, SLOT( accept() ) );
00086   connect( myList,       SIGNAL( itemSelectionChanged() ),
00087                                               this, SLOT( updateState() ) );
00088   myList->addItems( studies );
00089 
00090   updateState();
00091 }
00092 
00096 SalomeApp_LoadStudiesDlg::~SalomeApp_LoadStudiesDlg()
00097 {
00098 }
00099 
00103 void SalomeApp_LoadStudiesDlg::updateState()
00104 {
00105   myButtonOk->setEnabled( myList->currentItem() != 0 );
00106 }
00107 
00112 QString SalomeApp_LoadStudiesDlg::selectedStudy()
00113 {
00114   QString study;
00115   if ( myList->currentItem() )
00116     study = myList->currentItem()->text();
00117   return study;
00118 }
00119 
00127 QString SalomeApp_LoadStudiesDlg::selectStudy( QWidget* parent, const QStringList& studies )
00128 {
00129   SalomeApp_LoadStudiesDlg dlg( parent, studies );
00130   QString study;
00131   if ( dlg.exec() == QDialog::Accepted )
00132     study = dlg.selectedStudy();
00133   return study;
00134 }