2 // File : SUPERVGUI_Notification.cxx
3 // Created : 21 / 02 / 2002
4 // Author : Francis KLOSS
9 #include "SUPERVGUI_Notification.h"
10 #include "QAD_Message.h"
11 #include "QAD_FileDlg.h"
12 #include "SUPERVGUI_Node.h"
13 #include "SUPERVGUI_Main.h"
14 #include "NOTIFICATION.hxx"
17 #include <qgroupbox.h>
19 #define SPACING_SIZE 6
20 #define MARGIN_SIZE 11
21 #define MAX( x, y ) ( x ) > ( y ) ? ( x ) : ( y )
22 #define DLG_SIZE_WIDTH 300
23 #define DLG_SIZE_HEIGHT 300
25 /******************************************
26 * Notification settings dialog box
27 ******************************************/
31 SUPERVGUI_Notification::SUPERVGUI_Notification( SUPERVGUI_Main* m )
32 : QDialog( QAD_Application::getDesktop(), "", TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
35 setCaption( tr( "TLT_FILTER_NOTIFY" ) );
36 setSizeGripEnabled( TRUE );
37 QVBoxLayout* topLayout = new QVBoxLayout( this );
38 topLayout->setSpacing( SPACING_SIZE );
39 topLayout->setMargin( MARGIN_SIZE );
41 /* Creating notofication widgets*/
43 myView = new QScrollView( this );
44 // myView->setMinimumSize( NOTIFICATION_WIDTH, NOTIFICATION_HEIGHT );
45 myBox = new QVBox( myView );
46 myBox->setMargin( MARGIN_SIZE );
47 myBox->setSpacing( SPACING_SIZE );
50 /* Notification logging */
51 QLabel* logg = new QLabel( tr( "NOTIFICATION_LOGGING_LBL" ), myBox );
52 QFont fnt = logg->font(); fnt.setBold( true ); logg->setFont( fnt );
53 QWidget* dumb = new QWidget( myBox );
54 QHBoxLayout* dumbLayout = new QHBoxLayout( dumb ); dumbLayout->setMargin( 0 ); dumbLayout->setSpacing( SPACING_SIZE );
55 myLogCheck = new QCheckBox( tr( "SAVE_LOG_LBL" ), dumb );
56 myFileEdit = new QLineEdit( dumb );
57 myFileEdit->setMinimumSize( 200, 0 );
58 myBrowseBtn = new QPushButton( tr( "BUT_BROWSE"), dumb );
59 dumbLayout->addWidget( myLogCheck );
60 dumbLayout->addWidget( myFileEdit );
61 dumbLayout->addWidget( myBrowseBtn );
62 myFilterCheck = new QCheckBox( tr( "FILTER_LOG_LBL" ), myBox );
64 lin = new QFrame( myBox );
65 lin->setFrameStyle( QFrame::HLine | QFrame::Plain );
67 /* dataflow notification */
68 myMainNotif = new SUPERVGUI_NotifWidget( myBox, QString( myMain->getDataflow()->Name() ) );
69 myMainNotif->setWarning( false );
70 myMainNotif->setStep( false );
71 myMainNotif->setTrace( false );
72 myMainNotif->setVerbose( false );
74 /* nodes notification */
75 QObjectList* ihmList = myMain->getGraph()->queryList( "SUPERVGUI_Node" );
76 QObjectListIt i( *ihmList );
77 SUPERVGUI_Node* theNode;
78 while ( ( theNode = ( ( SUPERVGUI_Node* )i.current() ) ) != 0) {
79 lin = new QFrame( myBox );
80 lin->setFrameStyle( QFrame::HLine | QFrame::Plain );
82 SUPERVGUI_NotifWidget* nw = new SUPERVGUI_NotifWidget( myBox, theNode );
83 nw->setWarning( theNode->isWarning() );
84 nw->setStep( theNode->isStep() );
85 nw->setTrace( theNode->isTrace() );
86 nw->setVerbose( theNode->isVerbose() );
87 myNotifList.append( nw );
92 QWidget* dumb1 = new QWidget( myBox );
93 myBox->setStretchFactor( dumb1, 10 );
95 myView->addChild( myBox, 0, 0 );
96 myView->setResizePolicy( QScrollView::AutoOneFit );
98 int w = myLogCheck->sizeHint().width() + myFileEdit->minimumSize().width() + myBrowseBtn->sizeHint().width() + SPACING_SIZE * 2;
99 w = MAX( w, logg->sizeHint().width() );
100 w = MAX( w, myMainNotif->sizeHint().width() );
101 w = MAX( w, myFilterCheck->sizeHint().width() );
102 myView->setMinimumWidth( w + MARGIN_SIZE * 4 );
104 /* OK/Cancel buttons */
105 QGroupBox* GroupButtons = new QGroupBox( this );
106 GroupButtons->setColumnLayout(0, Qt::Vertical );
107 GroupButtons->layout()->setSpacing( 0 ); GroupButtons->layout()->setMargin( 0 );
108 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
109 GroupButtonsLayout->setAlignment( Qt::AlignTop );
110 GroupButtonsLayout->setSpacing( SPACING_SIZE );
111 GroupButtonsLayout->setMargin( MARGIN_SIZE );
112 myOkBtn = new QPushButton( tr( "BUT_OK" ), GroupButtons, "buttonOk" );
113 myOkBtn->setAutoDefault( TRUE );
114 myOkBtn->setDefault( TRUE );
115 GroupButtonsLayout->addWidget( myOkBtn );
116 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
117 myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons, "buttonCancel" );
118 myCancelBtn->setAutoDefault( TRUE );
119 GroupButtonsLayout->addWidget( myCancelBtn );
121 topLayout->addWidget( myView );
122 topLayout->addWidget( GroupButtons );
124 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
125 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
126 connect( myLogCheck, SIGNAL( clicked() ), this, SLOT( loggedClicked() ) );
127 connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( browseClicked() ) );
129 QString file = QString( "/tmp/Notif_" );
130 file += myMain->getDataflow()->Name();
132 myFileEdit->setText( file );
135 resize( MAX( w + MARGIN_SIZE * 4, DLG_SIZE_WIDTH ), DLG_SIZE_HEIGHT );
141 SUPERVGUI_Notification::~SUPERVGUI_Notification()
148 void SUPERVGUI_Notification::accept()
150 Trace("SUPERVGUI_Notification::accept");
151 for ( int i = 0; i < myNotifList.count(); i++ ) {
152 if ( myNotifList.at( i )->getNode() ) {
153 myNotifList.at( i )->getNode()->setWarning( myNotifList.at( i )->getWarning() );
154 myNotifList.at( i )->getNode()->setStep( myNotifList.at( i )->getStep() );
155 myNotifList.at( i )->getNode()->setTrace( myNotifList.at( i )->getTrace() );
156 myNotifList.at( i )->getNode()->setVerbose( myNotifList.at( i )->getVerbose() );
165 void SUPERVGUI_Notification::reject()
167 Trace("SUPERVGUI_Notification::reject");
172 Called when <Save to file> check box is clicked
174 void SUPERVGUI_Notification::loggedClicked()
176 myFileEdit->setEnabled( myLogCheck->isChecked() );
177 myBrowseBtn->setEnabled( myLogCheck->isChecked() );
178 myFilterCheck->setEnabled( myLogCheck->isChecked() );
184 void SUPERVGUI_Notification::browseClicked()
186 QString fn = QAD_FileDlg::getFileName( this,
189 tr( "CHOOSE_LOG_FILES_TLT" ),
192 myFileEdit->setText( fn );
198 bool SUPERVGUI_Notification::getLogged()
200 return myLogCheck->isChecked();
202 void SUPERVGUI_Notification::setLogged( bool on, QString logFile )
204 myLogCheck->setChecked( on );
205 if ( !logFile.isNull() ) {
206 myFileEdit->setText( logFile );
207 myFileEdit->home( false );
211 QString SUPERVGUI_Notification::getLogFile()
213 return myFileEdit->text().stripWhiteSpace();
215 bool SUPERVGUI_Notification::getFiltered()
217 return myFilterCheck->isChecked();
219 void SUPERVGUI_Notification::setFiltered( bool on )
221 myFilterCheck->setChecked( on );
223 bool SUPERVGUI_Notification::getWarning()
225 return myMainNotif->getWarning();
227 void SUPERVGUI_Notification::setWarning( bool on )
229 myMainNotif->setWarning( on );
231 bool SUPERVGUI_Notification::getStep()
233 return myMainNotif->getStep();
235 void SUPERVGUI_Notification::setStep( bool on )
237 myMainNotif->setStep( on );
239 bool SUPERVGUI_Notification::getTrace()
241 return myMainNotif->getTrace();
243 void SUPERVGUI_Notification::setTrace( bool on )
245 myMainNotif->setTrace( on );
247 bool SUPERVGUI_Notification::getVerbose()
249 return myMainNotif->getVerbose();
251 void SUPERVGUI_Notification::setVerbose( bool on )
253 myMainNotif->setVerbose( on );
256 /******************************************
257 * Widget containing title and checkboxes
258 ******************************************/
262 SUPERVGUI_NotifWidget::SUPERVGUI_NotifWidget( QWidget* parent, SUPERVGUI_Node* n )
263 : QWidget( parent ), myNode ( n )
270 SUPERVGUI_NotifWidget::SUPERVGUI_NotifWidget( QWidget* parent, QString title )
271 : QWidget( parent ), myNode ( 0 ), myTitle( title )
278 SUPERVGUI_NotifWidget::~SUPERVGUI_NotifWidget()
282 Creates widget's layout
284 void SUPERVGUI_NotifWidget::init()
286 QGridLayout* topLayout = new QGridLayout( this );
287 topLayout->setMargin( 0 );
288 topLayout->setSpacing( SPACING_SIZE );
290 QLabel* tltLab = new QLabel( this );
292 tltLab->setText( myNode->name() );
294 tltLab->setText( myTitle );
295 QFont fnt = tltLab->font(); fnt.setBold( true ); tltLab->setFont( fnt );
297 myWarningCheck = new QCheckBox( tr( NOTIF_WARNING ), this );
298 myStepCheck = new QCheckBox( tr( NOTIF_STEP ), this );
299 myTraceCheck = new QCheckBox( tr( NOTIF_TRACE ), this );
300 myVerboseCheck = new QCheckBox( tr( NOTIF_VERBOSE ), this );
302 topLayout->addMultiCellWidget( tltLab, 0, 0, 0, 4 );
303 topLayout->addWidget( myWarningCheck, 1, 1 );
304 topLayout->addWidget( myStepCheck, 1, 2 );
305 topLayout->addWidget( myTraceCheck, 1, 3 );
306 topLayout->addWidget( myVerboseCheck, 1, 4 );
307 topLayout->addColSpacing( 0, 15 );
308 topLayout->setColStretch( 1, 5 );
309 topLayout->setColStretch( 2, 5 );
310 topLayout->setColStretch( 3, 5 );
311 topLayout->setColStretch( 4, 5 );