Salome HOME
Remove unnecessary trace from CMake.
[modules/gui.git] / src / PyEditor / PyEditor_SettingsDlg.cxx
1 // Copyright (C) 2015-2016  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, or (at your option) any later version.
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 // File   : PyEditor_SettingsDlg.cxx
20 // Author : Maxim GLIBIN, Open CASCADE S.A.S. (maxim.glibin@opencascade.com)
21 //
22
23 #include "PyEditor_SettingsDlg.h"
24
25 #include "PyEditor_Editor.h"
26 #include "PyEditor_Settings.h"
27
28 #include <QCheckBox>
29 #include <QGroupBox>
30 #include <QLabel>
31 #include <QPushButton>
32 #include <QSpinBox>
33 #include <QVBoxLayout>
34 #include <QtxFontEdit.h>
35
36 /*!
37   \class PyEditor_SettingsDlg
38   \brief Dialog settings for python editor.
39 */
40
41 /*!
42   \brief Constructor.
43   \param theEditor widget that is used to edit and display text
44   \param theParent parent widget
45 */
46 PyEditor_SettingsDlg::PyEditor_SettingsDlg( PyEditor_Editor* theEditor, QWidget* theParent ) :
47   QDialog( theParent ),
48   my_Editor( theEditor )
49 {
50   setWindowTitle( tr("TIT_PY_PREF") );
51   QVBoxLayout* aMainLayout = new QVBoxLayout( this );
52   
53   // . Font settings <start>
54   QGroupBox* aFontSetBox = new QGroupBox( tr( "GR_FONT_SET" ) );
55   QHBoxLayout* aFontSetLayout = new QHBoxLayout( aFontSetBox );
56   w_FontWidget = new QtxFontEdit( QtxFontEdit::Family|QtxFontEdit::Size|QtxFontEdit::UserSize, this );
57   aFontSetLayout->addWidget( w_FontWidget );
58   // . Font settings <end>
59   
60   // . Display settings <start>
61   QGroupBox* aDisplaySetBox = new QGroupBox( tr( "GR_DISP_SET" ) );
62   QVBoxLayout* aDisplaySetLayout = new QVBoxLayout;
63   w_HighlightCurrentLine = new QCheckBox( tr( "LBL_CURRLINE_HIGHLIGHT" ) );
64   w_TextWrapping = new QCheckBox( tr( "LBL_TEXT_WRAP" ) );
65   w_CenterCursorOnScroll = new QCheckBox( tr( "LBL_CURSOR_SCROLL" ) );
66   w_LineNumberArea = new QCheckBox( tr( "LBL_LINE_NUMBS_AREA" ) );
67   aDisplaySetLayout->addWidget( w_HighlightCurrentLine );
68   aDisplaySetLayout->addWidget( w_TextWrapping );
69   aDisplaySetLayout->addWidget( w_CenterCursorOnScroll );
70   aDisplaySetLayout->addWidget( w_LineNumberArea );
71   aDisplaySetLayout->addStretch( 1 );
72   aDisplaySetBox->setLayout( aDisplaySetLayout );
73   // . Display settings <end>
74
75   QHBoxLayout* aTabVertEdgeLayout = new QHBoxLayout;
76
77   // . Tab settings <start>
78   QGroupBox* aTabSetBox = new QGroupBox( tr( "GR_TAB_SET" ) );
79   QVBoxLayout* aTabSetLayout = new QVBoxLayout;
80   w_TabSpaceVisible = new QCheckBox( tr( "LBL_TAB_SPACES" ) );
81   QHBoxLayout* aTabSizeLayout = new QHBoxLayout;
82   QLabel* aTabSizeLabel = new QLabel( tr( "LBL_TAB_SIZE" ) );
83   w_TabSize = new QSpinBox;
84   w_TabSize->setMinimum( 0 );
85   w_TabSize->setSingleStep( 1 );
86   aTabSizeLayout->addWidget( aTabSizeLabel );
87   aTabSizeLayout->addWidget( w_TabSize );
88   aTabSizeLayout->addStretch( 1 );
89   aTabSetLayout->addWidget( w_TabSpaceVisible );
90   aTabSetLayout->addLayout( aTabSizeLayout );
91   aTabSetBox->setLayout( aTabSetLayout );
92   // . Tab settings <end>
93
94   // . Vertical edge settings <start>
95   QGroupBox* aVertEdgeSetBox = new QGroupBox( tr( "GR_VERT_EDGE_SET" ) );
96   QVBoxLayout* aVertEdgeLayout = new QVBoxLayout;
97   w_VerticalEdge = new QCheckBox( tr( "LBL_VERT_EDGE" ) );
98   QHBoxLayout* aNumberColLayout = new QHBoxLayout;
99   lbl_NumColumns = new QLabel( tr( "LBL_NUM_COLUMNS" ) );
100   w_NumberColumns = new QSpinBox;
101   w_NumberColumns->setMinimum( 0 );
102   w_NumberColumns->setSingleStep( 1 );
103   aNumberColLayout->addWidget( lbl_NumColumns );
104   aNumberColLayout->addWidget( w_NumberColumns );
105   aNumberColLayout->addStretch( 1 );
106   aVertEdgeLayout->addWidget( w_VerticalEdge );
107   aVertEdgeLayout->addLayout( aNumberColLayout );
108   aVertEdgeSetBox->setLayout( aVertEdgeLayout );
109   connect( w_VerticalEdge, SIGNAL( clicked( bool ) ), 
110            this, SLOT( onVerticalEdgeChecked( bool ) ) );
111   // . Vertical edge settings <end>
112
113   aTabVertEdgeLayout->addWidget( aTabSetBox );
114   aTabVertEdgeLayout->addWidget( aVertEdgeSetBox );
115
116   // . "Set as default" check box
117   w_DefaultCheck = new QCheckBox( tr( "WDG_SET_AS_DEFAULT_CHECK" ), this );
118   
119   aMainLayout->addWidget( aFontSetBox );
120   aMainLayout->addWidget( aDisplaySetBox );
121   aMainLayout->addLayout( aTabVertEdgeLayout );
122   aMainLayout->addWidget( w_DefaultCheck );
123   aMainLayout->addStretch( 1 );
124   
125   myOkBtn = new QPushButton( tr( "BUT_OK" ), this );
126   myOkBtn->setAutoDefault( true );
127   myOkBtn->setDefault( true );
128   myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this );
129   myCancelBtn->setAutoDefault( true );
130   myHelpBtn = new QPushButton( tr( "BUT_HELP" ), this );
131   myHelpBtn->setAutoDefault( true );
132   QHBoxLayout* aButtonLayout = new QHBoxLayout;
133   aButtonLayout->addWidget( myOkBtn );
134   aButtonLayout->addStretch();
135   aButtonLayout->addWidget( myCancelBtn );
136   aButtonLayout->addWidget( myHelpBtn );
137   aMainLayout->addLayout( aButtonLayout );
138
139   connect( myOkBtn,         SIGNAL( clicked() ), this, SLOT( onOk() ) );
140   connect( myCancelBtn,     SIGNAL( clicked() ), this, SLOT( reject() ) );
141   connect( myHelpBtn,       SIGNAL( clicked() ), this, SLOT( onHelp() ) );
142   
143   settingsToGui();
144 }
145
146 /*!
147   \brief Get "Set settings as default" check box value.
148   \return \c true if "Set settings as default" check box is on
149 */
150 bool PyEditor_SettingsDlg::isSetAsDefault()
151 {
152   return w_DefaultCheck->isChecked();
153 }
154
155 /*!
156   SLOT: Changes the widget visibility depending on the set theState flag.
157   \param theState flag of visibility
158  */
159 void PyEditor_SettingsDlg::onVerticalEdgeChecked( bool theState )
160 {
161   lbl_NumColumns->setEnabled( theState );
162   w_NumberColumns->setEnabled( theState );
163 }
164
165 /*!
166   \brief Sets settings from preferences dialog.
167  */
168 void PyEditor_SettingsDlg::settingsFromGui()
169 {
170   my_Editor->settings()->p_HighlightCurrentLine = w_HighlightCurrentLine->isChecked();
171   my_Editor->settings()->p_TextWrapping = w_TextWrapping->isChecked();
172   my_Editor->settings()->p_CenterCursorOnScroll = w_CenterCursorOnScroll->isChecked();
173   my_Editor->settings()->p_LineNumberArea = w_LineNumberArea->isChecked();
174   my_Editor->settings()->p_TabSpaceVisible = w_TabSpaceVisible->isChecked();
175   my_Editor->settings()->p_TabSize = w_TabSize->value();
176   my_Editor->settings()->p_VerticalEdge = w_VerticalEdge->isChecked();
177   my_Editor->settings()->p_NumberColumns = w_NumberColumns->value();
178   my_Editor->settings()->p_Font = w_FontWidget->currentFont();
179 }
180
181 /*!
182   \brief Sets settings into preferences dialog.
183  */
184 void PyEditor_SettingsDlg::settingsToGui()
185 {
186   w_HighlightCurrentLine->setChecked( my_Editor->settings()->p_HighlightCurrentLine );
187   w_TextWrapping->setChecked( my_Editor->settings()->p_TextWrapping );
188   w_CenterCursorOnScroll->setChecked( my_Editor->settings()->p_CenterCursorOnScroll );
189   w_LineNumberArea->setChecked( my_Editor->settings()->p_LineNumberArea );
190   w_TabSpaceVisible->setChecked( my_Editor->settings()->p_TabSpaceVisible );
191   w_TabSize->setValue( my_Editor->settings()->p_TabSize );
192   w_VerticalEdge->setChecked( my_Editor->settings()->p_VerticalEdge );
193   w_NumberColumns->setValue( my_Editor->settings()->p_NumberColumns );
194   w_FontWidget->setCurrentFont( my_Editor->settings()->p_Font );
195   w_FontWidget->setSizes();
196
197   onVerticalEdgeChecked( my_Editor->settings()->p_VerticalEdge );
198 }
199
200 /*!
201   \brief Sets settings into the setting resources or file
202   if the flag is set as default is true.
203  */
204 void PyEditor_SettingsDlg::setSettings()
205 {
206   if ( isSetAsDefault() )
207     my_Editor->settings()->writeSettings();
208
209   my_Editor->updateStatement();
210 }
211
212 /*!
213   Slot, called when user clicks "OK" button
214 */
215 void PyEditor_SettingsDlg::onOk()
216 {
217   settingsFromGui();
218   setSettings();
219   accept();
220 }
221
222 /*!
223   Slot, called when user clicks "Help" button.
224 */
225 void PyEditor_SettingsDlg::onHelp()
226 {
227   emit onHelpClicked();
228 }