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 "QAD_Message.h"
36 #include "QAD_FileDlg.h"
40 #include <qgroupbox.h>
42 #define SPACING_SIZE 6
43 #define MARGIN_SIZE 11
44 #define MAX( x, y ) ( x ) > ( y ) ? ( x ) : ( y )
45 #define DLG_SIZE_WIDTH 300
46 #define DLG_SIZE_HEIGHT 300
48 /******************************************
49 * Notification settings dialog box
50 ******************************************/
54 SUPERVGUI_Notification::SUPERVGUI_Notification( SUPERVGUI_Main* m )
55 : QDialog( QAD_Application::getDesktop(), "", TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
58 setCaption( tr( "TLT_FILTER_NOTIFY" ) );
59 setSizeGripEnabled( TRUE );
60 QVBoxLayout* topLayout = new QVBoxLayout( this );
61 topLayout->setSpacing( SPACING_SIZE );
62 topLayout->setMargin( MARGIN_SIZE );
64 /* Creating notofication widgets*/
66 myView = new QScrollView( this );
67 // myView->setMinimumSize( NOTIFICATION_WIDTH, NOTIFICATION_HEIGHT );
68 myBox = new QVBox( myView );
69 myBox->setMargin( MARGIN_SIZE );
70 myBox->setSpacing( SPACING_SIZE );
73 /* Notification logging */
74 QLabel* logg = new QLabel( tr( "NOTIFICATION_LOGGING_LBL" ), myBox );
75 QFont fnt = logg->font(); fnt.setBold( true ); logg->setFont( fnt );
76 QWidget* dumb = new QWidget( myBox );
77 QHBoxLayout* dumbLayout = new QHBoxLayout( dumb ); dumbLayout->setMargin( 0 ); dumbLayout->setSpacing( SPACING_SIZE );
78 myLogCheck = new QCheckBox( tr( "SAVE_LOG_LBL" ), dumb );
79 myFileEdit = new QLineEdit( dumb );
80 myFileEdit->setMinimumSize( 200, 0 );
81 myBrowseBtn = new QPushButton( tr( "BUT_BROWSE"), dumb );
82 dumbLayout->addWidget( myLogCheck );
83 dumbLayout->addWidget( myFileEdit );
84 dumbLayout->addWidget( myBrowseBtn );
85 myFilterCheck = new QCheckBox( tr( "FILTER_LOG_LBL" ), myBox );
87 lin = new QFrame( myBox );
88 lin->setFrameStyle( QFrame::HLine | QFrame::Plain );
90 /* dataflow notification */
91 myMainNotif = new SUPERVGUI_NotifWidget( myBox, QString( myMain->getDataflow()->Name() ) );
92 myMainNotif->setWarning( false );
93 myMainNotif->setStep( false );
94 myMainNotif->setTrace( false );
95 myMainNotif->setVerbose( false );
97 /* nodes notification */
98 QObjectList* ihmList = myMain->/*getGraph()->*/queryList( "SUPERVGUI_CanvasNode" );
99 QObjectListIt i( *ihmList );
100 SUPERVGUI_CanvasNode* theNode;
101 while ( ( theNode = ( ( SUPERVGUI_CanvasNode* )i.current() ) ) != 0) {
102 lin = new QFrame( myBox );
103 lin->setFrameStyle( QFrame::HLine | QFrame::Plain );
105 SUPERVGUI_NotifWidget* nw = new SUPERVGUI_NotifWidget( myBox, theNode );
106 nw->setWarning( theNode->isWarning() );
107 nw->setStep( theNode->isStep() );
108 nw->setTrace( theNode->isTrace() );
109 nw->setVerbose( theNode->isVerbose() );
110 myNotifList.append( nw );
115 QWidget* dumb1 = new QWidget( myBox );
116 myBox->setStretchFactor( dumb1, 10 );
118 myView->addChild( myBox, 0, 0 );
119 myView->setResizePolicy( QScrollView::AutoOneFit );
121 int w = myLogCheck->sizeHint().width() + myFileEdit->minimumSize().width() + myBrowseBtn->sizeHint().width() + SPACING_SIZE * 2;
122 w = MAX( w, logg->sizeHint().width() );
123 w = MAX( w, myMainNotif->sizeHint().width() );
124 w = MAX( w, myFilterCheck->sizeHint().width() );
125 myView->setMinimumWidth( w + MARGIN_SIZE * 4 );
127 /* OK/Cancel buttons */
128 QGroupBox* GroupButtons = new QGroupBox( this );
129 GroupButtons->setColumnLayout(0, Qt::Vertical );
130 GroupButtons->layout()->setSpacing( 0 ); GroupButtons->layout()->setMargin( 0 );
131 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
132 GroupButtonsLayout->setAlignment( Qt::AlignTop );
133 GroupButtonsLayout->setSpacing( SPACING_SIZE );
134 GroupButtonsLayout->setMargin( MARGIN_SIZE );
135 myOkBtn = new QPushButton( tr( "BUT_OK" ), GroupButtons, "buttonOk" );
136 myOkBtn->setAutoDefault( TRUE );
137 myOkBtn->setDefault( TRUE );
138 GroupButtonsLayout->addWidget( myOkBtn );
139 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
140 myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons, "buttonCancel" );
141 myCancelBtn->setAutoDefault( TRUE );
142 GroupButtonsLayout->addWidget( myCancelBtn );
144 topLayout->addWidget( myView );
145 topLayout->addWidget( GroupButtons );
147 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
148 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
149 connect( myLogCheck, SIGNAL( clicked() ), this, SLOT( loggedClicked() ) );
150 connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( browseClicked() ) );
152 QString file = QString( "/tmp/Notif_" );
153 file += myMain->getDataflow()->Name();
155 myFileEdit->setText( file );
158 resize( MAX( w + MARGIN_SIZE * 4, DLG_SIZE_WIDTH ), DLG_SIZE_HEIGHT );
164 SUPERVGUI_Notification::~SUPERVGUI_Notification()
171 void SUPERVGUI_Notification::accept()
173 Trace("SUPERVGUI_Notification::accept");
174 for ( int i = 0; i < myNotifList.count(); i++ ) {
175 if ( myNotifList.at( i )->getNode() ) {
176 myNotifList.at( i )->getNode()->setWarning( myNotifList.at( i )->getWarning() );
177 myNotifList.at( i )->getNode()->setStep( myNotifList.at( i )->getStep() );
178 myNotifList.at( i )->getNode()->setTrace( myNotifList.at( i )->getTrace() );
179 myNotifList.at( i )->getNode()->setVerbose( myNotifList.at( i )->getVerbose() );
188 void SUPERVGUI_Notification::reject()
190 Trace("SUPERVGUI_Notification::reject");
195 Called when <Save to file> check box is clicked
197 void SUPERVGUI_Notification::loggedClicked()
199 myFileEdit->setEnabled( myLogCheck->isChecked() );
200 myBrowseBtn->setEnabled( myLogCheck->isChecked() );
201 myFilterCheck->setEnabled( myLogCheck->isChecked() );
207 void SUPERVGUI_Notification::browseClicked()
209 QString fn = QAD_FileDlg::getFileName( this,
212 tr( "CHOOSE_LOG_FILES_TLT" ),
215 myFileEdit->setText( fn );
221 bool SUPERVGUI_Notification::getLogged()
223 return myLogCheck->isChecked();
225 void SUPERVGUI_Notification::setLogged( bool on, QString logFile )
227 myLogCheck->setChecked( on );
228 if ( !logFile.isNull() ) {
229 myFileEdit->setText( logFile );
230 myFileEdit->home( false );
234 QString SUPERVGUI_Notification::getLogFile()
236 return myFileEdit->text().stripWhiteSpace();
238 bool SUPERVGUI_Notification::getFiltered()
240 return myFilterCheck->isChecked();
242 void SUPERVGUI_Notification::setFiltered( bool on )
244 myFilterCheck->setChecked( on );
246 bool SUPERVGUI_Notification::getWarning()
248 return myMainNotif->getWarning();
250 void SUPERVGUI_Notification::setWarning( bool on )
252 myMainNotif->setWarning( on );
254 bool SUPERVGUI_Notification::getStep()
256 return myMainNotif->getStep();
258 void SUPERVGUI_Notification::setStep( bool on )
260 myMainNotif->setStep( on );
262 bool SUPERVGUI_Notification::getTrace()
264 return myMainNotif->getTrace();
266 void SUPERVGUI_Notification::setTrace( bool on )
268 myMainNotif->setTrace( on );
270 bool SUPERVGUI_Notification::getVerbose()
272 return myMainNotif->getVerbose();
274 void SUPERVGUI_Notification::setVerbose( bool on )
276 myMainNotif->setVerbose( on );
279 /******************************************
280 * Widget containing title and checkboxes
281 ******************************************/
285 SUPERVGUI_NotifWidget::SUPERVGUI_NotifWidget( QWidget* parent, SUPERVGUI_CanvasNode* n )
286 : QWidget( parent ), myNode ( n )
293 SUPERVGUI_NotifWidget::SUPERVGUI_NotifWidget( QWidget* parent, QString title )
294 : QWidget( parent ), myNode ( 0 ), myTitle( title )
301 SUPERVGUI_NotifWidget::~SUPERVGUI_NotifWidget()
305 Creates widget's layout
307 void SUPERVGUI_NotifWidget::init()
309 QGridLayout* topLayout = new QGridLayout( this );
310 topLayout->setMargin( 0 );
311 topLayout->setSpacing( SPACING_SIZE );
313 QLabel* tltLab = new QLabel( this );
315 tltLab->setText( myNode->name() );
317 tltLab->setText( myTitle );
318 QFont fnt = tltLab->font(); fnt.setBold( true ); tltLab->setFont( fnt );
320 myWarningCheck = new QCheckBox( tr( NOTIF_WARNING ), this );
321 myStepCheck = new QCheckBox( tr( NOTIF_STEP ), this );
322 myTraceCheck = new QCheckBox( tr( NOTIF_TRACE ), this );
323 myVerboseCheck = new QCheckBox( tr( NOTIF_VERBOSE ), this );
325 topLayout->addMultiCellWidget( tltLab, 0, 0, 0, 4 );
326 topLayout->addWidget( myWarningCheck, 1, 1 );
327 topLayout->addWidget( myStepCheck, 1, 2 );
328 topLayout->addWidget( myTraceCheck, 1, 3 );
329 topLayout->addWidget( myVerboseCheck, 1, 4 );
330 topLayout->addColSpacing( 0, 15 );
331 topLayout->setColStretch( 1, 5 );
332 topLayout->setColStretch( 2, 5 );
333 topLayout->setColStretch( 3, 5 );
334 topLayout->setColStretch( 4, 5 );