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, bool theIsOneColor )
35 : QDialog( theParent ),
36 myIsOneColor( theIsOneColor )
38 QVBoxLayout* aMainLayout = new QVBoxLayout( this );
39 aMainLayout->setMargin( 5 );
40 aMainLayout->setSpacing( 5 );
45 QFrame* aFillingFrame = new QFrame( this );
46 QLabel* aFillingLabel = new QLabel( tr( "FILLING_COLOR" ), aFillingFrame );
47 myFillingTransparent = new QRadioButton( tr( "TRANSPARENT" ), aFillingFrame );
48 myFillingTransparent->setChecked( true );
49 myFillingColor = new QRadioButton( tr( "COLOR" ), aFillingFrame );
50 myFillingColorBox = new HYDROGUI_ColorWidget( aFillingFrame );
52 QGridLayout* aFillingLayout = new QGridLayout( aFillingFrame );
53 aFillingLayout->setMargin( 5 );
54 aFillingLayout->setSpacing( 5 );
55 aFillingLayout->addWidget( aFillingLabel, 0, 0, 2, 1 );
56 aFillingLayout->addWidget( myFillingTransparent, 0, 1 );
57 aFillingLayout->addWidget( myFillingColor, 1, 1 );
58 aFillingLayout->addWidget( myFillingColorBox, 1, 2 );
61 myBorderColorGroup = new QGroupBox( tr( "BORDER_COLOR" ), this );
62 myBorderColorGroup->setCheckable( true );
64 myBorderColorBox = new HYDROGUI_ColorWidget( myBorderColorGroup );
66 QBoxLayout* aBorderColorLayout = new QHBoxLayout( myBorderColorGroup );
67 aBorderColorLayout->setMargin( 5 );
68 aBorderColorLayout->setSpacing( 5 );
69 aBorderColorLayout->addWidget( new QLabel( tr( "COLOR" ), myBorderColorGroup ) );
70 aBorderColorLayout->addWidget( myBorderColorBox );
72 aMainLayout->addWidget( aFillingFrame );
73 aMainLayout->addWidget( myBorderColorGroup );
77 QFrame* aColorFrame = new QFrame( this );
78 QLabel* aColorLabel = new QLabel( tr( "OBJECT_COLOR" ), aColorFrame );
79 myColorBox = new HYDROGUI_ColorWidget( aColorFrame );
80 myColorBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
81 myColorBox->setFixedHeight( 20 );
83 QBoxLayout* aColorLayout = new QHBoxLayout( aColorFrame );
84 aColorLayout->setMargin( 10 );
85 aColorLayout->setSpacing( 5 );
86 aColorLayout->addWidget( aColorLabel );
87 aColorLayout->addWidget( myColorBox );
89 aMainLayout->addWidget( aColorFrame );
93 QPushButton* anOkButton = new QPushButton( tr( "OK" ), this );
94 anOkButton->setDefault( true );
95 QPushButton* aCancelButton = new QPushButton( tr( "CANCEL" ), this );
96 aCancelButton->setAutoDefault( true );
98 QHBoxLayout* aButtonsLayout = new QHBoxLayout;
99 aButtonsLayout->setMargin( 5 );
100 aButtonsLayout->setSpacing( 5 );
101 aButtonsLayout->addWidget( anOkButton );
102 aButtonsLayout->addStretch();
103 aButtonsLayout->addWidget( aCancelButton );
106 aMainLayout->addStretch();
107 aMainLayout->addLayout( aButtonsLayout );
109 setLayout( aMainLayout );
111 // Connect signals and slots
112 connect( anOkButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
113 connect( aCancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
115 setFixedSize( 300, theIsOneColor ? 90 : 150 );
118 HYDROGUI_ColorDlg::~HYDROGUI_ColorDlg()
122 void HYDROGUI_ColorDlg::setFirstColor( const QColor& theColor )
126 if( theColor.alpha() == 0 ) // transparent
127 myFillingTransparent->setChecked( true );
129 myFillingColor->setChecked( true );
131 myFillingColorBox->setColor( theColor );
135 myColorBox->setColor( theColor );
139 QColor HYDROGUI_ColorDlg::getFirstColor() const
144 aColor = QColor( 255, 255, 255, 0 ); // transparent
145 if( myFillingColor->isChecked() )
146 aColor = myFillingColorBox->color();
150 aColor = myColorBox->color();
156 void HYDROGUI_ColorDlg::setSecondColor( const QColor& theColor )
161 bool isTransparent = theColor.alpha() == 0;
162 myBorderColorGroup->setChecked( !isTransparent );
163 myBorderColorBox->setColor( !isTransparent ? theColor : QColor( Qt::black ) );
166 QColor HYDROGUI_ColorDlg::getSecondColor() const
168 QColor aColor( Qt::transparent ); // transparent
173 if( myBorderColorGroup->isChecked() )
174 aColor = myBorderColorBox->color();