Salome HOME
92839a13a6d41aaa416a56323a6b75858f4b49a1
[modules/visu.git] / src / VISUGUI / VisuGUI_ValuesLabelingDlg.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  File   : VisuGUI_ValuesLabelingDlg.cxx
21 //  Author : Litonin SERGEY
22 //  Module : SALOME
23 //
24 #include "VisuGUI_ValuesLabelingDlg.h"
25 #include "VisuGUI.h"
26
27 #include <QGroupBox>
28 #include <QHBoxLayout>
29 #include <QLabel>
30 #include <QPushButton>
31 #include <QtxColorButton.h>
32 #include <QtxFontEdit.h>
33 #include <QVBoxLayout>
34
35 /*!
36   \class VisuGUI_ValuesLabelingDlg
37   \brief This class is intended for changing parameters of labeling values
38   of 3D colored presentations
39 */
40
41 /*!
42   \brief Constructor
43   \param theModule module
44 */
45 VisuGUI_ValuesLabelingDlg::VisuGUI_ValuesLabelingDlg( SalomeApp_Module* theModule )
46 : VisuGUI_Prs3dDlg( theModule )
47 {
48   setWindowTitle( tr( "PARAMETERS_OF_VALUES_LABELING" ) );
49
50   // font groups
51
52   QGroupBox* aFGrp = new QGroupBox( tr( "LABELS" ), this );
53
54   QLabel* aFont = new QLabel( tr( "FONT" ) );
55   QLabel* aColor = new QLabel( tr( "COLOR" ) );
56   myFont = new QtxFontEdit( aFGrp );
57   myColor = new  QtxColorButton( aFGrp );
58   myColor->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
59
60   QGridLayout* aFLay = new QGridLayout( aFGrp );
61   aFLay->setSpacing( 5 );
62   aFLay->setMargin( 5 );
63
64   aFLay->addWidget( aFont, 0, 0 );
65   aFLay->addWidget( myFont, 0, 1 );
66   aFLay->addWidget( aColor, 1, 0 );
67   aFLay->addWidget( myColor, 1, 1 );
68
69   // buttons
70
71   QGroupBox* aBtnGrp = new QGroupBox( this );
72   QGridLayout* aBtnLay = new QGridLayout( aBtnGrp );
73   aBtnLay->setAlignment( Qt::AlignTop );
74   aBtnLay->setSpacing( 5 );
75   aBtnLay->setMargin( 5 );
76
77   QPushButton* anOK = new QPushButton( tr("BUT_OK"), aBtnGrp );
78   anOK->setAutoDefault( true );
79   anOK->setDefault( true );
80   aBtnLay->addWidget( anOK, 0, 0 );
81   aBtnLay->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
82
83   QPushButton* aCancel = new QPushButton( tr("BUT_CANCEL") , aBtnGrp );
84   aCancel->setAutoDefault( true );
85   aBtnLay->addWidget( aCancel, 0, 2 );
86
87   QPushButton* aHelp = new QPushButton( tr("BUT_HELP") , aBtnGrp );
88   aHelp->setAutoDefault( true );
89   aBtnLay->addWidget( aHelp, 0, 3 );
90
91   myFont->setMode( QtxFontEdit::Custom );
92   myFont->setFeatures( QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic |
93     QtxFontEdit::Shadow | QtxFontEdit::UserSize | QtxFontEdit::Size );
94   QStringList fam;
95   fam.append( tr( "VISU_FONT_ARIAL" ) );
96   fam.append( tr( "VISU_FONT_COURIER" ) );
97   fam.append( tr( "VISU_FONT_TIMES" ) );
98   myFont->setFonts( fam );
99
100   // Layout widgets
101
102   QVBoxLayout* aMainLay = new QVBoxLayout( this );
103   aMainLay->setSpacing( 5 );
104   aMainLay->setMargin( 5 );
105   aMainLay->addWidget( aFGrp );
106   aMainLay->addWidget( aBtnGrp );
107
108   // Connect signals and slots
109   connect( anOK,SIGNAL( clicked() ), SLOT( accept() ) );
110   connect( aCancel, SIGNAL( clicked() ), SLOT( reject() ) );
111   connect( aHelp, SIGNAL( clicked() ), SLOT( onHelp() ) );
112
113   setFixedSize( minimumSizeHint() );
114 }
115
116 /*!
117   \brief Destructor
118 */
119 VisuGUI_ValuesLabelingDlg::~VisuGUI_ValuesLabelingDlg()
120 {
121 }
122
123 /*!
124   \brief Initializes dialog fields using specified presentation
125   \param thePrs presentation
126   \param theInit not used
127   \sa storeToPrsObject()
128 */
129 void VisuGUI_ValuesLabelingDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs, bool )
130 {
131   if ( !thePrs )
132     return;
133
134   int aFType = thePrs->GetValLblFontType();
135
136   double aSize = thePrs->GetValLblFontSize();
137
138   bool isBold = thePrs->IsBoldValLbl();
139   bool isItalic = thePrs->IsItalicValLbl();
140   bool isShadow = thePrs->IsShadowValLbl();
141
142   vtkFloatingPointType aGRB[ 3 ];
143   thePrs->GetValLblFontColor( aGRB[ 0 ], aGRB[ 1 ], aGRB[ 2 ] );
144
145   // font
146   QFont aFont;
147
148   QString aFamily;
149   if ( aFType == VTK_ARIAL )
150     aFamily = "Arial";
151   else if ( aFType == VTK_COURIER )
152     aFamily = "Courier";
153   else if ( aFType == VTK_TIMES )
154     aFamily = "Times";
155
156   aFont.setFamily( aFamily );
157   aFont.setPointSize( aSize );
158   aFont.setBold( isBold );
159   aFont.setItalic( isItalic );
160   aFont.setOverline( isShadow );
161
162   myFont->setCurrentFont( aFont );
163
164   // color
165   QColor aColor( aGRB[ 0 ] * 255, aGRB[ 1 ] * 255, aGRB[ 2 ] * 255 );
166   myColor->setColor( aColor );
167 }
168
169 /*!
170   \brief Updates presentation in accordance with dialog input data
171   \param thePrs to be updated
172   \sa initFromPrsObject()
173 */
174 int VisuGUI_ValuesLabelingDlg::storeToPrsObject( VISU::ColoredPrs3d_i* thePrs )
175 {
176   if ( !thePrs )
177     return 0;
178
179   QFont aFont = myFont->currentFont();
180
181   // type
182   if ( aFont.family() == "Arial" )
183     thePrs->SetValLblFontType( VTK_ARIAL );
184   else if ( aFont.family() == "Courier" )
185     thePrs->SetValLblFontType( VTK_COURIER );
186   else if ( aFont.family() == "Times" )
187     thePrs->SetValLblFontType( VTK_TIMES );
188
189   // size
190   int aSize = aFont.pointSize();
191   if ( aSize > 0 )
192     thePrs->SetValLblFontSize( aSize );
193
194   // bold, italic, shadow
195   thePrs->SetBoldValLbl( aFont.bold() );
196   thePrs->SetItalicValLbl( aFont.italic() );
197   thePrs->SetShadowValLbl( aFont.overline() );
198
199   // color
200   QColor aColor = myColor->color();
201   thePrs->SetValLblFontColor(
202     aColor.red() / 255., aColor.green() / 255., aColor.blue() / 255. );
203
204   return 1;
205 }
206
207 /*!
208   \brief Gets help file name
209 */
210 QString VisuGUI_ValuesLabelingDlg::GetContextHelpFilePath()
211 {
212   return "viewing_3d_presentations_page.html#labeling_parameters_anchor";
213 }