1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SUPERVGUI_Notification.cxx
25 // Author : Francis KLOSS
30 #include "SUPERVGUI_Notification.h"
31 #include "SUPERVGUI_Main.h"
32 #include "SUPERVGUI_CanvasNode.h"
34 #include "NOTIFICATION.hxx"
35 #include "SUIT_Desktop.h"
36 #include "SUIT_FileDlg.h"
37 #include "SUIT_Session.h"
41 #include <qgroupbox.h>
43 #define SPACING_SIZE 6
44 #define MARGIN_SIZE 11
45 #define MAX( x, y ) ( x ) > ( y ) ? ( x ) : ( y )
46 #define DLG_SIZE_WIDTH 300
47 #define DLG_SIZE_HEIGHT 300
49 /******************************************
50 * Notification settings dialog box
51 ******************************************/
55 SUPERVGUI_Notification::SUPERVGUI_Notification( SUPERVGUI_Main* m )
56 : QDialog( SUIT_Session::session()->activeApplication()->desktop(), "", TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
59 setCaption( tr( "TLT_FILTER_NOTIFY" ) );
60 setSizeGripEnabled( TRUE );
61 QVBoxLayout* topLayout = new QVBoxLayout( this );
62 topLayout->setSpacing( SPACING_SIZE );
63 topLayout->setMargin( MARGIN_SIZE );
65 /* Creating notofication widgets*/
67 myView = new QScrollView( this );
68 // myView->setMinimumSize( NOTIFICATION_WIDTH, NOTIFICATION_HEIGHT );
69 myBox = new QVBox( myView );
70 myBox->setMargin( MARGIN_SIZE );
71 myBox->setSpacing( SPACING_SIZE );
74 /* Notification logging */
75 QLabel* logg = new QLabel( tr( "NOTIFICATION_LOGGING_LBL" ), myBox );
76 QFont fnt = logg->font(); fnt.setBold( true ); logg->setFont( fnt );
77 QWidget* dumb = new QWidget( myBox );
78 QHBoxLayout* dumbLayout = new QHBoxLayout( dumb ); dumbLayout->setMargin( 0 ); dumbLayout->setSpacing( SPACING_SIZE );
79 myLogCheck = new QCheckBox( tr( "SAVE_LOG_LBL" ), dumb );
80 myFileEdit = new QLineEdit( dumb );
81 myFileEdit->setMinimumSize( 200, 0 );
82 myBrowseBtn = new QPushButton( tr( "BUT_BROWSE"), dumb );
83 dumbLayout->addWidget( myLogCheck );
84 dumbLayout->addWidget( myFileEdit );
85 dumbLayout->addWidget( myBrowseBtn );
86 myFilterCheck = new QCheckBox( tr( "FILTER_LOG_LBL" ), myBox );
88 lin = new QFrame( myBox );
89 lin->setFrameStyle( QFrame::HLine | QFrame::Plain );
91 /* dataflow notification */
92 myMainNotif = new SUPERVGUI_NotifWidget( myBox, QString( myMain->getDataflow()->Name() ) );
93 myMainNotif->setWarning( false );
94 myMainNotif->setStep( false );
95 myMainNotif->setTrace( false );
96 myMainNotif->setVerbose( false );
98 /* nodes notification */
99 QObjectList* ihmList = myMain->/*getGraph()->*/queryList( "SUPERVGUI_CanvasNode" );
100 QObjectListIt i( *ihmList );
101 SUPERVGUI_CanvasNode* theNode;
102 while ( ( theNode = ( ( SUPERVGUI_CanvasNode* )i.current() ) ) != 0) {
103 lin = new QFrame( myBox );
104 lin->setFrameStyle( QFrame::HLine | QFrame::Plain );
106 SUPERVGUI_NotifWidget* nw = new SUPERVGUI_NotifWidget( myBox, theNode );
107 nw->setWarning( theNode->isWarning() );
108 nw->setStep( theNode->isStep() );
109 nw->setTrace( theNode->isTrace() );
110 nw->setVerbose( theNode->isVerbose() );
111 myNotifList.append( nw );
116 QWidget* dumb1 = new QWidget( myBox );
117 myBox->setStretchFactor( dumb1, 10 );
119 myView->addChild( myBox, 0, 0 );
120 myView->setResizePolicy( QScrollView::AutoOneFit );
122 int w = myLogCheck->sizeHint().width() + myFileEdit->minimumSize().width() + myBrowseBtn->sizeHint().width() + SPACING_SIZE * 2;
123 w = MAX( w, logg->sizeHint().width() );
124 w = MAX( w, myMainNotif->sizeHint().width() );
125 w = MAX( w, myFilterCheck->sizeHint().width() );
126 myView->setMinimumWidth( w + MARGIN_SIZE * 4 );
128 /* OK/Cancel buttons */
129 QGroupBox* GroupButtons = new QGroupBox( this );
130 GroupButtons->setColumnLayout(0, Qt::Vertical );
131 GroupButtons->layout()->setSpacing( 0 ); GroupButtons->layout()->setMargin( 0 );
132 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
133 GroupButtonsLayout->setAlignment( Qt::AlignTop );
134 GroupButtonsLayout->setSpacing( SPACING_SIZE );
135 GroupButtonsLayout->setMargin( MARGIN_SIZE );
136 myOkBtn = new QPushButton( tr( "BUT_OK" ), GroupButtons, "buttonOk" );
137 myOkBtn->setAutoDefault( TRUE );
138 myOkBtn->setDefault( TRUE );
139 GroupButtonsLayout->addWidget( myOkBtn );
140 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
141 myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons, "buttonCancel" );
142 myCancelBtn->setAutoDefault( TRUE );
143 GroupButtonsLayout->addWidget( myCancelBtn );
145 topLayout->addWidget( myView );
146 topLayout->addWidget( GroupButtons );
148 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
149 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
150 connect( myLogCheck, SIGNAL( clicked() ), this, SLOT( loggedClicked() ) );
151 connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( browseClicked() ) );
153 QString file = QString( "/tmp/Notif_" );
154 file += myMain->getDataflow()->Name();
156 myFileEdit->setText( file );
159 resize( MAX( w + MARGIN_SIZE * 4, DLG_SIZE_WIDTH ), DLG_SIZE_HEIGHT );
165 SUPERVGUI_Notification::~SUPERVGUI_Notification()
172 void SUPERVGUI_Notification::accept()
174 Trace("SUPERVGUI_Notification::accept");
175 for ( int i = 0; i < myNotifList.count(); i++ ) {
176 if ( myNotifList.at( i )->getNode() ) {
177 myNotifList.at( i )->getNode()->setWarning( myNotifList.at( i )->getWarning() );
178 myNotifList.at( i )->getNode()->setStep( myNotifList.at( i )->getStep() );
179 myNotifList.at( i )->getNode()->setTrace( myNotifList.at( i )->getTrace() );
180 myNotifList.at( i )->getNode()->setVerbose( myNotifList.at( i )->getVerbose() );
189 void SUPERVGUI_Notification::reject()
191 Trace("SUPERVGUI_Notification::reject");
196 Called when <Save to file> check box is clicked
198 void SUPERVGUI_Notification::loggedClicked()
200 myFileEdit->setEnabled( myLogCheck->isChecked() );
201 myBrowseBtn->setEnabled( myLogCheck->isChecked() );
202 myFilterCheck->setEnabled( myLogCheck->isChecked() );
208 void SUPERVGUI_Notification::browseClicked()
210 QString fn = SUIT_FileDlg::getFileName( this,
213 tr( "CHOOSE_LOG_FILES_TLT" ),
216 myFileEdit->setText( fn );
222 bool SUPERVGUI_Notification::getLogged()
224 return myLogCheck->isChecked();
226 void SUPERVGUI_Notification::setLogged( bool on, QString logFile )
228 myLogCheck->setChecked( on );
229 if ( !logFile.isNull() ) {
230 myFileEdit->setText( logFile );
231 myFileEdit->home( false );
235 QString SUPERVGUI_Notification::getLogFile()
237 return myFileEdit->text().stripWhiteSpace();
239 bool SUPERVGUI_Notification::getFiltered()
241 return myFilterCheck->isChecked();
243 void SUPERVGUI_Notification::setFiltered( bool on )
245 myFilterCheck->setChecked( on );
247 bool SUPERVGUI_Notification::getWarning()
249 return myMainNotif->getWarning();
251 void SUPERVGUI_Notification::setWarning( bool on )
253 myMainNotif->setWarning( on );
255 bool SUPERVGUI_Notification::getStep()
257 return myMainNotif->getStep();
259 void SUPERVGUI_Notification::setStep( bool on )
261 myMainNotif->setStep( on );
263 bool SUPERVGUI_Notification::getTrace()
265 return myMainNotif->getTrace();
267 void SUPERVGUI_Notification::setTrace( bool on )
269 myMainNotif->setTrace( on );
271 bool SUPERVGUI_Notification::getVerbose()
273 return myMainNotif->getVerbose();
275 void SUPERVGUI_Notification::setVerbose( bool on )
277 myMainNotif->setVerbose( on );
280 /******************************************
281 * Widget containing title and checkboxes
282 ******************************************/
286 SUPERVGUI_NotifWidget::SUPERVGUI_NotifWidget( QWidget* parent, SUPERVGUI_CanvasNode* n )
287 : QWidget( parent ), myNode ( n )
294 SUPERVGUI_NotifWidget::SUPERVGUI_NotifWidget( QWidget* parent, QString title )
295 : QWidget( parent ), myNode ( 0 ), myTitle( title )
302 SUPERVGUI_NotifWidget::~SUPERVGUI_NotifWidget()
306 Creates widget's layout
308 void SUPERVGUI_NotifWidget::init()
310 QGridLayout* topLayout = new QGridLayout( this );
311 topLayout->setMargin( 0 );
312 topLayout->setSpacing( SPACING_SIZE );
314 QLabel* tltLab = new QLabel( this );
316 tltLab->setText( myNode->name() );
318 tltLab->setText( myTitle );
319 QFont fnt = tltLab->font(); fnt.setBold( true ); tltLab->setFont( fnt );
321 myWarningCheck = new QCheckBox( tr( NOTIF_WARNING ), this );
322 myStepCheck = new QCheckBox( tr( NOTIF_STEP ), this );
323 myTraceCheck = new QCheckBox( tr( NOTIF_TRACE ), this );
324 myVerboseCheck = new QCheckBox( tr( NOTIF_VERBOSE ), this );
326 topLayout->addMultiCellWidget( tltLab, 0, 0, 0, 4 );
327 topLayout->addWidget( myWarningCheck, 1, 1 );
328 topLayout->addWidget( myStepCheck, 1, 2 );
329 topLayout->addWidget( myTraceCheck, 1, 3 );
330 topLayout->addWidget( myVerboseCheck, 1, 4 );
331 topLayout->addColSpacing( 0, 15 );
332 topLayout->setColStretch( 1, 5 );
333 topLayout->setColStretch( 2, 5 );
334 topLayout->setColStretch( 3, 5 );
335 topLayout->setColStretch( 4, 5 );