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_Information.cxx
25 // Author : Francis KLOSS
29 #include "SUPERVGUI_Information.h"
31 #include "CAM_Application.h"
32 #include "SUIT_Desktop.h"
33 #include "SUIT_Session.h"
35 #include <qapplication.h>
37 #include <qgroupbox.h>
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 )
47 Trace("SUPERVGUI_Information::SUPERVGUI_Information");
48 setCaption( tr( "TLT_INFORMATIONS" ) );
49 setSizeGripEnabled( true );
52 QGridLayout* TopLayout = new QGridLayout( this );
53 TopLayout->setSpacing( 6 );
54 TopLayout->setMargin( 11 );
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 );
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() );
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() );
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() );
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
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() );
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() ) );
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() ) );
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() );
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 );
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 );
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 );
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 );
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 );
171 TopLayout->addWidget( TopGroup, 0, 0 );
172 TopLayout->addWidget( GroupButtons, 1, 0 );
173 TopLayout->setRowStretch( 0, 1 );
174 TopLayout->setRowStretch( 1, 0 );
176 connect( cancelB, SIGNAL( clicked() ), this, SLOT( koButton() ) );
182 SUPERVGUI_Information::~SUPERVGUI_Information() {
183 Trace("SUPERVGUI_Information::~SUPERVGUI_Information");
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 );
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());
209 qApp->processEvents();
212 //commV->setText( node->Comment() );
213 cdatV->setText( date( node->CreationDate() ) );
214 udatV->setText( date( node->LastUpdateDate() ) );
221 if ( exec() == Accepted ) {
223 //b3 = node->SetContainer( contV->text().latin1() );
226 if ( strcmp( node->Name(), nameV->text().latin1() ) != 0 ) {
227 b1 = node->SetName( nameV->text().latin1() );
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() );
234 b4 = node->SetComment ( commV->text().latin1() );
236 result = b1 && b2 && b3 && b4;
238 QAD_MessageBox::warn1( this, tr( "ERROR" ), tr( "MSG_CANT_CHANGE_INFO" ), tr( "BUT_OK" ) );
245 Returns string representation of date
247 QString SUPERVGUI_Information::date( SUPERV_Date d ) {
248 Trace("SUPERVGUI_Information::date");
252 dt += ( char )( d.Day / 10 + 48 );
253 dt += ( char )( d.Day % 10 + 48 );
255 dt += ( char )( d.Month / 10 + 48 );
256 dt += ( char )( d.Month % 10 + 48 );
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 );
263 dt += ( char )( d.Hour / 10 + 48 );
264 dt += ( char )( d.Hour % 10 + 48 );
266 dt += ( char )( d.Minute / 10 + 48 );
267 dt += ( char )( d.Minute % 10 + 48 );
269 dt += ( char )( d.Second / 10 + 48 );
270 dt += ( char )( d.Second % 10 + 48 );
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" ) );
287 myNode->SetAuthor( authV->text().latin1() );
288 if (myNode->IsFactory()) {
289 SUPERV_FNode aFNode = SUPERV::FNode::_narrow(myNode);
290 aFNode->SetContainer( contV->text().latin1() );
292 myNode->SetComment( commV->text().latin1() );
293 if ( aIsAccept ) accept();
299 void SUPERVGUI_Information::koButton() {
300 Trace("SUPERVGUI_Information::koButton");