1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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 );
75 connect( myFillingTransparent, SIGNAL( toggled( bool ) ),
76 myFillingColorBox, SLOT( setDisabled( bool ) ) );
80 QFrame* aColorFrame = new QFrame( this );
81 QLabel* aColorLabel = new QLabel( tr( "OBJECT_COLOR" ), aColorFrame );
82 myColorBox = new HYDROGUI_ColorWidget( aColorFrame );
83 myColorBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
84 myColorBox->setFixedHeight( 20 );
86 QBoxLayout* aColorLayout = new QHBoxLayout( aColorFrame );
87 aColorLayout->setMargin( 10 );
88 aColorLayout->setSpacing( 5 );
89 aColorLayout->addWidget( aColorLabel );
90 aColorLayout->addWidget( myColorBox );
92 aMainLayout->addWidget( aColorFrame );
96 QPushButton* anOkButton = new QPushButton( tr( "OK" ), this );
97 anOkButton->setDefault( true );
98 QPushButton* aCancelButton = new QPushButton( tr( "CANCEL" ), this );
99 aCancelButton->setAutoDefault( true );
101 QHBoxLayout* aButtonsLayout = new QHBoxLayout;
102 aButtonsLayout->setMargin( 5 );
103 aButtonsLayout->setSpacing( 5 );
104 aButtonsLayout->addWidget( anOkButton );
105 aButtonsLayout->addStretch();
106 aButtonsLayout->addWidget( aCancelButton );
109 aMainLayout->addStretch();
110 aMainLayout->addLayout( aButtonsLayout );
112 setLayout( aMainLayout );
114 // Connect signals and slots
115 connect( anOkButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
116 connect( aCancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
118 setFixedSize( 300, theIsOneColor ? 90 : 150 );
121 HYDROGUI_ColorDlg::~HYDROGUI_ColorDlg()
125 void HYDROGUI_ColorDlg::setFirstColor( const QColor& theColor )
129 if( theColor.alpha() == 0 ) // transparent
130 myFillingTransparent->setChecked( true );
132 myFillingColor->setChecked( true );
134 myFillingColorBox->setColor( theColor );
138 myColorBox->setColor( theColor );
142 QColor HYDROGUI_ColorDlg::getFirstColor() const
147 aColor = QColor( 255, 255, 255, 0 ); // transparent
148 if( myFillingColor->isChecked() )
149 aColor = myFillingColorBox->color();
153 aColor = myColorBox->color();
159 void HYDROGUI_ColorDlg::setSecondColor( const QColor& theColor )
164 bool isTransparent = theColor.alpha() == 0;
165 myBorderColorGroup->setChecked( !isTransparent );
166 myBorderColorBox->setColor( !isTransparent ? theColor : QColor( Qt::black ) );
169 QColor HYDROGUI_ColorDlg::getSecondColor() const
171 QColor aColor( Qt::transparent ); // transparent
176 if( myBorderColorGroup->isChecked() )
177 aColor = myBorderColorBox->color();