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 */
98 //QObjectList* ihmList = myMain->/*getGraph()->*/queryList( "SUPERVGUI_CanvasNode" );
100 if ( myMain->getViewType() == CANVASTABLE )
101 ihmList = myMain->getCanvasArray()->queryList( "SUPERVGUI_CanvasNode" );
103 ihmList = myMain->getCanvas()->queryList( "SUPERVGUI_CanvasNode" );
105 QObjectListIt i( *ihmList );
106 SUPERVGUI_CanvasNode* theNode;
107 while ( ( theNode = ( ( SUPERVGUI_CanvasNode* )i.current() ) ) != 0) {
108 lin = new QFrame( myBox );
109 lin->setFrameStyle( QFrame::HLine | QFrame::Plain );
111 SUPERVGUI_NotifWidget* nw = new SUPERVGUI_NotifWidget( myBox, theNode );
112 nw->setWarning( theNode->isWarning() );
113 nw->setStep( theNode->isStep() );
114 nw->setTrace( theNode->isTrace() );
115 nw->setVerbose( theNode->isVerbose() );
116 myNotifList.append( nw );
121 QWidget* dumb1 = new QWidget( myBox );
122 myBox->setStretchFactor( dumb1, 10 );
124 myView->addChild( myBox, 0, 0 );
125 myView->setResizePolicy( QScrollView::AutoOneFit );
127 int w = myLogCheck->sizeHint().width() + myFileEdit->minimumSize().width() + myBrowseBtn->sizeHint().width() + SPACING_SIZE * 2;
128 w = MAX( w, logg->sizeHint().width() );
129 w = MAX( w, myMainNotif->sizeHint().width() );
130 w = MAX( w, myFilterCheck->sizeHint().width() );
131 myView->setMinimumWidth( w + MARGIN_SIZE * 4 );
133 /* OK/Cancel buttons */
134 QGroupBox* GroupButtons = new QGroupBox( this );
135 GroupButtons->setColumnLayout(0, Qt::Vertical );
136 GroupButtons->layout()->setSpacing( 0 ); GroupButtons->layout()->setMargin( 0 );
137 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
138 GroupButtonsLayout->setAlignment( Qt::AlignTop );
139 GroupButtonsLayout->setSpacing( SPACING_SIZE );
140 GroupButtonsLayout->setMargin( MARGIN_SIZE );
141 myOkBtn = new QPushButton( tr( "BUT_OK" ), GroupButtons, "buttonOk" );
142 myOkBtn->setAutoDefault( TRUE );
143 myOkBtn->setDefault( TRUE );
144 GroupButtonsLayout->addWidget( myOkBtn );
145 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
146 myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons, "buttonCancel" );
147 myCancelBtn->setAutoDefault( TRUE );
148 GroupButtonsLayout->addWidget( myCancelBtn );
150 topLayout->addWidget( myView );
151 topLayout->addWidget( GroupButtons );
153 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
154 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
155 connect( myLogCheck, SIGNAL( clicked() ), this, SLOT( loggedClicked() ) );
156 connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( browseClicked() ) );
158 QString file = QString( "/tmp/Notif_" );
159 file += myMain->getDataflow()->Name();
161 myFileEdit->setText( file );
164 resize( MAX( w + MARGIN_SIZE * 4, DLG_SIZE_WIDTH ), DLG_SIZE_HEIGHT );
170 SUPERVGUI_Notification::~SUPERVGUI_Notification()
177 void SUPERVGUI_Notification::accept()
179 Trace("SUPERVGUI_Notification::accept");
180 for ( int i = 0; i < myNotifList.count(); i++ ) {
181 if ( myNotifList.at( i )->getNode() ) {
182 myNotifList.at( i )->getNode()->setWarning( myNotifList.at( i )->getWarning() );
183 myNotifList.at( i )->getNode()->setStep( myNotifList.at( i )->getStep() );
184 myNotifList.at( i )->getNode()->setTrace( myNotifList.at( i )->getTrace() );
185 myNotifList.at( i )->getNode()->setVerbose( myNotifList.at( i )->getVerbose() );
194 void SUPERVGUI_Notification::reject()
196 Trace("SUPERVGUI_Notification::reject");
201 Called when <Save to file> check box is clicked
203 void SUPERVGUI_Notification::loggedClicked()
205 myFileEdit->setEnabled( myLogCheck->isChecked() );
206 myBrowseBtn->setEnabled( myLogCheck->isChecked() );
207 myFilterCheck->setEnabled( myLogCheck->isChecked() );
213 void SUPERVGUI_Notification::browseClicked()
215 QString fn = SUIT_FileDlg::getFileName( this,
218 tr( "CHOOSE_LOG_FILES_TLT" ),
221 myFileEdit->setText( fn );
227 bool SUPERVGUI_Notification::getLogged()
229 return myLogCheck->isChecked();
231 void SUPERVGUI_Notification::setLogged( bool on, QString logFile )
233 myLogCheck->setChecked( on );
234 if ( !logFile.isNull() ) {
235 myFileEdit->setText( logFile );
236 myFileEdit->home( false );
240 QString SUPERVGUI_Notification::getLogFile()
242 return myFileEdit->text().stripWhiteSpace();
244 bool SUPERVGUI_Notification::getFiltered()
246 return myFilterCheck->isChecked();
248 void SUPERVGUI_Notification::setFiltered( bool on )
250 myFilterCheck->setChecked( on );
252 bool SUPERVGUI_Notification::getWarning()
254 return myMainNotif->getWarning();
256 void SUPERVGUI_Notification::setWarning( bool on )
258 myMainNotif->setWarning( on );
260 bool SUPERVGUI_Notification::getStep()
262 return myMainNotif->getStep();
264 void SUPERVGUI_Notification::setStep( bool on )
266 myMainNotif->setStep( on );
268 bool SUPERVGUI_Notification::getTrace()
270 return myMainNotif->getTrace();
272 void SUPERVGUI_Notification::setTrace( bool on )
274 myMainNotif->setTrace( on );
276 bool SUPERVGUI_Notification::getVerbose()
278 return myMainNotif->getVerbose();
280 void SUPERVGUI_Notification::setVerbose( bool on )
282 myMainNotif->setVerbose( on );
285 /******************************************
286 * Widget containing title and checkboxes
287 ******************************************/
291 SUPERVGUI_NotifWidget::SUPERVGUI_NotifWidget( QWidget* parent, SUPERVGUI_CanvasNode* n )
292 : QWidget( parent ), myNode ( n )
299 SUPERVGUI_NotifWidget::SUPERVGUI_NotifWidget( QWidget* parent, QString title )
300 : QWidget( parent ), myNode ( 0 ), myTitle( title )
307 SUPERVGUI_NotifWidget::~SUPERVGUI_NotifWidget()
311 Creates widget's layout
313 void SUPERVGUI_NotifWidget::init()
315 QGridLayout* topLayout = new QGridLayout( this );
316 topLayout->setMargin( 0 );
317 topLayout->setSpacing( SPACING_SIZE );
319 QLabel* tltLab = new QLabel( this );
321 tltLab->setText( myNode->name() );
323 tltLab->setText( myTitle );
324 QFont fnt = tltLab->font(); fnt.setBold( true ); tltLab->setFont( fnt );
326 myWarningCheck = new QCheckBox( tr( NOTIF_WARNING ), this );
327 myStepCheck = new QCheckBox( tr( NOTIF_STEP ), this );
328 myTraceCheck = new QCheckBox( tr( NOTIF_TRACE ), this );
329 myVerboseCheck = new QCheckBox( tr( NOTIF_VERBOSE ), this );
331 topLayout->addMultiCellWidget( tltLab, 0, 0, 0, 4 );
332 topLayout->addWidget( myWarningCheck, 1, 1 );
333 topLayout->addWidget( myStepCheck, 1, 2 );
334 topLayout->addWidget( myTraceCheck, 1, 3 );
335 topLayout->addWidget( myVerboseCheck, 1, 4 );
336 topLayout->addColSpacing( 0, 15 );
337 topLayout->setColStretch( 1, 5 );
338 topLayout->setColStretch( 2, 5 );
339 topLayout->setColStretch( 3, 5 );
340 topLayout->setColStretch( 4, 5 );