1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SalomeApp_LoadStudiesDlg.h"
23 #include <QHBoxLayout>
24 #include <QVBoxLayout>
25 #include <QListWidget>
26 #include <QPushButton>
27 #include <QStringList>
29 #define SPACING_SIZE 6
30 #define MARGIN_SIZE 11
31 #define MIN_LISTBOX_WIDTH 150
32 #define MIN_LISTBOX_HEIGHT 100
35 \class SalomeApp_LoadStudiesDlg
36 \brief Dialog box which allows selecting study to be loaded
42 \param parent a parent widget
43 \param studies list of study names
45 SalomeApp_LoadStudiesDlg::SalomeApp_LoadStudiesDlg( QWidget* parent, const QStringList& studies )
50 setWindowTitle( tr("DLG_LOAD_STUDY_CAPTION") );
51 setSizeGripEnabled( true );
53 QVBoxLayout* topLayout = new QVBoxLayout( this );
54 topLayout->setMargin( MARGIN_SIZE );
55 topLayout->setSpacing( SPACING_SIZE );
57 QLabel* lab = new QLabel( tr( "MEN_STUDIES_CHOICE" ), this );
59 myButtonOk = new QPushButton( tr( "BUT_OK" ), this );
60 myButtonOk->setAutoDefault( true );
61 myButtonOk->setDefault( true );
63 QPushButton* buttonCancel = new QPushButton( tr( "BUT_CANCEL" ), this );
65 QHBoxLayout* btnLayout = new QHBoxLayout;
66 btnLayout->setSpacing( SPACING_SIZE );
67 btnLayout->setMargin( 0 );
68 btnLayout->addWidget( myButtonOk );
69 btnLayout->addStretch();
70 btnLayout->addWidget( buttonCancel );
72 myList = new QListWidget( this );
73 myList->setMinimumSize( MIN_LISTBOX_WIDTH, MIN_LISTBOX_HEIGHT );
74 myList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding,
75 QSizePolicy::Expanding ) );
76 myList->setSelectionMode( QAbstractItemView::SingleSelection );
78 topLayout->addWidget( lab );
79 topLayout->addWidget( myList );
80 topLayout->addLayout( btnLayout );
82 connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
83 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
84 connect( myList, SIGNAL( itemDoubleClicked( QListWidgetItem* ) ),
85 this, SLOT( accept() ) );
86 connect( myList, SIGNAL( itemSelectionChanged() ),
87 this, SLOT( updateState() ) );
88 myList->addItems( studies );
96 SalomeApp_LoadStudiesDlg::~SalomeApp_LoadStudiesDlg()
101 \brief Updates buttons state.
103 void SalomeApp_LoadStudiesDlg::updateState()
105 myButtonOk->setEnabled( myList->currentItem() != 0 );
109 \brief Get selected study name
110 \return selected study name or null string if study is not selected
112 QString SalomeApp_LoadStudiesDlg::selectedStudy()
115 if ( myList->currentItem() )
116 study = myList->currentItem()->text();
121 \brief Executes dialog box to select study from the list
122 and returns the study selected.
123 \param parent parent widget
124 \param studies list of study names
125 \return select study (or null string if dialog box is rejected)
127 QString SalomeApp_LoadStudiesDlg::selectStudy( QWidget* parent, const QStringList& studies )
129 SalomeApp_LoadStudiesDlg dlg( parent, studies );
131 if ( dlg.exec() == QDialog::Accepted )
132 study = dlg.selectedStudy();