1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_TwoImagesDlg.h"
25 #include "HYDROGUI_ColorWidget.h"
26 #include "HYDROGUI_ObjSelector.h"
33 #include <QRadioButton>
35 HYDROGUI_TwoImagesDlg::HYDROGUI_TwoImagesDlg( HYDROGUI_Module* theModule, const QString& theTitle )
36 : HYDROGUI_InputPanel( theModule, theTitle ),
41 QGroupBox* anImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ) );
43 QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), anImageNameGroup );
44 myImageName = new QLineEdit( anImageNameGroup );
46 myModifySelectedImage = new QCheckBox( tr( "MODIFY_SELECTED_IMAGE" ) );
48 QGridLayout* anImageNameLayout = new QGridLayout( anImageNameGroup );
49 anImageNameLayout->setMargin( 5 );
50 anImageNameLayout->setSpacing( 5 );
51 anImageNameLayout->addWidget( anImageNameLabel, 0, 0 );
52 anImageNameLayout->addWidget( myImageName, 0, 1 );
53 anImageNameLayout->addWidget( myModifySelectedImage, 1, 0, 1, 2 );
56 QGroupBox* aParamGroup = new QGroupBox( tr( "PARAMETERS" ) );
58 myImage1Label = new QLabel( tr( "IMAGE_1" ), aParamGroup );
59 myImage1 = new HYDROGUI_ObjSelector( theModule, KIND_IMAGE, aParamGroup );
61 myImage2Label = new QLabel( tr( "IMAGE_2" ), aParamGroup );
62 myImage2 = new HYDROGUI_ObjSelector( theModule, KIND_IMAGE, aParamGroup );
64 myPolylineLabel = new QLabel( tr( "POLYLINE" ), aParamGroup );
65 myPolyline = new HYDROGUI_ObjSelector( theModule, KIND_POLYLINEXY, aParamGroup,
66 HYDROGUI_ObjSelector::ClosedPolyline);
68 QFrame* aBackgroundFrame = new QFrame( aParamGroup );
69 QLabel* aBackgroundLabel = new QLabel( tr( "BACKGROUND" ), aBackgroundFrame );
70 myTransparent = new QRadioButton( tr( "TRANSPARENT" ), aBackgroundFrame );
71 myTransparent->setChecked( true );
72 myColor = new QRadioButton( tr( "COLOR" ), aBackgroundFrame );
73 myColorBox = new HYDROGUI_ColorWidget( aBackgroundFrame );
75 QGridLayout* aBackgroundLayout = new QGridLayout( aBackgroundFrame );
76 aBackgroundLayout->setMargin( 0 );
77 aBackgroundLayout->setSpacing( 5 );
78 aBackgroundLayout->addWidget( aBackgroundLabel, 0, 0, 2, 1 );
79 aBackgroundLayout->addWidget( myTransparent, 0, 1 );
80 aBackgroundLayout->addWidget( myColor, 1, 1 );
81 aBackgroundLayout->addWidget( myColorBox, 1, 2 );
83 QGridLayout* aParamLayout = new QGridLayout( aParamGroup );
84 aParamLayout->setMargin( 5 );
85 aParamLayout->setSpacing( 5 );
86 aParamLayout->addWidget( myImage1Label, 0, 0 );
87 aParamLayout->addWidget( myImage1, 0, 1 );
88 aParamLayout->addWidget( myImage2Label, 1, 0 );
89 aParamLayout->addWidget( myImage2, 1, 1 );
90 aParamLayout->addWidget( myPolylineLabel, 1, 0 );
91 aParamLayout->addWidget( myPolyline, 1, 1 );
92 aParamLayout->addWidget( aBackgroundFrame, 2, 0, 1, 2 );
95 addWidget( anImageNameGroup );
96 addWidget( aParamGroup );
99 connect( myModifySelectedImage, SIGNAL( toggled( bool ) ),
100 this, SLOT( onModifySelectedImage( bool ) ) );
101 connect( myTransparent, SIGNAL( toggled( bool ) ),
102 myColorBox, SLOT( setDisabled( bool ) ) );
103 connect( myImage1, SIGNAL( alreadySelected( const QString& ) ),
104 this, SIGNAL( alreadySelected( const QString& ) ) );
105 connect( myImage2, SIGNAL( alreadySelected( const QString& ) ),
106 this, SIGNAL( alreadySelected( const QString& ) ) );
108 setMode( myMode, myIsEdit );
111 HYDROGUI_TwoImagesDlg::~HYDROGUI_TwoImagesDlg()
115 void HYDROGUI_TwoImagesDlg::reset()
117 myImageName->clear();
118 myModifySelectedImage->setChecked( false );
122 myTransparent->setChecked( true );
123 myColorBox->resetColor();
124 myColorBox->setDisabled( true );
127 void HYDROGUI_TwoImagesDlg::setMode( const int theMode, const bool theIsEdit )
130 myIsEdit = theIsEdit;
132 bool anIsTwoImages = myMode == TwoImages;
134 myModifySelectedImage->setVisible( !anIsTwoImages && !myIsEdit );
136 myImage1Label->setText( anIsTwoImages ? tr( "IMAGE_1" ) : tr( "IMAGE" ) );
138 myImage2Label->setVisible( anIsTwoImages );
139 myImage2->setVisible( anIsTwoImages );
140 myPolylineLabel->setVisible( !anIsTwoImages );
141 myPolyline->setVisible( !anIsTwoImages );
144 bool HYDROGUI_TwoImagesDlg::isModifySelected() const
146 return myModifySelectedImage->isChecked();
149 void HYDROGUI_TwoImagesDlg::setImageName( const QString& theName )
151 myImageName->setText( theName );
154 QString HYDROGUI_TwoImagesDlg::getImageName() const
156 return myImageName->text();
159 void HYDROGUI_TwoImagesDlg::setSelectedObjects( const QString& theName1,
160 const QString& theName2 )
162 myImage1->SetName( theName1 );
163 if( myMode == TwoImages )
164 myImage2->SetName( theName2 );
166 myPolyline->SetName( theName2 );
169 bool HYDROGUI_TwoImagesDlg::getSelectedObjects( QString& theName1,
170 QString& theName2 ) const
172 theName1 = myImage1->GetName();
173 if( myMode == TwoImages )
174 theName2 = myImage2->GetName();
176 theName2 = myPolyline->GetName();
177 return !theName1.isEmpty() && !theName2.isEmpty();
180 void HYDROGUI_TwoImagesDlg::setPreselectedObject( const QString& theName )
182 myImage1->SetName( theName );
184 HYDROGUI_ObjSelector* aSelector = myMode == TwoImages ? myImage2 : myPolyline;
185 aSelector->SetChecked( true );
186 aSelector->SetName( QString() );
189 void HYDROGUI_TwoImagesDlg::setColor( const QColor& theColor )
191 if( theColor.alpha() == 0 ) // transparent
192 myTransparent->setChecked( true );
194 myColor->setChecked( true );
195 myColorBox->setColor( theColor );
198 QColor HYDROGUI_TwoImagesDlg::getColor() const
200 QColor aColor( 255, 255, 255, 0 ); // transparent
201 if( myColor->isChecked() )
202 aColor = myColorBox->color();
206 void HYDROGUI_TwoImagesDlg::onModifySelectedImage( bool theState )
208 myImageName->setEnabled( !theState );