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