kis_config.cc 47.5 KB
Newer Older
1
/*
Patrick Julien's avatar
Patrick Julien committed
2
 *  Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
3 4 5 6 7 8 9 10 11 12 13 14 15
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  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
 */
Halla Rempt's avatar
Halla Rempt committed
18 19

#include "kis_config.h"
20

21
#include <limits.h>
22

23
#include <QtGlobal>
24 25
#include <QApplication>
#include <QDesktopWidget>
26
#include <QMutex>
David Faure's avatar
David Faure committed
27
#include <QFont>
28
#include <QThread>
29
#include <QStringList>
30

Halla Rempt's avatar
Halla Rempt committed
31

32 33
#include <kconfig.h>

34
#include <KisDocument.h>
35

36
#include <KoColor.h>
37
#include <KoColorSpaceRegistry.h>
38
#include <KoColorModelStandardIds.h>
39
#include <KoColorProfile.h>
Halla Rempt's avatar
Halla Rempt committed
40

41 42 43
#include <kis_debug.h>

#include "kis_canvas_resource_provider.h"
44
#include "kis_config_notifier.h"
45
#include "kis_snap_config.h"
46

Yuri Chornoivan's avatar
Yuri Chornoivan committed
47
#include <config-ocio.h>
48

49
#include <kis_color_manager.h>
50

Patrick Julien's avatar
Patrick Julien committed
51
KisConfig::KisConfig()
52
    : m_cfg( KSharedConfig::openConfig()->group(""))
53 54 55 56 57
{
}

KisConfig::~KisConfig()
{
58
    if (qApp->thread() != QThread::currentThread()) {
Halla Rempt's avatar
Halla Rempt committed
59
        //dbgKrita << "WARNING: KisConfig: requested config synchronization from nonGUI thread! Skipping...";
60 61 62
        return;
    }

Adrian Page's avatar
Adrian Page committed
63
    m_cfg.sync();
64 65 66
}


67
bool KisConfig::disableTouchOnCanvas(bool defaultValue) const
68
{
69
    return (defaultValue ? false : m_cfg.readEntry("disableTouchOnCanvas", false));
70 71 72 73 74 75 76
}

void KisConfig::setDisableTouchOnCanvas(bool value) const
{
    m_cfg.writeEntry("disableTouchOnCanvas", value);
}

77
bool KisConfig::useProjections(bool defaultValue) const
78
{
79
    return (defaultValue ? true : m_cfg.readEntry("useProjections", true));
80 81
}

82
void KisConfig::setUseProjections(bool useProj) const
83
{
Halla Rempt's avatar
Halla Rempt committed
84
    m_cfg.writeEntry("useProjections", useProj);
85 86
}

87
bool KisConfig::undoEnabled(bool defaultValue) const
88
{
89
    return (defaultValue ? true : m_cfg.readEntry("undoEnabled", true));
90 91
}

92
void KisConfig::setUndoEnabled(bool undo) const
93
{
Adrian Page's avatar
Adrian Page committed
94
    m_cfg.writeEntry("undoEnabled", undo);
95 96
}

97
int KisConfig::undoStackLimit(bool defaultValue) const
98
{
99
    return (defaultValue ? 30 : m_cfg.readEntry("undoStackLimit", 30));
100 101
}

102
void KisConfig::setUndoStackLimit(int limit) const
103 104 105
{
    m_cfg.writeEntry("undoStackLimit", limit);
}
106 107

bool KisConfig::useCumulativeUndoRedo(bool defaultValue) const
108
{
109
    return (defaultValue ? false : m_cfg.readEntry("useCumulativeUndoRedo",false));
110 111 112 113 114 115 116
}

void KisConfig::setCumulativeUndoRedo(bool value)
{
    m_cfg.writeEntry("useCumulativeUndoRedo", value);
}

117
qreal KisConfig::stackT1(bool defaultValue) const
118
{
119
     return (defaultValue ? 5 : m_cfg.readEntry("stackT1",5));
120 121 122 123 124 125 126
}

void KisConfig::setStackT1(int T1)
{
    m_cfg.writeEntry("stackT1", T1);
}

127
qreal KisConfig::stackT2(bool defaultValue) const
128
{
129
     return (defaultValue ? 1 : m_cfg.readEntry("stackT2",1));
130 131 132 133 134 135 136
}

void KisConfig::setStackT2(int T2)
{
    m_cfg.writeEntry("stackT2", T2);
}

137
int KisConfig::stackN(bool defaultValue) const
138
{
139
    return (defaultValue ? 5 : m_cfg.readEntry("stackN",5));
140 141 142 143 144 145
}

void KisConfig::setStackN(int N)
{
     m_cfg.writeEntry("stackN", N);
}
146

147
qint32 KisConfig::defImageWidth(bool defaultValue) const
148
{
149
    return (defaultValue ? 1600 : m_cfg.readEntry("imageWidthDef", 1600));
150 151
}

152
qint32 KisConfig::defImageHeight(bool defaultValue) const
153
{
154
    return (defaultValue ? 1200 : m_cfg.readEntry("imageHeightDef", 1200));
155 156
}

157
qreal KisConfig::defImageResolution(bool defaultValue) const
158
{
159
    return (defaultValue ? 100.0 : m_cfg.readEntry("imageResolutionDef", 100.0)) / 72.0;
160 161
}

162
QString KisConfig::defColorModel(bool defaultValue) const
163
{
164 165
    return (defaultValue ? KoColorSpaceRegistry::instance()->rgb8()->colorModelId().id()
                        : m_cfg.readEntry("colorModelDef", KoColorSpaceRegistry::instance()->rgb8()->colorModelId().id()));
166 167
}

168
void KisConfig::defColorModel(const QString & model) const
169 170 171 172
{
    m_cfg.writeEntry("colorModelDef", model);
}

173
QString KisConfig::defaultColorDepth(bool defaultValue) const
174
{
175 176
    return (defaultValue ? KoColorSpaceRegistry::instance()->rgb8()->colorDepthId().id()
                        : m_cfg.readEntry("colorDepthDef", KoColorSpaceRegistry::instance()->rgb8()->colorDepthId().id()));
177 178
}

179
void KisConfig::setDefaultColorDepth(const QString & depth) const
180 181 182 183
{
    m_cfg.writeEntry("colorDepthDef", depth);
}

184
QString KisConfig::defColorProfile(bool defaultValue) const
185
{
186 187 188
    return (defaultValue ? KoColorSpaceRegistry::instance()->rgb8()->profile()->name() :
                           m_cfg.readEntry("colorProfileDef",
                                           KoColorSpaceRegistry::instance()->rgb8()->profile()->name()));
189 190
}

191
void KisConfig::defColorProfile(const QString & profile) const
192 193 194 195
{
    m_cfg.writeEntry("colorProfileDef", profile);
}

196
void KisConfig::defImageWidth(qint32 width) const
197
{
Halla Rempt's avatar
Halla Rempt committed
198
    m_cfg.writeEntry("imageWidthDef", width);
199 200
}

201
void KisConfig::defImageHeight(qint32 height) const
202
{
Halla Rempt's avatar
Halla Rempt committed
203
    m_cfg.writeEntry("imageHeightDef", height);
204 205
}

206
void KisConfig::defImageResolution(qreal res) const
207
{
Halla Rempt's avatar
Halla Rempt committed
208
    m_cfg.writeEntry("imageResolutionDef", res*72.0);
209 210
}

211
void cleanOldCursorStyleKeys(KConfigGroup &cfg)
212
{
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
    if (cfg.hasKey("newCursorStyle") &&
        cfg.hasKey("newOutlineStyle")) {

        cfg.deleteEntry("cursorStyleDef");
    }
}

CursorStyle KisConfig::newCursorStyle(bool defaultValue) const
{
    if (defaultValue) {
        return CURSOR_STYLE_NO_CURSOR;
    }


    int style = m_cfg.readEntry("newCursorStyle", int(-1));

    if (style < 0) {
        // old style format
        style = m_cfg.readEntry("cursorStyleDef", int(OLD_CURSOR_STYLE_OUTLINE));

        switch (style) {
        case OLD_CURSOR_STYLE_TOOLICON:
            style = CURSOR_STYLE_TOOLICON;
            break;
        case OLD_CURSOR_STYLE_CROSSHAIR:
        case OLD_CURSOR_STYLE_OUTLINE_CENTER_CROSS:
            style = CURSOR_STYLE_CROSSHAIR;
            break;
        case OLD_CURSOR_STYLE_POINTER:
            style = CURSOR_STYLE_POINTER;
            break;
        case OLD_CURSOR_STYLE_OUTLINE:
        case OLD_CURSOR_STYLE_NO_CURSOR:
            style = CURSOR_STYLE_NO_CURSOR;
            break;
        case OLD_CURSOR_STYLE_SMALL_ROUND:
        case OLD_CURSOR_STYLE_OUTLINE_CENTER_DOT:
            style = CURSOR_STYLE_SMALL_ROUND;
            break;
        case OLD_CURSOR_STYLE_TRIANGLE_RIGHTHANDED:
        case OLD_CURSOR_STYLE_OUTLINE_TRIANGLE_RIGHTHANDED:
            style = CURSOR_STYLE_TRIANGLE_RIGHTHANDED;
            break;
        case OLD_CURSOR_STYLE_TRIANGLE_LEFTHANDED:
        case OLD_CURSOR_STYLE_OUTLINE_TRIANGLE_LEFTHANDED:
            style = CURSOR_STYLE_TRIANGLE_LEFTHANDED;
            break;
        default:
            style = -1;
        }
    }

    cleanOldCursorStyleKeys(m_cfg);

267 268
    // compatibility with future versions
    if (style < 0 || style >= N_CURSOR_STYLE_SIZE) {
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
        style = CURSOR_STYLE_NO_CURSOR;
    }

    return (CursorStyle) style;
}

void KisConfig::setNewCursorStyle(CursorStyle style)
{
    m_cfg.writeEntry("newCursorStyle", (int)style);
}

OutlineStyle KisConfig::newOutlineStyle(bool defaultValue) const
{
    if (defaultValue) {
        return OUTLINE_FULL;
    }

    int style = m_cfg.readEntry("newOutlineStyle", int(-1));

    if (style < 0) {
        // old style format
        style = m_cfg.readEntry("cursorStyleDef", int(OLD_CURSOR_STYLE_OUTLINE));

        switch (style) {
        case OLD_CURSOR_STYLE_TOOLICON:
        case OLD_CURSOR_STYLE_CROSSHAIR:
        case OLD_CURSOR_STYLE_POINTER:
        case OLD_CURSOR_STYLE_NO_CURSOR:
        case OLD_CURSOR_STYLE_SMALL_ROUND:
        case OLD_CURSOR_STYLE_TRIANGLE_RIGHTHANDED:
        case OLD_CURSOR_STYLE_TRIANGLE_LEFTHANDED:
            style = OUTLINE_NONE;
            break;
        case OLD_CURSOR_STYLE_OUTLINE:
        case OLD_CURSOR_STYLE_OUTLINE_CENTER_DOT:
        case OLD_CURSOR_STYLE_OUTLINE_CENTER_CROSS:
        case OLD_CURSOR_STYLE_OUTLINE_TRIANGLE_RIGHTHANDED:
        case OLD_CURSOR_STYLE_OUTLINE_TRIANGLE_LEFTHANDED:
            style = OUTLINE_FULL;
            break;
        default:
            style = -1;
        }
    }

    cleanOldCursorStyleKeys(m_cfg);

316 317
    // compatibility with future versions
    if (style < 0 || style >= N_OUTLINE_STYLE_SIZE) {
318 319 320 321
        style = OUTLINE_FULL;
    }

    return (OutlineStyle) style;
322 323
}

324
void KisConfig::setNewOutlineStyle(OutlineStyle style)
325
{
326
    m_cfg.writeEntry("newOutlineStyle", (int)style);
327
}
328

329 330 331 332 333 334 335 336 337 338
QRect KisConfig::colorPreviewRect() const
{
    return m_cfg.readEntry("colorPreviewRect", QVariant(QRect(32, 32, 48, 48))).toRect();
}

void KisConfig::setColorPreviewRect(const QRect &rect)
{
    m_cfg.writeEntry("colorPreviewRect", QVariant(rect));
}

339
bool KisConfig::useDirtyPresets(bool defaultValue) const
340
{
341
   return (defaultValue ? false : m_cfg.readEntry("useDirtyPresets",false));
342 343 344 345
}
void KisConfig::setUseDirtyPresets(bool value)
{
    m_cfg.writeEntry("useDirtyPresets",value);
346
    KisConfigNotifier::instance()->notifyConfigChanged();
347
}
348

349
bool KisConfig::useEraserBrushSize(bool defaultValue) const
350
{
351
   return (defaultValue ? false : m_cfg.readEntry("useEraserBrushSize",false));
352
}
353

354 355 356
void KisConfig::setUseEraserBrushSize(bool value)
{
    m_cfg.writeEntry("useEraserBrushSize",value);
357
    KisConfigNotifier::instance()->notifyConfigChanged();
358 359
}

360
QColor KisConfig::getMDIBackgroundColor(bool defaultValue) const
361
{
362
    QColor col(77, 77, 77);
363
    return (defaultValue ? col : m_cfg.readEntry("mdiBackgroundColor", col));
364 365 366 367 368 369 370
}

void KisConfig::setMDIBackgroundColor(const QColor &v) const
{
    m_cfg.writeEntry("mdiBackgroundColor", v);
}

371
QString KisConfig::getMDIBackgroundImage(bool defaultValue) const
372
{
373
    return (defaultValue ? "" : m_cfg.readEntry("mdiBackgroundImage", ""));
374 375 376 377 378 379
}

void KisConfig::setMDIBackgroundImage(const QString &filename) const
{
    m_cfg.writeEntry("mdiBackgroundImage", filename);
}
380

381 382
QString KisConfig::monitorProfile(int screen) const
{
383 384
    // Note: keep this in sync with the default profile for the RGB colorspaces!
    QString profile = m_cfg.readEntry("monitorProfile" + QString(screen == 0 ? "": QString("_%1").arg(screen)), "sRGB-elle-V2-srgbtrc.icc");
Halla Rempt's avatar
Halla Rempt committed
385
    //dbgKrita << "KisConfig::monitorProfile()" << profile;
386 387 388
    return profile;
}

389
QString KisConfig::monitorForScreen(int screen, const QString &defaultMonitor, bool defaultValue) const
390
{
391 392
    return (defaultValue ? defaultMonitor
                         : m_cfg.readEntry(QString("monitor_for_screen_%1").arg(screen), defaultMonitor));
393 394 395 396 397 398 399 400 401 402 403 404 405
}

void KisConfig::setMonitorForScreen(int screen, const QString& monitor)
{
    m_cfg.writeEntry(QString("monitor_for_screen_%1").arg(screen), monitor);
}

void KisConfig::setMonitorProfile(int screen, const QString & monitorProfile, bool override) const
{
    m_cfg.writeEntry("monitorProfile/OverrideX11", override);
    m_cfg.writeEntry("monitorProfile" + QString(screen == 0 ? "": QString("_%1").arg(screen)), monitorProfile);
}

406 407
const KoColorProfile *KisConfig::getScreenProfile(int screen)
{
408 409
    if (screen < 0) return 0;

410
    KisConfig cfg;
411
    QString monitorId;
412
    if (KisColorManager::instance()->devices().size() > screen && screen > 0) {
413 414
        monitorId = cfg.monitorForScreen(screen, KisColorManager::instance()->devices()[screen]);
    }
Halla Rempt's avatar
Halla Rempt committed
415
    //dbgKrita << "getScreenProfile(). Screen" << screen << "monitor id" << monitorId;
416

417 418 419 420 421 422
    if (monitorId.isEmpty()) {
        return 0;
    }

    QByteArray bytes = KisColorManager::instance()->displayProfile(monitorId);

Halla Rempt's avatar
Halla Rempt committed
423
    //dbgKrita << "\tgetScreenProfile()" << bytes.size();
424

425
    if (bytes.length() > 0) {
426
        const KoColorProfile *profile = KoColorSpaceRegistry::instance()->createColorProfile(RGBAColorModelID.id(), Integer8BitsColorDepthID.id(), bytes);
Halla Rempt's avatar
Halla Rempt committed
427
        //dbgKrita << "\tKisConfig::getScreenProfile for screen" << screen << profile->name();
428
        return profile;
429 430
    }
    else {
Halla Rempt's avatar
Halla Rempt committed
431
        //dbgKrita << "\tCould not get a system monitor profile";
432 433 434 435
        return 0;
    }
}

436
const KoColorProfile *KisConfig::displayProfile(int screen) const
437
{
438 439
    if (screen < 0) return 0;

440
    // if the user plays with the settings, they can override the display profile, in which case
441
    // we don't want the system setting.
442
    bool override = useSystemMonitorProfile();
Halla Rempt's avatar
Halla Rempt committed
443
    //dbgKrita << "KisConfig::displayProfile(). Override X11:" << override;
444
    const KoColorProfile *profile = 0;
445
    if (override) {
Halla Rempt's avatar
Halla Rempt committed
446
        //dbgKrita << "\tGoing to get the screen profile";
447 448
        profile = KisConfig::getScreenProfile(screen);
    }
449 450 451

    // if it fails. check the configuration
    if (!profile || !profile->isSuitableForDisplay()) {
Halla Rempt's avatar
Halla Rempt committed
452
        //dbgKrita << "\tGoing to get the monitor profile";
453
        QString monitorProfileName = monitorProfile(screen);
Halla Rempt's avatar
Halla Rempt committed
454
        //dbgKrita << "\t\tmonitorProfileName:" << monitorProfileName;
455 456 457
        if (!monitorProfileName.isEmpty()) {
            profile = KoColorSpaceRegistry::instance()->profileByName(monitorProfileName);
        }
458
        if (profile) {
Halla Rempt's avatar
Halla Rempt committed
459
            //dbgKrita << "\t\tsuitable for display" << profile->isSuitableForDisplay();
460 461
        }
        else {
Halla Rempt's avatar
Halla Rempt committed
462
            //dbgKrita << "\t\tstill no profile";
463
        }
464 465 466 467
    }
    // if we still don't have a profile, or the profile isn't suitable for display,
    // we need to get a last-resort profile. the built-in sRGB is a good choice then.
    if (!profile || !profile->isSuitableForDisplay()) {
Halla Rempt's avatar
Halla Rempt committed
468
        //dbgKrita << "\tnothing worked, going to get sRGB built-in";
469
        profile = KoColorSpaceRegistry::instance()->profileByName("sRGB Built-in");
470
    }
471

472
    if (profile) {
Halla Rempt's avatar
Halla Rempt committed
473
        //dbgKrita << "\tKisConfig::displayProfile for screen" << screen << "is" << profile->name();
474 475
    }
    else {
Halla Rempt's avatar
Halla Rempt committed
476
        //dbgKrita << "\tCouldn't get a display profile at all";
477
    }
478

479 480
    return profile;
}
481

482
QString KisConfig::workingColorSpace(bool defaultValue) const
483
{
484
    return (defaultValue ? "RGBA" : m_cfg.readEntry("workingColorSpace", "RGBA"));
485 486
}

487
void KisConfig::setWorkingColorSpace(const QString & workingColorSpace) const
488
{
489
    m_cfg.writeEntry("workingColorSpace", workingColorSpace);
490 491
}

492
QString KisConfig::printerColorSpace(bool /*defaultValue*/) const
493
{
494
    //TODO currently only rgb8 is supported
495
    //return (defaultValue ? "RGBA" : m_cfg.readEntry("printerColorSpace", "RGBA"));
496
    return QString("RGBA");
497 498
}

499
void KisConfig::setPrinterColorSpace(const QString & printerColorSpace) const
500
{
Adrian Page's avatar
Adrian Page committed
501
    m_cfg.writeEntry("printerColorSpace", printerColorSpace);
502 503 504
}


505
QString KisConfig::printerProfile(bool defaultValue) const
506
{
507
    return (defaultValue ? "" : m_cfg.readEntry("printerProfile", ""));
508 509
}

510
void KisConfig::setPrinterProfile(const QString & printerProfile) const
511
{
Adrian Page's avatar
Adrian Page committed
512
    m_cfg.writeEntry("printerProfile", printerProfile);
513 514 515
}


516
bool KisConfig::useBlackPointCompensation(bool defaultValue) const
517
{
518
    return (defaultValue ? true : m_cfg.readEntry("useBlackPointCompensation", true));
519 520
}

521
void KisConfig::setUseBlackPointCompensation(bool useBlackPointCompensation) const
522
{
Adrian Page's avatar
Adrian Page committed
523
    m_cfg.writeEntry("useBlackPointCompensation", useBlackPointCompensation);
524 525
}

526
bool KisConfig::allowLCMSOptimization(bool defaultValue) const
527
{
528
    return (defaultValue ? true : m_cfg.readEntry("allowLCMSOptimization", true));
529 530 531 532 533 534 535
}

void KisConfig::setAllowLCMSOptimization(bool allowLCMSOptimization)
{
    m_cfg.writeEntry("allowLCMSOptimization", allowLCMSOptimization);
}

536

537
bool KisConfig::showRulers(bool defaultValue) const
538
{
539
    return (defaultValue ? false : m_cfg.readEntry("showrulers", false));
540 541
}

542
void KisConfig::setShowRulers(bool rulers) const
543
{
Adrian Page's avatar
Adrian Page committed
544
    m_cfg.writeEntry("showrulers", rulers);
545
}
546

547 548 549 550 551 552 553 554 555
bool KisConfig::rulersTrackMouse(bool defaultValue) const
{
    return (defaultValue ? true : m_cfg.readEntry("rulersTrackMouse", true));
}

void KisConfig::setRulersTrackMouse(bool value) const
{
    m_cfg.writeEntry("rulersTrackMouse", value);
}
556

557
qint32 KisConfig::pasteBehaviour(bool defaultValue) const
558
{
559
    return (defaultValue ? 2 : m_cfg.readEntry("pasteBehaviour", 2));
560 561
}

562
void KisConfig::setPasteBehaviour(qint32 renderIntent) const
563
{
Adrian Page's avatar
Adrian Page committed
564
    m_cfg.writeEntry("pasteBehaviour", renderIntent);
565 566 567
}


568
qint32 KisConfig::monitorRenderIntent(bool defaultValue) const
569
{
570 571 572
    qint32 intent = m_cfg.readEntry("renderIntent", INTENT_PERCEPTUAL);
    if (intent > 3) intent = 3;
    if (intent < 0) intent = 0;
573
    return (defaultValue ? INTENT_PERCEPTUAL : intent);
574 575
}

576
void KisConfig::setRenderIntent(qint32 renderIntent) const
577
{
578 579
    if (renderIntent > 3) renderIntent = 3;
    if (renderIntent < 0) renderIntent = 0;
Adrian Page's avatar
Adrian Page committed
580
    m_cfg.writeEntry("renderIntent", renderIntent);
581 582
}

583
bool KisConfig::useOpenGL(bool defaultValue) const
584
{
585 586
    if (defaultValue) {
        return true;
587
    }
588 589 590 591

    //dbgKrita << "use opengl" << m_cfg.readEntry("useOpenGL", true) << "success" << m_cfg.readEntry("canvasState", "OPENGL_SUCCESS");
    QString canvasState = m_cfg.readEntry("canvasState", "OPENGL_SUCCESS");
    return (m_cfg.readEntry("useOpenGL", true) && (canvasState == "OPENGL_SUCCESS" || canvasState == "TRY_OPENGL"));
592 593
}

594
void KisConfig::setUseOpenGL(bool useOpenGL) const
595
{
Adrian Page's avatar
Adrian Page committed
596
    m_cfg.writeEntry("useOpenGL", useOpenGL);
597 598
}

599
int KisConfig::openGLFilteringMode(bool defaultValue) const
600
{
601
    return (defaultValue ? 3 : m_cfg.readEntry("OpenGLFilterMode", 3));
602 603
}

604
void KisConfig::setOpenGLFilteringMode(int filteringMode)
605
{
606
    m_cfg.writeEntry("OpenGLFilterMode", filteringMode);
607 608
}

609
bool KisConfig::useOpenGLTextureBuffer(bool defaultValue) const
610
{
611
    return (defaultValue ? true : m_cfg.readEntry("useOpenGLTextureBuffer", true));
612 613 614 615 616 617 618
}

void KisConfig::setUseOpenGLTextureBuffer(bool useBuffer)
{
    m_cfg.writeEntry("useOpenGLTextureBuffer", useBuffer);
}

619
int KisConfig::openGLTextureSize(bool defaultValue) const
620
{
621
    return (defaultValue ? 256 : m_cfg.readEntry("textureSize", 256));
622 623
}

624
bool KisConfig::disableVSync(bool defaultValue) const
625
{
626
    return (defaultValue ? true : m_cfg.readEntry("disableVSync", true));
627 628 629 630 631 632 633
}

void KisConfig::setDisableVSync(bool disableVSync)
{
    m_cfg.writeEntry("disableVSync", disableVSync);
}

634
bool KisConfig::showAdvancedOpenGLSettings(bool defaultValue) const
635
{
636
    return (defaultValue ? false : m_cfg.readEntry("showAdvancedOpenGLSettings", false));
637 638
}

639
bool KisConfig::forceOpenGLFenceWorkaround(bool defaultValue) const
640
{
641
    return (defaultValue ? false : m_cfg.readEntry("forceOpenGLFenceWorkaround", false));
642 643
}

644
int KisConfig::numMipmapLevels(bool defaultValue) const
645
{
646
    return (defaultValue ? 4 : m_cfg.readEntry("numMipmapLevels", 4));
647 648 649 650
}

int KisConfig::textureOverlapBorder() const
{
651
    return 1 << qMax(0, numMipmapLevels());
652 653
}

654
qint32 KisConfig::maxNumberOfThreads(bool defaultValue) const
655
{
656
    return (defaultValue ? QThread::idealThreadCount() : m_cfg.readEntry("maxthreads", QThread::idealThreadCount()));
657 658
}

Laurent Montel's avatar
Laurent Montel committed
659
void KisConfig::setMaxNumberOfThreads(qint32 maxThreads)
660
{
Adrian Page's avatar
Adrian Page committed
661
    m_cfg.writeEntry("maxthreads", maxThreads);
662 663
}

664
quint32 KisConfig::getGridMainStyle(bool defaultValue) const
665
{
666 667
    int v = m_cfg.readEntry("gridmainstyle", 0);
    v = qBound(0, v, 2);
668
    return (defaultValue ? 0 : v);
669 670
}

671
void KisConfig::setGridMainStyle(quint32 v) const
672
{
Adrian Page's avatar
Adrian Page committed
673
    m_cfg.writeEntry("gridmainstyle", v);
674 675
}

676
quint32 KisConfig::getGridSubdivisionStyle(bool defaultValue) const
677
{
Adrian Page's avatar
Adrian Page committed
678
    quint32 v = m_cfg.readEntry("gridsubdivisionstyle", 1);
679
    if (v > 2) v = 2;
680
    return (defaultValue ? 1 : v);
681 682
}

683
void KisConfig::setGridSubdivisionStyle(quint32 v) const
684
{
Adrian Page's avatar
Adrian Page committed
685
    m_cfg.writeEntry("gridsubdivisionstyle", v);
686 687
}

688
QColor KisConfig::getGridMainColor(bool defaultValue) const
689
{
Halla Rempt's avatar
Halla Rempt committed
690
    QColor col(99, 99, 99);
691
    return (defaultValue ? col : m_cfg.readEntry("gridmaincolor", col));
692 693
}

694
void KisConfig::setGridMainColor(const QColor & v) const
695
{
Adrian Page's avatar
Adrian Page committed
696
    m_cfg.writeEntry("gridmaincolor", v);
697 698
}

699
QColor KisConfig::getGridSubdivisionColor(bool defaultValue) const
700
{
Halla Rempt's avatar
Halla Rempt committed
701
    QColor col(150, 150, 150);
702
    return (defaultValue ? col : m_cfg.readEntry("gridsubdivisioncolor", col));
703 704
}

705
void KisConfig::setGridSubdivisionColor(const QColor & v) const
706
{
Adrian Page's avatar
Adrian Page committed
707
    m_cfg.writeEntry("gridsubdivisioncolor", v);
708 709
}

710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
quint32 KisConfig::guidesLineStyle(bool defaultValue) const
{
    int v = m_cfg.readEntry("guidesLineStyle", 0);
    v = qBound(0, v, 2);
    return (defaultValue ? 0 : v);
}

void KisConfig::setGuidesLineStyle(quint32 v) const
{
    m_cfg.writeEntry("guidesLineStyle", v);
}

QColor KisConfig::guidesColor(bool defaultValue) const
{
    QColor col(99, 99, 99);
    return (defaultValue ? col : m_cfg.readEntry("guidesColor", col));
}

void KisConfig::setGuidesColor(const QColor & v) const
{
    m_cfg.writeEntry("guidesColor", v);
}

733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
void KisConfig::loadSnapConfig(KisSnapConfig *config, bool defaultValue) const
{
    KisSnapConfig defaultConfig(false);

    if (defaultValue) {
        *config = defaultConfig;
        return;
    }

    config->setOrthogonal(m_cfg.readEntry("globalSnapOrthogonal", defaultConfig.orthogonal()));
    config->setNode(m_cfg.readEntry("globalSnapNode", defaultConfig.node()));
    config->setExtension(m_cfg.readEntry("globalSnapExtension", defaultConfig.extension()));
    config->setIntersection(m_cfg.readEntry("globalSnapIntersection", defaultConfig.intersection()));
    config->setBoundingBox(m_cfg.readEntry("globalSnapBoundingBox", defaultConfig.boundingBox()));
    config->setImageBounds(m_cfg.readEntry("globalSnapImageBounds", defaultConfig.imageBounds()));
    config->setImageCenter(m_cfg.readEntry("globalSnapImageCenter", defaultConfig.imageCenter()));
}

void KisConfig::saveSnapConfig(const KisSnapConfig &config)
{
    m_cfg.writeEntry("globalSnapOrthogonal", config.orthogonal());
    m_cfg.writeEntry("globalSnapNode", config.node());
    m_cfg.writeEntry("globalSnapExtension", config.extension());
    m_cfg.writeEntry("globalSnapIntersection", config.intersection());
    m_cfg.writeEntry("globalSnapBoundingBox", config.boundingBox());
    m_cfg.writeEntry("globalSnapImageBounds", config.imageBounds());
    m_cfg.writeEntry("globalSnapImageCenter", config.imageCenter());
}

762
qint32 KisConfig::checkSize(bool defaultValue) const
763
{
764
    return (defaultValue ? 32 : m_cfg.readEntry("checksize", 32));
765 766
}

767
void KisConfig::setCheckSize(qint32 checksize) const
768
{
Halla Rempt's avatar
Halla Rempt committed
769
    m_cfg.writeEntry("checksize", checksize);
770 771
}

772
bool KisConfig::scrollCheckers(bool defaultValue) const
773
{
774
    return (defaultValue ? false : m_cfg.readEntry("scrollingcheckers", false));
775 776
}

777
void KisConfig::setScrollingCheckers(bool sc) const
778
{
Adrian Page's avatar
Adrian Page committed
779
    m_cfg.writeEntry("scrollingcheckers", sc);
780
}
781

782
QColor KisConfig::canvasBorderColor(bool defaultValue) const
783
{
Halla Rempt's avatar
Halla Rempt committed
784
    QColor color(QColor(128,128,128));
785
    return (defaultValue ? color : m_cfg.readEntry("canvasBorderColor", color));
786 787
}

788
void KisConfig::setCanvasBorderColor(const QColor& color) const
789 790 791 792
{
    m_cfg.writeEntry("canvasBorderColor", color);
}

793
bool KisConfig::hideScrollbars(bool defaultValue) const
794
{
795
    return (defaultValue ? false : m_cfg.readEntry("hideScrollbars", false));
796 797 798 799 800 801 802
}

void KisConfig::setHideScrollbars(bool value) const
{
    m_cfg.writeEntry("hideScrollbars", value);
}

803

804
QColor KisConfig::checkersColor1(bool defaultValue) const
805 806
{
    QColor col(220, 220, 220);
807
    return (defaultValue ? col : m_cfg.readEntry("checkerscolor", col));
808 809
}

810
void KisConfig::setCheckersColor1(const QColor & v) const
811
{
Adrian Page's avatar
Adrian Page committed
812
    m_cfg.writeEntry("checkerscolor", v);
813
}
814

815
QColor KisConfig::checkersColor2(bool defaultValue) const
816
{
817
    return (defaultValue ? QColor(Qt::white) : m_cfg.readEntry("checkerscolor2", QColor(Qt::white)));
818 819
}

820
void KisConfig::setCheckersColor2(const QColor & v) const
821 822 823 824
{
    m_cfg.writeEntry("checkerscolor2", v);
}

825
bool KisConfig::antialiasCurves(bool defaultValue) const
826
{
827
    return (defaultValue ? true : m_cfg.readEntry("antialiascurves", true));
828 829
}

830
void KisConfig::setAntialiasCurves(bool v) const
831 832 833 834
{
    m_cfg.writeEntry("antialiascurves", v);
}

835
QColor KisConfig::selectionOverlayMaskColor(bool defaultValue) const
836 837
{
    QColor def(255, 0, 0, 220);
838
    return (defaultValue ? def : m_cfg.readEntry("selectionOverlayMaskColor", def));
839 840 841 842 843 844 845
}

void KisConfig::setSelectionOverlayMaskColor(const QColor &color)
{
    m_cfg.writeEntry("selectionOverlayMaskColor", color);
}

846
bool KisConfig::antialiasSelectionOutline(bool defaultValue) const
847
{
848
    return (defaultValue ? false : m_cfg.readEntry("AntialiasSelectionOutline", false));
849 850 851 852 853 854 855
}

void KisConfig::setAntialiasSelectionOutline(bool v) const
{
    m_cfg.writeEntry("AntialiasSelectionOutline", v);
}

856
bool KisConfig::showRootLayer(bool defaultValue) const
857
{
858
    return (defaultValue ? false : m_cfg.readEntry("ShowRootLayer", false));