]> SALOME platform Git repositories - modules/gui.git/blob - src/SVTK/SVTK_FontWidget.cxx
Salome HOME
679b8257e18f1a8dfb86391746e92da72dc04717
[modules/gui.git] / src / SVTK / SVTK_FontWidget.cxx
1 //  Copyright (C) 2007-2008  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.
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 //  VISU VISUGUI : GUI for SMESH component
23 //  File   : 
24 //  Author : Sergey LITONIN
25 //  Module : 
26 //
27 #include "SVTK_FontWidget.h"
28
29 #include <QToolButton>
30 #include <QComboBox>
31 #include <QColorDialog>
32 #include <QCheckBox>
33 #include <QHBoxLayout>
34
35 #include <vtkTextProperty.h>
36
37 /*!
38  * Class       : SVTK_FontWidget
39  * Description : Dialog for specifynig font
40  */
41
42 /*!
43   Constructor
44 */
45 SVTK_FontWidget::SVTK_FontWidget( QWidget* theParent )
46 : QWidget( theParent )
47 {
48   myColorBtn = new QToolButton( this );
49   myColorBtn->setMinimumWidth( 20 );
50
51   myFamily = new QComboBox( this );
52   myFamily->insertItem( myFamily->count(), tr( "ARIAL" ) );
53   myFamily->insertItem( myFamily->count(), tr( "COURIER" ) );
54   myFamily->insertItem( myFamily->count(), tr( "TIMES" ) );
55
56   myBold = new QCheckBox( tr( "BOLD" ), this );
57   myItalic = new QCheckBox( tr( "ITALIC" ), this );
58   myShadow = new QCheckBox( tr( "SHADOW" ), this );
59
60   QHBoxLayout* aHBLayout = new QHBoxLayout;
61   aHBLayout->setSpacing( 5 );
62   aHBLayout->addWidget(myColorBtn);
63   aHBLayout->addWidget(myFamily);
64   aHBLayout->addWidget(myBold);
65   aHBLayout->addWidget(myItalic);
66   aHBLayout->addWidget(myShadow);
67   this->setLayout(aHBLayout);
68
69   connect( myColorBtn, SIGNAL( clicked() ), SLOT( onColor() ) );
70 }
71
72 /*!
73   Destructor
74 */
75 SVTK_FontWidget::~SVTK_FontWidget()
76 {
77 }
78
79 void SVTK_FontWidget::SetColor( const QColor& theColor )
80 {
81   QPalette palette;
82   palette.setColor(myColorBtn->backgroundRole(), theColor);
83   myColorBtn->setPalette(palette);
84 }
85
86 QColor SVTK_FontWidget::GetColor() const
87 {
88   return myColorBtn->palette().color( myColorBtn->backgroundRole() );
89 }
90
91 void SVTK_FontWidget::onColor()
92 {
93   QColor aColor = QColorDialog::getColor( GetColor(), this );
94   if ( aColor.isValid() )
95     SetColor( aColor );
96 }
97
98 void SVTK_FontWidget::SetData( const QColor& theColor,
99                               const int theFamily,
100                               const bool theBold,
101                               const bool theItalic,
102                               const bool theShadow )
103 {
104   SetColor( theColor );
105
106   if ( theFamily == VTK_ARIAL )
107     myFamily->setCurrentIndex( 0 );
108   else if ( theFamily == VTK_COURIER )
109     myFamily->setCurrentIndex( 1 );
110   else
111     myFamily->setCurrentIndex( 2 );
112
113   myBold->setChecked( theBold );
114   myItalic->setChecked( theItalic );
115   myShadow->setChecked( theShadow );
116 }
117
118 void SVTK_FontWidget::GetData( QColor& theColor,
119                                int& theFamily,
120                                bool& theBold,
121                                bool& theItalic,
122                                bool& theShadow ) const
123 {
124   theColor = GetColor();
125
126   int anItem =myFamily->currentIndex();
127   if ( anItem == 0 )
128     theFamily = VTK_ARIAL;
129   else if ( anItem == 1 )
130     theFamily = VTK_COURIER;
131   else
132     theFamily = VTK_TIMES;
133
134   theBold = myBold->isChecked();
135   theItalic = myItalic->isChecked();
136   theShadow = myShadow->isChecked();
137 }