Salome HOME
copyrights are updated
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ColorWidget.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_ColorWidget.h"
20
21 #include <QApplication>
22 #include <QColorDialog>
23
24 HYDROGUI_ColorWidget::HYDROGUI_ColorWidget( QWidget* parent )
25 : QFrame( parent )
26 {
27   setFrameShape( QFrame::Box );
28   //setFixedSize( 40, 20 );
29   //commented for correct layout management
30   //(otherwise the column with color widget can not be resized
31   //and all free space is arranged on sides
32 }
33
34 HYDROGUI_ColorWidget::~HYDROGUI_ColorWidget()
35 {
36 }
37
38 QColor HYDROGUI_ColorWidget::color() const
39 {
40   QPalette aPalette = palette();
41   return aPalette.color( QPalette::Window );
42 }
43
44 void HYDROGUI_ColorWidget::setColor( const QColor& c )
45 {
46   QPalette aPalette = palette();
47   aPalette.setColor( QPalette::Window, c );
48   setAutoFillBackground( true );
49   setPalette( aPalette );
50 }
51
52 void HYDROGUI_ColorWidget::resetColor()
53 {
54   QPalette aDefPalette = QApplication::palette();
55   QColor aColor = aDefPalette.color( QPalette::Window );
56   setColor( aColor );
57 }
58
59 void HYDROGUI_ColorWidget::mouseDoubleClickEvent( QMouseEvent* )
60 {
61   QColor c = QColorDialog::getColor( color(), this );
62   if( c.isValid() )
63   {
64     setColor( c );
65     emit colorChanged( c );
66   }
67 }
68 /*
69 int HYDROGUI_ColorWidget::intColor() const
70 {
71   return HYDROGUI_Tools::color2int( color() );
72 }
73
74 void HYDROGUI_ColorWidget::setColor( const int col )
75 {
76   setColor( HYDROGUI_Tools::int2color( col ) );
77 }
78 */
79 /*void HYDROGUI_ColorWidget::setRandColor()
80 {
81   setColor( HYDROGUI_Tools::randColor() );
82 }*/