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