Salome HOME
Merge with branch V2_2_0_VISU_improvement
[modules/visu.git] / src / VISUGUI / VisuGUI_FontWg.cxx
1 //  VISU VISUGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  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.
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : VisuGUI_CubeAxesDlg.cxx
25 //  Author : Sergey LITONIN
26 //  Module : VISU
27
28 #include "VisuGUI_FontWg.h"
29
30 #include <qtoolbutton.h>
31 #include <qcombobox.h>
32 #include <qcolordialog.h>
33 #include <qcheckbox.h>
34
35 #include <vtkTextProperty.h>
36
37 /*!
38  * Class       : VisuGUI_FontWg
39  * Description : Dialog for specifynig font
40  */
41
42 //=======================================================================
43 // name    : VisuGUI_FontWg
44 // Purpose : Constructor
45 //=======================================================================
46 VisuGUI_FontWg::VisuGUI_FontWg( QWidget* theParent )
47 : QHBox( theParent )
48 {
49   setSpacing( 5 );
50   myColorBtn = new QToolButton( this );
51
52   myFamily = new QComboBox( this );
53   myFamily->insertItem( tr( "ARIAL" ) );
54   myFamily->insertItem( tr( "COURIER" ) );
55   myFamily->insertItem( tr( "TIMES" ) );
56
57   myBold = new QCheckBox( tr( "BOLD" ), this );
58   myItalic = new QCheckBox( tr( "ITALIC" ), this );
59   myShadow = new QCheckBox( tr( "SHADOW" ), this );
60
61   connect( myColorBtn, SIGNAL( clicked() ), SLOT( onColor() ) );
62 }
63
64 //=======================================================================
65 // name    : ~VisuGUI_FontWg
66 // Purpose : Destructor
67 //=======================================================================
68 VisuGUI_FontWg::~VisuGUI_FontWg()
69 {
70 }
71
72 //=======================================================================
73 // name    : SetColor
74 // Purpose :
75 //=======================================================================
76 void VisuGUI_FontWg::SetColor( const QColor& theColor )
77 {
78   myColorBtn->setPaletteBackgroundColor( theColor );
79 }
80
81 //=======================================================================
82 // name    : GetColor
83 // Purpose :
84 //=======================================================================
85 QColor VisuGUI_FontWg::GetColor() const
86 {
87   return myColorBtn->paletteBackgroundColor();
88 }
89
90 //=======================================================================
91 // name    : onColor
92 // Purpose :
93 //=======================================================================
94 void VisuGUI_FontWg::onColor()
95 {
96   QColor aColor = QColorDialog::getColor( GetColor(), this );
97   if ( aColor.isValid() )
98     SetColor( aColor );
99 }
100
101 //=======================================================================
102 // name    : SetData
103 // Purpose :
104 //=======================================================================
105 void VisuGUI_FontWg::SetData( const QColor& theColor,
106                               const int theFamily,
107                               const bool theBold,
108                               const bool theItalic,
109                               const bool theShadow )
110 {
111   SetColor( theColor );
112
113   if ( theFamily == VTK_ARIAL )
114     myFamily->setCurrentItem( 0 );
115   else if ( theFamily == VTK_COURIER )
116     myFamily->setCurrentItem( 1 );
117   else
118     myFamily->setCurrentItem( 2 );
119
120   myBold->setChecked( theBold );
121   myItalic->setChecked( theItalic );
122   myShadow->setChecked( theShadow );
123 }
124
125 //=======================================================================
126 // name    : GetData
127 // Purpose :
128 //=======================================================================
129 void VisuGUI_FontWg::GetData( QColor& theColor,
130                               int& theFamily,
131                               bool& theBold,
132                               bool& theItalic,
133                               bool& theShadow ) const
134 {
135   theColor = GetColor();
136
137   int anItem =myFamily->currentItem();
138   if ( anItem == 0 )
139     theFamily = VTK_ARIAL;
140   else if ( anItem == 1 )
141     theFamily = VTK_COURIER;
142   else
143     theFamily = VTK_TIMES;
144
145   theBold = myBold->isChecked();
146   theItalic = myItalic->isChecked();
147   theShadow = myShadow->isChecked();
148 }