1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "SalomeApp_LoadStudiesDlg.h"
25 #include <QHBoxLayout>
26 #include <QVBoxLayout>
27 #include <QListWidget>
28 #include <QPushButton>
29 #include <QStringList>
31 #define SPACING_SIZE 6
32 #define MARGIN_SIZE 11
33 #define MIN_LISTBOX_WIDTH 150
34 #define MIN_LISTBOX_HEIGHT 100
37 \class SalomeApp_LoadStudiesDlg
38 \brief Dialog box which allows selecting study to be loaded
44 \param parent a parent widget
45 \param studies list of study names
47 SalomeApp_LoadStudiesDlg::SalomeApp_LoadStudiesDlg( QWidget* parent, const QStringList& studies )
52 setWindowTitle( tr("DLG_LOAD_STUDY_CAPTION") );
53 setSizeGripEnabled( true );
55 QVBoxLayout* topLayout = new QVBoxLayout( this );
56 topLayout->setMargin( MARGIN_SIZE );
57 topLayout->setSpacing( SPACING_SIZE );
59 QLabel* lab = new QLabel( tr( "MEN_STUDIES_CHOICE" ), this );
61 myButtonOk = new QPushButton( tr( "BUT_OK" ), this );
62 myButtonOk->setAutoDefault( true );
63 myButtonOk->setDefault( true );
65 QPushButton* buttonCancel = new QPushButton( tr( "BUT_CANCEL" ), this );
67 QHBoxLayout* btnLayout = new QHBoxLayout;
68 btnLayout->setSpacing( SPACING_SIZE );
69 btnLayout->setMargin( 0 );
70 btnLayout->addWidget( myButtonOk );
71 btnLayout->addStretch();
72 btnLayout->addWidget( buttonCancel );
74 myList = new QListWidget( this );
75 myList->setMinimumSize( MIN_LISTBOX_WIDTH, MIN_LISTBOX_HEIGHT );
76 myList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding,
77 QSizePolicy::Expanding ) );
78 myList->setSelectionMode( QAbstractItemView::SingleSelection );
80 topLayout->addWidget( lab );
81 topLayout->addWidget( myList );
82 topLayout->addLayout( btnLayout );
84 connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
85 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
86 connect( myList, SIGNAL( itemDoubleClicked( QListWidgetItem* ) ),
87 this, SLOT( accept() ) );
88 connect( myList, SIGNAL( itemSelectionChanged() ),
89 this, SLOT( updateState() ) );
90 myList->addItems( studies );
98 SalomeApp_LoadStudiesDlg::~SalomeApp_LoadStudiesDlg()
103 \brief Updates buttons state.
105 void SalomeApp_LoadStudiesDlg::updateState()
107 myButtonOk->setEnabled( myList->currentItem() != 0 );
111 \brief Get selected study name
112 \return selected study name or null string if study is not selected
114 QString SalomeApp_LoadStudiesDlg::selectedStudy()
117 if ( myList->currentItem() )
118 study = myList->currentItem()->text();
123 \brief Executes dialog box to select study from the list
124 and returns the study selected.
125 \param parent parent widget
126 \param studies list of study names
127 \return select study (or null string if dialog box is rejected)
129 QString SalomeApp_LoadStudiesDlg::selectStudy( QWidget* parent, const QStringList& studies )
131 SalomeApp_LoadStudiesDlg dlg( parent, studies );
133 if ( dlg.exec() == QDialog::Accepted )
134 study = dlg.selectedStudy();