Salome HOME
Size of color widget (Bug #120).
[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 )
35 : QDialog( theParent )
36 {
37   // Filling color
38   QFrame* aFillingFrame = new QFrame( this );
39   QLabel* aFillingLabel = new QLabel( tr( "FILLING_COLOR" ), aFillingFrame );
40   myFillingTransparent = new QRadioButton( tr( "TRANSPARENT" ), aFillingFrame );
41   myFillingTransparent->setChecked( true );
42   myFillingColor = new QRadioButton( tr( "COLOR" ), aFillingFrame );
43   myFillingColorBox = new HYDROGUI_ColorWidget( aFillingFrame );
44
45   QGridLayout* aFillingLayout = new QGridLayout( aFillingFrame );
46   aFillingLayout->setMargin( 5 );
47   aFillingLayout->setSpacing( 5 );
48   aFillingLayout->addWidget( aFillingLabel, 0, 0, 2, 1 );
49   aFillingLayout->addWidget( myFillingTransparent, 0, 1 );
50   aFillingLayout->addWidget( myFillingColor,       1, 1 );
51   aFillingLayout->addWidget( myFillingColorBox,    1, 2 );
52
53   // Border color
54   myBorderColorGroup = new QGroupBox( tr( "BORDER_COLOR" ), this );
55   myBorderColorGroup->setCheckable( true );
56
57   myBorderColorBox = new HYDROGUI_ColorWidget( myBorderColorGroup );
58
59   QBoxLayout* aBorderColorLayout = new QHBoxLayout( myBorderColorGroup );
60   aBorderColorLayout->setMargin( 5 );
61   aBorderColorLayout->setSpacing( 5 );
62   aBorderColorLayout->addWidget( new QLabel( tr( "COLOR" ), myBorderColorGroup ) );
63   aBorderColorLayout->addWidget( myBorderColorBox );
64
65   // Buttons
66   QPushButton* anOkButton = new QPushButton( tr( "OK" ), this );
67   anOkButton->setDefault( true ); 
68   QPushButton* aCancelButton = new QPushButton( tr( "CANCEL" ), this );
69   aCancelButton->setAutoDefault( true );
70
71   QHBoxLayout* aButtonsLayout = new QHBoxLayout;
72   aButtonsLayout->setMargin( 5 );
73   aButtonsLayout->setSpacing( 5 );
74   aButtonsLayout->addWidget( anOkButton );
75   aButtonsLayout->addStretch();
76   aButtonsLayout->addWidget( aCancelButton );
77
78   // Common
79   QVBoxLayout* aMainLayout = new QVBoxLayout( this );
80   aMainLayout->setMargin( 5 );
81   aMainLayout->setSpacing( 5 );
82
83   aMainLayout->addWidget( aFillingFrame );
84   aMainLayout->addWidget( myBorderColorGroup );
85   aMainLayout->addStretch();
86   aMainLayout->addLayout( aButtonsLayout );
87
88   setLayout( aMainLayout );  
89
90   // Connect signals and slots
91   connect( anOkButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
92   connect( aCancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
93
94   setFixedSize( 300, 150 );
95 }
96
97 HYDROGUI_ColorDlg::~HYDROGUI_ColorDlg()
98 {
99 }
100
101 void HYDROGUI_ColorDlg::setFillingColor( const QColor& theColor )
102 {
103   if( theColor.alpha() == 0 ) // transparent
104     myFillingTransparent->setChecked( true );
105   else
106     myFillingColor->setChecked( true );
107
108   myFillingColorBox->setColor( theColor );
109 }
110
111 QColor HYDROGUI_ColorDlg::getFillingColor() const
112 {
113   QColor aColor( 255, 255, 255, 0 ); // transparent
114   if( myFillingColor->isChecked() )
115     aColor = myFillingColorBox->color();
116   return aColor;
117 }
118
119 void HYDROGUI_ColorDlg::setBorderColor( const QColor& theColor )
120 {
121   bool isTransparent = theColor.alpha() == 0;
122   myBorderColorGroup->setChecked( !isTransparent );
123   myBorderColorBox->setColor( !isTransparent ? theColor : QColor( Qt::black ) );
124 }
125
126 QColor HYDROGUI_ColorDlg::getBorderColor() const
127 {
128   QColor aColor( Qt::transparent ); // transparent
129   if( myBorderColorGroup->isChecked() )
130     aColor = myBorderColorBox->color();
131   return aColor;
132 }
133
134