1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_ColorDlg.h"
25 #include "HYDROGUI_ColorWidget.h"
26 #include "HYDROGUI_Tool.h"
31 #include <QRadioButton>
32 #include <QPushButton>
34 HYDROGUI_ColorDlg::HYDROGUI_ColorDlg( QWidget* theParent )
35 : QDialog( theParent )
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 );
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 );
54 myBorderColorGroup = new QGroupBox( tr( "BORDER_COLOR" ), this );
55 myBorderColorGroup->setCheckable( true );
57 myBorderColorBox = new HYDROGUI_ColorWidget( myBorderColorGroup );
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 );
66 QPushButton* anOkButton = new QPushButton( tr( "OK" ), this );
67 anOkButton->setDefault( true );
68 QPushButton* aCancelButton = new QPushButton( tr( "CANCEL" ), this );
69 aCancelButton->setAutoDefault( true );
71 QHBoxLayout* aButtonsLayout = new QHBoxLayout;
72 aButtonsLayout->setMargin( 5 );
73 aButtonsLayout->setSpacing( 5 );
74 aButtonsLayout->addWidget( anOkButton );
75 aButtonsLayout->addStretch();
76 aButtonsLayout->addWidget( aCancelButton );
79 QVBoxLayout* aMainLayout = new QVBoxLayout( this );
80 aMainLayout->setMargin( 5 );
81 aMainLayout->setSpacing( 5 );
83 aMainLayout->addWidget( aFillingFrame );
84 aMainLayout->addWidget( myBorderColorGroup );
85 aMainLayout->addStretch();
86 aMainLayout->addLayout( aButtonsLayout );
88 setLayout( aMainLayout );
90 // Connect signals and slots
91 connect( anOkButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
92 connect( aCancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
95 HYDROGUI_ColorDlg::~HYDROGUI_ColorDlg()
99 void HYDROGUI_ColorDlg::setFillingColor( const QColor& theColor )
101 if( theColor.alpha() == 0 ) // transparent
102 myFillingTransparent->setChecked( true );
104 myFillingColor->setChecked( true );
106 myFillingColorBox->setColor( theColor );
109 QColor HYDROGUI_ColorDlg::getFillingColor() const
111 QColor aColor( 255, 255, 255, 0 ); // transparent
112 if( myFillingColor->isChecked() )
113 aColor = myFillingColorBox->color();
117 void HYDROGUI_ColorDlg::setBorderColor( const QColor& theColor )
119 bool isTransparent = theColor.alpha() == 0;
120 myBorderColorGroup->setChecked( !isTransparent );
121 myBorderColorBox->setColor( !isTransparent ? theColor : QColor( Qt::black ) );
124 QColor HYDROGUI_ColorDlg::getBorderColor() const
126 QColor aColor( Qt::transparent ); // transparent
127 if( myBorderColorGroup->isChecked() )
128 aColor = myBorderColorBox->color();