]> SALOME platform Git repositories - modules/superv.git/blob - src/SUPERVGUI/SUPERVGUI_Information.cxx
Salome HOME
Patch from Christian CAREMOLI for bug PAL10339 : random GUI freeze.
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Information.cxx
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SUPERVGUI_Information.cxx
25 //  Author : Francis KLOSS
26 //  Module : SUPERV
27
28 using namespace std;
29 #include "SUPERVGUI_Information.h"
30
31 #include "CAM_Application.h"
32 #include "SUIT_Desktop.h"
33 #include "SUIT_Session.h"
34
35 #include <qapplication.h>
36 #include <qlabel.h>
37 #include <qgroupbox.h>
38 #include <qlayout.h>
39
40
41 /*!
42   Constructor
43 */
44 SUPERVGUI_Information::SUPERVGUI_Information(SUPERV_CNode node, bool isReadOnly)
45      : QDialog( SUIT_Session::session()->activeApplication()->desktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) 
46 {
47   Trace("SUPERVGUI_Information::SUPERVGUI_Information");
48   setCaption( tr( "TLT_INFORMATIONS" ) );
49   setSizeGripEnabled( true );
50   myNode = node;
51
52   QGridLayout* TopLayout = new QGridLayout( this );
53   TopLayout->setSpacing( 6 );
54   TopLayout->setMargin( 11 );
55     
56   QGroupBox* TopGroup = new QGroupBox( this, "TopGroup" );
57   TopGroup->setColumnLayout(0, Qt::Vertical );
58   TopGroup->layout()->setSpacing( 0 );
59   TopGroup->layout()->setMargin( 0 );
60   QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
61   TopGroupLayout->setAlignment( Qt::AlignTop );
62   TopGroupLayout->setSpacing( 6 );
63   TopGroupLayout->setMargin( 11 );
64
65   QLabel* nameL = new QLabel( tr( "NAME_LBL" ), TopGroup );  
66   nameV = new QLineEdit( TopGroup );      
67   nameV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
68   nameV->setMinimumSize( 200, 0 );
69   nameV->setReadOnly( isReadOnly );
70   nameV->setText( node->Name() );
71   
72   QLabel* authL = new QLabel( tr( "AUTHOR_LBL" ), TopGroup); 
73   authV = new QLineEdit( TopGroup );
74   authV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
75   authV->setMinimumSize( 200, 0 );
76   authV->setReadOnly( isReadOnly );
77   authV->setText( node->Author() );
78
79   
80   if (node->IsFactory()) {
81     contL = new QLabel( tr( "CONTAINER_LBL" ), TopGroup ); 
82     contV = new QLineEdit( TopGroup );
83     contV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
84     contV->setMinimumSize( 200, 0 );
85     contV->setReadOnly( false/*isReadOnly*/ );
86     contV->setText( SUPERV::FNode::_narrow(node)->GetContainer() );
87
88     compnameL = new QLabel( tr( "COMPONENT_NAME_LBL" ), TopGroup ); 
89     compnameV = new QLineEdit( TopGroup );      
90     compnameV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
91     compnameV->setMinimumSize( 200, 0 );
92     compnameV->setReadOnly( true/*isReadOnly*/ );
93     compnameV->setText( SUPERV::FNode::_narrow(node)->GetComponentName() ); // mkr : IPAL10198
94
95     intnameL = new QLabel( tr( "INTERFACE_NAME_LBL" ), TopGroup ); 
96     intnameV = new QLineEdit( TopGroup );      
97     intnameV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
98     intnameV->setMinimumSize( 200, 0 );
99     intnameV->setReadOnly( true/*isReadOnly*/ );
100     intnameV->setText( SUPERV::FNode::_narrow(node)->GetInterfaceName() );
101
102   }
103   QLabel* cdatL = new QLabel( tr( "DATE_CREATION_LBL" ), TopGroup ); 
104   cdatV = new QLabel( TopGroup );
105   cdatV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
106   cdatV->setMinimumSize( 200, 0 );
107   cdatV->setText( date( node->CreationDate() ) );
108
109   QLabel* udatL = new QLabel( tr( "DATE_MODIFICATION_LBL" ), TopGroup ); 
110   udatV = new QLabel( TopGroup );
111   udatV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
112   udatV->setMinimumSize( 200, 0 );
113   udatV->setText( date( node->LastUpdateDate() ) );
114
115   QLabel* commL = new QLabel( tr( "COMMENT_LBL" ), TopGroup); 
116   commV = new QMultiLineEdit( TopGroup );
117   commV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
118   commV->setMinimumSize( 200, 100 );
119   commV->setReadOnly( isReadOnly );
120   commV->setText( node->Comment() );
121
122   TopGroupLayout->addWidget( nameL, 0, 0 );
123   TopGroupLayout->addWidget( nameV, 0, 1 );
124   TopGroupLayout->addWidget( authL, 1, 0 );
125   TopGroupLayout->addWidget( authV, 1, 1 );
126   if (node->IsFactory()) {
127     TopGroupLayout->addWidget( contL, 2, 0 );
128     TopGroupLayout->addWidget( contV, 2, 1 );
129     TopGroupLayout->addWidget( compnameL, 3, 0 );
130     TopGroupLayout->addWidget( compnameV, 3, 1 );
131     TopGroupLayout->addWidget( intnameL, 4, 0 );
132     TopGroupLayout->addWidget( intnameV, 4, 1 );
133   }
134   TopGroupLayout->addWidget( cdatL, 5, 0 );
135   TopGroupLayout->addWidget( cdatV, 5, 1 );
136   TopGroupLayout->addWidget( udatL, 6, 0 );
137   TopGroupLayout->addWidget( udatV, 6, 1 );
138   TopGroupLayout->addWidget( commL, 7, 0 );
139   TopGroupLayout->addMultiCellWidget( commV, 7, 8, 1, 1 );
140   TopGroupLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Minimum, QSizePolicy::Expanding  ), 8, 0 );
141   TopGroupLayout->setColStretch( 1, 5 );
142
143   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
144   GroupButtons->setColumnLayout(0, Qt::Vertical );
145   GroupButtons->layout()->setSpacing( 0 );
146   GroupButtons->layout()->setMargin( 0 );
147   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
148   GroupButtonsLayout->setAlignment( Qt::AlignTop );
149   GroupButtonsLayout->setSpacing( 6 );
150   GroupButtonsLayout->setMargin( 11 );
151
152   // fix for PAL6904: when isReadOnly is set ON (the dataflow was imported) then only "CLOSE" button
153   // should be present instead of 2 buttons OK and Cancel.
154   QPushButton* cancelB;
155   if ( !isReadOnly || node->IsFactory() )  {
156     /*added node->IsFactory() because only for Factory nodes we ALWAYS have editable "Container" field  */
157     QPushButton* okB = new QPushButton( tr( "BUT_OK" ), GroupButtons );
158     connect( okB,     SIGNAL( clicked() ), this, SLOT( okButton() ) );
159     cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
160     GroupButtonsLayout->addWidget( okB, 0, 0 );
161     GroupButtonsLayout->addItem  ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
162     GroupButtonsLayout->addWidget( cancelB, 0, 2 );
163   }
164   else {
165     cancelB = new QPushButton( tr( "BUT_CLOSE" ), GroupButtons );
166     GroupButtonsLayout->addItem  ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 0 );
167     GroupButtonsLayout->addWidget( cancelB, 0, 1 );
168     GroupButtonsLayout->addItem  ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 2 );
169   }
170
171   TopLayout->addWidget( TopGroup,     0, 0 );
172   TopLayout->addWidget( GroupButtons, 1, 0 );
173   TopLayout->setRowStretch( 0, 1 );
174   TopLayout->setRowStretch( 1, 0 );
175
176   connect( cancelB, SIGNAL( clicked() ), this, SLOT( koButton() ) );
177 }
178
179 /*!
180   Destructor
181 */
182 SUPERVGUI_Information::~SUPERVGUI_Information() {
183   Trace("SUPERVGUI_Information::~SUPERVGUI_Information");
184 }
185
186 /*!
187   Executes dialog
188 */
189 /*
190 bool SUPERVGUI_Information::run( SUPERV_CNode node, bool isReadOnly ) {
191   Trace("SUPERVGUI_Information::run");
192   nameV->setReadOnly( isReadOnly );
193   authV->setReadOnly( isReadOnly );
194   commV->setReadOnly( isReadOnly );
195
196   nameV->setText( node->Name() );
197   authV->setText( node->Author() );
198   commV->setText( node->Comment() );
199   if (node->IsFactory()) {
200     SUPERV_FNode aFNode = SUPERV::FNode::_narrow(node);
201     contV->setText( aFNode->GetContainer());
202     contL->show();
203     contV->show();
204   }
205   else {
206     contL->hide();
207     contV->hide();
208   }
209   qApp->processEvents();
210   adjustSize();
211
212   //commV->setText( node->Comment() );
213   cdatV->setText( date( node->CreationDate() ) );
214   udatV->setText( date( node->LastUpdateDate() ) );
215
216   bool b1     = true;
217   bool b2     = true;
218   bool b3     = true;
219   bool b4     = true;
220   bool result = false;
221   if ( exec() == Accepted ) {
222     if (! isReadOnly ) {
223       //b3 = node->SetContainer( contV->text().latin1() );
224       //} 
225       //else {
226       if ( strcmp( node->Name(), nameV->text().latin1() ) != 0 ) {
227         b1 = node->SetName( nameV->text().latin1() );
228       }
229       b2 = node->SetAuthor   ( authV->text().latin1() );
230       if (node->IsFactory()) {
231         SUPERV_FNode aFNode = SUPERV::FNode::_narrow(node);
232         b3 = aFNode->SetContainer( contV->text().latin1() );
233       }
234       b4 = node->SetComment  ( commV->text().latin1() );
235     }
236     result = b1 && b2 && b3 && b4;
237     if ( !result ) {
238       QAD_MessageBox::warn1( this, tr( "ERROR" ), tr( "MSG_CANT_CHANGE_INFO" ), tr( "BUT_OK" ) );
239     }
240   }
241   return result;
242   }*/
243
244 /*!
245   Returns string representation of date
246 */
247 QString SUPERVGUI_Information::date( SUPERV_Date d ) {
248   Trace("SUPERVGUI_Information::date");
249   QString dt( "" );
250
251   if ( d.Day != 0 ) {
252     dt += ( char )( d.Day / 10 + 48 );
253     dt += ( char )( d.Day % 10 + 48 );
254     dt += '/';
255     dt += ( char )( d.Month / 10 + 48 );
256     dt += ( char )( d.Month % 10 + 48 );
257     dt += '/';
258     dt += ( char )( ( d.Year / 1000 ) %10 + 48 );
259     dt += ( char )( ( d.Year / 100 ) % 10 + 48 );
260     dt += ( char )( ( d.Year / 10  ) % 10 + 48 );
261     dt += ( char )( d.Year %10 + 48 );
262     dt += ' ';
263     dt += ( char )( d.Hour / 10 + 48 );
264     dt += ( char )( d.Hour % 10 + 48 );
265     dt += ':';
266     dt += ( char )( d.Minute / 10 + 48 );
267     dt += ( char )( d.Minute % 10 + 48 );
268     dt += ':';
269     dt += ( char )( d.Second / 10 + 48 );
270     dt += ( char )( d.Second % 10 + 48 );
271   };
272   return( dt );
273 }
274
275 /*!
276   <OK> button slot
277 */
278 void SUPERVGUI_Information::okButton() {
279   Trace("SUPERVGUI_Information::okButton");
280   //mkr : modifications for fixing bug IPAL9972
281   bool aIsAccept = true;
282   if ( QString( myNode->Name() ).compare( nameV->text() ) != 0 )
283     if ( !myNode->SetName( nameV->text().latin1()) ) {
284       QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), tr( "ERROR" ), tr( "MSG_CANT_RENAMENODE" ) );
285       aIsAccept = false;
286     }
287   myNode->SetAuthor( authV->text().latin1() );
288   if (myNode->IsFactory()) {
289     SUPERV_FNode aFNode = SUPERV::FNode::_narrow(myNode);
290     aFNode->SetContainer( contV->text().latin1() );
291   }
292   myNode->SetComment( commV->text().latin1() );
293   if ( aIsAccept ) accept();
294 }
295
296 /*!
297   <Cancel> button slot
298 */
299 void SUPERVGUI_Information::koButton() {
300   Trace("SUPERVGUI_Information::koButton");
301   reject();
302 }