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 // File : LightApp_ModuleDlg.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 #include "LightApp_ModuleDlg.h"
28 #include <QPushButton>
29 #include <QGridLayout>
30 #include <QHBoxLayout>
33 \brief Pixmap used as default icon for the module.
36 static const char* const default_icon[] = {
55 "................................................",
56 "................................................",
57 "................................................",
58 "................................................",
59 "................................................",
60 "................########.########.########......",
61 "...............#aaaaaa###aaaaaa###aaaaaa##......",
62 "..............#aaaaaa#b#aaaaaa#b#aaaaaa#c#......",
63 ".............########b########b########cc#......",
64 ".............#dddddd#b#dddddd#b#dddddd#cc#......",
65 "...........########d########d########d#cc#......",
66 "..........#aaaaaa###aaaaaa###aaaaaa##d#cc#......",
67 ".........#aaaaaa#b#aaaaaa#b#aaaaaa#c#d#cc#......",
68 "........########b########e########cc#d#c#.......",
69 "........#dddddd#b#dddddd#e#ffffff#cc#d####......",
70 "......########d########d########f#cc###g##......",
71 ".....#aaaaaa###aaaaaa###hhhhhh##f#cc#gg#c#......",
72 "....#aaaaaa#b#aaaaaa#i#hhhhhh#j#f#cc###cc#......",
73 "...########b########i########jj#f#c#gg#cc#......",
74 "...#kkkkkk#b#kkkkkk#i#llllll#jj#f####g#cc#......",
75 "...#kkkkkk#b#kkkkkk#i#llllll#jj###m##g#cc#......",
76 "...#knnkkk#b#kkkkkk#i#llllll#jj#mm#c#g#cc#......",
77 "...#knnkkk#b#kkkkkk#i#llllll#jj###cc#g#c#.......",
78 "...#kkkkkk#b#kkkkkk#i#llllll#j#dd#cc#g####......",
79 "...#kkkkkk###kkkkkk###llllll####d#cc###g##......",
80 "...########g########g########o##d#cc#gg#c#......",
81 "....#gggggg#b#gggggg#b#oooooo#c#d#cc###cc#......",
82 "...########b########b########cc#d#c#gg#cc#......",
83 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#d####g#cc#......",
84 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###g##g#cc#......",
85 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#gg#c#g#cc#......",
86 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###cc#g#c#.......",
87 "...#kkkkkk#b#kkkkkk#b#kkkkkk#c#gg#cc#g##........",
88 "...#kkkkkk###kkkkkk###kkkkkk####g#cc###.........",
89 "...########g########g########g##g#cc#...........",
90 "....#gggggg#b#gggggg#b#gggggg#c#g#cc#...........",
91 "...########b########b########cc#g#c#............",
92 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#g##.............",
93 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###..............",
94 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#................",
95 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#................",
96 "...#kkkkkk#b#kkkkkk#b#kkkkkk#c#.................",
97 "...#kkkkkk###kkkkkk###kkkkkk##..................",
98 "...########.########.########...................",
99 "................................................",
100 "................................................",
101 "................................................",
102 "................................................"};
105 \class LightApp_ModuleDlg
106 \brief A dialog box allowing to select study operation to be performed
107 on the module activating.
109 The dialog box is shown when the user tries to activate any module
110 while there is no opened study. The dialog box proposes user to select
111 one of the possible operations which should be done before module activating,
112 for example, create new study or open study from the file.
113 The available operations are assigned by adding the buttons with the unique
114 identifier to the dialog box. When the user clicks any operation button,
115 the dialog box sets its identifier as the return code and closes.
117 The typical usage of the dialog box:
119 LightApp_ModuleDlg dlg( desktop() );
120 dlg.addButton( "New study", NewStudyId );
121 dlg.addButton( "Open study...", OpenStudyId );
122 int ret = dlg.exec();
129 // open study from the file
130 // ... show dialog box to choose the file
131 QString fileName = QFileDialog::getOpenFileName( desktop(), "Open File" );
132 if ( !fileName.isEmpty() )
133 openStudy( fileName );
136 // operation is cancelled
146 \param parent parent widget
147 \param component module name
148 \param icon module icon
150 LightApp_ModuleDlg::LightApp_ModuleDlg( QWidget* parent,
151 const QString& component,
152 const QPixmap& icon )
157 QPixmap defaultIcon( default_icon );
158 setWindowTitle( tr( "CAPTION" ) );
161 QLabel* iconLab = new QLabel( this );
162 iconLab->setFrameStyle( QFrame::Box | QFrame::Sunken );
163 iconLab->setMinimumSize( 70, 70 );
164 iconLab->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
165 iconLab->setPixmap( !icon.isNull() ? icon : defaultIcon );
166 iconLab->setScaledContents( false );
167 iconLab->setAlignment( Qt::AlignCenter );
170 QLabel* infoLab = new QLabel( tr ( "DESCRIPTION" ).arg( component ), this );
171 infoLab->setTextFormat( Qt::RichText );
172 infoLab->setAlignment( Qt::AlignCenter );
175 myButtonLayout = new QHBoxLayout();
176 myButtonLayout->setMargin( 0 );
177 myButtonLayout->setSpacing( 6 );
180 QPushButton* cancelBtn = new QPushButton( tr( "CANCEL" ), this );
181 myButtonLayout->addSpacing( 70 );
182 myButtonLayout->addStretch();
183 myButtonLayout->addWidget( cancelBtn );
185 QGridLayout* layout = new QGridLayout( this );
186 layout->setMargin( 11 );
187 layout->setSpacing( 6 );
189 layout->addWidget( iconLab, 0, 0 );
190 layout->addWidget( infoLab, 0, 1 );
191 layout->addLayout( myButtonLayout, 1, 0, 1, 2 );
193 // signals and slots connections
194 connect( cancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
200 LightApp_ModuleDlg::~LightApp_ModuleDlg()
205 \brief Add operation button to the dialog box.
207 If the parameter \a id is equal to -1, then the
208 button identifier is generated automatically.
210 \param button button text
211 \param id button identifier
212 \return button identifier
214 int LightApp_ModuleDlg::addButton( const QString& button, const int id )
216 static int lastId = 0;
217 int bid = id == -1 ? --lastId : id;
219 QPushButton* b = findButton( bid );
221 myButtons.remove( b );
225 QPushButton* newButton = new QPushButton( button, this );
227 if ( myButtons.empty() ) newButton->setDefault( true );
229 myButtons.insert( newButton, bid );
230 myButtonLayout->insertWidget( myButtonLayout->count()-3, newButton );
231 connect( newButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
237 \brief Search button with the specified identifier.
238 \param id button identifier
239 \return button or 0 if \a id is invalid
241 QPushButton* LightApp_ModuleDlg::findButton( const int id ) const
243 QPushButton* btn = 0;
244 for ( ButtonMap::ConstIterator it = myButtons.begin();
245 it != myButtons.end() && !btn; ++it ) {
246 if ( it.value() == id )
253 \brief Called when any dialog button (except \c Cancel)
256 Closes the dialog and sets its result code to the identifier
257 of the button clicked by the user.
259 void LightApp_ModuleDlg::accept()
261 QPushButton* btn = ( QPushButton* )sender();
262 done( myButtons[ btn ] );