Salome HOME
First implementation of automatic mode of regions creation in the calculation case...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ColorDlg.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_ColorDlg.h"
24
25 #include "HYDROGUI_ColorWidget.h"
26 #include "HYDROGUI_Tool.h"
27
28 #include <QGroupBox>
29 #include <QLabel>
30 #include <QLayout>
31 #include <QRadioButton>
32 #include <QPushButton>
33
34 HYDROGUI_ColorDlg::HYDROGUI_ColorDlg( QWidget* theParent, bool theIsOneColor )
35 : QDialog( theParent ),
36   myIsOneColor( theIsOneColor )
37 {
38   QVBoxLayout* aMainLayout = new QVBoxLayout( this );
39   aMainLayout->setMargin( 5 );
40   aMainLayout->setSpacing( 5 );
41
42   if ( !theIsOneColor )
43   {
44     // Filling color
45     QFrame* aFillingFrame = new QFrame( this );
46     QLabel* aFillingLabel = new QLabel( tr( "FILLING_COLOR" ), aFillingFrame );
47     myFillingTransparent = new QRadioButton( tr( "TRANSPARENT" ), aFillingFrame );
48     myFillingTransparent->setChecked( true );
49     myFillingColor = new QRadioButton( tr( "COLOR" ), aFillingFrame );
50     myFillingColorBox = new HYDROGUI_ColorWidget( aFillingFrame );
51
52     QGridLayout* aFillingLayout = new QGridLayout( aFillingFrame );
53     aFillingLayout->setMargin( 5 );
54     aFillingLayout->setSpacing( 5 );
55     aFillingLayout->addWidget( aFillingLabel, 0, 0, 2, 1 );
56     aFillingLayout->addWidget( myFillingTransparent, 0, 1 );
57     aFillingLayout->addWidget( myFillingColor,       1, 1 );
58     aFillingLayout->addWidget( myFillingColorBox,    1, 2 );
59
60     // Border color
61     myBorderColorGroup = new QGroupBox( tr( "BORDER_COLOR" ), this );
62     myBorderColorGroup->setCheckable( true );
63
64     myBorderColorBox = new HYDROGUI_ColorWidget( myBorderColorGroup );
65
66     QBoxLayout* aBorderColorLayout = new QHBoxLayout( myBorderColorGroup );
67     aBorderColorLayout->setMargin( 5 );
68     aBorderColorLayout->setSpacing( 5 );
69     aBorderColorLayout->addWidget( new QLabel( tr( "COLOR" ), myBorderColorGroup ) );
70     aBorderColorLayout->addWidget( myBorderColorBox );
71
72     aMainLayout->addWidget( aFillingFrame );
73     aMainLayout->addWidget( myBorderColorGroup );
74
75     connect( myFillingTransparent, SIGNAL( toggled( bool ) ), 
76              myFillingColorBox, SLOT( setDisabled( bool ) ) );
77   }
78   else
79   {
80     QFrame* aColorFrame = new QFrame( this );
81     QLabel* aColorLabel = new QLabel( tr( "OBJECT_COLOR" ), aColorFrame );
82     myColorBox = new HYDROGUI_ColorWidget( aColorFrame );
83     myColorBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); 
84     myColorBox->setFixedHeight( 20 );
85
86     QBoxLayout* aColorLayout = new QHBoxLayout( aColorFrame );
87     aColorLayout->setMargin( 10 );
88     aColorLayout->setSpacing( 5 );
89     aColorLayout->addWidget( aColorLabel );
90     aColorLayout->addWidget( myColorBox );
91
92     aMainLayout->addWidget( aColorFrame );
93   }
94
95   // Buttons
96   QPushButton* anOkButton = new QPushButton( tr( "OK" ), this );
97   anOkButton->setDefault( true ); 
98   QPushButton* aCancelButton = new QPushButton( tr( "CANCEL" ), this );
99   aCancelButton->setAutoDefault( true );
100
101   QHBoxLayout* aButtonsLayout = new QHBoxLayout;
102   aButtonsLayout->setMargin( 5 );
103   aButtonsLayout->setSpacing( 5 );
104   aButtonsLayout->addWidget( anOkButton );
105   aButtonsLayout->addStretch();
106   aButtonsLayout->addWidget( aCancelButton );
107
108   // Common
109   aMainLayout->addStretch();
110   aMainLayout->addLayout( aButtonsLayout );
111
112   setLayout( aMainLayout );  
113
114   // Connect signals and slots
115   connect( anOkButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
116   connect( aCancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
117
118   setFixedSize( 300, theIsOneColor ? 90 : 150 );
119 }
120
121 HYDROGUI_ColorDlg::~HYDROGUI_ColorDlg()
122 {
123 }
124
125 void HYDROGUI_ColorDlg::setFirstColor( const QColor& theColor )
126 {
127   if ( !myIsOneColor )
128   {
129     if( theColor.alpha() == 0 ) // transparent
130       myFillingTransparent->setChecked( true );
131     else
132       myFillingColor->setChecked( true );
133
134     myFillingColorBox->setColor( theColor );
135   }
136   else
137   {
138     myColorBox->setColor( theColor );
139   }
140 }
141
142 QColor HYDROGUI_ColorDlg::getFirstColor() const
143 {
144   QColor aColor;
145   if ( !myIsOneColor )
146   {
147     aColor = QColor( 255, 255, 255, 0 ); // transparent
148     if( myFillingColor->isChecked() )
149       aColor = myFillingColorBox->color();
150   }
151   else
152   {
153     aColor = myColorBox->color();
154   }
155
156   return aColor;
157 }
158
159 void HYDROGUI_ColorDlg::setSecondColor( const QColor& theColor )
160 {
161   if ( myIsOneColor )
162     return;
163
164   bool isTransparent = theColor.alpha() == 0;
165   myBorderColorGroup->setChecked( !isTransparent );
166   myBorderColorBox->setColor( !isTransparent ? theColor : QColor( Qt::black ) );
167 }
168
169 QColor HYDROGUI_ColorDlg::getSecondColor() const
170 {
171   QColor aColor( Qt::transparent ); // transparent
172  
173   if ( myIsOneColor )
174     return aColor;
175
176   if( myBorderColorGroup->isChecked() )
177     aColor = myBorderColorBox->color();
178   
179   return aColor;
180 }
181
182