Salome HOME
a84935cc8d38e2d5ebb68f2d3ba50ed38edff7bf
[modules/gui.git] / src / ViewerTools / ViewerTools_FontWidgetBase.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "ViewerTools_FontWidgetBase.h"
24
25 #include <QToolButton>
26 #include <QComboBox>
27 #include <QColorDialog>
28 #include <QCheckBox>
29 #include <QHBoxLayout>
30
31 /*!
32  * Class       : ViewerTools_FontWidgetBase
33  * Description : Dialog for specifynig font
34  */
35
36 /*!
37   Constructor
38 */
39 ViewerTools_FontWidgetBase::ViewerTools_FontWidgetBase( QWidget* theParent )
40 : QWidget( theParent )
41 {
42 }
43
44 /*!
45   Destructor
46 */
47 ViewerTools_FontWidgetBase::~ViewerTools_FontWidgetBase()
48 {
49 }
50
51 void ViewerTools_FontWidgetBase::Initialize()
52 {
53   myColorBtn = new QToolButton( this );
54   myColorBtn->setMinimumWidth( 20 );
55
56   myFamily = new QComboBox( this );
57   InitializeFamilies();
58
59   myBold = new QCheckBox( tr( "BOLD" ), this );
60   myItalic = new QCheckBox( tr( "ITALIC" ), this );
61   myShadow = new QCheckBox( tr( "SHADOW" ), this );
62
63   QHBoxLayout* aHBLayout = new QHBoxLayout;
64   aHBLayout->setMargin( 0 );
65   aHBLayout->setSpacing( 5 );
66   aHBLayout->addWidget(myColorBtn);
67   aHBLayout->addWidget(myFamily);
68   aHBLayout->addWidget(myBold);
69   aHBLayout->addWidget(myItalic);
70   aHBLayout->addWidget(myShadow);
71   aHBLayout->addStretch();
72   this->setLayout(aHBLayout);
73
74   connect( myColorBtn, SIGNAL( clicked() ), SLOT( onColor() ) );
75
76   if( myFamily->count() == 0 )
77   {
78     myFamily->hide();
79     myBold->hide();
80     myItalic->hide();
81     myShadow->hide();
82   }
83 }
84
85 void ViewerTools_FontWidgetBase::SetColor( const QColor& theColor )
86 {
87   QPalette palette;
88   palette.setColor(myColorBtn->backgroundRole(), theColor);
89   myColorBtn->setPalette(palette);
90 }
91
92 QColor ViewerTools_FontWidgetBase::GetColor() const
93 {
94   return myColorBtn->palette().color( myColorBtn->backgroundRole() );
95 }
96
97 void ViewerTools_FontWidgetBase::onColor()
98 {
99   QColor aColor = QColorDialog::getColor( GetColor(), this );
100   if ( aColor.isValid() )
101     SetColor( aColor );
102 }
103
104 void ViewerTools_FontWidgetBase::SetData( const QColor& theColor,
105                                           const int /*theFamily*/,
106                                           const bool theBold,
107                                           const bool theItalic,
108                                           const bool theShadow )
109 {
110   SetColor( theColor );
111
112   myBold->setChecked( theBold );
113   myItalic->setChecked( theItalic );
114   myShadow->setChecked( theShadow );
115 }
116
117 void ViewerTools_FontWidgetBase::GetData( QColor& theColor,
118                                           int& /*theFamily*/,
119                                           bool& theBold,
120                                           bool& theItalic,
121                                           bool& theShadow ) const
122 {
123   theColor = GetColor();
124
125   theBold = myBold->isChecked();
126   theItalic = myItalic->isChecked();
127   theShadow = myShadow->isChecked();
128 }