krita

kis_config.cc

00001 /*
00002  *  Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 #include <limits.h>
00019 
00020 #include <kglobalsettings.h>
00021 #include <kconfig.h>
00022 #include <kglobal.h>
00023 #include <kdebug.h>
00024 #include <config.h>
00025 
00026 #include LCMS_HEADER
00027 
00028 #include "kis_global.h"
00029 #include "kis_config.h"
00030 
00031 namespace {
00032     const double IMG_DEFAULT_RESOLUTION = 100.0;
00033     const Q_INT32 IMG_DEFAULT_WIDTH = 512;
00034     const Q_INT32 IMG_DEFAULT_HEIGHT = 512;
00035     const enumCursorStyle DEFAULT_CURSOR_STYLE = CURSOR_STYLE_OUTLINE;
00036     const Q_INT32 DEFAULT_MAX_THREADS = 4;
00037     const Q_INT32 DEFAULT_MAX_TILES_MEM = 500; // 8192 kilobytes given 64x64 tiles with 32bpp
00038     const Q_INT32 DEFAULT_SWAPPINESS = 100;
00039     const Q_INT32 DEFAULT_PRESSURE_CORRECTION = 50;
00040     const Q_INT32 DEFAULT_DOCKABILITY = 0;
00041     const Q_INT32 DEFAULT_UNDO_LIMIT = 50;
00042 }
00043 
00044 KisConfig::KisConfig()
00045 {
00046 
00047     m_cfg = KGlobal::config();
00048     if (!m_cfg) {
00049         // Allow unit tests to test parts of the code without having to run the
00050         // full application.
00051         m_cfg = new KConfig();
00052     }
00053     m_cfg->setGroup("");
00054 }
00055 
00056 KisConfig::~KisConfig()
00057 {
00058     m_cfg->sync();
00059 }
00060 
00061 
00062 bool KisConfig::fixDockerWidth() const
00063 {
00064     return m_cfg->readBoolEntry("fixDockerWidth", true);
00065 }
00066 
00067 void KisConfig::setFixedDockerWidth(bool fix)
00068 {
00069     m_cfg->writeEntry("fixDockerWidth", fix);
00070 }
00071 
00072 bool KisConfig::undoEnabled() const
00073 {
00074     return m_cfg->readBoolEntry("undoEnabled", true);
00075 }
00076 
00077 void KisConfig::setUndoEnabled(bool undo)
00078 {
00079     m_cfg->writeEntry("undoEnabled", undo);
00080 }
00081 
00082 
00083 Q_INT32 KisConfig::defUndoLimit() const
00084 {
00085     return m_cfg->readNumEntry("undolimit", DEFAULT_UNDO_LIMIT);
00086 }
00087 
00088 void KisConfig::defUndoLimit(Q_INT32 limit)
00089 {
00090     m_cfg->writeEntry("undolimit", limit);
00091 }
00092 
00093 Q_INT32 KisConfig::defImgWidth() const
00094 {
00095     return m_cfg->readNumEntry("imgWidthDef", IMG_DEFAULT_WIDTH);
00096 }
00097 
00098 Q_INT32 KisConfig::defImgHeight() const
00099 {
00100     return m_cfg->readNumEntry("imgHeightDef", IMG_DEFAULT_HEIGHT);
00101 }
00102 
00103 double KisConfig::defImgResolution() const
00104 {
00105     return m_cfg->readDoubleNumEntry("imgResolutionDef", IMG_DEFAULT_RESOLUTION);
00106 }
00107 
00108 void KisConfig::defImgWidth(Q_INT32 width)
00109 {
00110     m_cfg->writeEntry("imgWidthDef", width);
00111 }
00112 
00113 void KisConfig::defImgHeight(Q_INT32 height)
00114 {
00115     m_cfg->writeEntry("imgHeightDef", height);
00116 }
00117 
00118 void KisConfig::defImgResolution(double res)
00119 {
00120     m_cfg->writeEntry("imgResolutionDef", res);
00121 }
00122 
00123 enumCursorStyle KisConfig::cursorStyle() const
00124 {
00125     return (enumCursorStyle) m_cfg->readNumEntry("cursorStyleDef", DEFAULT_CURSOR_STYLE);
00126 }
00127 
00128 enumCursorStyle KisConfig::getDefaultCursorStyle() const
00129 {
00130     return DEFAULT_CURSOR_STYLE;
00131 }
00132 
00133 void KisConfig::setCursorStyle(enumCursorStyle style)
00134 {
00135     m_cfg->writeEntry("cursorStyleDef", style);
00136 }
00137 
00138 
00139 QString KisConfig::monitorProfile() const
00140 {
00141     return m_cfg->readEntry("monitorProfile", "");
00142 }
00143 
00144 void KisConfig::setMonitorProfile(QString monitorProfile)
00145 {
00146     m_cfg->writeEntry("monitorProfile", monitorProfile);
00147 }
00148 
00149 
00150 QString KisConfig::workingColorSpace() const
00151 {
00152     return m_cfg->readEntry("workingColorSpace", "RGBA");
00153 }
00154 
00155 void KisConfig::setWorkingColorSpace(QString workingColorSpace)
00156 {
00157     m_cfg->writeEntry(workingColorSpace, workingColorSpace);
00158 }
00159 
00160 
00161 QString KisConfig::printerColorSpace() const
00162 {
00163     return m_cfg->readEntry("printerColorSpace", "CMYK");
00164 }
00165 
00166 void KisConfig::setPrinterColorSpace(QString printerColorSpace)
00167 {
00168     m_cfg->writeEntry("printerColorSpace", printerColorSpace);
00169 }
00170 
00171 
00172 QString KisConfig::printerProfile() const
00173 {
00174     return m_cfg->readEntry("printerProfile", "");
00175 }
00176 
00177 void KisConfig::setPrinterProfile(QString printerProfile)
00178 {
00179     m_cfg->writeEntry("printerProfile", printerProfile);
00180 }
00181 
00182 
00183 bool KisConfig::useBlackPointCompensation() const
00184 {
00185     return m_cfg->readBoolEntry("useBlackPointCompensation", false);
00186 }
00187 
00188 void KisConfig::setUseBlackPointCompensation(bool useBlackPointCompensation)
00189 {
00190     m_cfg->writeEntry("useBlackPointCompensation", useBlackPointCompensation);
00191 }
00192 
00193 
00194 bool KisConfig::showRulers() const
00195 {
00196     return m_cfg->readBoolEntry("showrulers", false);
00197 }
00198 
00199 void KisConfig::setShowRulers(bool rulers)
00200 {
00201     m_cfg->writeEntry("showrulers", rulers);
00202 }
00203 
00204 
00205 Q_INT32 KisConfig::pasteBehaviour() const
00206 {
00207     return m_cfg->readNumEntry("pasteBehaviour", 2);
00208 }
00209 
00210 void KisConfig::setPasteBehaviour(Q_INT32 renderIntent)
00211 {
00212     m_cfg->writeEntry("pasteBehaviour", renderIntent);
00213 }
00214 
00215 
00216 Q_INT32 KisConfig::renderIntent() const
00217 {
00218     return m_cfg->readNumEntry("renderIntent", INTENT_PERCEPTUAL);
00219 }
00220 
00221 void KisConfig::setRenderIntent(Q_INT32 renderIntent)
00222 {
00223     m_cfg->writeEntry("renderIntent", renderIntent);
00224 }
00225 
00226 bool KisConfig::useOpenGL() const
00227 {
00228     return m_cfg->readBoolEntry("useOpenGL", false);
00229 }
00230 
00231 void KisConfig::setUseOpenGL(bool useOpenGL)
00232 {
00233     m_cfg->writeEntry("useOpenGL", useOpenGL);
00234 }
00235 
00236 bool KisConfig::useOpenGLShaders() const
00237 {
00238     return m_cfg->readBoolEntry("useOpenGLShaders", false);
00239 }
00240 
00241 void KisConfig::setUseOpenGLShaders(bool useOpenGLShaders)
00242 {
00243     m_cfg->writeEntry("useOpenGLShaders", useOpenGLShaders);
00244 }
00245 
00246 Q_INT32 KisConfig::maxNumberOfThreads()
00247 {
00248     return m_cfg->readNumEntry("maxthreads", DEFAULT_MAX_THREADS);
00249 }
00250 
00251 void KisConfig::setMaxNumberOfThreads(Q_INT32 maxThreads)
00252 {
00253     m_cfg->writeEntry("maxthreads", maxThreads);
00254 }
00255 
00256 Q_INT32 KisConfig::maxTilesInMem() const
00257 {
00258     return m_cfg->readNumEntry("maxtilesinmem", DEFAULT_MAX_TILES_MEM);
00259 }
00260 
00261 void KisConfig::setMaxTilesInMem(Q_INT32 tiles)
00262 {
00263     m_cfg->writeEntry("maxtilesinmem", tiles);
00264 }
00265 
00266 Q_INT32 KisConfig::swappiness() const
00267 {
00268     return m_cfg->readNumEntry("swappiness", DEFAULT_SWAPPINESS);
00269 }
00270 
00271 void KisConfig::setSwappiness(Q_INT32 swappiness)
00272 {
00273     m_cfg->writeEntry("swappiness", swappiness);
00274 }
00275 
00276 Q_INT32 KisConfig::getPressureCorrection()
00277 {
00278     return m_cfg->readNumEntry( "pressurecorrection", DEFAULT_PRESSURE_CORRECTION );
00279 }
00280 
00281 void KisConfig::setPressureCorrection( Q_INT32 correction )
00282 {
00283     m_cfg->writeEntry( "pressurecorrection",  correction );
00284 }
00285 
00286 Q_INT32 KisConfig::getDefaultPressureCorrection()
00287 {
00288     return DEFAULT_PRESSURE_CORRECTION;
00289 }
00290 
00291 bool KisConfig::tabletDeviceEnabled(const QString& tabletDeviceName) const
00292 {
00293     return m_cfg->readBoolEntry("TabletDevice" + tabletDeviceName + "Enabled", false);
00294 }
00295 
00296 void KisConfig::setTabletDeviceEnabled(const QString& tabletDeviceName, bool enabled)
00297 {
00298     m_cfg->writeEntry("TabletDevice" + tabletDeviceName + "Enabled", enabled);
00299 }
00300 
00301 Q_INT32 KisConfig::tabletDeviceAxis(const QString& tabletDeviceName, const QString& axisName, Q_INT32 defaultAxis) const
00302 {
00303     return m_cfg->readNumEntry("TabletDevice" + tabletDeviceName + axisName, defaultAxis);
00304 }
00305 
00306 void KisConfig::setTabletDeviceAxis(const QString& tabletDeviceName, const QString& axisName, Q_INT32 axis) const
00307 {
00308     m_cfg->writeEntry("TabletDevice" + tabletDeviceName + axisName, axis);
00309 }
00310 
00311 void KisConfig::setDockability( Q_INT32 dockability )
00312 {
00313     m_cfg->writeEntry( "palettesdockability", dockability );
00314 }
00315 
00316 Q_INT32 KisConfig::dockability()
00317 {
00318     return m_cfg->readNumEntry("palettesdockability", DEFAULT_DOCKABILITY);
00319 }
00320 
00321 Q_INT32 KisConfig::getDefaultDockability()
00322 {
00323     return DEFAULT_DOCKABILITY;
00324 }
00325 
00326 float KisConfig::dockerFontSize()
00327 {
00328     return (float) m_cfg->readNumEntry("palettefontsize", (int)getDefaultDockerFontSize());
00329 }
00330 
00331 float KisConfig::getDefaultDockerFontSize()
00332 {
00333     float ps = QMIN(9, KGlobalSettings::generalFont().pointSize() * 0.8);
00334     if (ps < 6) ps = 6;
00335     return ps;
00336 }
00337 
00338 void KisConfig::setDockerFontSize(float size)
00339 {
00340     m_cfg->writeEntry("palettefontsize", size);
00341 }
00342 
00343 Q_UINT32 KisConfig::getGridMainStyle()
00344 {
00345     Q_UINT32 v = m_cfg->readNumEntry("gridmainstyle", 0);
00346     if (v > 2)
00347         v = 2;
00348     return v;
00349 }
00350 
00351 void KisConfig::setGridMainStyle(Q_UINT32 v)
00352 {
00353     m_cfg->writeEntry("gridmainstyle", v);
00354 }
00355 
00356 Q_UINT32 KisConfig::getGridSubdivisionStyle()
00357 {
00358     Q_UINT32 v = m_cfg->readNumEntry("gridsubdivisionstyle", 1);
00359     if (v > 2) v = 2;
00360     return v;
00361 }
00362 
00363 void KisConfig::setGridSubdivisionStyle(Q_UINT32 v)
00364 {
00365     m_cfg->writeEntry("gridsubdivisionstyle", v);
00366 }
00367 
00368 QColor KisConfig::getGridMainColor()
00369 {
00370     return m_cfg->readColorEntry("gridmaincolor", new QColor(99,99,99));
00371 }
00372 
00373 void KisConfig::setGridMainColor(QColor v)
00374 {
00375     m_cfg->writeEntry("gridmaincolor", v);
00376 }
00377 
00378 QColor KisConfig::getGridSubdivisionColor()
00379 {
00380     return m_cfg->readColorEntry("gridsubdivisioncolor", new QColor(150,150,150));
00381 }
00382 
00383 void KisConfig::setGridSubdivisionColor(QColor v)
00384 {
00385     m_cfg->writeEntry("gridsubdivisioncolor", v);
00386 }
00387 
00388 Q_UINT32 KisConfig::getGridHSpacing()
00389 {
00390     Q_INT32 v = m_cfg->readNumEntry("gridhspacing", 10);
00391     return (Q_UINT32)QMAX(1, v );
00392 }
00393 
00394 void KisConfig::setGridHSpacing(Q_UINT32 v)
00395 {
00396     m_cfg->writeEntry("gridhspacing", v);
00397 }
00398 
00399 Q_UINT32 KisConfig::getGridVSpacing()
00400 {
00401     Q_INT32 v = m_cfg->readNumEntry("gridvspacing", 10);
00402     return (Q_UINT32)QMAX(1, v );
00403 }
00404 
00405 void KisConfig::setGridVSpacing(Q_UINT32 v)
00406 {
00407     m_cfg->writeEntry("gridvspacing", v);
00408 }
00409 
00410 Q_UINT32 KisConfig::getGridSubdivisions()
00411 {
00412     Q_INT32 v = m_cfg->readNumEntry("gridsubsivisons", 2);
00413     return (Q_UINT32)QMAX(1, v );
00414 }
00415 
00416 void KisConfig::setGridSubdivisions(Q_UINT32 v)
00417 {
00418     return m_cfg->writeEntry("gridsubsivisons", v);
00419 }
00420 
00421 Q_UINT32 KisConfig::getGridOffsetX()
00422 {
00423     Q_INT32 v = m_cfg->readNumEntry("gridoffsetx", 0);
00424     return (Q_UINT32)QMAX(0, v );
00425 }
00426 
00427 void KisConfig::setGridOffsetX(Q_UINT32 v)
00428 {
00429     m_cfg->writeEntry("gridoffsetx", v);
00430 }
00431 
00432 Q_UINT32 KisConfig::getGridOffsetY()
00433 {
00434     Q_INT32 v = m_cfg->readNumEntry("gridoffsety", 0);
00435     return (Q_UINT32)QMAX(0, v );
00436 }
00437 
00438 void KisConfig::setGridOffsetY(Q_UINT32 v)
00439 {
00440     m_cfg->writeEntry("gridoffsety", v);
00441 }
00442 
KDE Home | KDE Accessibility Home | Description of Access Keys