kis_dlg_preferences.cc 38.6 KB
Newer Older
1 2 3 4
/*
 *  preferencesdlg.cc - part of KImageShop
 *
 *  Copyright (c) 1999 Michael Koch <koch@kde.org>
5
 *  Copyright (c) 2003-2011 Boudewijn Rempt <boud@valdyas.org>
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 *  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
19
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 21
 */

Boudewijn Rempt's avatar
Boudewijn Rempt committed
22 23
#include "kis_dlg_preferences.h"

24
#include <opengl/kis_opengl.h>
25

26
#include <QBitmap>
27
#include <QCheckBox>
28
#include <QCursor>
29 30 31 32
#include <QLabel>
#include <QLayout>
#include <QLineEdit>
#include <QPushButton>
33 34
#include <QSlider>
#include <QToolButton>
35
#include <QThread>
36
#include <QDesktopServices>
37
#include <QGridLayout>
38 39
#include <QRadioButton>
#include <QGroupBox>
40
#include <QMdiArea>
41
#include <QMessageBox>
42
#include <QDesktopWidget>
43
#include <QFileDialog>
44

45
#include <KisDocument.h>
46
#include <KoColorProfile.h>
47
#include <KisApplication.h>
Yue Liu's avatar
Yue Liu committed
48
#include <KoFileDialog.h>
49
#include <KisPart.h>
50
#include <KoColorSpaceEngine.h>
51
#include <kis_icon.h>
52
#include <KoConfig.h>
53
#include "KoID.h"
54
#include <KoConfigAuthorPage.h>
Boudewijn Rempt's avatar
Boudewijn Rempt committed
55
#include <KoVBox.h>
56

57
#include <klocalizedstring.h>
Alexander Potashev's avatar
Alexander Potashev committed
58
#include <kundo2stack.h>
59
#include <KoResourcePaths.h>
60
#include "kis_action_registry.h"
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
61

62
#include "widgets/squeezedcombobox.h"
63
#include "kis_clipboard.h"
64
#include "widgets/kis_cmb_idlist.h"
65
#include "KoColorSpace.h"
66
#include "KoColorSpaceRegistry.h"
67
#include "KoColorConversionTransformation.h"
68 69
#include "kis_cursor.h"
#include "kis_config.h"
70
#include "kis_canvas_resource_provider.h"
71
#include "kis_preference_set_registry.h"
72
#include "kis_color_manager.h"
73 74
#include "KisProofingConfiguration.h"
#include "kis_image_config.h"
Boudewijn Rempt's avatar
Boudewijn Rempt committed
75

76 77
#include "slider_and_spin_box_sync.h"

78
// for the performance update
79
#include <kis_cubic_curve.h>
80

81 82
#include "input/config/kis_input_configuration_page.h"

83

Boudewijn Rempt's avatar
Boudewijn Rempt committed
84
GeneralTab::GeneralTab(QWidget *_parent, const char *_name)
85
    : WdgGeneralSettings(_parent, _name)
86
{
87
    KisConfig cfg;
88

89
    m_cmbCursorShape->addItem(i18n("No Cursor"));
Boudewijn Rempt's avatar
Boudewijn Rempt committed
90 91
    m_cmbCursorShape->addItem(i18n("Tool Icon"));
    m_cmbCursorShape->addItem(i18n("Arrow"));
92
    m_cmbCursorShape->addItem(i18n("Small Circle"));
93
    m_cmbCursorShape->addItem(i18n("Crosshair"));
94 95
    m_cmbCursorShape->addItem(i18n("Triangle Righthanded"));
    m_cmbCursorShape->addItem(i18n("Triangle Lefthanded"));
96 97
    m_cmbCursorShape->addItem(i18n("Black Pixel"));
    m_cmbCursorShape->addItem(i18n("White Pixel"));
98

99 100 101
    m_cmbOutlineShape->addItem(i18n("No Outline"));
    m_cmbOutlineShape->addItem(i18n("Circle Outline"));
    m_cmbOutlineShape->addItem(i18n("Preview Outline"));
102
    m_cmbOutlineShape->addItem(i18n("Tilt Outline"));
103 104 105 106

    m_cmbCursorShape->setCurrentIndex(cfg.newCursorStyle());
    m_cmbOutlineShape->setCurrentIndex(cfg.newOutlineStyle());

107
    chkShowRootLayer->setChecked(cfg.showRootLayer());
108

109
    int autosaveInterval = cfg.autoSaveInterval();
110
    //convert to minutes
111 112
    m_autosaveSpinBox->setValue(autosaveInterval / 60);
    m_autosaveCheckBox->setChecked(autosaveInterval > 0);
113
    m_undoStackSize->setValue(cfg.undoStackLimit());
114
    m_backupFileCheckBox->setChecked(cfg.backupFile());
115
    m_showOutlinePainting->setChecked(cfg.showOutlineWhilePainting());
116
    m_hideSplashScreen->setChecked(cfg.hideSplashScreen());
117
    m_cmbMDIType->setCurrentIndex(cfg.readEntry<int>("mdi_viewmode", (int)QMdiArea::TabbedView));
118
    m_chkRubberBand->setChecked(cfg.readEntry<int>("mdi_rubberband", cfg.useOpenGL()));
119
    m_favoritePresetsSpinBox->setValue(cfg.favoritePresets());
120
    m_mdiColor->setColor(cfg.getMDIBackgroundColor());
121
    m_backgroundimage->setText(cfg.getMDIBackgroundImage());
122
    m_chkCanvasMessages->setChecked(cfg.showCanvasMessages());
123
    m_chkCompressKra->setChecked(cfg.compressKra());
124
    m_radioToolOptionsInDocker->setChecked(cfg.toolOptionsInDocker());
125
    m_chkSwitchSelectionCtrlAlt->setChecked(cfg.switchSelectionCtrlAlt());
126
    m_chkConvertOnImport->setChecked(cfg.convertToImageColorspaceOnImport());
127

128
    connect(m_bnFileName, SIGNAL(clicked()), SLOT(getBackgroundImage()));
129
    connect(clearBgImageButton, SIGNAL(clicked()), SLOT(clearBackgroundImage()));
130 131
}

Laurent Montel's avatar
Laurent Montel committed
132 133
void GeneralTab::setDefault()
{
134
    KisConfig cfg;
135

136 137
    m_cmbCursorShape->setCurrentIndex(cfg.newCursorStyle(true));
    m_cmbOutlineShape->setCurrentIndex(cfg.newOutlineStyle(true));
138 139
    chkShowRootLayer->setChecked(cfg.showRootLayer(true));
    m_autosaveCheckBox->setChecked(cfg.autoSaveInterval(true) > 0);
140
    //convert to minutes
141 142 143 144 145 146 147 148 149 150 151 152
    m_autosaveSpinBox->setValue(cfg.autoSaveInterval(true) / 60);
    m_undoStackSize->setValue(cfg.undoStackLimit(true));
    m_backupFileCheckBox->setChecked(cfg.backupFile(true));
    m_showOutlinePainting->setChecked(cfg.showOutlineWhilePainting(true));
    m_hideSplashScreen->setChecked(cfg.hideSplashScreen(true));
    m_cmbMDIType->setCurrentIndex((int)QMdiArea::TabbedView);
    m_chkRubberBand->setChecked(cfg.useOpenGL(true));
    m_favoritePresetsSpinBox->setValue(cfg.favoritePresets(true));
    m_mdiColor->setColor(cfg.getMDIBackgroundColor(true));
    m_backgroundimage->setText(cfg.getMDIBackgroundImage(true));
    m_chkCanvasMessages->setChecked(cfg.showCanvasMessages(true));
    m_chkCompressKra->setChecked(cfg.compressKra(true));
153
    m_radioToolOptionsInDocker->setChecked(cfg.toolOptionsInDocker(true));
154
    m_chkSwitchSelectionCtrlAlt->setChecked(cfg.switchSelectionCtrlAlt(true));
155
    m_chkConvertOnImport->setChecked(cfg.convertToImageColorspaceOnImport(true));
156

157 158
}

159 160 161 162 163 164
CursorStyle GeneralTab::cursorStyle()
{
    return (CursorStyle)m_cmbCursorShape->currentIndex();
}

OutlineStyle GeneralTab::outlineStyle()
165
{
166
    return (OutlineStyle)m_cmbOutlineShape->currentIndex();
Laurent Montel's avatar
Laurent Montel committed
167
}
168

169 170 171 172
bool GeneralTab::showRootLayer()
{
    return chkShowRootLayer->isChecked();
}
173

174 175
int GeneralTab::autoSaveInterval()
{
176
    //convert to seconds
177
    return m_autosaveCheckBox->isChecked() ? m_autosaveSpinBox->value()*60 : 0;
178 179
}

180 181 182 183 184
int GeneralTab::undoStackSize()
{
    return m_undoStackSize->value();
}

185 186 187 188 189
bool GeneralTab::showOutlineWhilePainting()
{
    return m_showOutlinePainting->isChecked();
}

190 191 192 193
bool GeneralTab::hideSplashScreen()
{
    return m_hideSplashScreen->isChecked();
}
194 195 196 197 198 199

int GeneralTab::mdiMode()
{
    return m_cmbMDIType->currentIndex();
}

200 201 202 203 204
int GeneralTab::favoritePresets()
{
    return m_favoritePresetsSpinBox->value();
}

205 206 207 208 209
bool GeneralTab::showCanvasMessages()
{
    return m_chkCanvasMessages->isChecked();
}

210 211 212 213 214
bool GeneralTab::compressKra()
{
    return m_chkCompressKra->isChecked();
}

215 216 217 218 219
bool GeneralTab::toolOptionsInDocker()
{
    return m_radioToolOptionsInDocker->isChecked();
}

220 221 222 223 224 225
bool GeneralTab::switchSelectionCtrlAlt()
{
    return m_chkSwitchSelectionCtrlAlt->isChecked();

}

226 227 228 229 230
bool GeneralTab::convertToImageColorspaceOnImport()
{
    return m_chkConvertOnImport->isChecked();
}

231

232 233 234 235 236 237
void GeneralTab::getBackgroundImage()
{
    KoFileDialog dialog(this, KoFileDialog::OpenFile, "BackgroundImages");
    dialog.setCaption(i18n("Select a Background Image"));
    dialog.setDefaultDir(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation));
    dialog.setImageFilters();
238

239
    QString fn = dialog.filename();
240 241 242 243 244
    // dialog box was canceled or somehow no file was selected
    if (fn.isEmpty()) {
        return;
    }

245 246 247 248 249 250 251 252 253
    QImage image(fn);
    if (image.isNull()) {
        QMessageBox::warning(this, i18nc("@title:window", "Krita"), i18n("%1 is not a valid image file!", fn));
    }
    else {
        m_backgroundimage->setText(fn);
    }
}

254 255 256 257 258
void GeneralTab::clearBackgroundImage()
{
    // clearing the background image text will implicitly make the background color be used
    m_backgroundimage->setText("");
}
259

260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
ShortcutSettingsTab::ShortcutSettingsTab(QWidget *parent, const char *name)
    : QWidget(parent)
{
    setObjectName(name);

    QGridLayout * l = new QGridLayout(this);
    l->setMargin(0);
    m_page = new WdgShortcutSettings(this);
    l->addWidget(m_page, 0, 0);

    KisPart::instance()->loadActions();
    KisActionRegistry::instance()->setupDialog(m_page);
}

void ShortcutSettingsTab::setDefault()
{
    m_page->allDefault();
}

void ShortcutSettingsTab::saveChanges()
{
281
    m_page->save();
282 283 284 285 286 287 288 289
    KisActionRegistry::instance()->settingsPageSaved();
}

void ShortcutSettingsTab::revertChanges()
{
    m_page->allDefault();
}

Boudewijn Rempt's avatar
Boudewijn Rempt committed
290
ColorSettingsTab::ColorSettingsTab(QWidget *parent, const char *name)
291
    : QWidget(parent)
292
{
293 294
    setObjectName(name);

295 296
    // XXX: Make sure only profiles that fit the specified color model
    // are shown in the profile combos
297

298
    QGridLayout * l = new QGridLayout(this);
299
    l->setMargin(0);
300
    m_page = new WdgColorSettings(this);
Boudewijn Rempt's avatar
Boudewijn Rempt committed
301
    l->addWidget(m_page, 0, 0);
302

303
    KisConfig cfg;
Laurent Montel's avatar
Laurent Montel committed
304

305
    m_page->chkUseSystemMonitorProfile->setChecked(cfg.useSystemMonitorProfile());
306
    connect(m_page->chkUseSystemMonitorProfile, SIGNAL(toggled(bool)), this, SLOT(toggleAllowMonitorProfileSelection(bool)));
307

308
// XXX: no color management integration on Windows or OSX yet
309
#ifndef HAVE_X11
310 311
    m_page->chkUseSystemMonitorProfile->setVisible(false);
#endif
312
    m_page->cmbWorkingColorSpace->setIDList(KoColorSpaceRegistry::instance()->listKeys());
313
    m_page->cmbWorkingColorSpace->setCurrent(cfg.workingColorSpace());
314

Timothée Giet's avatar
Timothée Giet committed
315
    m_page->bnAddColorProfile->setIcon(KisIconUtils::loadIcon("document-open"));
316 317 318
    m_page->bnAddColorProfile->setToolTip( i18n("Open Color Profile") );
    connect(m_page->bnAddColorProfile, SIGNAL(clicked()), SLOT(installProfile()));

319 320
    QGridLayout *monitorProfileGrid = new QGridLayout(m_page->monitorprofileholder);
    for(int i = 0; i < QApplication::desktop()->screenCount(); ++i) {
321
        QLabel *lbl = new QLabel(i18nc("The number of the screen", "Screen %1:", i + 1));
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
        monitorProfileGrid->addWidget(lbl, i, 0);
        m_monitorProfileLabels << lbl;
        SqueezedComboBox *cmb = new SqueezedComboBox();
        monitorProfileGrid->addWidget(cmb, i, 1);
        m_monitorProfileWidgets << cmb;
    }

    refillMonitorProfiles(KoID("RGBA", ""));

    for(int i = 0; i < QApplication::desktop()->screenCount(); ++i) {
        if (m_monitorProfileWidgets[i]->contains(cfg.monitorProfile(i))) {
            m_monitorProfileWidgets[i]->setCurrent(cfg.monitorProfile(i));
        }
    }

337
    m_page->chkBlackpoint->setChecked(cfg.useBlackPointCompensation());
338
    m_page->chkAllowLCMSOptimization->setChecked(cfg.allowLCMSOptimization());
339

340 341 342 343 344 345 346
    KisImageConfig cfgImage;

    KisProofingConfiguration *proofingConfig = cfgImage.defaultProofingconfiguration();
    m_gamutWarning = new KoColorPopupAction(this);
    m_gamutWarning->setToolTip(i18n("Set default color used for out of Gamut Warning"));
    m_gamutWarning->setCurrentColor(proofingConfig->warningColor);
    m_page->gamutAlarm->setDefaultAction(m_gamutWarning);
347 348 349
    m_page->sldAdaptationState->setMaximum(20);
    m_page->sldAdaptationState->setMinimum(0);
    m_page->sldAdaptationState->setValue((int)proofingConfig->adaptationState*20);
350 351 352 353 354 355 356

    const KoColorSpace *proofingSpace =  KoColorSpaceRegistry::instance()->colorSpace(proofingConfig->proofingModel,proofingConfig->proofingDepth,proofingConfig->proofingProfile);
    m_page->proofingSpaceSelector->setCurrentColorSpace(proofingSpace);

    m_page->cmbProofingIntent->setCurrentIndex((int)proofingConfig->intent);
    m_page->ckbProofBlackPoint->setChecked(proofingConfig->conversionFlags.testFlag(KoColorConversionTransformation::BlackpointCompensation));

357 358 359 360 361 362 363 364 365 366 367
    m_pasteBehaviourGroup.addButton(m_page->radioPasteWeb, PASTE_ASSUME_WEB);
    m_pasteBehaviourGroup.addButton(m_page->radioPasteMonitor, PASTE_ASSUME_MONITOR);
    m_pasteBehaviourGroup.addButton(m_page->radioPasteAsk, PASTE_ASK);

    QAbstractButton *button = m_pasteBehaviourGroup.button(cfg.pasteBehaviour());
    Q_ASSERT(button);

    if (button) {
        button->setChecked(true);
    }

368
    m_page->cmbMonitorIntent->setCurrentIndex(cfg.monitorRenderIntent());
369

370
    toggleAllowMonitorProfileSelection(cfg.useSystemMonitorProfile());
371

372 373
}

374 375
void ColorSettingsTab::installProfile()
{
376 377 378
    KoFileDialog dialog(this, KoFileDialog::OpenFiles, "OpenDocumentICC");
    dialog.setCaption(i18n("Install Color Profiles"));
    dialog.setDefaultDir(QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
379
    dialog.setMimeTypeFilters(QStringList() << "application/vnd.iccprofile", "application/vnd.iccprofile");
380
    QStringList profileNames = dialog.filenames();
381 382 383 384

    KoColorSpaceEngine *iccEngine = KoColorSpaceEngineRegistry::instance()->get("icc");
    Q_ASSERT(iccEngine);

385
    QString saveLocation = KoResourcePaths::saveLocation("icc_profiles");
386

387
    Q_FOREACH (const QString &profileName, profileNames) {
Boudewijn Rempt's avatar
Boudewijn Rempt committed
388
        QUrl file(profileName);
389
        if (!QFile::copy(profileName, saveLocation + file.fileName())) {
390
            dbgKrita << "Could not install profile!";
391 392 393 394 395 396 397 398 399
            return;
        }
        iccEngine->addProfile(saveLocation + file.fileName());

    }

    KisConfig cfg;
    refillMonitorProfiles(KoID("RGBA", ""));

400 401 402 403 404 405
    for(int i = 0; i < QApplication::desktop()->screenCount(); ++i) {
        if (m_monitorProfileWidgets[i]->contains(cfg.monitorProfile(i))) {
            m_monitorProfileWidgets[i]->setCurrent(cfg.monitorProfile(i));
        }
    }

406 407 408 409 410
}

void ColorSettingsTab::toggleAllowMonitorProfileSelection(bool useSystemProfile)
{
    if (useSystemProfile) {
411 412 413 414 415 416
        KisConfig cfg;
        QStringList devices = KisColorManager::instance()->devices();
        if (devices.size() == QApplication::desktop()->screenCount()) {
            for(int i = 0; i < QApplication::desktop()->screenCount(); ++i) {
                m_monitorProfileWidgets[i]->clear();
                QString monitorForScreen = cfg.monitorForScreen(i, devices[i]);
417
                Q_FOREACH (const QString &device, devices) {
418 419 420 421 422 423 424
                    m_monitorProfileLabels[i]->setText(i18nc("The display/screen we got from Qt", "Screen %1:", i + 1));
                    m_monitorProfileWidgets[i]->addSqueezedItem(KisColorManager::instance()->deviceName(device), device);
                    if (devices[i] == monitorForScreen) {
                        m_monitorProfileWidgets[i]->setCurrentIndex(i);
                    }
                }
            }
425 426 427
        }
    }
    else {
428
        KisConfig cfg;
429
        refillMonitorProfiles(KoID("RGBA", ""));
430 431 432 433 434 435

        for(int i = 0; i < QApplication::desktop()->screenCount(); ++i) {
            if (m_monitorProfileWidgets[i]->contains(cfg.monitorProfile(i))) {
                m_monitorProfileWidgets[i]->setCurrent(cfg.monitorProfile(i));
            }
        }
436 437 438
    }
}

Laurent Montel's avatar
Laurent Montel committed
439 440
void ColorSettingsTab::setDefault()
{
441
    m_page->cmbWorkingColorSpace->setCurrent("RGBA");
Laurent Montel's avatar
Laurent Montel committed
442

443 444
    refillMonitorProfiles(KoID("RGBA", ""));

445
    KisConfig cfg;
446 447 448 449 450 451
    KisImageConfig cfgImage;
    KisProofingConfiguration *proofingConfig =  cfgImage.defaultProofingconfiguration();
    const KoColorSpace *proofingSpace =  KoColorSpaceRegistry::instance()->colorSpace(proofingConfig->proofingModel,proofingConfig->proofingDepth,proofingConfig->proofingProfile);
    m_page->proofingSpaceSelector->setCurrentColorSpace(proofingSpace);
    m_page->cmbProofingIntent->setCurrentIndex((int)proofingConfig->intent);
    m_page->ckbProofBlackPoint->setChecked(proofingConfig->conversionFlags.testFlag(KoColorConversionTransformation::BlackpointCompensation));
452
    m_page->sldAdaptationState->setValue(0);
453 454

    m_gamutWarning->setCurrentColor(proofingConfig->warningColor);
455

456 457 458 459 460 461
    m_page->chkBlackpoint->setChecked(cfg.useBlackPointCompensation(true));
    m_page->chkAllowLCMSOptimization->setChecked(cfg.allowLCMSOptimization(true));
    m_page->cmbMonitorIntent->setCurrentIndex(cfg.monitorRenderIntent(true));
    m_page->chkUseSystemMonitorProfile->setChecked(cfg.useSystemMonitorProfile(true));
    QAbstractButton *button = m_pasteBehaviourGroup.button(cfg.pasteBehaviour(true));
    Q_ASSERT(button);
462 463 464
    if (button) {
        button->setChecked(true);
    }
Laurent Montel's avatar
Laurent Montel committed
465 466
}

467

468
void ColorSettingsTab::refillMonitorProfiles(const KoID & s)
469
{
470
    const KoColorSpaceFactory * csf = KoColorSpaceRegistry::instance()->colorSpaceFactory(s.id());
471

472 473 474
    for (int i = 0; i < QApplication::desktop()->screenCount(); ++i) {
        m_monitorProfileWidgets[i]->clear();
    }
475

Boudewijn Rempt's avatar
Boudewijn Rempt committed
476 477
    if (!csf)
        return;
478

Boudewijn Rempt's avatar
Boudewijn Rempt committed
479
    QList<const KoColorProfile *>  profileList = KoColorSpaceRegistry::instance()->profilesFor(csf);
480

481
    Q_FOREACH (const KoColorProfile *profile, profileList) {
482
//        //dbgKrita << "Profile" << profile->name() << profile->isSuitableForDisplay() << csf->defaultProfile();
483 484 485 486 487
        if (profile->isSuitableForDisplay()) {
            for (int i = 0; i < QApplication::desktop()->screenCount(); ++i) {
                m_monitorProfileWidgets[i]->addSqueezedItem(profile->name());
            }
        }
488
    }
489

490
    for (int i = 0; i < QApplication::desktop()->screenCount(); ++i) {
491
        m_monitorProfileLabels[i]->setText(i18nc("The number of the screen", "Screen %1:", i + 1));
492 493
        m_monitorProfileWidgets[i]->setCurrent(csf->defaultProfile());
    }
494 495
}

496

497 498
//---------------------------------------------------------------------------------------------------

499 500 501 502 503 504 505 506 507 508
void TabletSettingsTab::setDefault()
{
    KisCubicCurve curve;
    curve.fromString(DEFAULT_CURVE_STRING);
    m_page->pressureCurve->setCurve(curve);
}

TabletSettingsTab::TabletSettingsTab(QWidget* parent, const char* name): QWidget(parent)
{
    setObjectName(name);
509 510 511

    QGridLayout * l = new QGridLayout(this);
    l->setMargin(0);
512
    m_page = new WdgTabletSettings(this);
513
    l->addWidget(m_page, 0, 0);
514

515 516 517
    KisConfig cfg;
    KisCubicCurve curve;
    curve.fromString( cfg.pressureTabletCurve() );
518

519
    m_page->pressureCurve->setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
520 521 522 523 524
    m_page->pressureCurve->setCurve(curve);
}


//---------------------------------------------------------------------------------------------------
525 526 527 528 529 530 531 532 533 534 535 536
#include "kis_acyclic_signal_connector.h"

int getTotalRAM() {
    KisImageConfig cfg;
    return cfg.totalRAM();
}

int PerformanceTab::realTilesRAM()
{
    return intMemoryLimit->value() - intPoolLimit->value();
}

Boudewijn Rempt's avatar
Boudewijn Rempt committed
537
PerformanceTab::PerformanceTab(QWidget *parent, const char *name)
538
    : WdgPerformanceSettings(parent, name)
539
{
540 541 542
    KisImageConfig cfg;
    const int totalRAM = cfg.totalRAM();
    lblTotalMemory->setText(i18n("%1 MiB", totalRAM));
543

544
    sliderMemoryLimit->setSuffix(i18n(" %"));
545 546 547
    sliderMemoryLimit->setRange(1, 100, 2);
    sliderMemoryLimit->setSingleStep(0.01);

548
    sliderPoolLimit->setSuffix(i18n(" %"));
549 550 551
    sliderPoolLimit->setRange(0, 20, 2);
    sliderMemoryLimit->setSingleStep(0.01);

552
    sliderUndoLimit->setSuffix(i18n(" %"));
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
    sliderUndoLimit->setRange(0, 50, 2);
    sliderMemoryLimit->setSingleStep(0.01);

    intMemoryLimit->setMinimumWidth(80);
    intPoolLimit->setMinimumWidth(80);
    intUndoLimit->setMinimumWidth(80);


    SliderAndSpinBoxSync *sync1 =
        new SliderAndSpinBoxSync(sliderMemoryLimit,
                                 intMemoryLimit,
                                 getTotalRAM);

    sync1->slotParentValueChanged();
    m_syncs << sync1;

    SliderAndSpinBoxSync *sync2 =
        new SliderAndSpinBoxSync(sliderPoolLimit,
                                 intPoolLimit,
572
                                 std::bind(&QSpinBox::value,
573 574 575 576 577 578 579 580 581 582
                                             intMemoryLimit));


    connect(intMemoryLimit, SIGNAL(valueChanged(int)), sync2, SLOT(slotParentValueChanged()));
    sync2->slotParentValueChanged();
    m_syncs << sync2;

    SliderAndSpinBoxSync *sync3 =
        new SliderAndSpinBoxSync(sliderUndoLimit,
                                 intUndoLimit,
583
                                 std::bind(&PerformanceTab::realTilesRAM,
584
                                             this));
585 586


587 588 589 590 591 592 593 594
    connect(intPoolLimit, SIGNAL(valueChanged(int)), sync3, SLOT(slotParentValueChanged()));
    sync3->slotParentValueChanged();
    m_syncs << sync3;

    sliderSwapSize->setSuffix(i18n(" GiB"));
    sliderSwapSize->setRange(1, 64);
    intSwapSize->setRange(1, 64);

595 596

    KisAcyclicSignalConnector *swapSizeConnector = new KisAcyclicSignalConnector(this);
597 598 599 600 601 602

    swapSizeConnector->connectForwardInt(sliderSwapSize, SIGNAL(valueChanged(int)),
                                         intSwapSize, SLOT(setValue(int)));

    swapSizeConnector->connectBackwardInt(intSwapSize, SIGNAL(valueChanged(int)),
                                          sliderSwapSize, SLOT(setValue(int)));
603

604 605
    lblSwapFileLocation->setText(cfg.swapDir());
    connect(bnSwapFile, SIGNAL(clicked()), SLOT(selectSwapDir()));
606 607

    load(false);
608 609
}

610
PerformanceTab::~PerformanceTab()
611
{
612 613 614 615 616 617 618 619 620 621 622 623
    qDeleteAll(m_syncs);
}

void PerformanceTab::load(bool requestDefault)
{
    KisImageConfig cfg;

    sliderMemoryLimit->setValue(cfg.memoryHardLimitPercent(requestDefault));
    sliderPoolLimit->setValue(cfg.memoryPoolLimitPercent(requestDefault));
    sliderUndoLimit->setValue(cfg.memorySoftLimitPercent(requestDefault));

    chkPerformanceLogging->setChecked(cfg.enablePerfLog(requestDefault));
624
    chkProgressReporting->setChecked(cfg.enableProgressReporting(requestDefault));
625 626

    sliderSwapSize->setValue(cfg.maxSwapSize(requestDefault) / 1024);
627
    lblSwapFileLocation->setText(cfg.swapDir(requestDefault));
628 629 630 631 632 633

    {
        KisConfig cfg2;
        chkOpenGLLogging->setChecked(cfg2.enableOpenGLDebugging(requestDefault));
        chkDisableVectorOptimizations->setChecked(cfg2.enableAmdVectorizationWorkaround(requestDefault));
    }
634 635 636 637 638 639 640 641 642 643 644
}

void PerformanceTab::save()
{
    KisImageConfig cfg;

    cfg.setMemoryHardLimitPercent(sliderMemoryLimit->value());
    cfg.setMemorySoftLimitPercent(sliderUndoLimit->value());
    cfg.setMemoryPoolLimitPercent(sliderPoolLimit->value());

    cfg.setEnablePerfLog(chkPerformanceLogging->isChecked());
645
    cfg.setEnableProgressReporting(chkProgressReporting->isChecked());
646 647

    cfg.setMaxSwapSize(sliderSwapSize->value() * 1024);
648 649

    cfg.setSwapDir(lblSwapFileLocation->text());
650 651 652 653 654 655

    {
        KisConfig cfg2;
        cfg2.setEnableOpenGLDebugging(chkOpenGLLogging->isChecked());
        cfg2.setEnableAmdVectorizationWorkaround(chkDisableVectorOptimizations->isChecked());
    }
656 657 658 659 660 661 662 663
}

void PerformanceTab::selectSwapDir()
{
    KisImageConfig cfg;
    QString swapDir = cfg.swapDir();
    swapDir = QFileDialog::getExistingDirectory(0, i18nc("@title:window", "Select a swap directory"), swapDir);
    lblSwapFileLocation->setText(swapDir);
664 665
}

666
//---------------------------------------------------------------------------------------------------
667

668 669 670
#include "KoColor.h"
#include "KoColorPopupAction.h"

Boudewijn Rempt's avatar
Boudewijn Rempt committed
671
DisplaySettingsTab::DisplaySettingsTab(QWidget *parent, const char *name)
672
    : WdgDisplaySettings(parent, name)
673
{
674 675
    KisConfig cfg;

676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
    if (!KisOpenGL::hasOpenGL()) {
        grpOpenGL->setEnabled(false);
        grpOpenGL->setChecked(false);
        chkUseTextureBuffer->setEnabled(false);
        chkDisableVsync->setEnabled(false);
        cmbFilterMode->setEnabled(false);
    } else {
        grpOpenGL->setEnabled(true);
        grpOpenGL->setChecked(cfg.useOpenGL());
        chkUseTextureBuffer->setEnabled(cfg.useOpenGL());
        chkUseTextureBuffer->setChecked(cfg.useOpenGLTextureBuffer());
        chkDisableVsync->setVisible(cfg.showAdvancedOpenGLSettings());
        chkDisableVsync->setEnabled(cfg.useOpenGL());
        chkDisableVsync->setChecked(cfg.disableVSync());
        cmbFilterMode->setEnabled(cfg.useOpenGL());
        cmbFilterMode->setCurrentIndex(cfg.openGLFilteringMode());
692 693 694 695
        // Don't show the high quality filtering mode if it's not available
        if (!KisOpenGL::supportsGLSL13()) {
            cmbFilterMode->removeItem(3);
        }
696
    }
697
    if (qApp->applicationName() == "kritasketch" || qApp->applicationName() == "kritagemini") {
698 699
       grpOpenGL->setVisible(false);
       grpOpenGL->setMaximumHeight(0);
700
    }
701

702 703 704 705 706 707 708
    KoColor c;
    c.fromQColor(cfg.selectionOverlayMaskColor());
    m_selectionOverlayColorAction = new KoColorPopupAction(this);
    m_selectionOverlayColorAction->setCurrentColor(c);
    m_selectionOverlayColorAction->setToolTip(i18n("Change the background color of the image"));
    btnSelectionOverlayColor->setDefaultAction(m_selectionOverlayColorAction);

Boudewijn Rempt's avatar
Boudewijn Rempt committed
709 710
    intCheckSize->setValue(cfg.checkSize());
    chkMoving->setChecked(cfg.scrollCheckers());
711
    colorChecks1->setColor(cfg.checkersColor1());
712
    colorChecks2->setColor(cfg.checkersColor2());
713
    canvasBorder->setColor(cfg.canvasBorderColor());
714
    hideScrollbars->setChecked(cfg.hideScrollbars());
715
    chkCurveAntialiasing->setChecked(cfg.antialiasCurves());
716
    chkSelectionOutlineAntialiasing->setChecked(cfg.antialiasSelectionOutline());
717
    chkChannelsAsColor->setChecked(cfg.showSingleChannelAsColor());
718
    chkHidePopups->setChecked(cfg.hidePopups());
719

720
    connect(grpOpenGL, SIGNAL(toggled(bool)), SLOT(slotUseOpenGLToggled(bool)));
721 722 723 724
}

void DisplaySettingsTab::setDefault()
{
725
    KisConfig cfg;
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
    if (!KisOpenGL::hasOpenGL()) {
        grpOpenGL->setEnabled(false);
        grpOpenGL->setChecked(false);
        chkUseTextureBuffer->setEnabled(false);
        chkDisableVsync->setEnabled(false);
        cmbFilterMode->setEnabled(false);
    }
    else {
        grpOpenGL->setEnabled(true);
        grpOpenGL->setChecked(cfg.useOpenGL(true));
        chkUseTextureBuffer->setChecked(cfg.useOpenGLTextureBuffer(true));
        chkUseTextureBuffer->setEnabled(true);
        chkDisableVsync->setEnabled(true);
        chkDisableVsync->setChecked(cfg.disableVSync(true));
        cmbFilterMode->setEnabled(true);
        cmbFilterMode->setCurrentIndex(cfg.openGLFilteringMode(true));
    }
743

744 745 746 747 748 749 750 751 752 753 754
    chkMoving->setChecked(cfg.scrollCheckers(true));
    intCheckSize->setValue(cfg.checkSize(true));
    colorChecks1->setColor(cfg.checkersColor1(true));
    colorChecks2->setColor(cfg.checkersColor2(true));
    canvasBorder->setColor(cfg.canvasBorderColor(true));
    hideScrollbars->setChecked(cfg.hideScrollbars(true));
    chkCurveAntialiasing->setChecked(cfg.antialiasCurves(true));
    chkSelectionOutlineAntialiasing->setChecked(cfg.antialiasSelectionOutline(true));
    chkChannelsAsColor->setChecked(cfg.showSingleChannelAsColor(true));
    chkHidePopups->setChecked(cfg.hidePopups(true));

755 756
}

757
void DisplaySettingsTab::slotUseOpenGLToggled(bool isChecked)
758
{
759
    chkUseTextureBuffer->setEnabled(isChecked);
760
    chkDisableVsync->setEnabled(isChecked);
761
    cmbFilterMode->setEnabled(isChecked);
762
}
763

764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
//---------------------------------------------------------------------------------------------------
FullscreenSettingsTab::FullscreenSettingsTab(QWidget* parent) : WdgFullscreenSettingsBase(parent)
{
    KisConfig cfg;

    chkDockers->setChecked(cfg.hideDockersFullscreen());
    chkMenu->setChecked(cfg.hideMenuFullscreen());
    chkScrollbars->setChecked(cfg.hideScrollbarsFullscreen());
    chkStatusbar->setChecked(cfg.hideStatusbarFullscreen());
    chkTitlebar->setChecked(cfg.hideTitlebarFullscreen());
    chkToolbar->setChecked(cfg.hideToolbarFullscreen());

}

void FullscreenSettingsTab::setDefault()
{
780 781 782 783 784 785 786
    KisConfig cfg;
    chkDockers->setChecked(cfg.hideDockersFullscreen(true));
    chkMenu->setChecked(cfg.hideMenuFullscreen(true));
    chkScrollbars->setChecked(cfg.hideScrollbarsFullscreen(true));
    chkStatusbar->setChecked(cfg.hideStatusbarFullscreen(true));
    chkTitlebar->setChecked(cfg.hideTitlebarFullscreen(true));
    chkToolbar->setChecked(cfg.hideToolbarFullscreen(true));
787 788
}

789

790
//---------------------------------------------------------------------------------------------------
791

792
KisDlgPreferences::KisDlgPreferences(QWidget* parent, const char* name)
793
    : KPageDialog(parent)
Laurent Montel's avatar
Port++  
Laurent Montel committed
794
{
795
    Q_UNUSED(name);
796 797 798 799 800
    setWindowTitle(i18n("Preferences"));
    // QT5TODO: help button needs custom wiring up to whatever help should be shown
    setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::RestoreDefaults);
    button(QDialogButtonBox::Ok)->setDefault(true);

Boudewijn Rempt's avatar
Boudewijn Rempt committed
801
    setFaceType(KPageDialog::List);
802 803

    // General
Boudewijn Rempt's avatar
Boudewijn Rempt committed
804
    KoVBox *vbox = new KoVBox();
Boudewijn Rempt's avatar
Boudewijn Rempt committed
805
    KPageWidgetItem *page = new KPageWidgetItem(vbox, i18n("General"));
806
    page->setObjectName("general");
Boudewijn Rempt's avatar
Boudewijn Rempt committed
807
    page->setHeader(i18n("General"));
808
    page->setIcon(KisIconUtils::loadIcon("go-home"));
Boudewijn Rempt's avatar
Boudewijn Rempt committed
809 810
    addPage(page);
    m_general = new GeneralTab(vbox);
811

812 813 814 815 816
    // Shortcuts
    vbox = new KoVBox();
    page = new KPageWidgetItem(vbox, i18n("Keyboard Shortcuts"));
    page->setObjectName("shortcuts");
    page->setHeader(i18n("Shortcuts"));
817
    page->setIcon(KisIconUtils::loadIcon("document-export"));
818 819 820 821 822 823 824 825 826
    addPage(page);
    m_shortcutSettings = new ShortcutSettingsTab(vbox);
    connect(this, SIGNAL(accepted()), m_shortcutSettings, SLOT(saveChanges()));

    // Canvas input settings
    m_inputConfiguration = new KisInputConfigurationPage();
    page = addPage(m_inputConfiguration, i18n("Canvas Input Settings"));
    page->setHeader(i18n("Canvas Input"));
    page->setObjectName("canvasinput");
827
    page->setIcon(KisIconUtils::loadIcon("configure"));
828

829
    // Display
Boudewijn Rempt's avatar
Boudewijn Rempt committed
830
    vbox = new KoVBox();
Boudewijn Rempt's avatar
Boudewijn Rempt committed
831
    page = new KPageWidgetItem(vbox, i18n("Display"));
832
    page->setObjectName("display");
Boudewijn Rempt's avatar
Boudewijn Rempt committed
833
    page->setHeader(i18n("Display"));
Timothée Giet's avatar
Timothée Giet committed
834
    page->setIcon(KisIconUtils::loadIcon("preferences-desktop-display"));
Boudewijn Rempt's avatar
Boudewijn Rempt committed
835 836
    addPage(page);
    m_displaySettings = new DisplaySettingsTab(vbox);
837

838
    // Color
Boudewijn Rempt's avatar
Boudewijn Rempt committed
839
    vbox = new KoVBox();
Boudewijn Rempt's avatar
Boudewijn Rempt committed
840
    page = new KPageWidgetItem(vbox, i18n("Color Management"));
841
    page->setObjectName("colormanagement");
Boudewijn Rempt's avatar
Boudewijn Rempt committed
842
    page->setHeader(i18n("Color"));
Timothée Giet's avatar
Timothée Giet committed
843
    page->setIcon(KisIconUtils::loadIcon("preferences-desktop-color"));
Boudewijn Rempt's avatar
Boudewijn Rempt committed
844 845
    addPage(page);
    m_colorSettings = new ColorSettingsTab(vbox);
846 847

    // Performance
Boudewijn Rempt's avatar
Boudewijn Rempt committed
848
    vbox = new KoVBox();
Boudewijn Rempt's avatar
Boudewijn Rempt committed
849
    page = new KPageWidgetItem(vbox, i18n("Performance"));
850
    page->setObjectName("performance");
Boudewijn Rempt's avatar
Boudewijn Rempt committed
851
    page->setHeader(i18n("Performance"));
Timothée Giet's avatar
Timothée Giet committed
852
    page->setIcon(KisIconUtils::loadIcon("applications-system"));
Boudewijn Rempt's avatar
Boudewijn Rempt committed
853 854
    addPage(page);
    m_performanceSettings = new PerformanceTab(vbox);
855

856
    // Tablet
Boudewijn Rempt's avatar
Boudewijn Rempt committed
857
    vbox = new KoVBox();
858
    page = new KPageWidgetItem(vbox, i18n("Tablet settings"));
859
    page->setObjectName("tablet");
860
    page->setHeader(i18n("Tablet"));
Timothée Giet's avatar
Timothée Giet committed
861
    page->setIcon(KisIconUtils::loadIcon("document-edit"));
862 863
    addPage(page);
    m_tabletSettings = new TabletSettingsTab(vbox);
864

865
    // full-screen mode
Boudewijn Rempt's avatar
Boudewijn Rempt committed
866
    vbox = new KoVBox();
867
    page = new KPageWidgetItem(vbox, i18n("Canvas-only settings"));
868
    page->setObjectName("canvasonly");
869
    page->setHeader(i18n("Canvas-only"));
Timothée Giet's avatar
Timothée Giet committed
870
    page->setIcon(KisIconUtils::loadIcon("folder-pictures"));
871 872 873
    addPage(page);
    m_fullscreenSettings = new FullscreenSettingsTab(vbox);

874 875 876
    // Author profiles
    m_authorPage = new KoConfigAuthorPage();
    page = addPage(m_authorPage, i18nc("@title:tab Author page", "Author" ));
877
    page->setObjectName("author");
878
    page->setHeader(i18n("Author"));
Timothée Giet's avatar
Timothée Giet committed
879
    page->setIcon(KisIconUtils::loadIcon("im-user"));
880

881

882 883 884 885
    QPushButton *restoreDefaultsButton = button(QDialogButtonBox::RestoreDefaults);

    connect(this, SIGNAL(accepted()), m_inputConfiguration, SLOT(saveChanges()));
    connect(this, SIGNAL(rejected()), m_inputConfiguration, SLOT(revertChanges()));
886

887
    KisPreferenceSetRegistry *preferenceSetRegistry = KisPreferenceSetRegistry::instance();
888
    Q_FOREACH (KisAbstractPreferenceSetFactory *preferenceSetFactory, preferenceSetRegistry->values()) {
889
        KisPreferenceSet* preferenceSet = preferenceSetFactory->createPreferenceSet();
Boudewijn Rempt's avatar
Boudewijn Rempt committed
890
        vbox = new KoVBox();
891 892 893 894 895
        page = new KPageWidgetItem(vbox, preferenceSet->name());
        page->setHeader(preferenceSet->header());
        page->setIcon(preferenceSet->icon());
        addPage(page);
        preferenceSet->setParent(vbox);
896 897
        preferenceSet->loadPreferences();

898 899
        connect(restoreDefaultsButton, SIGNAL(clicked(bool)), preferenceSet, SLOT(loadDefaultPreferences()), Qt::UniqueConnection);
        connect(this, SIGNAL(accepted()), preferenceSet, SLOT(savePreferences()), Qt::UniqueConnection);
900 901
    }

902

903
    connect(restoreDefaultsButton, SIGNAL(clicked(bool)), this, SLOT(slotDefault()));
904

905 906
}

907
KisDlgPreferences::~KisDlgPreferences()
908 909 910
{
}

911
void KisDlgPreferences::slotDefault()
Laurent Montel's avatar
Laurent Montel committed
912
{
913
    if (currentPage()->objectName() == "general") {
914 915
        m_general->setDefault();
    }
916 917 918
    else if (currentPage()->objectName() == "shortcuts") {
        m_shortcutSettings->setDefault();
    }