chalk

kis_config.cpp
1/*
2 * Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18#include <limits.h>
19
20#include <tdeglobalsettings.h>
21#include <tdeconfig.h>
22#include <tdeglobal.h>
23#include <kdebug.h>
24#include <config.h>
25
26#include LCMS_HEADER
27
28#include "kis_global.h"
29#include "kis_config.h"
30
31namespace {
32 const double IMG_DEFAULT_RESOLUTION = 100.0;
33 const TQ_INT32 IMG_DEFAULT_WIDTH = 512;
34 const TQ_INT32 IMG_DEFAULT_HEIGHT = 512;
35 const enumCursorStyle DEFAULT_CURSOR_STYLE = CURSOR_STYLE_OUTLINE;
36 const TQ_INT32 DEFAULT_MAX_THREADS = 4;
37 const TQ_INT32 DEFAULT_MAX_TILES_MEM = 500; // 8192 kilobytes given 64x64 tiles with 32bpp
38 const TQ_INT32 DEFAULT_SWAPPINESS = 100;
39 const TQ_INT32 DEFAULT_PRESSURE_CORRECTION = 50;
40 const TQ_INT32 DEFAULT_DOCKABILITY = 0;
41 const TQ_INT32 DEFAULT_UNDO_LIMIT = 50;
42}
43
44KisConfig::KisConfig()
45{
46
47 m_cfg = TDEGlobal::config();
48 if (!m_cfg) {
49 // Allow unit tests to test parts of the code without having to run the
50 // full application.
51 m_cfg = new TDEConfig();
52 }
53 m_cfg->setGroup("");
54}
55
56KisConfig::~KisConfig()
57{
58 m_cfg->sync();
59}
60
61
62bool KisConfig::fixDockerWidth() const
63{
64 return m_cfg->readBoolEntry("fixDockerWidth", true);
65}
66
67void KisConfig::setFixedDockerWidth(bool fix)
68{
69 m_cfg->writeEntry("fixDockerWidth", fix);
70}
71
72bool KisConfig::undoEnabled() const
73{
74 return m_cfg->readBoolEntry("undoEnabled", true);
75}
76
77void KisConfig::setUndoEnabled(bool undo)
78{
79 m_cfg->writeEntry("undoEnabled", undo);
80}
81
82
83TQ_INT32 KisConfig::defUndoLimit() const
84{
85 return m_cfg->readNumEntry("undolimit", DEFAULT_UNDO_LIMIT);
86}
87
88void KisConfig::defUndoLimit(TQ_INT32 limit)
89{
90 m_cfg->writeEntry("undolimit", limit);
91}
92
93TQ_INT32 KisConfig::defImgWidth() const
94{
95 return m_cfg->readNumEntry("imgWidthDef", IMG_DEFAULT_WIDTH);
96}
97
98TQ_INT32 KisConfig::defImgHeight() const
99{
100 return m_cfg->readNumEntry("imgHeightDef", IMG_DEFAULT_HEIGHT);
101}
102
103double KisConfig::defImgResolution() const
104{
105 return m_cfg->readDoubleNumEntry("imgResolutionDef", IMG_DEFAULT_RESOLUTION);
106}
107
108void KisConfig::defImgWidth(TQ_INT32 width)
109{
110 m_cfg->writeEntry("imgWidthDef", width);
111}
112
113void KisConfig::defImgHeight(TQ_INT32 height)
114{
115 m_cfg->writeEntry("imgHeightDef", height);
116}
117
118void KisConfig::defImgResolution(double res)
119{
120 m_cfg->writeEntry("imgResolutionDef", res);
121}
122
123enumCursorStyle KisConfig::cursorStyle() const
124{
125 return (enumCursorStyle) m_cfg->readNumEntry("cursorStyleDef", DEFAULT_CURSOR_STYLE);
126}
127
128enumCursorStyle KisConfig::getDefaultCursorStyle() const
129{
130 return DEFAULT_CURSOR_STYLE;
131}
132
133void KisConfig::setCursorStyle(enumCursorStyle style)
134{
135 m_cfg->writeEntry("cursorStyleDef", style);
136}
137
138
139TQString KisConfig::monitorProfile() const
140{
141 return m_cfg->readEntry("monitorProfile", "");
142}
143
144void KisConfig::setMonitorProfile(TQString monitorProfile)
145{
146 m_cfg->writeEntry("monitorProfile", monitorProfile);
147}
148
149
150TQString KisConfig::workingColorSpace() const
151{
152 return m_cfg->readEntry("workingColorSpace", "RGBA");
153}
154
155void KisConfig::setWorkingColorSpace(TQString workingColorSpace)
156{
157 m_cfg->writeEntry(workingColorSpace, workingColorSpace);
158}
159
160
161TQString KisConfig::printerColorSpace() const
162{
163 return m_cfg->readEntry("printerColorSpace", "CMYK");
164}
165
166void KisConfig::setPrinterColorSpace(TQString printerColorSpace)
167{
168 m_cfg->writeEntry("printerColorSpace", printerColorSpace);
169}
170
171
172TQString KisConfig::printerProfile() const
173{
174 return m_cfg->readEntry("printerProfile", "");
175}
176
177void KisConfig::setPrinterProfile(TQString printerProfile)
178{
179 m_cfg->writeEntry("printerProfile", printerProfile);
180}
181
182
183bool KisConfig::useBlackPointCompensation() const
184{
185 return m_cfg->readBoolEntry("useBlackPointCompensation", false);
186}
187
188void KisConfig::setUseBlackPointCompensation(bool useBlackPointCompensation)
189{
190 m_cfg->writeEntry("useBlackPointCompensation", useBlackPointCompensation);
191}
192
193
194bool KisConfig::showRulers() const
195{
196 return m_cfg->readBoolEntry("showrulers", false);
197}
198
199void KisConfig::setShowRulers(bool rulers)
200{
201 m_cfg->writeEntry("showrulers", rulers);
202}
203
204
205TQ_INT32 KisConfig::pasteBehaviour() const
206{
207 return m_cfg->readNumEntry("pasteBehaviour", 2);
208}
209
210void KisConfig::setPasteBehaviour(TQ_INT32 renderIntent)
211{
212 m_cfg->writeEntry("pasteBehaviour", renderIntent);
213}
214
215
216TQ_INT32 KisConfig::renderIntent() const
217{
218 return m_cfg->readNumEntry("renderIntent", INTENT_PERCEPTUAL);
219}
220
221void KisConfig::setRenderIntent(TQ_INT32 renderIntent)
222{
223 m_cfg->writeEntry("renderIntent", renderIntent);
224}
225
226bool KisConfig::useOpenGL() const
227{
228 return m_cfg->readBoolEntry("useOpenGL", false);
229}
230
231void KisConfig::setUseOpenGL(bool useOpenGL)
232{
233 m_cfg->writeEntry("useOpenGL", useOpenGL);
234}
235
236bool KisConfig::useOpenGLShaders() const
237{
238 return m_cfg->readBoolEntry("useOpenGLShaders", false);
239}
240
241void KisConfig::setUseOpenGLShaders(bool useOpenGLShaders)
242{
243 m_cfg->writeEntry("useOpenGLShaders", useOpenGLShaders);
244}
245
246TQ_INT32 KisConfig::maxNumberOfThreads()
247{
248 return m_cfg->readNumEntry("maxthreads", DEFAULT_MAX_THREADS);
249}
250
251void KisConfig::setMaxNumberOfThreads(TQ_INT32 maxThreads)
252{
253 m_cfg->writeEntry("maxthreads", maxThreads);
254}
255
256TQ_INT32 KisConfig::maxTilesInMem() const
257{
258 return m_cfg->readNumEntry("maxtilesinmem", DEFAULT_MAX_TILES_MEM);
259}
260
261void KisConfig::setMaxTilesInMem(TQ_INT32 tiles)
262{
263 m_cfg->writeEntry("maxtilesinmem", tiles);
264}
265
266TQ_INT32 KisConfig::swappiness() const
267{
268 return m_cfg->readNumEntry("swappiness", DEFAULT_SWAPPINESS);
269}
270
271void KisConfig::setSwappiness(TQ_INT32 swappiness)
272{
273 m_cfg->writeEntry("swappiness", swappiness);
274}
275
276TQ_INT32 KisConfig::getPressureCorrection()
277{
278 return m_cfg->readNumEntry( "pressurecorrection", DEFAULT_PRESSURE_CORRECTION );
279}
280
281void KisConfig::setPressureCorrection( TQ_INT32 correction )
282{
283 m_cfg->writeEntry( "pressurecorrection", correction );
284}
285
286TQ_INT32 KisConfig::getDefaultPressureCorrection()
287{
288 return DEFAULT_PRESSURE_CORRECTION;
289}
290
291bool KisConfig::tabletDeviceEnabled(const TQString& tabletDeviceName) const
292{
293 return m_cfg->readBoolEntry("TabletDevice" + tabletDeviceName + "Enabled", false);
294}
295
296void KisConfig::setTabletDeviceEnabled(const TQString& tabletDeviceName, bool enabled)
297{
298 m_cfg->writeEntry("TabletDevice" + tabletDeviceName + "Enabled", enabled);
299}
300
301TQ_INT32 KisConfig::tabletDeviceAxis(const TQString& tabletDeviceName, const TQString& axisName, TQ_INT32 defaultAxis) const
302{
303 return m_cfg->readNumEntry("TabletDevice" + tabletDeviceName + axisName, defaultAxis);
304}
305
306void KisConfig::setTabletDeviceAxis(const TQString& tabletDeviceName, const TQString& axisName, TQ_INT32 axis) const
307{
308 m_cfg->writeEntry("TabletDevice" + tabletDeviceName + axisName, axis);
309}
310
311void KisConfig::setDockability( TQ_INT32 dockability )
312{
313 m_cfg->writeEntry( "palettesdockability", dockability );
314}
315
316TQ_INT32 KisConfig::dockability()
317{
318 return m_cfg->readNumEntry("palettesdockability", DEFAULT_DOCKABILITY);
319}
320
321TQ_INT32 KisConfig::getDefaultDockability()
322{
323 return DEFAULT_DOCKABILITY;
324}
325
326float KisConfig::dockerFontSize()
327{
328 return (float) m_cfg->readNumEntry("palettefontsize", (int)getDefaultDockerFontSize());
329}
330
331float KisConfig::getDefaultDockerFontSize()
332{
333 float ps = TQMIN(9, TDEGlobalSettings::generalFont().pointSize() * 0.8);
334 if (ps < 6) ps = 6;
335 return ps;
336}
337
338void KisConfig::setDockerFontSize(float size)
339{
340 m_cfg->writeEntry("palettefontsize", size);
341}
342
343TQ_UINT32 KisConfig::getGridMainStyle()
344{
345 TQ_UINT32 v = m_cfg->readNumEntry("gridmainstyle", 0);
346 if (v > 2)
347 v = 2;
348 return v;
349}
350
351void KisConfig::setGridMainStyle(TQ_UINT32 v)
352{
353 m_cfg->writeEntry("gridmainstyle", v);
354}
355
356TQ_UINT32 KisConfig::getGridSubdivisionStyle()
357{
358 TQ_UINT32 v = m_cfg->readNumEntry("gridsubdivisionstyle", 1);
359 if (v > 2) v = 2;
360 return v;
361}
362
363void KisConfig::setGridSubdivisionStyle(TQ_UINT32 v)
364{
365 m_cfg->writeEntry("gridsubdivisionstyle", v);
366}
367
368TQColor KisConfig::getGridMainColor()
369{
370 return m_cfg->readColorEntry("gridmaincolor", new TQColor(99,99,99));
371}
372
373void KisConfig::setGridMainColor(TQColor v)
374{
375 m_cfg->writeEntry("gridmaincolor", v);
376}
377
378TQColor KisConfig::getGridSubdivisionColor()
379{
380 return m_cfg->readColorEntry("gridsubdivisioncolor", new TQColor(150,150,150));
381}
382
383void KisConfig::setGridSubdivisionColor(TQColor v)
384{
385 m_cfg->writeEntry("gridsubdivisioncolor", v);
386}
387
388TQ_UINT32 KisConfig::getGridHSpacing()
389{
390 TQ_INT32 v = m_cfg->readNumEntry("gridhspacing", 10);
391 return (TQ_UINT32)TQMAX(1, v );
392}
393
394void KisConfig::setGridHSpacing(TQ_UINT32 v)
395{
396 m_cfg->writeEntry("gridhspacing", v);
397}
398
399TQ_UINT32 KisConfig::getGridVSpacing()
400{
401 TQ_INT32 v = m_cfg->readNumEntry("gridvspacing", 10);
402 return (TQ_UINT32)TQMAX(1, v );
403}
404
405void KisConfig::setGridVSpacing(TQ_UINT32 v)
406{
407 m_cfg->writeEntry("gridvspacing", v);
408}
409
410TQ_UINT32 KisConfig::getGridSubdivisions()
411{
412 TQ_INT32 v = m_cfg->readNumEntry("gridsubsivisons", 2);
413 return (TQ_UINT32)TQMAX(1, v );
414}
415
416void KisConfig::setGridSubdivisions(TQ_UINT32 v)
417{
418 return m_cfg->writeEntry("gridsubsivisons", v);
419}
420
421TQ_UINT32 KisConfig::getGridOffsetX()
422{
423 TQ_INT32 v = m_cfg->readNumEntry("gridoffsetx", 0);
424 return (TQ_UINT32)TQMAX(0, v );
425}
426
427void KisConfig::setGridOffsetX(TQ_UINT32 v)
428{
429 m_cfg->writeEntry("gridoffsetx", v);
430}
431
432TQ_UINT32 KisConfig::getGridOffsetY()
433{
434 TQ_INT32 v = m_cfg->readNumEntry("gridoffsety", 0);
435 return (TQ_UINT32)TQMAX(0, v );
436}
437
438void KisConfig::setGridOffsetY(TQ_UINT32 v)
439{
440 m_cfg->writeEntry("gridoffsety", v);
441}
442