1 // Copyright (C) 2015 OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : PyEditor_Settings.cxx
20 // Author : Maxim GLIBIN, Open CASCADE S.A.S. (maxim.glibin@opencascade.com)
23 #include "PyEditor_Settings.h"
25 #include <QtxResourceMgr.h>
32 \class PyEditor_Settings
33 \brief Manager of setting values.
38 \param isSingle flag determined single application or reccesed.
40 PyEditor_Settings::PyEditor_Settings( QtxResourceMgr* theMgr, bool isSingle )
41 : p_HighlightCurrentLine( true ),
42 p_LineNumberArea( true ),
43 p_TextWrapping( false ),
44 p_CenterCursorOnScroll( true ),
45 p_TabSpaceVisible( true ),
47 p_VerticalEdge( true ),
48 p_NumberColumns( 80 ),
49 p_Font( "Courier", 10 ),
50 m_ResourceMgr(theMgr),
56 m_Settings = new QSettings( "config.ini", QSettings::IniFormat );
57 if ( !QFile::exists( m_Settings->fileName() ) )
58 toSettings( PY_EDITOR );
65 \brief Reads the setting values.
67 void PyEditor_Settings::readSettings()
70 fromSettings( PY_EDITOR );
76 \brief Writes the setting values.
78 void PyEditor_Settings::writeSettings()
81 toSettings( PY_EDITOR );
87 \return \c true if the application is single
89 bool PyEditor_Settings::isSingle()
95 \brief Loads the setting values from file settings.
97 void PyEditor_Settings::fromSettings( const QString &theCategory )
99 QString aGroup = theCategory;
102 p_HighlightCurrentLine = m_Settings->value(aGroup + QLatin1String( HIGHLIGHT_CURRLINE ), p_HighlightCurrentLine).toBool();
103 p_LineNumberArea = m_Settings->value(aGroup + QLatin1String( LINE_NUMBER_AREA ), p_LineNumberArea).toBool();
104 p_TextWrapping = m_Settings->value(aGroup + QLatin1String( TEXT_WRAP ), p_TextWrapping).toBool();
105 p_CenterCursorOnScroll = m_Settings->value(aGroup + QLatin1String( CURSOR_SCROLL ), p_CenterCursorOnScroll).toBool();
106 p_TabSpaceVisible = m_Settings->value(aGroup + QLatin1String( TAB_WHITESPACES ), p_TabSpaceVisible).toBool();
107 p_TabSize = m_Settings->value(aGroup + QLatin1String( TAB_SIZE ), p_TabSize).toInt();
108 p_VerticalEdge = m_Settings->value(aGroup + QLatin1String( VERTICAL_EDGE ), p_VerticalEdge).toBool();
109 p_NumberColumns = m_Settings->value(aGroup + QLatin1String( NUM_COLUMNS ), p_NumberColumns).toInt();
110 p_Font = QFont( m_Settings->value(aGroup + QLatin1String( FONT_FAMILY ), p_Font.family()).toString(),
111 m_Settings->value(aGroup + QLatin1String( FONT_SIZE ), p_Font.pointSize()).toInt() );
115 \brief Saves the setting values into file settings.
117 void PyEditor_Settings::toSettings( const QString &theCategory ) const
119 m_Settings->beginGroup( theCategory );
120 m_Settings->setValue( QLatin1String( HIGHLIGHT_CURRLINE ), p_HighlightCurrentLine );
121 m_Settings->setValue( QLatin1String( LINE_NUMBER_AREA ), p_LineNumberArea );
122 m_Settings->setValue( QLatin1String( TEXT_WRAP ), p_TextWrapping );
123 m_Settings->setValue( QLatin1String( CURSOR_SCROLL ), p_CenterCursorOnScroll );
124 m_Settings->setValue( QLatin1String( TAB_WHITESPACES ), p_TabSpaceVisible );
125 m_Settings->setValue( QLatin1String( TAB_SIZE ), p_TabSize );
126 m_Settings->setValue( QLatin1String( VERTICAL_EDGE ), p_VerticalEdge );
127 m_Settings->setValue( QLatin1String( NUM_COLUMNS ), p_NumberColumns );
128 m_Settings->setValue( QLatin1String( FONT_FAMILY ), p_Font.family() );
129 m_Settings->setValue( QLatin1String( FONT_SIZE ), p_Font.pointSize() );
130 m_Settings->endGroup();
134 \brief Loads the setting values from setting resources.
136 void PyEditor_Settings::readPreferences()
140 p_HighlightCurrentLine = m_ResourceMgr->booleanValue( "PyEditor", "HighlightCurrentLine", p_HighlightCurrentLine );
141 p_LineNumberArea = m_ResourceMgr->booleanValue( "PyEditor", "LineNumberArea", p_LineNumberArea );
142 p_TextWrapping = m_ResourceMgr->booleanValue( "PyEditor", "TextWrapping", p_TextWrapping );
143 p_CenterCursorOnScroll = m_ResourceMgr->booleanValue( "PyEditor", "CenterCursorOnScroll", p_CenterCursorOnScroll );
144 p_TabSpaceVisible = m_ResourceMgr->booleanValue( "PyEditor", "TabSpaceVisible", p_TabSpaceVisible );
145 p_TabSize = m_ResourceMgr->integerValue( "PyEditor", "TabSize", p_TabSize );
146 p_VerticalEdge = m_ResourceMgr->booleanValue( "PyEditor", "VerticalEdge", p_VerticalEdge );
147 p_NumberColumns = m_ResourceMgr->integerValue( "PyEditor", "NumberColumns", p_NumberColumns );
148 p_Font = m_ResourceMgr->fontValue( "PyEditor", "Font", p_Font );
153 \brief Saves the setting values into setting resources.
155 void PyEditor_Settings::writePreferences()
159 m_ResourceMgr->setValue( "PyEditor", "HighlightCurrentLine", p_HighlightCurrentLine );
160 m_ResourceMgr->setValue( "PyEditor", "LineNumberArea", p_LineNumberArea );
161 m_ResourceMgr->setValue( "PyEditor", "TextWrapping", p_TextWrapping );
162 m_ResourceMgr->setValue( "PyEditor", "CenterCursorOnScroll", p_CenterCursorOnScroll );
163 m_ResourceMgr->setValue( "PyEditor", "TabSpaceVisible", p_TabSpaceVisible );
164 m_ResourceMgr->setValue( "PyEditor", "TabSize", p_TabSize );
165 m_ResourceMgr->setValue( "PyEditor", "VerticalEdge", p_VerticalEdge );
166 m_ResourceMgr->setValue( "PyEditor", "NumberColumns", p_NumberColumns );
167 m_ResourceMgr->setValue( "PyEditor", "Font", p_Font );