Salome HOME
Image composing.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ColorWidget.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_ColorWidget.h"
24
25 #include <QApplication>
26 #include <QColorDialog>
27
28 HYDROGUI_ColorWidget::HYDROGUI_ColorWidget( QWidget* parent )
29 : QFrame( parent )
30 {
31   setFrameShape( QFrame::Box );
32   //setFixedSize( 40, 20 );
33   //commented for correct layout management
34   //(otherwise the column with color widget can not be resized
35   //and all free space is arranged on sides
36 }
37
38 HYDROGUI_ColorWidget::~HYDROGUI_ColorWidget()
39 {
40 }
41
42 QColor HYDROGUI_ColorWidget::color() const
43 {
44   QPalette aPalette = palette();
45   return aPalette.color( QPalette::Window );
46 }
47
48 void HYDROGUI_ColorWidget::setColor( const QColor& c )
49 {
50   QPalette aPalette = palette();
51   aPalette.setColor( QPalette::Window, c );
52   setAutoFillBackground( true );
53   setPalette( aPalette );
54 }
55
56 void HYDROGUI_ColorWidget::resetColor()
57 {
58   QPalette aDefPalette = QApplication::palette();
59   QColor aColor = aDefPalette.color( QPalette::Window );
60   setColor( aColor );
61 }
62
63 void HYDROGUI_ColorWidget::mouseDoubleClickEvent( QMouseEvent* )
64 {
65   QColor c = QColorDialog::getColor( color(), this );
66   if( c.isValid() )
67   {
68     setColor( c );
69     emit colorChanged( c );
70   }
71 }
72 /*
73 int HYDROGUI_ColorWidget::intColor() const
74 {
75   return HYDROGUI_Tools::color2int( color() );
76 }
77
78 void HYDROGUI_ColorWidget::setColor( const int col )
79 {
80   setColor( HYDROGUI_Tools::int2color( col ) );
81 }
82 */
83 /*void HYDROGUI_ColorWidget::setRandColor()
84 {
85   setColor( HYDROGUI_Tools::randColor() );
86 }*/