Salome HOME
Upgrade to paraview 5.4
[modules/gui.git] / tools / PyEditor / src / PyEditor_Settings.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_Settings.cxx
20 // Author : Maxim GLIBIN, Open CASCADE S.A.S. (maxim.glibin@opencascade.com)
21 //
22
23 #include "PyEditor_Settings.h"
24
25 /*!
26   \class PyEditor_Settings
27   \brief Manager of setting values.
28 */
29
30 PyEditor_Settings* PyEditor_Settings::myGlobalSettings = 0;
31
32 /*!
33   Get global settings.
34   \return reference to global settings object
35 */
36 PyEditor_Settings* PyEditor_Settings::settings()
37 {
38   return myGlobalSettings;
39 }
40
41 /*!
42   Set global settings.
43   \param settings reference to global settings object
44 */
45 void PyEditor_Settings::setSettings( PyEditor_Settings* settings )
46 {
47   if ( myGlobalSettings )
48     delete myGlobalSettings;
49   myGlobalSettings = settings;
50 }
51
52 /*!
53   \brief Constructor.
54 */
55 PyEditor_Settings::PyEditor_Settings()
56   : myHighlightCurrentLine( true ),
57     myTextWrapping( false ),
58     myCenterCursorOnScroll( true ),
59     myLineNumberArea( true ),
60     myVerticalEdge( true ),
61     myNumberColumns( 80 ),
62     myTabSpaceVisible( true ),
63     myTabSize( 4 ),
64     myFont( "Courier", 10 )
65 {
66 }
67
68 /*!
69   \brief Set "highlight current line" option.
70   \param on option value
71 */
72 void PyEditor_Settings::setHighlightCurrentLine( bool on )
73 {
74   myHighlightCurrentLine = on;
75 }
76
77 /*!
78   \brief Get "highlight current line" option.
79   \return option value
80 */
81 bool PyEditor_Settings::highlightCurrentLine() const
82 {
83   return myHighlightCurrentLine;
84 }
85
86 /*!
87   \brief Set "text wrapping" option.
88   \param on option value
89 */
90 void PyEditor_Settings::setTextWrapping( bool on )
91 {
92   myTextWrapping = on;
93 }
94
95 /*!
96   \brief Get "text wrapping line" option.
97   \return option value
98 */
99 bool PyEditor_Settings::textWrapping() const
100 {
101   return myTextWrapping;
102 }
103
104 /*!
105   \brief Set "center cursor on scroll" option.
106   \param on option value
107 */
108 void PyEditor_Settings::setCenterCursorOnScroll( bool on )
109 {
110   myCenterCursorOnScroll = on;
111 }
112
113 /*!
114   \brief Get "center cursor on scroll" option.
115   \return option value
116 */
117 bool PyEditor_Settings::centerCursorOnScroll() const
118 {
119   return myCenterCursorOnScroll;
120 }
121
122 /*!
123   \brief Set "show line number area" option.
124   \param on option value
125 */
126 void PyEditor_Settings::setLineNumberArea( bool on )
127 {
128   myLineNumberArea = on;
129 }
130
131 /*!
132   \brief Get "show line number area" option.
133   \return option value
134 */
135 bool PyEditor_Settings::lineNumberArea() const
136 {
137   return myLineNumberArea;
138 }
139
140 /*!
141   \brief Set "show vertical edge" option.
142   \param on option value
143 */
144 void PyEditor_Settings::setVerticalEdge( bool on )
145 {
146   myVerticalEdge = on;
147 }
148
149 /*!
150   \brief Get "show vertical edge" option.
151   \return option value
152 */
153 bool PyEditor_Settings::verticalEdge() const
154 {
155   return myVerticalEdge;
156 }
157
158 /*!
159   \brief Set "number of columns" option.
160   \param value option value
161 */
162 void PyEditor_Settings::setNumberColumns( int value )
163 {
164   myNumberColumns = value;
165 }
166
167 /*!
168   \brief Get "number of columns" option.
169   \return option value
170 */
171 int PyEditor_Settings::numberColumns() const
172 {
173   return myNumberColumns;
174 }
175
176 /*!
177   \brief Set "show tab spaces" option.
178   \param on option value
179 */
180 void PyEditor_Settings::setTabSpaceVisible( bool on )
181 {
182   myTabSpaceVisible = on;
183 }
184
185 /*!
186   \brief Get "show tab spaces" option.
187   \return option value
188 */
189 bool PyEditor_Settings::tabSpaceVisible() const
190 {
191   return myTabSpaceVisible;
192 }
193
194 /*!
195   \brief Set "tab size" option.
196   \param value option value
197 */
198 void PyEditor_Settings::setTabSize( int value )
199 {
200   myTabSize = value;
201 }
202
203 /*!
204   \brief Get "tab size" option.
205   \return option value
206 */
207 int PyEditor_Settings::tabSize() const
208 {
209   return myTabSize;
210 }
211
212 /*!
213   \brief Set "font" option.
214   \param font option value
215 */
216 void PyEditor_Settings::setFont( const QFont& font )
217 {
218   myFont = font;
219 }
220
221 /*!
222   \brief Get "font" option.
223   \return option value
224 */
225 QFont PyEditor_Settings::font() const
226 {
227   return myFont;
228 }
229
230 /*!
231   \brief Read settings from the persistence storage.
232   Base implementation does nothing; it should be reimplemented in successors.
233 */
234 void PyEditor_Settings::load()
235 {
236 }
237
238 /*!
239   \brief Write settings to the persistence storage.
240   Base implementation does nothing; it should be reimplemented in successors.
241 */
242 void PyEditor_Settings::save()
243 {
244 }
245
246 /*!
247   \brief Copy settings from another object.
248   \param other source settings object
249 */
250 void PyEditor_Settings::copyFrom( const PyEditor_Settings& other )
251 {
252   setHighlightCurrentLine( other.highlightCurrentLine() );
253   setTextWrapping( other.textWrapping() );
254   setCenterCursorOnScroll( other.centerCursorOnScroll() );
255   setLineNumberArea( other.lineNumberArea() );
256   setTabSpaceVisible( other.tabSpaceVisible() );
257   setTabSize( other.tabSize() );
258   setVerticalEdge( other.verticalEdge() );
259   setNumberColumns( other.numberColumns() );
260   setFont( other.font() );
261   save();
262 }
263
264 /*!
265   \brief Get preference item's identifier.
266   \return string identifier
267 */
268 QString PyEditor_Settings::option( Option option )
269 {
270   static const char* options[] = {
271     "PythonEditor",
272     "HighlightCurrentLine",
273     "TextWrapping",
274     "CenterCursorOnScroll",
275     "LineNumberArea",
276     "VerticalEdge",
277     "NumberColumns",
278     "TabSpaceVisible",
279     "TabSize",
280     "Font",
281   };
282   return option >= 0 && option <= snFont ? options[option] : "Unknown";
283 }