Salome HOME
HYDRO feature 2: Images composing (T 1.3).
[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 <QGroupBox>
29 #include <QLabel>
30 #include <QLayout>
31 #include <QLineEdit>
32 #include <QRadioButton>
33
34 HYDROGUI_TwoImagesDlg::HYDROGUI_TwoImagesDlg( HYDROGUI_Module* theModule, const QString& theTitle )
35 : HYDROGUI_InputPanel( theModule, theTitle )
36 {
37   // Image name
38   QGroupBox* anImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ) );
39
40   QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), anImageNameGroup );
41   myImageName = new QLineEdit( anImageNameGroup );
42
43   QBoxLayout* anImageNameLayout = new QHBoxLayout( anImageNameGroup );
44   anImageNameLayout->setMargin( 5 );
45   anImageNameLayout->setSpacing( 5 );
46   anImageNameLayout->addWidget( anImageNameLabel );
47   anImageNameLayout->addWidget( myImageName );
48
49   // Image name
50   QGroupBox* aParamGroup = new QGroupBox( tr( "PARAMETERS" ) );
51
52   QLabel* anImage1Label = new QLabel( tr( "IMAGE_1" ), aParamGroup );
53   myImage1 = new HYDROGUI_ObjSelector( theModule, aParamGroup );
54
55   QLabel* anImage2Label = new QLabel( tr( "IMAGE_2" ), aParamGroup );
56   myImage2 = new HYDROGUI_ObjSelector( theModule, aParamGroup );
57
58   QFrame* aBackgroundFrame = new QFrame( aParamGroup );
59   QLabel* aBackgroundLabel = new QLabel( tr( "BACKGROUND" ), aBackgroundFrame );
60   myTransparent = new QRadioButton( tr( "TRANSPARENT" ), aBackgroundFrame );
61   myTransparent->setChecked( true );
62   myColor = new QRadioButton( tr( "COLOR" ), aBackgroundFrame );
63   myColorBox = new HYDROGUI_ColorWidget( aBackgroundFrame );
64
65   QGridLayout* aBackgroundLayout = new QGridLayout( aBackgroundFrame );
66   aBackgroundLayout->setMargin( 0 );
67   aBackgroundLayout->setSpacing( 5 );
68   aBackgroundLayout->addWidget( aBackgroundLabel, 0, 0, 2, 1 );
69   aBackgroundLayout->addWidget( myTransparent,    0, 1 );
70   aBackgroundLayout->addWidget( myColor,          1, 1 );
71   aBackgroundLayout->addWidget( myColorBox,       1, 2 );
72
73   QGridLayout* aParamLayout = new QGridLayout( aParamGroup );
74   aParamLayout->setMargin( 5 );
75   aParamLayout->setSpacing( 5 );
76   aParamLayout->addWidget( anImage1Label,    0, 0 );
77   aParamLayout->addWidget( myImage1,         0, 1 );
78   aParamLayout->addWidget( anImage2Label,    1, 0 );
79   aParamLayout->addWidget( myImage2,         1, 1 );
80   aParamLayout->addWidget( aBackgroundFrame, 2, 0, 1, 2 );
81
82   // Common
83   addWidget( anImageNameGroup );
84   addWidget( aParamGroup );
85   addStretch();
86 }
87
88 HYDROGUI_TwoImagesDlg::~HYDROGUI_TwoImagesDlg()
89 {
90 }
91
92 void HYDROGUI_TwoImagesDlg::reset()
93 {
94   myImageName->clear();
95   myImage1->Clear();
96   myImage2->Clear();
97   myTransparent->setChecked( true );
98   myColorBox->resetColor();
99 }
100
101 void HYDROGUI_TwoImagesDlg::setImageName( const QString& theName )
102 {
103   myImageName->setText( theName );
104 }
105
106 QString HYDROGUI_TwoImagesDlg::getImageName() const
107 {
108   return myImageName->text();
109 }
110
111 void HYDROGUI_TwoImagesDlg::setSelectedImages( const QString& theName1,
112                                                const QString& theName2 )
113 {
114   myImage1->SetName( theName1 );
115   myImage2->SetName( theName2 );
116 }
117
118 bool HYDROGUI_TwoImagesDlg::getSelectedImages( QString& theName1,
119                                                QString& theName2 ) const
120 {
121   theName1 = myImage1->GetName();
122   theName2 = myImage2->GetName();
123   return !theName1.isEmpty() && !theName2.isEmpty();
124 }
125
126 void HYDROGUI_TwoImagesDlg::setColor( const QColor& theColor )
127 {
128   if( theColor.alpha() == 0 ) // transparent
129     myTransparent->setChecked( true );
130   else
131     myColor->setChecked( true );
132   myColorBox->setColor( theColor );
133 }
134
135 QColor HYDROGUI_TwoImagesDlg::getColor() const
136 {
137   QColor aColor( 255, 255, 255, 0 ); // transparent
138   if( myColor->isChecked() )
139     aColor = myColorBox->color();
140   return aColor;
141 }