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
29 #include "SUPERVGUI_Notification.h"
30 #include "QAD_Message.h"
31 #include "QAD_FileDlg.h"
32 #include "SUPERVGUI_Node.h"
33 #include "SUPERVGUI_Main.h"
34 #include "NOTIFICATION.hxx"
37 #include <qgroupbox.h>
39 #define SPACING_SIZE 6
40 #define MARGIN_SIZE 11
41 #define MAX( x, y ) ( x ) > ( y ) ? ( x ) : ( y )
42 #define DLG_SIZE_WIDTH 300
43 #define DLG_SIZE_HEIGHT 300
45 /******************************************
46 * Notification settings dialog box
47 ******************************************/
51 SUPERVGUI_Notification::SUPERVGUI_Notification( SUPERVGUI_Main* m )
52 : QDialog( QAD_Application::getDesktop(), "", TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
55 setCaption( tr( "TLT_FILTER_NOTIFY" ) );
56 setSizeGripEnabled( TRUE );
57 QVBoxLayout* topLayout = new QVBoxLayout( this );
58 topLayout->setSpacing( SPACING_SIZE );
59 topLayout->setMargin( MARGIN_SIZE );
61 /* Creating notofication widgets*/
63 myView = new QScrollView( this );
64 // myView->setMinimumSize( NOTIFICATION_WIDTH, NOTIFICATION_HEIGHT );
65 myBox = new QVBox( myView );
66 myBox->setMargin( MARGIN_SIZE );
67 myBox->setSpacing( SPACING_SIZE );
70 /* Notification logging */
71 QLabel* logg = new QLabel( tr( "NOTIFICATION_LOGGING_LBL" ), myBox );
72 QFont fnt = logg->font(); fnt.setBold( true ); logg->setFont( fnt );
73 QWidget* dumb = new QWidget( myBox );
74 QHBoxLayout* dumbLayout = new QHBoxLayout( dumb ); dumbLayout->setMargin( 0 ); dumbLayout->setSpacing( SPACING_SIZE );
75 myLogCheck = new QCheckBox( tr( "SAVE_LOG_LBL" ), dumb );
76 myFileEdit = new QLineEdit( dumb );
77 myFileEdit->setMinimumSize( 200, 0 );
78 myBrowseBtn = new QPushButton( tr( "BUT_BROWSE"), dumb );
79 dumbLayout->addWidget( myLogCheck );
80 dumbLayout->addWidget( myFileEdit );
81 dumbLayout->addWidget( myBrowseBtn );
82 myFilterCheck = new QCheckBox( tr( "FILTER_LOG_LBL" ), myBox );
84 lin = new QFrame( myBox );
85 lin->setFrameStyle( QFrame::HLine | QFrame::Plain );
87 /* dataflow notification */
88 myMainNotif = new SUPERVGUI_NotifWidget( myBox, QString( myMain->getDataflow()->Name() ) );
89 myMainNotif->setWarning( false );
90 myMainNotif->setStep( false );
91 myMainNotif->setTrace( false );
92 myMainNotif->setVerbose( false );
94 /* nodes notification */
95 QObjectList* ihmList = myMain->getGraph()->queryList( "SUPERVGUI_Node" );
96 QObjectListIt i( *ihmList );
97 SUPERVGUI_Node* theNode;
98 while ( ( theNode = ( ( SUPERVGUI_Node* )i.current() ) ) != 0) {
99 lin = new QFrame( myBox );
100 lin->setFrameStyle( QFrame::HLine | QFrame::Plain );
102 SUPERVGUI_NotifWidget* nw = new SUPERVGUI_NotifWidget( myBox, theNode );
103 nw->setWarning( theNode->isWarning() );
104 nw->setStep( theNode->isStep() );
105 nw->setTrace( theNode->isTrace() );
106 nw->setVerbose( theNode->isVerbose() );
107 myNotifList.append( nw );
112 QWidget* dumb1 = new QWidget( myBox );
113 myBox->setStretchFactor( dumb1, 10 );
115 myView->addChild( myBox, 0, 0 );
116 myView->setResizePolicy( QScrollView::AutoOneFit );
118 int w = myLogCheck->sizeHint().width() + myFileEdit->minimumSize().width() + myBrowseBtn->sizeHint().width() + SPACING_SIZE * 2;
119 w = MAX( w, logg->sizeHint().width() );
120 w = MAX( w, myMainNotif->sizeHint().width() );
121 w = MAX( w, myFilterCheck->sizeHint().width() );
122 myView->setMinimumWidth( w + MARGIN_SIZE * 4 );
124 /* OK/Cancel buttons */
125 QGroupBox* GroupButtons = new QGroupBox( this );
126 GroupButtons->setColumnLayout(0, Qt::Vertical );
127 GroupButtons->layout()->setSpacing( 0 ); GroupButtons->layout()->setMargin( 0 );
128 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
129 GroupButtonsLayout->setAlignment( Qt::AlignTop );
130 GroupButtonsLayout->setSpacing( SPACING_SIZE );
131 GroupButtonsLayout->setMargin( MARGIN_SIZE );
132 myOkBtn = new QPushButton( tr( "BUT_OK" ), GroupButtons, "buttonOk" );
133 myOkBtn->setAutoDefault( TRUE );
134 myOkBtn->setDefault( TRUE );
135 GroupButtonsLayout->addWidget( myOkBtn );
136 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
137 myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons, "buttonCancel" );
138 myCancelBtn->setAutoDefault( TRUE );
139 GroupButtonsLayout->addWidget( myCancelBtn );
141 topLayout->addWidget( myView );
142 topLayout->addWidget( GroupButtons );
144 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
145 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
146 connect( myLogCheck, SIGNAL( clicked() ), this, SLOT( loggedClicked() ) );
147 connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( browseClicked() ) );
149 QString file = QString( "/tmp/Notif_" );
150 file += myMain->getDataflow()->Name();
152 myFileEdit->setText( file );
155 resize( MAX( w + MARGIN_SIZE * 4, DLG_SIZE_WIDTH ), DLG_SIZE_HEIGHT );
161 SUPERVGUI_Notification::~SUPERVGUI_Notification()
168 void SUPERVGUI_Notification::accept()
170 Trace("SUPERVGUI_Notification::accept");
171 for ( int i = 0; i < myNotifList.count(); i++ ) {
172 if ( myNotifList.at( i )->getNode() ) {
173 myNotifList.at( i )->getNode()->setWarning( myNotifList.at( i )->getWarning() );
174 myNotifList.at( i )->getNode()->setStep( myNotifList.at( i )->getStep() );
175 myNotifList.at( i )->getNode()->setTrace( myNotifList.at( i )->getTrace() );
176 myNotifList.at( i )->getNode()->setVerbose( myNotifList.at( i )->getVerbose() );
185 void SUPERVGUI_Notification::reject()
187 Trace("SUPERVGUI_Notification::reject");
192 Called when <Save to file> check box is clicked
194 void SUPERVGUI_Notification::loggedClicked()
196 myFileEdit->setEnabled( myLogCheck->isChecked() );
197 myBrowseBtn->setEnabled( myLogCheck->isChecked() );
198 myFilterCheck->setEnabled( myLogCheck->isChecked() );
204 void SUPERVGUI_Notification::browseClicked()
206 QString fn = QAD_FileDlg::getFileName( this,
209 tr( "CHOOSE_LOG_FILES_TLT" ),
212 myFileEdit->setText( fn );
218 bool SUPERVGUI_Notification::getLogged()
220 return myLogCheck->isChecked();
222 void SUPERVGUI_Notification::setLogged( bool on, QString logFile )
224 myLogCheck->setChecked( on );
225 if ( !logFile.isNull() ) {
226 myFileEdit->setText( logFile );
227 myFileEdit->home( false );
231 QString SUPERVGUI_Notification::getLogFile()
233 return myFileEdit->text().stripWhiteSpace();
235 bool SUPERVGUI_Notification::getFiltered()
237 return myFilterCheck->isChecked();
239 void SUPERVGUI_Notification::setFiltered( bool on )
241 myFilterCheck->setChecked( on );
243 bool SUPERVGUI_Notification::getWarning()
245 return myMainNotif->getWarning();
247 void SUPERVGUI_Notification::setWarning( bool on )
249 myMainNotif->setWarning( on );
251 bool SUPERVGUI_Notification::getStep()
253 return myMainNotif->getStep();
255 void SUPERVGUI_Notification::setStep( bool on )
257 myMainNotif->setStep( on );
259 bool SUPERVGUI_Notification::getTrace()
261 return myMainNotif->getTrace();
263 void SUPERVGUI_Notification::setTrace( bool on )
265 myMainNotif->setTrace( on );
267 bool SUPERVGUI_Notification::getVerbose()
269 return myMainNotif->getVerbose();
271 void SUPERVGUI_Notification::setVerbose( bool on )
273 myMainNotif->setVerbose( on );
276 /******************************************
277 * Widget containing title and checkboxes
278 ******************************************/
282 SUPERVGUI_NotifWidget::SUPERVGUI_NotifWidget( QWidget* parent, SUPERVGUI_Node* n )
283 : QWidget( parent ), myNode ( n )
290 SUPERVGUI_NotifWidget::SUPERVGUI_NotifWidget( QWidget* parent, QString title )
291 : QWidget( parent ), myNode ( 0 ), myTitle( title )
298 SUPERVGUI_NotifWidget::~SUPERVGUI_NotifWidget()
302 Creates widget's layout
304 void SUPERVGUI_NotifWidget::init()
306 QGridLayout* topLayout = new QGridLayout( this );
307 topLayout->setMargin( 0 );
308 topLayout->setSpacing( SPACING_SIZE );
310 QLabel* tltLab = new QLabel( this );
312 tltLab->setText( myNode->name() );
314 tltLab->setText( myTitle );
315 QFont fnt = tltLab->font(); fnt.setBold( true ); tltLab->setFont( fnt );
317 myWarningCheck = new QCheckBox( tr( NOTIF_WARNING ), this );
318 myStepCheck = new QCheckBox( tr( NOTIF_STEP ), this );
319 myTraceCheck = new QCheckBox( tr( NOTIF_TRACE ), this );
320 myVerboseCheck = new QCheckBox( tr( NOTIF_VERBOSE ), this );
322 topLayout->addMultiCellWidget( tltLab, 0, 0, 0, 4 );
323 topLayout->addWidget( myWarningCheck, 1, 1 );
324 topLayout->addWidget( myStepCheck, 1, 2 );
325 topLayout->addWidget( myTraceCheck, 1, 3 );
326 topLayout->addWidget( myVerboseCheck, 1, 4 );
327 topLayout->addColSpacing( 0, 15 );
328 topLayout->setColStretch( 1, 5 );
329 topLayout->setColStretch( 2, 5 );
330 topLayout->setColStretch( 3, 5 );
331 topLayout->setColStretch( 4, 5 );