source: trunk/tools/designer/editor/conf.cpp

Last change on this file was 197, checked in by rudi, 14 years ago

Added QtDesigner

File size: 7.7 KB
Line 
1/**********************************************************************
2** Copyright (C) 2000-2007 Trolltech ASA. All rights reserved.
3**
4** This file is part of Qt Designer.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
12** licenses may use this file in accordance with the Qt Commercial License
13** Agreement provided with the Software.
14**
15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17**
18** See http://www.trolltech.com/gpl/ for GPL licensing information.
19** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
20** information about Qt Commercial License Agreements.
21**
22** Contact info@trolltech.com if any conditions of this licensing are
23** not clear to you.
24**
25**********************************************************************/
26
27#include "conf.h"
28#include <qapplication.h>
29#include <qfont.h>
30#include <qcolor.h>
31#include <qsettings.h>
32
33QMap<QString, ConfigStyle> Config::defaultStyles()
34{
35 ConfigStyle s;
36 QMap<QString, ConfigStyle> styles;
37 int normalSize = qApp->font().pointSize();
38 QString normalFamily = qApp->font().family();
39 QString commentFamily = "times";
40 int normalWeight = qApp->font().weight();
41
42 s.font = QFont( normalFamily, normalSize, normalWeight );
43 s.color = Qt::black;
44 styles.insert( "Standard", s );
45
46 s.font = QFont( commentFamily, normalSize, normalWeight, TRUE );
47 s.color = Qt::red;
48 styles.insert( "Comment", s );
49
50 s.font = QFont( normalFamily, normalSize, normalWeight );
51 s.color = Qt::blue;
52 styles.insert( "Number", s );
53
54 s.font = QFont( normalFamily, normalSize, normalWeight );
55 s.color = Qt::darkGreen;
56 styles.insert( "String", s );
57
58 s.font = QFont( normalFamily, normalSize, normalWeight );
59 s.color = Qt::darkMagenta;
60 styles.insert( "Type", s );
61
62 s.font = QFont( normalFamily, normalSize, normalWeight );
63 s.color = Qt::darkYellow;
64 styles.insert( "Keyword", s );
65
66 s.font = QFont( normalFamily, normalSize, normalWeight );
67 s.color = Qt::darkBlue;
68 styles.insert( "Preprocessor", s );
69
70 s.font = QFont( normalFamily, normalSize, normalWeight );
71 s.color = Qt::darkRed;
72 styles.insert( "Label", s );
73
74 return styles;
75}
76
77QMap<QString, ConfigStyle> Config::readStyles( const QString &path )
78{
79 QMap<QString, ConfigStyle> styles;
80 styles = defaultStyles();
81
82 QString family;
83 int size = 10;
84 bool bold = FALSE, italic = FALSE, underline = FALSE;
85 int red = 0, green = 0, blue = 0;
86
87 QString elements[] = {
88 "Comment",
89 "Number",
90 "String",
91 "Type",
92 "Keyword",
93 "Preprocessor",
94 "Label",
95 "Standard",
96 QString::null
97 };
98
99 for ( int i = 0; elements[ i ] != QString::null; ++i ) {
100 QSettings settings;
101 bool ok = TRUE;
102 for (;;) {
103 family = settings.readEntry( path + elements[ i ] + "/family", QString::null, &ok );
104 if ( !ok )
105 break;
106 size = settings.readNumEntry( path + elements[ i ] + "/size", 10, &ok );
107 if ( !ok )
108 break;
109 bold = settings.readBoolEntry( path + elements[ i ] + "/bold", FALSE, &ok );
110 if ( !ok )
111 break;
112 italic = settings.readBoolEntry( path + elements[ i ] + "/italic", FALSE, &ok );
113 if ( !ok )
114 break;
115 underline = settings.readBoolEntry( path + elements[ i ] + "/underline", FALSE, &ok );
116 if ( !ok )
117 break;
118 red = settings.readNumEntry( path + elements[ i ] + "/red", 0, &ok );
119 if ( !ok )
120 break;
121 green = settings.readNumEntry( path + elements[ i ] + "/green", 0, &ok );
122 if ( !ok )
123 break;
124 blue = settings.readNumEntry( path + elements[ i ] + "/blue", 0, &ok );
125 if ( !ok )
126 break;
127 break;
128 }
129 if ( !ok )
130 continue;
131 QFont f( family );
132 f.setPointSize( size );
133 f.setBold( bold );
134 f.setItalic( italic );
135 f.setUnderline( underline );
136 QColor c( red, green, blue );
137 ConfigStyle s;
138 s.font = f;
139 s.color = c;
140 styles.remove( elements[ i ] );
141 styles.insert( elements[ i ], s );
142 }
143 return styles;
144}
145
146void Config::saveStyles( const QMap<QString, ConfigStyle> &styles, const QString &path )
147{
148 QString elements[] = {
149 "Comment",
150 "Number",
151 "String",
152 "Type",
153 "Keyword",
154 "Preprocessor",
155 "Label",
156 "Standard",
157 QString::null
158 };
159
160 QSettings settings;
161 for ( int i = 0; elements[ i ] != QString::null; ++i ) {
162 settings.writeEntry( path + "/" + elements[ i ] + "/family", styles[ elements[ i ] ].font.family() );
163 settings.writeEntry( path + "/" + elements[ i ] + "/size", styles[ elements[ i ] ].font.pointSize() );
164 settings.writeEntry( path + "/" + elements[ i ] + "/bold", styles[ elements[ i ] ].font.bold() );
165 settings.writeEntry( path + "/" + elements[ i ] + "/italic", styles[ elements[ i ] ].font.italic() );
166 settings.writeEntry( path + "/" + elements[ i ] + "/underline", styles[ elements[ i ] ].font.underline() );
167 settings.writeEntry( path + "/" + elements[ i ] + "/red", styles[ elements[ i ] ].color.red() );
168 settings.writeEntry( path + "/" + elements[ i ] + "/green", styles[ elements[ i ] ].color.green() );
169 settings.writeEntry( path + "/" + elements[ i ] + "/blue", styles[ elements[ i ] ].color.blue() );
170 }
171}
172
173bool Config::completion( const QString &path )
174{
175 QSettings settings;
176 bool ret = settings.readBoolEntry( path + "/completion", TRUE );
177 return ret;
178}
179
180bool Config::wordWrap( const QString &path )
181{
182 QSettings settings;
183 bool ret = settings.readBoolEntry( path + "/wordWrap", TRUE );
184 return ret;
185}
186
187bool Config::parenMatching( const QString &path )
188{
189 QSettings settings;
190 bool ret = settings.readBoolEntry( path + "/parenMatching", TRUE );
191 return ret;
192}
193
194int Config::indentTabSize( const QString &path )
195{
196 QSettings settings;
197 int ret = settings.readNumEntry( path + "/indentTabSize", 8 );
198 return ret;
199}
200
201int Config::indentIndentSize( const QString &path )
202{
203 QSettings settings;
204 int ret = settings.readNumEntry( path + "/indentIndentSize", 4 );
205 return ret;
206}
207
208bool Config::indentKeepTabs( const QString &path )
209{
210 QSettings settings;
211 bool ret = settings.readBoolEntry( path + "/indentKeepTabs", TRUE );
212 return ret;
213}
214
215bool Config::indentAutoIndent( const QString &path )
216{
217 QSettings settings;
218 bool ret = settings.readBoolEntry( path + "/indentAutoIndent", TRUE );
219 return ret;
220}
221
222void Config::setCompletion( bool b, const QString &path )
223{
224 QSettings settings;
225 settings.writeEntry( path + "/completion", b );
226}
227
228void Config::setWordWrap( bool b, const QString &path )
229{
230 QSettings settings;
231 settings.writeEntry( path + "/wordWrap", b );
232}
233
234void Config::setParenMatching( bool b,const QString &path )
235{
236 QSettings settings;
237 settings.writeEntry( path + "/parenMatching", b );
238}
239
240void Config::setIndentTabSize( int s, const QString &path )
241{
242 QSettings settings;
243 settings.writeEntry( path + "/indentTabSize", s );
244}
245
246void Config::setIndentIndentSize( int s, const QString &path )
247{
248 QSettings settings;
249 settings.writeEntry( path + "/indentIndentSize", s );
250}
251
252void Config::setIndentKeepTabs( bool b, const QString &path )
253{
254 QSettings settings;
255 settings.writeEntry( path + "/indentKeepTabs", b );
256}
257
258void Config::setIndentAutoIndent( bool b, const QString &path )
259{
260 QSettings settings;
261 settings.writeEntry( path + "/indentAutoIndent", b );
262}
Note: See TracBrowser for help on using the repository browser.