Salome HOME
Image positioning by two points.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_TwoImagesDlg.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_TwoImagesDlg.h"
24
25 #include "HYDROGUI_ColorWidget.h"
26 #include "HYDROGUI_ObjSelector.h"
27
28 #include <QCheckBox>
29 #include <QGroupBox>
30 #include <QLabel>
31 #include <QLayout>
32 #include <QLineEdit>
33 #include <QRadioButton>
34
35 HYDROGUI_TwoImagesDlg::HYDROGUI_TwoImagesDlg( HYDROGUI_Module* theModule, const QString& theTitle )
36 : HYDROGUI_InputPanel( theModule, theTitle ),
37   myMode( TwoImages ),
38   myIsEdit( false )
39 {
40   // Image name
41   QGroupBox* anImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ) );
42
43   QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), anImageNameGroup );
44   myImageName = new QLineEdit( anImageNameGroup );
45
46   myModifySelectedImage = new QCheckBox( tr( "MODIFY_SELECTED_IMAGE" ) );
47
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 );
54
55   // Parameters
56   QGroupBox* aParamGroup = new QGroupBox( tr( "PARAMETERS" ) );
57
58   myImage1Label = new QLabel( tr( "IMAGE_1" ), aParamGroup );
59   myImage1 = new HYDROGUI_ObjSelector( theModule, KIND_IMAGE, aParamGroup );
60
61   myImage2Label = new QLabel( tr( "IMAGE_2" ), aParamGroup );
62   myImage2 = new HYDROGUI_ObjSelector( theModule, KIND_IMAGE, aParamGroup );
63
64   myPolylineLabel = new QLabel( tr( "POLYLINE" ), aParamGroup );
65   myPolyline = new HYDROGUI_ObjSelector( theModule, KIND_POLYLINE, aParamGroup );
66
67   QFrame* aBackgroundFrame = new QFrame( aParamGroup );
68   QLabel* aBackgroundLabel = new QLabel( tr( "BACKGROUND" ), aBackgroundFrame );
69   myTransparent = new QRadioButton( tr( "TRANSPARENT" ), aBackgroundFrame );
70   myTransparent->setChecked( true );
71   myColor = new QRadioButton( tr( "COLOR" ), aBackgroundFrame );
72   myColorBox = new HYDROGUI_ColorWidget( aBackgroundFrame );
73
74   QGridLayout* aBackgroundLayout = new QGridLayout( aBackgroundFrame );
75   aBackgroundLayout->setMargin( 0 );
76   aBackgroundLayout->setSpacing( 5 );
77   aBackgroundLayout->addWidget( aBackgroundLabel, 0, 0, 2, 1 );
78   aBackgroundLayout->addWidget( myTransparent,    0, 1 );
79   aBackgroundLayout->addWidget( myColor,          1, 1 );
80   aBackgroundLayout->addWidget( myColorBox,       1, 2 );
81
82   QGridLayout* aParamLayout = new QGridLayout( aParamGroup );
83   aParamLayout->setMargin( 5 );
84   aParamLayout->setSpacing( 5 );
85   aParamLayout->addWidget( myImage1Label,    0, 0 );
86   aParamLayout->addWidget( myImage1,         0, 1 );
87   aParamLayout->addWidget( myImage2Label,    1, 0 );
88   aParamLayout->addWidget( myImage2,         1, 1 );
89   aParamLayout->addWidget( myPolylineLabel,  1, 0 );
90   aParamLayout->addWidget( myPolyline,       1, 1 );
91   aParamLayout->addWidget( aBackgroundFrame, 2, 0, 1, 2 );
92
93   // Common
94   addWidget( anImageNameGroup );
95   addWidget( aParamGroup );
96   addStretch();
97
98   connect( myModifySelectedImage, SIGNAL( toggled( bool ) ),
99            this, SLOT( onModifySelectedImage( bool ) ) );
100
101   setMode( myMode, myIsEdit );
102 }
103
104 HYDROGUI_TwoImagesDlg::~HYDROGUI_TwoImagesDlg()
105 {
106 }
107
108 void HYDROGUI_TwoImagesDlg::reset()
109 {
110   myImageName->clear();
111   myModifySelectedImage->setChecked( false );
112   myImage1->Clear();
113   myImage2->Clear();
114   myPolyline->Clear();
115   myTransparent->setChecked( true );
116   myColorBox->resetColor();
117 }
118
119 void HYDROGUI_TwoImagesDlg::setMode( const int theMode, const bool theIsEdit )
120 {
121   myMode = theMode;
122   myIsEdit = theIsEdit;
123
124   bool anIsTwoImages = myMode == TwoImages;
125
126   myModifySelectedImage->setVisible( !anIsTwoImages && !myIsEdit );
127
128   myImage1Label->setText( anIsTwoImages ? tr( "IMAGE_1" ) : tr( "IMAGE" ) );
129
130   myImage2Label->setVisible( anIsTwoImages );
131   myImage2->setVisible( anIsTwoImages );
132   myPolylineLabel->setVisible( !anIsTwoImages );
133   myPolyline->setVisible( !anIsTwoImages );
134 }
135
136 bool HYDROGUI_TwoImagesDlg::isModifySelected() const
137 {
138   return myModifySelectedImage->isChecked();
139 }
140
141 void HYDROGUI_TwoImagesDlg::setImageName( const QString& theName )
142 {
143   myImageName->setText( theName );
144 }
145
146 QString HYDROGUI_TwoImagesDlg::getImageName() const
147 {
148   return myImageName->text();
149 }
150
151 void HYDROGUI_TwoImagesDlg::setSelectedObjects( const QString& theName1,
152                                                 const QString& theName2 )
153 {
154   myImage1->SetName( theName1 );
155   if( myMode == TwoImages )
156     myImage2->SetName( theName2 );
157   else
158     myPolyline->SetName( theName2 );
159 }
160
161 bool HYDROGUI_TwoImagesDlg::getSelectedObjects( QString& theName1,
162                                                 QString& theName2 ) const
163 {
164   theName1 = myImage1->GetName();
165   if( myMode == TwoImages )
166     theName2 = myImage2->GetName();
167   else
168     theName2 = myPolyline->GetName();
169   return !theName1.isEmpty() && !theName2.isEmpty();
170 }
171
172 void HYDROGUI_TwoImagesDlg::setPreselectedObject( const QString& theName )
173 {
174   myImage1->SetName( theName );
175
176   HYDROGUI_ObjSelector* aSelector = myMode == TwoImages ? myImage2 : myPolyline;
177   aSelector->SetChecked( true );
178   aSelector->SetName( QString() );
179 }
180
181 void HYDROGUI_TwoImagesDlg::setColor( const QColor& theColor )
182 {
183   if( theColor.alpha() == 0 ) // transparent
184     myTransparent->setChecked( true );
185   else
186     myColor->setChecked( true );
187   myColorBox->setColor( theColor );
188 }
189
190 QColor HYDROGUI_TwoImagesDlg::getColor() const
191 {
192   QColor aColor( 255, 255, 255, 0 ); // transparent
193   if( myColor->isChecked() )
194     aColor = myColorBox->color();
195   return aColor;
196 }
197
198 void HYDROGUI_TwoImagesDlg::onModifySelectedImage( bool theState )
199 {
200   myImageName->setEnabled( !theState );
201 }