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( dynamic_cast<CAM_Application*>( SUIT_Session::session()->activeApplication() )->
94 moduleTitle(SUPERV::FNode::_narrow(node)->GetComponentName()) );
96 intnameL = new QLabel( tr( "INTERFACE_NAME_LBL" ), TopGroup );
97 intnameV = new QLineEdit( TopGroup );
98 intnameV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
99 intnameV->setMinimumSize( 200, 0 );
100 intnameV->setReadOnly( true/*isReadOnly*/ );
101 intnameV->setText( SUPERV::FNode::_narrow(node)->GetInterfaceName() );
104 QLabel* cdatL = new QLabel( tr( "DATE_CREATION_LBL" ), TopGroup );
105 cdatV = new QLabel( TopGroup );
106 cdatV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
107 cdatV->setMinimumSize( 200, 0 );
108 cdatV->setText( date( node->CreationDate() ) );
110 QLabel* udatL = new QLabel( tr( "DATE_MODIFICATION_LBL" ), TopGroup );
111 udatV = new QLabel( TopGroup );
112 udatV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
113 udatV->setMinimumSize( 200, 0 );
114 udatV->setText( date( node->LastUpdateDate() ) );
116 QLabel* commL = new QLabel( tr( "COMMENT_LBL" ), TopGroup);
117 commV = new QMultiLineEdit( TopGroup );
118 commV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
119 commV->setMinimumSize( 200, 100 );
120 commV->setReadOnly( isReadOnly );
121 commV->setText( node->Comment() );
123 TopGroupLayout->addWidget( nameL, 0, 0 );
124 TopGroupLayout->addWidget( nameV, 0, 1 );
125 TopGroupLayout->addWidget( authL, 1, 0 );
126 TopGroupLayout->addWidget( authV, 1, 1 );
127 if (node->IsFactory()) {
128 TopGroupLayout->addWidget( contL, 2, 0 );
129 TopGroupLayout->addWidget( contV, 2, 1 );
130 TopGroupLayout->addWidget( compnameL, 3, 0 );
131 TopGroupLayout->addWidget( compnameV, 3, 1 );
132 TopGroupLayout->addWidget( intnameL, 4, 0 );
133 TopGroupLayout->addWidget( intnameV, 4, 1 );
135 TopGroupLayout->addWidget( cdatL, 5, 0 );
136 TopGroupLayout->addWidget( cdatV, 5, 1 );
137 TopGroupLayout->addWidget( udatL, 6, 0 );
138 TopGroupLayout->addWidget( udatV, 6, 1 );
139 TopGroupLayout->addWidget( commL, 7, 0 );
140 TopGroupLayout->addMultiCellWidget( commV, 7, 8, 1, 1 );
141 TopGroupLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Minimum, QSizePolicy::Expanding ), 8, 0 );
142 TopGroupLayout->setColStretch( 1, 5 );
144 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
145 GroupButtons->setColumnLayout(0, Qt::Vertical );
146 GroupButtons->layout()->setSpacing( 0 );
147 GroupButtons->layout()->setMargin( 0 );
148 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
149 GroupButtonsLayout->setAlignment( Qt::AlignTop );
150 GroupButtonsLayout->setSpacing( 6 );
151 GroupButtonsLayout->setMargin( 11 );
153 // fix for PAL6904: when isReadOnly is set ON (the dataflow was imported) then only "CLOSE" button
154 // should be present instead of 2 buttons OK and Cancel.
155 QPushButton* cancelB;
156 if ( !isReadOnly || node->IsFactory() ) {
157 /*added node->IsFactory() because only for Factory nodes we ALWAYS have editable "Container" field */
158 QPushButton* okB = new QPushButton( tr( "BUT_OK" ), GroupButtons );
159 connect( okB, SIGNAL( clicked() ), this, SLOT( okButton() ) );
160 cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
161 GroupButtonsLayout->addWidget( okB, 0, 0 );
162 GroupButtonsLayout->addItem ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
163 GroupButtonsLayout->addWidget( cancelB, 0, 2 );
166 cancelB = new QPushButton( tr( "BUT_CLOSE" ), GroupButtons );
167 GroupButtonsLayout->addItem ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 0 );
168 GroupButtonsLayout->addWidget( cancelB, 0, 1 );
169 GroupButtonsLayout->addItem ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 2 );
172 TopLayout->addWidget( TopGroup, 0, 0 );
173 TopLayout->addWidget( GroupButtons, 1, 0 );
174 TopLayout->setRowStretch( 0, 1 );
175 TopLayout->setRowStretch( 1, 0 );
177 connect( cancelB, SIGNAL( clicked() ), this, SLOT( koButton() ) );
183 SUPERVGUI_Information::~SUPERVGUI_Information() {
184 Trace("SUPERVGUI_Information::~SUPERVGUI_Information");
191 bool SUPERVGUI_Information::run( SUPERV_CNode node, bool isReadOnly ) {
192 Trace("SUPERVGUI_Information::run");
193 nameV->setReadOnly( isReadOnly );
194 authV->setReadOnly( isReadOnly );
195 commV->setReadOnly( isReadOnly );
197 nameV->setText( node->Name() );
198 authV->setText( node->Author() );
199 commV->setText( node->Comment() );
200 if (node->IsFactory()) {
201 SUPERV_FNode aFNode = SUPERV::FNode::_narrow(node);
202 contV->setText( aFNode->GetContainer());
210 qApp->processEvents();
213 //commV->setText( node->Comment() );
214 cdatV->setText( date( node->CreationDate() ) );
215 udatV->setText( date( node->LastUpdateDate() ) );
222 if ( exec() == Accepted ) {
224 //b3 = node->SetContainer( contV->text().latin1() );
227 if ( strcmp( node->Name(), nameV->text().latin1() ) != 0 ) {
228 b1 = node->SetName( nameV->text().latin1() );
230 b2 = node->SetAuthor ( authV->text().latin1() );
231 if (node->IsFactory()) {
232 SUPERV_FNode aFNode = SUPERV::FNode::_narrow(node);
233 b3 = aFNode->SetContainer( contV->text().latin1() );
235 b4 = node->SetComment ( commV->text().latin1() );
237 result = b1 && b2 && b3 && b4;
239 QAD_MessageBox::warn1( this, tr( "ERROR" ), tr( "MSG_CANT_CHANGE_INFO" ), tr( "BUT_OK" ) );
246 Returns string representation of date
248 QString SUPERVGUI_Information::date( SUPERV_Date d ) {
249 Trace("SUPERVGUI_Information::date");
253 dt += ( char )( d.Day / 10 + 48 );
254 dt += ( char )( d.Day % 10 + 48 );
256 dt += ( char )( d.Month / 10 + 48 );
257 dt += ( char )( d.Month % 10 + 48 );
259 dt += ( char )( ( d.Year / 1000 ) %10 + 48 );
260 dt += ( char )( ( d.Year / 100 ) % 10 + 48 );
261 dt += ( char )( ( d.Year / 10 ) % 10 + 48 );
262 dt += ( char )( d.Year %10 + 48 );
264 dt += ( char )( d.Hour / 10 + 48 );
265 dt += ( char )( d.Hour % 10 + 48 );
267 dt += ( char )( d.Minute / 10 + 48 );
268 dt += ( char )( d.Minute % 10 + 48 );
270 dt += ( char )( d.Second / 10 + 48 );
271 dt += ( char )( d.Second % 10 + 48 );
279 void SUPERVGUI_Information::okButton() {
280 Trace("SUPERVGUI_Information::okButton");
281 myNode->SetName( nameV->text().latin1());
282 myNode->SetAuthor( authV->text().latin1() );
283 if (myNode->IsFactory()) {
284 SUPERV_FNode aFNode = SUPERV::FNode::_narrow(myNode);
285 aFNode->SetContainer( contV->text().latin1() );
287 myNode->SetComment( commV->text().latin1() );
294 void SUPERVGUI_Information::koButton() {
295 Trace("SUPERVGUI_Information::koButton");