1 // Copyright (C) 2007-2024 CEA, EDF, 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, or (at your option) any later version.
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
23 // File : LightApp_ModuleDlg.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #include "LightApp_ModuleDlg.h"
29 #include <QPushButton>
30 #include <QGridLayout>
31 #include <QHBoxLayout>
34 \brief Pixmap used as default icon for the module.
37 static const char* const default_icon[] = {
56 "................................................",
57 "................................................",
58 "................................................",
59 "................................................",
60 "................................................",
61 "................########.########.########......",
62 "...............#aaaaaa###aaaaaa###aaaaaa##......",
63 "..............#aaaaaa#b#aaaaaa#b#aaaaaa#c#......",
64 ".............########b########b########cc#......",
65 ".............#dddddd#b#dddddd#b#dddddd#cc#......",
66 "...........########d########d########d#cc#......",
67 "..........#aaaaaa###aaaaaa###aaaaaa##d#cc#......",
68 ".........#aaaaaa#b#aaaaaa#b#aaaaaa#c#d#cc#......",
69 "........########b########e########cc#d#c#.......",
70 "........#dddddd#b#dddddd#e#ffffff#cc#d####......",
71 "......########d########d########f#cc###g##......",
72 ".....#aaaaaa###aaaaaa###hhhhhh##f#cc#gg#c#......",
73 "....#aaaaaa#b#aaaaaa#i#hhhhhh#j#f#cc###cc#......",
74 "...########b########i########jj#f#c#gg#cc#......",
75 "...#kkkkkk#b#kkkkkk#i#llllll#jj#f####g#cc#......",
76 "...#kkkkkk#b#kkkkkk#i#llllll#jj###m##g#cc#......",
77 "...#knnkkk#b#kkkkkk#i#llllll#jj#mm#c#g#cc#......",
78 "...#knnkkk#b#kkkkkk#i#llllll#jj###cc#g#c#.......",
79 "...#kkkkkk#b#kkkkkk#i#llllll#j#dd#cc#g####......",
80 "...#kkkkkk###kkkkkk###llllll####d#cc###g##......",
81 "...########g########g########o##d#cc#gg#c#......",
82 "....#gggggg#b#gggggg#b#oooooo#c#d#cc###cc#......",
83 "...########b########b########cc#d#c#gg#cc#......",
84 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#d####g#cc#......",
85 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###g##g#cc#......",
86 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#gg#c#g#cc#......",
87 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###cc#g#c#.......",
88 "...#kkkkkk#b#kkkkkk#b#kkkkkk#c#gg#cc#g##........",
89 "...#kkkkkk###kkkkkk###kkkkkk####g#cc###.........",
90 "...########g########g########g##g#cc#...........",
91 "....#gggggg#b#gggggg#b#gggggg#c#g#cc#...........",
92 "...########b########b########cc#g#c#............",
93 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#g##.............",
94 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###..............",
95 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#................",
96 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#................",
97 "...#kkkkkk#b#kkkkkk#b#kkkkkk#c#.................",
98 "...#kkkkkk###kkkkkk###kkkkkk##..................",
99 "...########.########.########...................",
100 "................................................",
101 "................................................",
102 "................................................",
103 "................................................"};
106 \class LightApp_ModuleDlg
107 \brief A dialog box allowing to select study operation to be performed
108 on the module activating.
110 The dialog box is shown when the user tries to activate any module
111 while there is no opened study. The dialog box proposes user to select
112 one of the possible operations which should be done before module activating,
113 for example, create new study or open study from the file.
114 The available operations are assigned by adding the buttons with the unique
115 identifier to the dialog box. When the user clicks any operation button,
116 the dialog box sets its identifier as the return code and closes.
118 The typical usage of the dialog box:
120 LightApp_ModuleDlg dlg( desktop() );
121 dlg.addButton( "New study", NewStudyId );
122 dlg.addButton( "Open study...", OpenStudyId );
123 int ret = dlg.exec();
130 // open study from the file
131 // ... show dialog box to choose the file
132 QString fileName = QFileDialog::getOpenFileName( desktop(), "Open File" );
133 if ( !fileName.isEmpty() )
134 openStudy( fileName );
137 // operation is cancelled
147 \param parent parent widget
148 \param component module name
149 \param icon module icon
151 LightApp_ModuleDlg::LightApp_ModuleDlg( QWidget* parent,
152 const QString& component,
153 const QPixmap& icon )
158 QPixmap defaultIcon( default_icon );
159 setWindowTitle( tr( "CAPTION" ) );
162 QLabel* iconLab = new QLabel( this );
163 iconLab->setFrameStyle( QFrame::Box | QFrame::Sunken );
164 iconLab->setMinimumSize( 70, 70 );
165 iconLab->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
166 iconLab->setPixmap( !icon.isNull() ? icon : defaultIcon );
167 iconLab->setScaledContents( false );
168 iconLab->setAlignment( Qt::AlignCenter );
171 QLabel* infoLab = new QLabel( tr ( "DESCRIPTION" ).arg( component ), this );
172 infoLab->setTextFormat( Qt::RichText );
173 infoLab->setAlignment( Qt::AlignCenter );
176 myButtonLayout = new QHBoxLayout();
177 myButtonLayout->setMargin( 0 );
178 myButtonLayout->setSpacing( 6 );
181 QPushButton* cancelBtn = new QPushButton( tr( "CANCEL" ), this );
182 cancelBtn->setAutoDefault( true );
184 myButtonLayout->addSpacing( 70 );
185 myButtonLayout->addStretch();
186 myButtonLayout->addWidget( cancelBtn );
188 QGridLayout* layout = new QGridLayout( this );
189 layout->setMargin( 11 );
190 layout->setSpacing( 6 );
192 layout->addWidget( iconLab, 0, 0 );
193 layout->addWidget( infoLab, 0, 1 );
194 layout->addLayout( myButtonLayout, 1, 0, 1, 2 );
196 // signals and slots connections
197 connect( cancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
203 LightApp_ModuleDlg::~LightApp_ModuleDlg()
208 \brief Add operation button to the dialog box.
210 If the parameter \a id is equal to -1, then the
211 button identifier is generated automatically.
213 \param button button text
214 \param id button identifier
215 \return button identifier
217 int LightApp_ModuleDlg::addButton( const QString& button, const int id )
219 static int lastId = 0;
220 int bid = id == -1 ? --lastId : id;
222 QPushButton* b = findButton( bid );
224 myButtons.remove( b );
228 QPushButton* newButton = new QPushButton( button, this );
229 newButton->setAutoDefault( true );
231 if ( myButtons.empty() ) {
232 newButton->setDefault( true );
233 newButton->setFocus();
236 myButtons.insert( newButton, bid );
237 myButtonLayout->insertWidget( myButtonLayout->count()-3, newButton );
238 connect( newButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
244 \brief Search button with the specified identifier.
245 \param id button identifier
246 \return button or 0 if \a id is invalid
248 QPushButton* LightApp_ModuleDlg::findButton( const int id ) const
250 QPushButton* btn = 0;
251 for ( ButtonMap::ConstIterator it = myButtons.begin();
252 it != myButtons.end() && !btn; ++it ) {
253 if ( it.value() == id )
260 \brief Called when any dialog button (except \c Cancel)
263 Closes the dialog and sets its result code to the identifier
264 of the button clicked by the user.
266 void LightApp_ModuleDlg::accept()
268 QPushButton* btn = ( QPushButton* )sender();
269 done( myButtons[ btn ] );