1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_TwoImagesDlg.h"
21 #include "HYDROGUI_ColorWidget.h"
22 #include "HYDROGUI_ObjSelector.h"
29 #include <QRadioButton>
31 HYDROGUI_TwoImagesDlg::HYDROGUI_TwoImagesDlg( HYDROGUI_Module* theModule, const QString& theTitle )
32 : HYDROGUI_InputPanel( theModule, theTitle ),
33 myMode( TwoFuseImage ),
37 QGroupBox* anImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ) );
39 QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), anImageNameGroup );
40 myImageName = new QLineEdit( anImageNameGroup );
42 myModifySelectedImage = new QCheckBox( tr( "MODIFY_SELECTED_IMAGE" ) );
44 QGridLayout* anImageNameLayout = new QGridLayout( anImageNameGroup );
45 anImageNameLayout->setMargin( 5 );
46 anImageNameLayout->setSpacing( 5 );
47 anImageNameLayout->addWidget( anImageNameLabel, 0, 0 );
48 anImageNameLayout->addWidget( myImageName, 0, 1 );
49 anImageNameLayout->addWidget( myModifySelectedImage, 1, 0, 1, 2 );
52 QGroupBox* aParamGroup = new QGroupBox( tr( "PARAMETERS" ) );
54 myImage1Label = new QLabel( tr( "IMAGE_1" ), aParamGroup );
55 myImage1 = new HYDROGUI_ObjSelector( theModule, KIND_IMAGE, aParamGroup );
57 myImage2Label = new QLabel( tr( "IMAGE_2" ), aParamGroup );
58 myImage2 = new HYDROGUI_ObjSelector( theModule, KIND_IMAGE, aParamGroup );
60 myPolylineLabel = new QLabel( tr( "POLYLINE" ), aParamGroup );
61 myPolyline = new HYDROGUI_ObjSelector( theModule, KIND_POLYLINEXY, aParamGroup,
62 HYDROGUI_ObjSelector::ClosedPolyline);
64 myBackgroundFrame = new QFrame( aParamGroup );
65 QLabel* aBackgroundLabel = new QLabel( tr( "BACKGROUND" ), myBackgroundFrame );
66 myTransparent = new QRadioButton( tr( "TRANSPARENT" ), myBackgroundFrame );
67 myTransparent->setChecked( true );
68 myColor = new QRadioButton( tr( "COLOR" ), myBackgroundFrame );
69 myColorBox = new HYDROGUI_ColorWidget( myBackgroundFrame );
71 QGridLayout* aBackgroundLayout = new QGridLayout( myBackgroundFrame );
72 aBackgroundLayout->setMargin( 0 );
73 aBackgroundLayout->setSpacing( 5 );
74 aBackgroundLayout->addWidget( aBackgroundLabel, 0, 0, 2, 1 );
75 aBackgroundLayout->addWidget( myTransparent, 0, 1 );
76 aBackgroundLayout->addWidget( myColor, 1, 1 );
77 aBackgroundLayout->addWidget( myColorBox, 1, 2 );
79 QGridLayout* aParamLayout = new QGridLayout( aParamGroup );
80 aParamLayout->setMargin( 5 );
81 aParamLayout->setSpacing( 5 );
82 aParamLayout->addWidget( myImage1Label, 0, 0 );
83 aParamLayout->addWidget( myImage1, 0, 1 );
84 aParamLayout->addWidget( myImage2Label, 1, 0 );
85 aParamLayout->addWidget( myImage2, 1, 1 );
86 aParamLayout->addWidget( myPolylineLabel, 1, 0 );
87 aParamLayout->addWidget( myPolyline, 1, 1 );
88 aParamLayout->addWidget( myBackgroundFrame, 2, 0, 1, 2 );
91 addWidget( anImageNameGroup );
92 addWidget( aParamGroup );
95 connect( myModifySelectedImage, SIGNAL( toggled( bool ) ),
96 this, SLOT( onModifySelectedImage( bool ) ) );
97 connect( myTransparent, SIGNAL( toggled( bool ) ),
98 myColorBox, SLOT( setDisabled( bool ) ) );
99 connect( myImage1, SIGNAL( alreadySelected( const QString& ) ),
100 this, SIGNAL( alreadySelected( const QString& ) ) );
101 connect( myImage2, SIGNAL( alreadySelected( const QString& ) ),
102 this, SIGNAL( alreadySelected( const QString& ) ) );
104 setMode( myMode, myIsEdit );
107 HYDROGUI_TwoImagesDlg::~HYDROGUI_TwoImagesDlg()
111 void HYDROGUI_TwoImagesDlg::reset()
113 myImageName->clear();
114 myModifySelectedImage->setChecked( false );
118 myTransparent->setChecked( true );
119 myColorBox->resetColor();
120 myColorBox->setDisabled( true );
123 void HYDROGUI_TwoImagesDlg::setMode( const int theMode, const bool theIsEdit )
126 myIsEdit = theIsEdit;
128 bool anIsTwoImages = isTwoImagesMode();
130 myBackgroundFrame->setVisible( theMode != TwoCutImage );
132 myModifySelectedImage->setVisible( !anIsTwoImages && !myIsEdit );
134 myImage1Label->setText( anIsTwoImages ? tr( "IMAGE_1" ) : tr( "IMAGE" ) );
136 myImage2Label->setVisible( anIsTwoImages );
137 myImage2->setVisible( anIsTwoImages );
138 myPolylineLabel->setVisible( !anIsTwoImages );
139 myPolyline->setVisible( !anIsTwoImages );
142 bool HYDROGUI_TwoImagesDlg::isModifySelected() const
144 return myModifySelectedImage->isChecked();
147 void HYDROGUI_TwoImagesDlg::setImageName( const QString& theName )
149 myImageName->setText( theName );
152 QString HYDROGUI_TwoImagesDlg::getImageName() const
154 return myImageName->text();
157 void HYDROGUI_TwoImagesDlg::setSelectedObjects( const QString& theName1,
158 const QString& theName2 )
160 myImage1->SetName( theName1 );
161 if( isTwoImagesMode() )
162 myImage2->SetName( theName2 );
164 myPolyline->SetName( theName2 );
167 bool HYDROGUI_TwoImagesDlg::getSelectedObjects( QString& theName1,
168 QString& theName2 ) const
170 theName1 = myImage1->GetName();
171 if( isTwoImagesMode() )
172 theName2 = myImage2->GetName();
174 theName2 = myPolyline->GetName();
175 return !theName1.isEmpty() && !theName2.isEmpty();
178 void HYDROGUI_TwoImagesDlg::setPreselectedObject( const QString& theName )
180 myImage1->SetName( theName );
182 HYDROGUI_ObjSelector* aSelector = isTwoImagesMode() ? myImage2 : myPolyline;
183 aSelector->SetChecked( true );
184 aSelector->SetName( QString() );
187 void HYDROGUI_TwoImagesDlg::setColor( const QColor& theColor )
189 if( theColor.alpha() == 0 ) { // transparent
190 myTransparent->setChecked( true );
191 myColorBox->resetColor();
194 myColor->setChecked( true );
195 myColorBox->setColor( theColor );
199 QColor HYDROGUI_TwoImagesDlg::getColor() const
201 QColor aColor( 255, 255, 255, 0 ); // transparent
202 if( myColor->isChecked() )
203 aColor = myColorBox->color();
207 void HYDROGUI_TwoImagesDlg::onModifySelectedImage( bool theState )
209 myImageName->setEnabled( !theState );
212 bool HYDROGUI_TwoImagesDlg::isTwoImagesMode() const
214 return myMode == TwoFuseImage || myMode == TwoCutImage;