Salome HOME
Update Help for VISU module.
[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   myColorBtn->setMinimumWidth( 20 );
52
53   myFamily = new QComboBox( this );
54   myFamily->insertItem( tr( "ARIAL" ) );
55   myFamily->insertItem( tr( "COURIER" ) );
56   myFamily->insertItem( tr( "TIMES" ) );
57
58   myBold = new QCheckBox( tr( "BOLD" ), this );
59   myItalic = new QCheckBox( tr( "ITALIC" ), this );
60   myShadow = new QCheckBox( tr( "SHADOW" ), this );
61
62   connect( myColorBtn, SIGNAL( clicked() ), SLOT( onColor() ) );
63 }
64
65 //=======================================================================
66 // name    : ~VisuGUI_FontWg
67 // Purpose : Destructor
68 //=======================================================================
69 VisuGUI_FontWg::~VisuGUI_FontWg()
70 {
71 }
72
73 //=======================================================================
74 // name    : SetColor
75 // Purpose :
76 //=======================================================================
77 void VisuGUI_FontWg::SetColor( const QColor& theColor )
78 {
79   myColorBtn->setPaletteBackgroundColor( theColor );
80 }
81
82 //=======================================================================
83 // name    : GetColor
84 // Purpose :
85 //=======================================================================
86 QColor VisuGUI_FontWg::GetColor() const
87 {
88   return myColorBtn->paletteBackgroundColor();
89 }
90
91 //=======================================================================
92 // name    : onColor
93 // Purpose :
94 //=======================================================================
95 void VisuGUI_FontWg::onColor()
96 {
97   QColor aColor = QColorDialog::getColor( GetColor(), this );
98   if ( aColor.isValid() )
99     SetColor( aColor );
100 }
101
102 //=======================================================================
103 // name    : SetData
104 // Purpose :
105 //=======================================================================
106 void VisuGUI_FontWg::SetData( const QColor& theColor,
107                               const int theFamily,
108                               const bool theBold,
109                               const bool theItalic,
110                               const bool theShadow )
111 {
112   SetColor( theColor );
113
114   if ( theFamily == VTK_ARIAL )
115     myFamily->setCurrentItem( 0 );
116   else if ( theFamily == VTK_COURIER )
117     myFamily->setCurrentItem( 1 );
118   else
119     myFamily->setCurrentItem( 2 );
120
121   myBold->setChecked( theBold );
122   myItalic->setChecked( theItalic );
123   myShadow->setChecked( theShadow );
124 }
125
126 //=======================================================================
127 // name    : GetData
128 // Purpose :
129 //=======================================================================
130 void VisuGUI_FontWg::GetData( QColor& theColor,
131                               int& theFamily,
132                               bool& theBold,
133                               bool& theItalic,
134                               bool& theShadow ) const
135 {
136   theColor = GetColor();
137
138   int anItem =myFamily->currentItem();
139   if ( anItem == 0 )
140     theFamily = VTK_ARIAL;
141   else if ( anItem == 1 )
142     theFamily = VTK_COURIER;
143   else
144     theFamily = VTK_TIMES;
145
146   theBold = myBold->isChecked();
147   theItalic = myItalic->isChecked();
148   theShadow = myShadow->isChecked();
149 }