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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_ColorDlg.h"
21 #include "HYDROGUI_ColorWidget.h"
22 #include "HYDROGUI_Tool.h"
27 #include <QRadioButton>
28 #include <QPushButton>
30 HYDROGUI_ColorDlg::HYDROGUI_ColorDlg( QWidget* theParent, bool theIsOneColor )
31 : QDialog( theParent ),
32 myIsOneColor( theIsOneColor )
34 QVBoxLayout* aMainLayout = new QVBoxLayout( this );
35 aMainLayout->setMargin( 5 );
36 aMainLayout->setSpacing( 5 );
41 QFrame* aFillingFrame = new QFrame( this );
42 QLabel* aFillingLabel = new QLabel( tr( "FILLING_COLOR" ), aFillingFrame );
43 myFillingTransparent = new QRadioButton( tr( "TRANSPARENT" ), aFillingFrame );
44 myFillingTransparent->setChecked( true );
45 myFillingColor = new QRadioButton( tr( "COLOR" ), aFillingFrame );
46 myFillingColorBox = new HYDROGUI_ColorWidget( aFillingFrame );
48 QGridLayout* aFillingLayout = new QGridLayout( aFillingFrame );
49 aFillingLayout->setMargin( 5 );
50 aFillingLayout->setSpacing( 5 );
51 aFillingLayout->addWidget( aFillingLabel, 0, 0, 2, 1 );
52 aFillingLayout->addWidget( myFillingTransparent, 0, 1 );
53 aFillingLayout->addWidget( myFillingColor, 1, 1 );
54 aFillingLayout->addWidget( myFillingColorBox, 1, 2 );
57 myBorderColorGroup = new QGroupBox( tr( "BORDER_COLOR" ), this );
58 myBorderColorGroup->setCheckable( true );
60 myBorderColorBox = new HYDROGUI_ColorWidget( myBorderColorGroup );
62 QBoxLayout* aBorderColorLayout = new QHBoxLayout( myBorderColorGroup );
63 aBorderColorLayout->setMargin( 5 );
64 aBorderColorLayout->setSpacing( 5 );
65 aBorderColorLayout->addWidget( new QLabel( tr( "COLOR" ), myBorderColorGroup ) );
66 aBorderColorLayout->addWidget( myBorderColorBox );
68 aMainLayout->addWidget( aFillingFrame );
69 aMainLayout->addWidget( myBorderColorGroup );
71 connect( myFillingTransparent, SIGNAL( toggled( bool ) ),
72 myFillingColorBox, SLOT( setDisabled( bool ) ) );
76 QFrame* aColorFrame = new QFrame( this );
77 QLabel* aColorLabel = new QLabel( tr( "OBJECT_COLOR" ), aColorFrame );
78 myColorBox = new HYDROGUI_ColorWidget( aColorFrame );
79 myColorBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
80 myColorBox->setFixedHeight( 20 );
82 QBoxLayout* aColorLayout = new QHBoxLayout( aColorFrame );
83 aColorLayout->setMargin( 10 );
84 aColorLayout->setSpacing( 5 );
85 aColorLayout->addWidget( aColorLabel );
86 aColorLayout->addWidget( myColorBox );
88 aMainLayout->addWidget( aColorFrame );
92 QPushButton* anOkButton = new QPushButton( tr( "OK" ), this );
93 anOkButton->setDefault( true );
94 QPushButton* aCancelButton = new QPushButton( tr( "CANCEL" ), this );
95 aCancelButton->setAutoDefault( true );
97 QHBoxLayout* aButtonsLayout = new QHBoxLayout;
98 aButtonsLayout->setMargin( 5 );
99 aButtonsLayout->setSpacing( 5 );
100 aButtonsLayout->addWidget( anOkButton );
101 aButtonsLayout->addStretch();
102 aButtonsLayout->addWidget( aCancelButton );
105 aMainLayout->addStretch();
106 aMainLayout->addLayout( aButtonsLayout );
108 setLayout( aMainLayout );
110 // Connect signals and slots
111 connect( anOkButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
112 connect( aCancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
114 setFixedSize( 300, theIsOneColor ? 90 : 150 );
117 HYDROGUI_ColorDlg::~HYDROGUI_ColorDlg()
121 void HYDROGUI_ColorDlg::setFirstColor( const QColor& theColor )
125 if( theColor.alpha() == 0 ) // transparent
126 myFillingTransparent->setChecked( true );
128 myFillingColor->setChecked( true );
130 myFillingColorBox->setColor( theColor );
134 myColorBox->setColor( theColor );
138 QColor HYDROGUI_ColorDlg::getFirstColor() const
143 aColor = QColor( 255, 255, 255, 0 ); // transparent
144 if( myFillingColor->isChecked() )
145 aColor = myFillingColorBox->color();
149 aColor = myColorBox->color();
155 void HYDROGUI_ColorDlg::setSecondColor( const QColor& theColor )
160 bool isTransparent = theColor.alpha() == 0;
161 myBorderColorGroup->setChecked( !isTransparent );
162 myBorderColorBox->setColor( !isTransparent ? theColor : QColor( Qt::black ) );
165 QColor HYDROGUI_ColorDlg::getSecondColor() const
167 QColor aColor( Qt::transparent ); // transparent
172 if( myBorderColorGroup->isChecked() )
173 aColor = myBorderColorBox->color();