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
28 #include "SUPERVGUI_Notification.h"
29 #include "SUPERVGUI_Main.h"
30 #include "SUPERVGUI_CanvasNode.h"
32 #include "NOTIFICATION.hxx"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_FileDlg.h"
35 #include "SUIT_Session.h"
39 #include <qgroupbox.h>
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
47 /******************************************
48 * Notification settings dialog box
49 ******************************************/
53 SUPERVGUI_Notification::SUPERVGUI_Notification( SUPERVGUI_Main* m )
54 : QDialog( SUIT_Session::session()->activeApplication()->desktop(), "", TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
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 );
63 /* Creating notofication widgets*/
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 );
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 );
86 lin = new QFrame( myBox );
87 lin->setFrameStyle( QFrame::HLine | QFrame::Plain );
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 );
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 );
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 );
114 QWidget* dumb1 = new QWidget( myBox );
115 myBox->setStretchFactor( dumb1, 10 );
117 myView->addChild( myBox, 0, 0 );
118 myView->setResizePolicy( QScrollView::AutoOneFit );
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 );
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 );
143 topLayout->addWidget( myView );
144 topLayout->addWidget( GroupButtons );
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() ) );
151 QString file = QString( "/tmp/Notif_" );
152 file += myMain->getDataflow()->Name();
154 myFileEdit->setText( file );
157 resize( MAX( w + MARGIN_SIZE * 4, DLG_SIZE_WIDTH ), DLG_SIZE_HEIGHT );
163 SUPERVGUI_Notification::~SUPERVGUI_Notification()
170 void SUPERVGUI_Notification::accept()
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() );
187 void SUPERVGUI_Notification::reject()
189 Trace("SUPERVGUI_Notification::reject");
194 Called when <Save to file> check box is clicked
196 void SUPERVGUI_Notification::loggedClicked()
198 myFileEdit->setEnabled( myLogCheck->isChecked() );
199 myBrowseBtn->setEnabled( myLogCheck->isChecked() );
200 myFilterCheck->setEnabled( myLogCheck->isChecked() );
206 void SUPERVGUI_Notification::browseClicked()
208 QString fn = SUIT_FileDlg::getFileName( this,
211 tr( "CHOOSE_LOG_FILES_TLT" ),
214 myFileEdit->setText( fn );
220 bool SUPERVGUI_Notification::getLogged()
222 return myLogCheck->isChecked();
224 void SUPERVGUI_Notification::setLogged( bool on, QString logFile )
226 myLogCheck->setChecked( on );
227 if ( !logFile.isNull() ) {
228 myFileEdit->setText( logFile );
229 myFileEdit->home( false );
233 QString SUPERVGUI_Notification::getLogFile()
235 return myFileEdit->text().stripWhiteSpace();
237 bool SUPERVGUI_Notification::getFiltered()
239 return myFilterCheck->isChecked();
241 void SUPERVGUI_Notification::setFiltered( bool on )
243 myFilterCheck->setChecked( on );
245 bool SUPERVGUI_Notification::getWarning()
247 return myMainNotif->getWarning();
249 void SUPERVGUI_Notification::setWarning( bool on )
251 myMainNotif->setWarning( on );
253 bool SUPERVGUI_Notification::getStep()
255 return myMainNotif->getStep();
257 void SUPERVGUI_Notification::setStep( bool on )
259 myMainNotif->setStep( on );
261 bool SUPERVGUI_Notification::getTrace()
263 return myMainNotif->getTrace();
265 void SUPERVGUI_Notification::setTrace( bool on )
267 myMainNotif->setTrace( on );
269 bool SUPERVGUI_Notification::getVerbose()
271 return myMainNotif->getVerbose();
273 void SUPERVGUI_Notification::setVerbose( bool on )
275 myMainNotif->setVerbose( on );
278 /******************************************
279 * Widget containing title and checkboxes
280 ******************************************/
284 SUPERVGUI_NotifWidget::SUPERVGUI_NotifWidget( QWidget* parent, SUPERVGUI_CanvasNode* n )
285 : QWidget( parent ), myNode ( n )
292 SUPERVGUI_NotifWidget::SUPERVGUI_NotifWidget( QWidget* parent, QString title )
293 : QWidget( parent ), myNode ( 0 ), myTitle( title )
300 SUPERVGUI_NotifWidget::~SUPERVGUI_NotifWidget()
304 Creates widget's layout
306 void SUPERVGUI_NotifWidget::init()
308 QGridLayout* topLayout = new QGridLayout( this );
309 topLayout->setMargin( 0 );
310 topLayout->setSpacing( SPACING_SIZE );
312 QLabel* tltLab = new QLabel( this );
314 tltLab->setText( myNode->name() );
316 tltLab->setText( myTitle );
317 QFont fnt = tltLab->font(); fnt.setBold( true ); tltLab->setFont( fnt );
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 );
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 );