]> SALOME platform Git repositories - modules/superv.git/blob - src/SUPERVGUI/SUPERVGUI_Notification.cxx
Salome HOME
Merge from OCC_development_generic_2006
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Notification.cxx
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SUPERVGUI_Notification.cxx
25 //  Author : Francis KLOSS
26 //  Module : SUPERV
27
28 #include "SUPERVGUI_Notification.h"
29 #include "SUPERVGUI_Main.h"
30 #include "SUPERVGUI_CanvasNode.h"
31
32 #include "NOTIFICATION.hxx"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_FileDlg.h"
35 #include "SUIT_Session.h"
36
37 #include <qlayout.h>
38 #include <qlabel.h>
39 #include <qgroupbox.h>
40
41 #define SPACING_SIZE   6
42 #define MARGIN_SIZE   11
43 #define MAX( x, y ) ( x ) > ( y ) ? ( x ) : ( y )
44 #define DLG_SIZE_WIDTH   300
45 #define DLG_SIZE_HEIGHT  300
46
47 /******************************************
48  * Notification settings dialog box
49  ******************************************/
50 /*!
51   Constructor
52 */
53 SUPERVGUI_Notification::SUPERVGUI_Notification( SUPERVGUI_Main* m )
54      : QDialog( SUIT_Session::session()->activeApplication()->desktop(), "", TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
55        myMain( m )
56 {
57   setCaption( tr( "TLT_FILTER_NOTIFY" ) );
58   setSizeGripEnabled( TRUE );
59   QVBoxLayout* topLayout = new QVBoxLayout( this ); 
60   topLayout->setSpacing( SPACING_SIZE );
61   topLayout->setMargin( MARGIN_SIZE );
62
63   /* Creating notofication widgets*/
64   /* Top scroll view */
65   myView = new QScrollView( this );
66 //  myView->setMinimumSize( NOTIFICATION_WIDTH, NOTIFICATION_HEIGHT );
67   myBox = new QVBox( myView );
68   myBox->setMargin( MARGIN_SIZE );
69   myBox->setSpacing( SPACING_SIZE );
70   QFrame* lin;
71
72   /* Notification logging */
73   QLabel* logg = new QLabel( tr( "NOTIFICATION_LOGGING_LBL" ), myBox );
74   QFont fnt = logg->font(); fnt.setBold( true ); logg->setFont( fnt );
75   QWidget* dumb = new QWidget( myBox );
76   QHBoxLayout* dumbLayout = new QHBoxLayout( dumb ); dumbLayout->setMargin( 0 ); dumbLayout->setSpacing( SPACING_SIZE );
77   myLogCheck = new QCheckBox( tr( "SAVE_LOG_LBL" ), dumb );
78   myFileEdit = new QLineEdit( dumb ); 
79   myFileEdit->setMinimumSize( 200, 0 );
80   myBrowseBtn = new QPushButton( tr( "BUT_BROWSE"), dumb );
81   dumbLayout->addWidget( myLogCheck );
82   dumbLayout->addWidget( myFileEdit );
83   dumbLayout->addWidget( myBrowseBtn );
84   myFilterCheck = new QCheckBox( tr( "FILTER_LOG_LBL" ), myBox );
85
86   lin = new QFrame( myBox );
87   lin->setFrameStyle( QFrame::HLine | QFrame::Plain );
88
89   /* dataflow notification */
90   myMainNotif = new SUPERVGUI_NotifWidget( myBox, QString( myMain->getDataflow()->Name() ) );
91   myMainNotif->setWarning( false );
92   myMainNotif->setStep( false );
93   myMainNotif->setTrace( false );
94   myMainNotif->setVerbose( false );
95
96   /* nodes notification */
97   QObjectList* ihmList = myMain->/*getGraph()->*/queryList( "SUPERVGUI_CanvasNode" );
98   QObjectListIt i( *ihmList );
99   SUPERVGUI_CanvasNode* theNode;
100   while ( ( theNode = ( ( SUPERVGUI_CanvasNode* )i.current() ) ) != 0) {
101     lin = new QFrame( myBox );
102     lin->setFrameStyle( QFrame::HLine | QFrame::Plain );
103
104     SUPERVGUI_NotifWidget* nw = new SUPERVGUI_NotifWidget( myBox, theNode );
105     nw->setWarning( theNode->isWarning() );
106     nw->setStep( theNode->isStep() );
107     nw->setTrace( theNode->isTrace() );
108     nw->setVerbose( theNode->isVerbose() );
109     myNotifList.append( nw );
110     ++i;
111   };
112   delete ihmList;
113
114   QWidget* dumb1 = new QWidget( myBox );
115   myBox->setStretchFactor( dumb1, 10 );
116
117   myView->addChild( myBox, 0, 0 );
118   myView->setResizePolicy( QScrollView::AutoOneFit );
119
120   int w = myLogCheck->sizeHint().width() + myFileEdit->minimumSize().width() + myBrowseBtn->sizeHint().width() + SPACING_SIZE * 2;
121   w = MAX( w, logg->sizeHint().width() );
122   w = MAX( w, myMainNotif->sizeHint().width() );
123   w = MAX( w, myFilterCheck->sizeHint().width() );
124   myView->setMinimumWidth( w + MARGIN_SIZE * 4 );
125
126   /* OK/Cancel buttons */
127   QGroupBox* GroupButtons = new QGroupBox( this );
128   GroupButtons->setColumnLayout(0, Qt::Vertical );
129   GroupButtons->layout()->setSpacing( 0 );  GroupButtons->layout()->setMargin( 0 );
130   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
131   GroupButtonsLayout->setAlignment( Qt::AlignTop );
132   GroupButtonsLayout->setSpacing( SPACING_SIZE );
133   GroupButtonsLayout->setMargin( MARGIN_SIZE );
134   myOkBtn = new QPushButton( tr( "BUT_OK" ), GroupButtons, "buttonOk" );
135   myOkBtn->setAutoDefault( TRUE );
136   myOkBtn->setDefault( TRUE );
137   GroupButtonsLayout->addWidget( myOkBtn );
138   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
139   myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons, "buttonCancel" );
140   myCancelBtn->setAutoDefault( TRUE );
141   GroupButtonsLayout->addWidget( myCancelBtn );
142
143   topLayout->addWidget( myView );
144   topLayout->addWidget( GroupButtons );
145   
146   connect( myOkBtn,     SIGNAL( clicked() ), this, SLOT( accept() ) );
147   connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
148   connect( myLogCheck,  SIGNAL( clicked() ), this, SLOT( loggedClicked() ) );
149   connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( browseClicked() ) );
150   
151   QString file = QString( "/tmp/Notif_" );
152   file += myMain->getDataflow()->Name();
153   file += ".log";
154   myFileEdit->setText( file );
155
156   loggedClicked();
157   resize( MAX( w + MARGIN_SIZE * 4, DLG_SIZE_WIDTH ), DLG_SIZE_HEIGHT  );
158 }
159
160 /*!
161   Destructor
162 */
163 SUPERVGUI_Notification::~SUPERVGUI_Notification() 
164 {
165 }
166
167 /*!
168   <OK> button slot
169 */
170 void SUPERVGUI_Notification::accept() 
171 {
172   Trace("SUPERVGUI_Notification::accept");
173   for ( int i = 0; i < myNotifList.count(); i++ ) {
174     if ( myNotifList.at( i )->getNode() ) {
175       myNotifList.at( i )->getNode()->setWarning( myNotifList.at( i )->getWarning() );
176       myNotifList.at( i )->getNode()->setStep( myNotifList.at( i )->getStep() );
177       myNotifList.at( i )->getNode()->setTrace( myNotifList.at( i )->getTrace() );
178       myNotifList.at( i )->getNode()->setVerbose( myNotifList.at( i )->getVerbose() );
179     }
180   }
181   QDialog::accept();
182 }
183
184 /*!
185    <Cancel> button slot
186 */
187 void SUPERVGUI_Notification::reject() 
188 {
189   Trace("SUPERVGUI_Notification::reject");
190   QDialog::reject();
191 }
192
193 /*!
194   Called when <Save to file> check box is clicked
195 */
196 void SUPERVGUI_Notification::loggedClicked()
197 {
198   myFileEdit->setEnabled( myLogCheck->isChecked() );
199   myBrowseBtn->setEnabled( myLogCheck->isChecked() );
200   myFilterCheck->setEnabled( myLogCheck->isChecked() );
201 }
202
203 /*!
204   <Browse> button slot
205 */
206 void SUPERVGUI_Notification::browseClicked()
207 {
208   QString fn = SUIT_FileDlg::getFileName( this, 
209                                           myFileEdit->text(), 
210                                           tr( "ALL_FILES" ),
211                                           tr( "CHOOSE_LOG_FILES_TLT" ),
212                                           false );
213   if ( !fn.isEmpty() )
214     myFileEdit->setText( fn );
215 }
216
217 /*!
218   Set/get methods
219 */
220 bool SUPERVGUI_Notification::getLogged() 
221 {
222   return myLogCheck->isChecked();
223 }
224 void SUPERVGUI_Notification::setLogged( bool on, QString logFile ) 
225 {
226   myLogCheck->setChecked( on );
227   if ( !logFile.isNull() ) {
228     myFileEdit->setText( logFile );
229     myFileEdit->home( false ); 
230   } 
231   loggedClicked();
232 }
233 QString SUPERVGUI_Notification::getLogFile() 
234 {
235   return myFileEdit->text().stripWhiteSpace();
236 }
237 bool SUPERVGUI_Notification::getFiltered() 
238 {
239   return myFilterCheck->isChecked();
240 }
241 void SUPERVGUI_Notification::setFiltered( bool on ) 
242 {
243   myFilterCheck->setChecked( on );
244 }
245 bool SUPERVGUI_Notification::getWarning()
246 {
247   return myMainNotif->getWarning();
248 }
249 void SUPERVGUI_Notification::setWarning( bool on )
250 {
251   myMainNotif->setWarning( on );
252 }
253 bool SUPERVGUI_Notification::getStep()
254 {
255   return myMainNotif->getStep();
256 }
257 void SUPERVGUI_Notification::setStep( bool on )
258 {
259   myMainNotif->setStep( on );
260 }
261 bool SUPERVGUI_Notification::getTrace()
262 {
263   return myMainNotif->getTrace();
264 }
265 void SUPERVGUI_Notification::setTrace( bool on )
266 {
267   myMainNotif->setTrace( on );
268 }
269 bool SUPERVGUI_Notification::getVerbose()
270 {
271   return myMainNotif->getVerbose();
272 }
273 void SUPERVGUI_Notification::setVerbose( bool on )
274 {
275   myMainNotif->setVerbose( on );
276 }
277
278 /******************************************
279  * Widget containing title and  checkboxes
280  ******************************************/
281 /*!
282   Constructor
283 */
284 SUPERVGUI_NotifWidget::SUPERVGUI_NotifWidget( QWidget* parent, SUPERVGUI_CanvasNode* n )
285      : QWidget( parent ), myNode ( n )
286 {
287   init();
288 }
289 /*!
290   Another constructor
291 */
292 SUPERVGUI_NotifWidget::SUPERVGUI_NotifWidget( QWidget* parent, QString title )
293      : QWidget( parent ), myNode ( 0 ), myTitle( title )
294 {
295   init();
296 }
297 /*!
298   Destructor
299 */
300 SUPERVGUI_NotifWidget::~SUPERVGUI_NotifWidget()
301 {
302 }
303 /*!
304   Creates widget's layout 
305 */
306 void SUPERVGUI_NotifWidget::init()
307 {
308   QGridLayout* topLayout = new QGridLayout( this );
309   topLayout->setMargin( 0 );
310   topLayout->setSpacing( SPACING_SIZE );
311
312   QLabel* tltLab = new QLabel( this );
313   if ( myNode )
314     tltLab->setText( myNode->name() );
315   else
316     tltLab->setText( myTitle );
317   QFont fnt = tltLab->font(); fnt.setBold( true ); tltLab->setFont( fnt );
318
319   myWarningCheck = new QCheckBox( tr( NOTIF_WARNING ), this );
320   myStepCheck    = new QCheckBox( tr( NOTIF_STEP ),    this );
321   myTraceCheck   = new QCheckBox( tr( NOTIF_TRACE ),   this );
322   myVerboseCheck = new QCheckBox( tr( NOTIF_VERBOSE ), this );
323   
324   topLayout->addMultiCellWidget( tltLab, 0, 0, 0, 4 );
325   topLayout->addWidget( myWarningCheck, 1, 1 );
326   topLayout->addWidget( myStepCheck,    1, 2 );
327   topLayout->addWidget( myTraceCheck,   1, 3 );
328   topLayout->addWidget( myVerboseCheck, 1, 4 );
329   topLayout->addColSpacing( 0, 15 );
330   topLayout->setColStretch( 1, 5 );
331   topLayout->setColStretch( 2, 5 );
332   topLayout->setColStretch( 3, 5 );
333   topLayout->setColStretch( 4, 5 );
334 }
335