Salome HOME
3e94ff7b5266f970db806dbdc20c55299dc86ea8
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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   // mkr : PAL7037 -->
98   //QObjectList* ihmList = myMain->/*getGraph()->*/queryList( "SUPERVGUI_CanvasNode" );
99   QObjectList* ihmList;
100   if ( myMain->getViewType() == CANVASTABLE )
101     ihmList = myMain->getCanvasArray()->queryList( "SUPERVGUI_CanvasNode" );
102   else
103     ihmList = myMain->getCanvas()->queryList( "SUPERVGUI_CanvasNode" );
104   // mkr : PAL7037 <--
105   QObjectListIt i( *ihmList );
106   SUPERVGUI_CanvasNode* theNode;
107   while ( ( theNode = ( ( SUPERVGUI_CanvasNode* )i.current() ) ) != 0) {
108     lin = new QFrame( myBox );
109     lin->setFrameStyle( QFrame::HLine | QFrame::Plain );
110
111     SUPERVGUI_NotifWidget* nw = new SUPERVGUI_NotifWidget( myBox, theNode );
112     nw->setWarning( theNode->isWarning() );
113     nw->setStep( theNode->isStep() );
114     nw->setTrace( theNode->isTrace() );
115     nw->setVerbose( theNode->isVerbose() );
116     myNotifList.append( nw );
117     ++i;
118   };
119   delete ihmList;
120
121   QWidget* dumb1 = new QWidget( myBox );
122   myBox->setStretchFactor( dumb1, 10 );
123
124   myView->addChild( myBox, 0, 0 );
125   myView->setResizePolicy( QScrollView::AutoOneFit );
126
127   int w = myLogCheck->sizeHint().width() + myFileEdit->minimumSize().width() + myBrowseBtn->sizeHint().width() + SPACING_SIZE * 2;
128   w = MAX( w, logg->sizeHint().width() );
129   w = MAX( w, myMainNotif->sizeHint().width() );
130   w = MAX( w, myFilterCheck->sizeHint().width() );
131   myView->setMinimumWidth( w + MARGIN_SIZE * 4 );
132
133   /* OK/Cancel buttons */
134   QGroupBox* GroupButtons = new QGroupBox( this );
135   GroupButtons->setColumnLayout(0, Qt::Vertical );
136   GroupButtons->layout()->setSpacing( 0 );  GroupButtons->layout()->setMargin( 0 );
137   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
138   GroupButtonsLayout->setAlignment( Qt::AlignTop );
139   GroupButtonsLayout->setSpacing( SPACING_SIZE );
140   GroupButtonsLayout->setMargin( MARGIN_SIZE );
141   myOkBtn = new QPushButton( tr( "BUT_OK" ), GroupButtons, "buttonOk" );
142   myOkBtn->setAutoDefault( TRUE );
143   myOkBtn->setDefault( TRUE );
144   GroupButtonsLayout->addWidget( myOkBtn );
145   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
146   myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons, "buttonCancel" );
147   myCancelBtn->setAutoDefault( TRUE );
148   GroupButtonsLayout->addWidget( myCancelBtn );
149
150   topLayout->addWidget( myView );
151   topLayout->addWidget( GroupButtons );
152   
153   connect( myOkBtn,     SIGNAL( clicked() ), this, SLOT( accept() ) );
154   connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
155   connect( myLogCheck,  SIGNAL( clicked() ), this, SLOT( loggedClicked() ) );
156   connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( browseClicked() ) );
157   
158   QString file = QString( "/tmp/Notif_" );
159   file += myMain->getDataflow()->Name();
160   file += ".log";
161   myFileEdit->setText( file );
162
163   loggedClicked();
164   resize( MAX( w + MARGIN_SIZE * 4, DLG_SIZE_WIDTH ), DLG_SIZE_HEIGHT  );
165 }
166
167 /*!
168   Destructor
169 */
170 SUPERVGUI_Notification::~SUPERVGUI_Notification() 
171 {
172 }
173
174 /*!
175   <OK> button slot
176 */
177 void SUPERVGUI_Notification::accept() 
178 {
179   Trace("SUPERVGUI_Notification::accept");
180   for ( int i = 0; i < myNotifList.count(); i++ ) {
181     if ( myNotifList.at( i )->getNode() ) {
182       myNotifList.at( i )->getNode()->setWarning( myNotifList.at( i )->getWarning() );
183       myNotifList.at( i )->getNode()->setStep( myNotifList.at( i )->getStep() );
184       myNotifList.at( i )->getNode()->setTrace( myNotifList.at( i )->getTrace() );
185       myNotifList.at( i )->getNode()->setVerbose( myNotifList.at( i )->getVerbose() );
186     }
187   }
188   QDialog::accept();
189 }
190
191 /*!
192    <Cancel> button slot
193 */
194 void SUPERVGUI_Notification::reject() 
195 {
196   Trace("SUPERVGUI_Notification::reject");
197   QDialog::reject();
198 }
199
200 /*!
201   Called when <Save to file> check box is clicked
202 */
203 void SUPERVGUI_Notification::loggedClicked()
204 {
205   myFileEdit->setEnabled( myLogCheck->isChecked() );
206   myBrowseBtn->setEnabled( myLogCheck->isChecked() );
207   myFilterCheck->setEnabled( myLogCheck->isChecked() );
208 }
209
210 /*!
211   <Browse> button slot
212 */
213 void SUPERVGUI_Notification::browseClicked()
214 {
215   QString fn = SUIT_FileDlg::getFileName( this, 
216                                           myFileEdit->text(), 
217                                           tr( "ALL_FILES" ),
218                                           tr( "CHOOSE_LOG_FILES_TLT" ),
219                                           false );
220   if ( !fn.isEmpty() )
221     myFileEdit->setText( fn );
222 }
223
224 /*!
225   Set/get methods
226 */
227 bool SUPERVGUI_Notification::getLogged() 
228 {
229   return myLogCheck->isChecked();
230 }
231 void SUPERVGUI_Notification::setLogged( bool on, QString logFile ) 
232 {
233   myLogCheck->setChecked( on );
234   if ( !logFile.isNull() ) {
235     myFileEdit->setText( logFile );
236     myFileEdit->home( false ); 
237   } 
238   loggedClicked();
239 }
240 QString SUPERVGUI_Notification::getLogFile() 
241 {
242   return myFileEdit->text().stripWhiteSpace();
243 }
244 bool SUPERVGUI_Notification::getFiltered() 
245 {
246   return myFilterCheck->isChecked();
247 }
248 void SUPERVGUI_Notification::setFiltered( bool on ) 
249 {
250   myFilterCheck->setChecked( on );
251 }
252 bool SUPERVGUI_Notification::getWarning()
253 {
254   return myMainNotif->getWarning();
255 }
256 void SUPERVGUI_Notification::setWarning( bool on )
257 {
258   myMainNotif->setWarning( on );
259 }
260 bool SUPERVGUI_Notification::getStep()
261 {
262   return myMainNotif->getStep();
263 }
264 void SUPERVGUI_Notification::setStep( bool on )
265 {
266   myMainNotif->setStep( on );
267 }
268 bool SUPERVGUI_Notification::getTrace()
269 {
270   return myMainNotif->getTrace();
271 }
272 void SUPERVGUI_Notification::setTrace( bool on )
273 {
274   myMainNotif->setTrace( on );
275 }
276 bool SUPERVGUI_Notification::getVerbose()
277 {
278   return myMainNotif->getVerbose();
279 }
280 void SUPERVGUI_Notification::setVerbose( bool on )
281 {
282   myMainNotif->setVerbose( on );
283 }
284
285 /******************************************
286  * Widget containing title and  checkboxes
287  ******************************************/
288 /*!
289   Constructor
290 */
291 SUPERVGUI_NotifWidget::SUPERVGUI_NotifWidget( QWidget* parent, SUPERVGUI_CanvasNode* n )
292      : QWidget( parent ), myNode ( n )
293 {
294   init();
295 }
296 /*!
297   Another constructor
298 */
299 SUPERVGUI_NotifWidget::SUPERVGUI_NotifWidget( QWidget* parent, QString title )
300      : QWidget( parent ), myNode ( 0 ), myTitle( title )
301 {
302   init();
303 }
304 /*!
305   Destructor
306 */
307 SUPERVGUI_NotifWidget::~SUPERVGUI_NotifWidget()
308 {
309 }
310 /*!
311   Creates widget's layout 
312 */
313 void SUPERVGUI_NotifWidget::init()
314 {
315   QGridLayout* topLayout = new QGridLayout( this );
316   topLayout->setMargin( 0 );
317   topLayout->setSpacing( SPACING_SIZE );
318
319   QLabel* tltLab = new QLabel( this );
320   if ( myNode )
321     tltLab->setText( myNode->name() );
322   else
323     tltLab->setText( myTitle );
324   QFont fnt = tltLab->font(); fnt.setBold( true ); tltLab->setFont( fnt );
325
326   myWarningCheck = new QCheckBox( tr( NOTIF_WARNING ), this );
327   myStepCheck    = new QCheckBox( tr( NOTIF_STEP ),    this );
328   myTraceCheck   = new QCheckBox( tr( NOTIF_TRACE ),   this );
329   myVerboseCheck = new QCheckBox( tr( NOTIF_VERBOSE ), this );
330   
331   topLayout->addMultiCellWidget( tltLab, 0, 0, 0, 4 );
332   topLayout->addWidget( myWarningCheck, 1, 1 );
333   topLayout->addWidget( myStepCheck,    1, 2 );
334   topLayout->addWidget( myTraceCheck,   1, 3 );
335   topLayout->addWidget( myVerboseCheck, 1, 4 );
336   topLayout->addColSpacing( 0, 15 );
337   topLayout->setColStretch( 1, 5 );
338   topLayout->setColStretch( 2, 5 );
339   topLayout->setColStretch( 3, 5 );
340   topLayout->setColStretch( 4, 5 );
341 }
342