Salome HOME
7909d7c06025e43514cdb1f98f22b0794271cf63
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Information.cxx
1 using namespace std;
2 //  File      : SUPERVGUI_Information.cxx
3 //  Created   : 22 / 01 / 2002
4 //  Author    : Francis KLOSS
5 //  Project   : SALOME
6 //  Module    : SUPERVGUI
7 //  Copyright : CEA
8
9 #include "SUPERVGUI_Information.h"
10 #include "QAD_Application.h"
11 #include "QAD_Desktop.h"
12 #include "QAD_MessageBox.h"
13 #include <qapplication.h>
14 #include <qlabel.h>
15 #include <qgroupbox.h>
16 #include <qlayout.h>
17
18
19 /*!
20   Constructor
21 */
22 SUPERVGUI_Information::SUPERVGUI_Information(SUPERV_CNode node, bool isReadOnly)
23      : QDialog( QAD_Application::getDesktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) 
24 {
25   Trace("SUPERVGUI_Information::SUPERVGUI_Information");
26   setCaption( tr( "TLT_INFORMATIONS" ) );
27   setSizeGripEnabled( true );
28   myNode = node;
29
30   QGridLayout* TopLayout = new QGridLayout( this );
31   TopLayout->setSpacing( 6 );
32   TopLayout->setMargin( 11 );
33     
34   QGroupBox* TopGroup = new QGroupBox( this, "TopGroup" );
35   TopGroup->setColumnLayout(0, Qt::Vertical );
36   TopGroup->layout()->setSpacing( 0 );
37   TopGroup->layout()->setMargin( 0 );
38   QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
39   TopGroupLayout->setAlignment( Qt::AlignTop );
40   TopGroupLayout->setSpacing( 6 );
41   TopGroupLayout->setMargin( 11 );
42
43   QLabel* nameL = new QLabel( tr( "NAME_LBL" ), TopGroup );  
44   nameV = new QLineEdit( TopGroup );      
45   nameV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
46   nameV->setMinimumSize( 200, 0 );
47   nameV->setReadOnly( isReadOnly );
48   nameV->setText( node->Name() );
49   
50   QLabel* authL = new QLabel( tr( "AUTHOR_LBL" ), TopGroup); 
51   authV = new QLineEdit( TopGroup );
52   authV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
53   authV->setMinimumSize( 200, 0 );
54   authV->setReadOnly( isReadOnly );
55   authV->setText( node->Author() );
56
57   
58   if (node->IsFactory()) {
59     contL = new QLabel( tr( "CONTAINER_LBL" ), TopGroup ); 
60     contV = new QLineEdit( TopGroup );
61     contV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
62     contV->setMinimumSize( 200, 0 );
63   }
64   QLabel* cdatL = new QLabel( tr( "DATE_CREATION_LBL" ), TopGroup ); 
65   cdatV = new QLabel( TopGroup );
66   cdatV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
67   cdatV->setMinimumSize( 200, 0 );
68   cdatV->setText( date( node->CreationDate() ) );
69
70   QLabel* udatL = new QLabel( tr( "DATE_MODIFICATION_LBL" ), TopGroup ); 
71   udatV = new QLabel( TopGroup );
72   udatV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
73   udatV->setMinimumSize( 200, 0 );
74   udatV->setText( date( node->LastUpdateDate() ) );
75
76   QLabel* commL = new QLabel( tr( "COMMENT_LBL" ), TopGroup); 
77   commV = new QMultiLineEdit( TopGroup );
78   commV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
79   commV->setMinimumSize( 200, 100 );
80   commV->setReadOnly( isReadOnly );
81   commV->setText( node->Comment() );
82
83   TopGroupLayout->addWidget( nameL, 0, 0 );
84   TopGroupLayout->addWidget( nameV, 0, 1 );
85   TopGroupLayout->addWidget( authL, 1, 0 );
86   TopGroupLayout->addWidget( authV, 1, 1 );
87   if (node->IsFactory()) {
88     TopGroupLayout->addWidget( contL, 2, 0 );
89     TopGroupLayout->addWidget( contV, 2, 1 );
90   }
91   TopGroupLayout->addWidget( cdatL, 3, 0 );
92   TopGroupLayout->addWidget( cdatV, 3, 1 );
93   TopGroupLayout->addWidget( udatL, 4, 0 );
94   TopGroupLayout->addWidget( udatV, 4, 1 );
95   TopGroupLayout->addWidget( commL, 5, 0 );
96   TopGroupLayout->addMultiCellWidget( commV, 5, 6, 1, 1 );
97   TopGroupLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Minimum, QSizePolicy::Expanding  ), 6, 0 );
98   TopGroupLayout->setColStretch( 1, 5 );
99
100   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
101   GroupButtons->setColumnLayout(0, Qt::Vertical );
102   GroupButtons->layout()->setSpacing( 0 );
103   GroupButtons->layout()->setMargin( 0 );
104   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
105   GroupButtonsLayout->setAlignment( Qt::AlignTop );
106   GroupButtonsLayout->setSpacing( 6 );
107   GroupButtonsLayout->setMargin( 11 );
108   
109   QPushButton* okB     = new QPushButton( tr( "BUT_OK" ),     GroupButtons );
110   QPushButton* cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
111
112   GroupButtonsLayout->addWidget( okB, 0, 0 );
113   GroupButtonsLayout->addItem  ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
114   GroupButtonsLayout->addWidget( cancelB, 0, 2 );
115
116   TopLayout->addWidget( TopGroup,     0, 0 );
117   TopLayout->addWidget( GroupButtons, 1, 0 );
118
119   connect( okB,     SIGNAL( clicked() ), this, SLOT( okButton() ) );
120   connect( cancelB, SIGNAL( clicked() ), this, SLOT( koButton() ) );
121 }
122
123 /*!
124   Destructor
125 */
126 SUPERVGUI_Information::~SUPERVGUI_Information() {
127   Trace("SUPERVGUI_Information::~SUPERVGUI_Information");
128 }
129
130 /*!
131   Executes dialog
132 */
133 /*
134 bool SUPERVGUI_Information::run( SUPERV_CNode node, bool isReadOnly ) {
135   Trace("SUPERVGUI_Information::run");
136   nameV->setReadOnly( isReadOnly );
137   authV->setReadOnly( isReadOnly );
138   commV->setReadOnly( isReadOnly );
139
140   nameV->setText( node->Name() );
141   authV->setText( node->Author() );
142   commV->setText( node->Comment() );
143   if (node->IsFactory()) {
144     SUPERV_FNode aFNode = SUPERV::FNode::_narrow(node);
145     contV->setText( aFNode->GetContainer());
146     contL->show();
147     contV->show();
148   }
149   else {
150     contL->hide();
151     contV->hide();
152   }
153   qApp->processEvents();
154   adjustSize();
155
156   //commV->setText( node->Comment() );
157   cdatV->setText( date( node->CreationDate() ) );
158   udatV->setText( date( node->LastUpdateDate() ) );
159
160   bool b1     = true;
161   bool b2     = true;
162   bool b3     = true;
163   bool b4     = true;
164   bool result = false;
165   if ( exec() == Accepted ) {
166     if (! isReadOnly ) {
167       //b3 = node->SetContainer( contV->text().latin1() );
168       //} 
169       //else {
170       if ( strcmp( node->Name(), nameV->text().latin1() ) != 0 ) {
171         b1 = node->SetName( nameV->text().latin1() );
172       }
173       b2 = node->SetAuthor   ( authV->text().latin1() );
174       if (node->IsFactory()) {
175         SUPERV_FNode aFNode = SUPERV::FNode::_narrow(node);
176         b3 = aFNode->SetContainer( contV->text().latin1() );
177       }
178       b4 = node->SetComment  ( commV->text().latin1() );
179     }
180     result = b1 && b2 && b3 && b4;
181     if ( !result ) {
182       QAD_MessageBox::warn1( this, tr( "ERROR" ), tr( "MSG_CANT_CHANGE_INFO" ), tr( "BUT_OK" ) );
183     }
184   }
185   return result;
186   }*/
187
188 /*!
189   Returns string representation of date
190 */
191 QString SUPERVGUI_Information::date( SUPERV_Date d ) {
192   Trace("SUPERVGUI_Information::date");
193   QString dt( "" );
194
195   if ( d.Day != 0 ) {
196     dt += ( char )( d.Day / 10 + 48 );
197     dt += ( char )( d.Day % 10 + 48 );
198     dt += '/';
199     dt += ( char )( d.Month / 10 + 48 );
200     dt += ( char )( d.Month % 10 + 48 );
201     dt += '/';
202     dt += ( char )( ( d.Year / 1000 ) %10 + 48 );
203     dt += ( char )( ( d.Year / 100 ) % 10 + 48 );
204     dt += ( char )( ( d.Year / 10  ) % 10 + 48 );
205     dt += ( char )( d.Year %10 + 48 );
206     dt += ' ';
207     dt += ( char )( d.Hour / 10 + 48 );
208     dt += ( char )( d.Hour % 10 + 48 );
209     dt += ':';
210     dt += ( char )( d.Minute / 10 + 48 );
211     dt += ( char )( d.Minute % 10 + 48 );
212     dt += ':';
213     dt += ( char )( d.Second / 10 + 48 );
214     dt += ( char )( d.Second % 10 + 48 );
215   };
216   return( dt );
217 }
218
219 /*!
220   <OK> button slot
221 */
222 void SUPERVGUI_Information::okButton() {
223   Trace("SUPERVGUI_Information::okButton");
224   myNode->SetName( nameV->text().latin1());
225   myNode->SetAuthor( authV->text().latin1() );
226   if (myNode->IsFactory()) {
227     SUPERV_FNode aFNode = SUPERV::FNode::_narrow(myNode);
228     aFNode->SetContainer( contV->text().latin1() );
229   }
230   myNode->SetComment( commV->text().latin1() );
231   accept();
232 }
233
234 /*!
235   <Cancel> button slot
236 */
237 void SUPERVGUI_Information::koButton() {
238   Trace("SUPERVGUI_Information::koButton");
239   reject();
240 }