Cppcheck - HTML report - digiKam-nl-search-more-criteria-rev-e2466e0973

# Cppcheck report - digiKam-nl-search-more-criteria-rev-e2466e0973: ../../core/libs/dimg/filters/bw/bwsepiasettings.cpp

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    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
    267
    268
    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
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    /* ============================================================
     *
     * This file is a part of digiKam project
     * https://www.digikam.org
     *
     * Date        : 2010-02-23
     * Description : black and white settings view.
     *
     * SPDX-FileCopyrightText: 2010-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
     *
     * SPDX-License-Identifier: GPL-2.0-or-later
     *
     * ============================================================ */

    #include "bwsepiasettings.h"

    // Qt includes

    #include <QGridLayout>
    #include <QLabel>
    #include <QString>
    #include <QFile>
    #include <QTextStream>
    #include <QCheckBox>
    #include <QStandardPaths>
    #include <QApplication>
    #include <QStyle>
    #include <QUrl>
    #include <QMessageBox>
    #include <QIcon>

    // KDE includes

    #include <kconfiggroup.h>
    #include <klocalizedstring.h>

    // Local includes

    #include "dlayoutbox.h"
    #include "dexpanderbox.h"
    #include "dfiledialog.h"
    #include "dnuminput.h"
    #include "digikam_debug.h"
    #include "previewlist.h"
    #include "curvesbox.h"
    #include "curveswidget.h"
    #include "imagecurves.h"

    namespace Digikam
    {

    class Q_DECL_HIDDEN BWSepiaSettings::Private
    {

    public:

        enum SettingsTab
        {
            FilmTab = 0,
            BWFiltersTab,
            ToneTab,
            LuminosityTab
        };

    public:

        Private() = default;

    public:

        const QString configSettingsTabEntry        = QLatin1String("Settings Tab");
        const QString configBWFilterEntry           = QLatin1String("BW Filter");
        const QString configBWFilmEntry             = QLatin1String("BW Film");
        const QString configBWToneEntry             = QLatin1String("BW Tone");
        const QString configContrastAdjustmentEntry = QLatin1String("ContrastValueAdjustment");
        const QString configStrengthAdjustmentEntry = QLatin1String("StrengthAdjustment");
        const QString configCurveEntry              = QLatin1String("BWSepiaCurve");

        PreviewList*               bwFilters        = nullptr;
        PreviewList*               bwFilm           = nullptr;
        PreviewList*               bwTone           = nullptr;

        DExpanderBoxExclusive*     tab              = nullptr;

        DIntNumInput*              cInput           = nullptr;
        DIntNumInput*              strengthInput    = nullptr;

        CurvesBox*                 curvesBox        = nullptr;

        DImg                       thumbImage;

    public:

        PreviewListItem* addItem(PreviewList* const list, const QString& name,
                                 BWSepiaContainer::BlackWhiteConversionType type);
    };

    PreviewListItem* BWSepiaSettings::Private::addItem(PreviewList* const list,
                                                       const QString& name,
                                                       BWSepiaContainer::BlackWhiteConversionType type)
    {
        BWSepiaFilter* const filter = new BWSepiaFilter(&thumbImage, nullptr, BWSepiaContainer(type));
        PreviewListItem* const item = list->addItem(filter, name, type);

        return item;
    }

    // --------------------------------------------------------

    BWSepiaSettings::BWSepiaSettings(QWidget* const parent, DImg* const img)<--- Either there is a missing override/final keyword, or the parameter 'img' can be declared as pointer to const
        : QWidget(parent),
          d      (new Private)
    {
        if (!img->isNull())
        {
            d->thumbImage = img->smoothScale(128, 128, Qt::KeepAspectRatio);
        }
        else
        {
            QString backGround = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
                                                        QLatin1String("digikam/about/images/body-background.jpg"));

            d->thumbImage      = DImg(backGround).smoothScale(128, 128, Qt::KeepAspectRatio);
        }

        const int spacing       = layoutSpacing();
        QGridLayout* const grid = new QGridLayout(parent);

        d->tab = new DExpanderBoxExclusive(this);

        PreviewListItem* item   = nullptr;
        d->bwFilm               = new PreviewList;

        item = d->addItem(d->bwFilm, i18nc("generic black and white film", "Generic"), BWSepiaContainer::BWGeneric);
        item->setWhatsThis(i18n("<b>Generic</b>:"
                                "<p>Simulate a generic black and white film.</p>"));

        item = d->addItem(d->bwFilm, i18n("Agfa 200X"), BWSepiaContainer::BWAgfa200X);
        item->setWhatsThis(i18n("<b>Agfa 200X</b>:"
                                "<p>Simulate the Agfa 200X black and white film at 200 ISO.</p>"));

        item = d->addItem(d->bwFilm, i18n("Agfa Pan 25"), BWSepiaContainer::BWAgfapan25);
        item->setWhatsThis(i18n("<b>Agfa Pan 25</b>:"
                                "<p>Simulate the Agfa Pan black and white film at 25 ISO.</p>"));

        item = d->addItem(d->bwFilm, i18n("Agfa Pan 100"), BWSepiaContainer::BWAgfapan100);
        item->setWhatsThis(i18n("<b>Agfa Pan 100</b>:"
                                "<p>Simulate the Agfa Pan black and white film at 100 ISO.</p>"));

        item = d->addItem(d->bwFilm, i18n("Agfa Pan 400"), BWSepiaContainer::BWAgfapan400);
        item->setWhatsThis(i18n("<b>Agfa Pan 400</b>:"
                                "<p>Simulate the Agfa Pan black and white film at 400 ISO.</p>"));

        item = d->addItem(d->bwFilm, i18n("Ilford Delta 100"), BWSepiaContainer::BWIlfordDelta100);
        item->setWhatsThis(i18n("<b>Ilford Delta 100</b>:"
                                "<p>Simulate the Ilford Delta black and white film at 100 ISO.</p>"));

        item = d->addItem(d->bwFilm, i18n("Ilford Delta 400"), BWSepiaContainer::BWIlfordDelta400);
        item->setWhatsThis(i18n("<b>Ilford Delta 400</b>:"
                                "<p>Simulate the Ilford Delta black and white film at 400 ISO.</p>"));

        item = d->addItem(d->bwFilm, i18n("Ilford Delta 400 Pro 3200"), BWSepiaContainer::BWIlfordDelta400Pro3200);
        item->setWhatsThis(i18n("<b>Ilford Delta 400 Pro 3200</b>:"
                                "<p>Simulate the Ilford Delta 400 Pro black and white film at 3200 ISO.</p>"));

        item = d->addItem(d->bwFilm, i18n("Ilford FP4 Plus"), BWSepiaContainer::BWIlfordFP4);
        item->setWhatsThis(i18n("<b>Ilford FP4 Plus</b>:"
                                "<p>Simulate the Ilford FP4 Plus black and white film at 125 ISO.</p>"));

        item = d->addItem(d->bwFilm, i18n("Ilford HP5 Plus"), BWSepiaContainer::BWIlfordHP5);
        item->setWhatsThis(i18n("<b>Ilford HP5 Plus</b>:"
                                "<p>Simulate the Ilford HP5 Plus black and white film at 400 ISO.</p>"));

        item = d->addItem(d->bwFilm, i18n("Ilford PanF Plus"), BWSepiaContainer::BWIlfordPanF);
        item->setWhatsThis(i18n("<b>Ilford PanF Plus</b>:"
                                "<p>Simulate the Ilford PanF Plus black and white film at 50 ISO.</p>"));

        item = d->addItem(d->bwFilm, i18n("Ilford XP2 Super"), BWSepiaContainer::BWIlfordXP2Super);
        item->setWhatsThis(i18n("<b>Ilford XP2 Super</b>:"
                                "<p>Simulate the Ilford XP2 Super black and white film at 400 ISO.</p>"));

        item = d->addItem(d->bwFilm, i18n("Kodak Tmax 100"), BWSepiaContainer::BWKodakTmax100);
        item->setWhatsThis(i18n("<b>Kodak Tmax 100</b>:"
                                "<p>Simulate the Kodak Tmax black and white film at 100 ISO.</p>"));

        item = d->addItem(d->bwFilm, i18n("Kodak Tmax 400"), BWSepiaContainer::BWKodakTmax400);
        item->setWhatsThis(i18n("<b>Kodak Tmax 400</b>:"
                                "<p>Simulate the Kodak Tmax black and white film at 400 ISO.</p>"));

        item = d->addItem(d->bwFilm, i18n("Kodak TriX"), BWSepiaContainer::BWKodakTriX);
        item->setWhatsThis(i18n("<b>Kodak TriX</b>:"
                                "<p>Simulate the Kodak TriX black and white film at 400 ISO.</p>"));

        // -------------------------------------------------------------

        item = d->addItem(d->bwFilm, i18n("Ilford SPX 200 (Infrared)"), BWSepiaContainer::BWIlfordSFX200);
        item->setWhatsThis(i18n("<b>Ilford SPX 200</b>:"
                                "<p>Simulate the Ilford SPX infrared film at 200 ISO.</p>"));

        item = d->addItem(d->bwFilm, i18n("Ilford SPX 400 (Infrared)"), BWSepiaContainer::BWIlfordSFX400);
        item->setWhatsThis(i18n("<b>Ilford SPX 400</b>:"
                                "<p>Simulate the Ilford SPX infrared film at 400 ISO.</p>"));

        item = d->addItem(d->bwFilm, i18n("Ilford SPX 800 (Infrared)"), BWSepiaContainer::BWIlfordSFX800);
        item->setWhatsThis(i18n("<b>Ilford SPX 800</b>:"
                                "<p>Simulate the Ilford SPX infrared film at 800 ISO.</p>"));

        item = d->addItem(d->bwFilm, i18n("Kodak HIE (Infrared)"), BWSepiaContainer::BWKodakHIE);
        item->setWhatsThis(i18n("<b>Kodak HIE</b>:"
                                "<p>Simulate the Kodak HIE infrared film.</p>"));

        // -------------------------------------------------------------

        QWidget* vbox     = new QWidget();
        QVBoxLayout* vlay = new QVBoxLayout(vbox);
        d->bwFilters      = new PreviewList(vbox);

        item = d->addItem(d->bwFilters, i18n("No Lens Filter"), BWSepiaContainer::BWNoFilter);
        item->setWhatsThis(i18n("<b>No Lens Filter</b>:"
                                "<p>Do not apply a lens filter when rendering the image.</p>"));

        item = d->addItem(d->bwFilters, i18n("Green Filter"), BWSepiaContainer::BWGreenFilter);
        item->setWhatsThis(i18n("<b>Black & White with Green Filter</b>:"
                                "<p>Simulate black and white film exposure using a green filter. "
                                "This is useful for all scenic shoots, especially "
                                "portraits photographed against the sky.</p>"));

        item = d->addItem(d->bwFilters, i18n("Orange Filter"), BWSepiaContainer::BWOrangeFilter);
        item->setWhatsThis(i18n("<b>Black & White with Orange Filter</b>:"
                                "<p>Simulate black and white film exposure using an orange filter. "
                                "This will enhance landscapes, marine scenes and aerial "
                                "photography.</p>"));

        item = d->addItem(d->bwFilters, i18n("Red Filter"), BWSepiaContainer::BWRedFilter);
        item->setWhatsThis(i18n("<b>Black & White with Red Filter</b>:"
                                "<p>Simulate black and white film exposure using a red filter. "
                                "This creates dramatic sky effects, and simulates moonlight scenes "
                                "in the daytime.</p>"));

        item = d->addItem(d->bwFilters, i18n("Yellow Filter"), BWSepiaContainer::BWYellowFilter);
        item->setWhatsThis(i18n("<b>Black & White with Yellow Filter</b>:"
                                "<p>Simulate black and white film exposure using a yellow filter. "
                                "This has the most natural tonal correction, and improves contrast. Ideal for "
                                "landscapes.</p>"));

        item = d->addItem(d->bwFilters, i18n("Yellow-Green Filter"), BWSepiaContainer::BWYellowGreenFilter);
        item->setWhatsThis(i18n("<b>Black & White with Yellow-Green Filter</b>:"
                                "<p>Simulate black and white film exposure using a yellow-green filter. "
                                "A yellow-green filter is highly effective for outdoor portraits because "
                                "red is rendered dark while green appears lighter. Great for correcting skin tones, "
                                "bringing out facial expressions in close-ups and emphasizing the feeling of liveliness. "
                                "This filter is highly effective for indoor portraits under tungsten lighting.</p>"));

        item = d->addItem(d->bwFilters, i18n("Blue Filter"), BWSepiaContainer::BWBlueFilter);
        item->setWhatsThis(i18n("<b>Black & White with Blue Filter</b>:"
                                "<p>Simulate black and white film exposure using a blue filter. "
                                "This accentuates haze and fog. Used for dye transfer and contrast effects.</p>"));

        DHBox* const hbox1   = new DHBox(vbox);
        QLabel* const label1 = new QLabel(i18n("Strength:"), hbox1);
        label1->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);

        d->strengthInput     = new DIntNumInput(hbox1);
        d->strengthInput->setRange(1, 5, 1);
        d->strengthInput->setDefaultValue(1);
        d->strengthInput->setWhatsThis(i18n("Here, set the strength adjustment of the lens filter."));

        vlay->addWidget(d->bwFilters);
        vlay->addWidget(hbox1);
        vlay->setContentsMargins(QMargins());
        vlay->setSpacing(spacing);

        // -------------------------------------------------------------

        d->bwTone = new PreviewList;

        item = d->addItem(d->bwTone, i18n("No Tone Filter"), BWSepiaContainer::BWNoTone);
        item->setWhatsThis(i18n("<b>No Tone Filter</b>:"
                                "<p>Do not apply a tone filter to the image.</p>"));

        item = d->addItem(d->bwTone, i18n("Sepia Filter"), BWSepiaContainer::BWSepiaTone);
        item->setWhatsThis(i18n("<b>Black & White with Sepia Tone</b>:"
                                "<p>Gives a warm highlight and mid-tone while adding a bit of coolness to "
                                "the shadows - very similar to the process of bleaching a print and "
                                "re-developing in a sepia toner.</p>"));

        item = d->addItem(d->bwTone, i18n("Brown Filter"), BWSepiaContainer::BWBrownTone);
        item->setWhatsThis(i18n("<b>Black & White with Brown Tone</b>:"
                                "<p>This filter is more neutral than the Sepia Tone "
                                "filter.</p>"));

        item = d->addItem(d->bwTone, i18n("Cold Filter"), BWSepiaContainer::BWColdTone);
        item->setWhatsThis(i18n("<b>Black & White with Cold Tone</b>:"
                                "<p>Start subtly and replicate printing on a cold tone black and white "
                                "paper such as a bromide enlarging "
                                "paper.</p>"));

        item = d->addItem(d->bwTone, i18n("Selenium Filter"), BWSepiaContainer::BWSeleniumTone);
        item->setWhatsThis(i18n("<b>Black & White with Selenium Tone</b>:"
                                "<p>This effect replicates traditional selenium chemical toning done "
                                "in the darkroom.</p>"));

        item = d->addItem(d->bwTone, i18n("Platinum Filter"), BWSepiaContainer::BWPlatinumTone);
        item->setWhatsThis(i18n("<b>Black & White with Platinum Tone</b>:"
                                "<p>This effect replicates traditional platinum chemical toning done "
                                "in the darkroom.</p>"));

        item = d->addItem(d->bwTone, i18n("Green Filter"), BWSepiaContainer::BWGreenTone);
        item->setWhatsThis(i18n("<b>Black & White with greenish tint</b>:"
                                "<p>This effect is also known as Verdante.</p>"));

        // -------------------------------------------------------------

        QWidget* const lumBox = new QWidget();

        // NOTE: add a method to be able to use curves widget without image data as simple curve editor.

        if (!img->isNull())
        {
            d->curvesBox = new CurvesBox(256, 192, *img, lumBox);
            d->curvesBox->enablePickers(true);
        }
        else
        {
            d->curvesBox = new CurvesBox(256, 192,
                                         DImg(1, 1, true, false,
                                              reinterpret_cast<unsigned char*>(const_cast<char*>("\x00\x00\x00\x00\x00\x00\x00\x00"))),
                                         lumBox);
            d->curvesBox->enablePickers(false);
        }

        d->curvesBox->enableCurveTypes(true);
        d->curvesBox->enableResetButton(true);
        d->curvesBox->setWhatsThis(i18n("This is the curve adjustment of the image luminosity"));

        // -------------------------------------------------------------

        DHBox* const hbox2   = new DHBox(lumBox);
        QLabel* const label2 = new QLabel(i18n("Contrast:"), hbox2);
        label2->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);

        d->cInput = new DIntNumInput(hbox2);
        d->cInput->setRange(-100, 100, 1);
        d->cInput->setDefaultValue(0);
        d->cInput->setWhatsThis(i18n("Set here the contrast adjustment of the image."));

        QGridLayout* gridTab2 = new QGridLayout(lumBox);
        gridTab2->addWidget(d->curvesBox, 0, 0, 1, 1);
        gridTab2->addWidget(hbox2,        1, 0, 1, 1);
        gridTab2->setRowStretch(2, 10);
        gridTab2->setContentsMargins(spacing, spacing, spacing, spacing);
        gridTab2->setSpacing(0);

        // -------------------------------------------------------------

        // Some new icons may be needed : a film roll, a lens filter and ?

        d->tab->addItem(d->bwFilm, QIcon::fromTheme(QLatin1String("filmgrain")),
                        i18n("Film"), QLatin1String("Film"), true);
        d->tab->addItem(vbox, QIcon::fromTheme(QLatin1String("lensautofix")),
                        i18n("Lens Filters"), QLatin1String("Lens Filters"), false);
        d->tab->addItem(d->bwTone, QIcon::fromTheme(QLatin1String("fill-color")),
                        i18n("Tone"), QLatin1String("Tone"), false);
        d->tab->addItem(lumBox, QIcon::fromTheme(QLatin1String("adjustcurves")),
                        i18n("Luminosity"), QLatin1String("Luminosity"), false);
        d->tab->addStretch();

        grid->addWidget(d->tab, 0, 0, 1, 10);
        grid->setRowStretch(0, 10);
        grid->setContentsMargins(spacing, spacing, spacing, spacing);
        grid->setSpacing(spacing);

        // -------------------------------------------------------------

        connect(d->bwFilters, SIGNAL(itemSelectionChanged()),
                this, SLOT(slotFilterSelected()));

        connect(d->strengthInput, SIGNAL(valueChanged(int)),
                this, SIGNAL(signalSettingsChanged()));

        connect(d->bwFilm, SIGNAL(itemSelectionChanged()),
                this, SIGNAL(signalSettingsChanged()));

        connect(d->bwTone, SIGNAL(itemSelectionChanged()),
                this, SIGNAL(signalSettingsChanged()));

        connect(d->cInput, SIGNAL(valueChanged(int)),
                this, SIGNAL(signalSettingsChanged()));

        connect(d->curvesBox, SIGNAL(signalCurvesChanged()),
                this, SIGNAL(signalSettingsChanged()));

        connect(d->curvesBox, SIGNAL(signalChannelReset(int)),
                this, SIGNAL(signalSettingsChanged()));
    }

    BWSepiaSettings::~BWSepiaSettings()
    {
        delete d;
    }

    CurvesBox* BWSepiaSettings::curvesBox() const
    {
        return d->curvesBox;
    }

    void BWSepiaSettings::startPreviewFilters()
    {
        d->bwFilters->startFilters();
        d->bwFilm->startFilters();
        d->bwTone->startFilters();
    }

    void BWSepiaSettings::slotFilterSelected()
    {
        int filter = d->bwFilters->currentId();

        if (filter == BWSepiaContainer::BWNoFilter)
        {
            d->strengthInput->setEnabled(false);
        }
        else
        {
            d->strengthInput->setEnabled(true);
        }

        Q_EMIT signalSettingsChanged();
    }

    BWSepiaContainer BWSepiaSettings::settings() const
    {
        BWSepiaContainer prm;

        prm.filmType               = d->bwFilm->currentId();
        prm.filterType             = d->bwFilters->currentId();
        prm.toneType               = d->bwTone->currentId();
        prm.bcgPrm.contrast        = ((double)(d->cInput->value() / 100.0) + 1.00);
        prm.strength               = 1.0 + ((double)d->strengthInput->value() - 1.0) * (1.0 / 3.0);
        prm.curvesPrm              = d->curvesBox->curves()->getContainer(LuminosityChannel);

        return prm;
    }

    void BWSepiaSettings::setSettings(const BWSepiaContainer& settings)<--- Shadow argument
    {
        blockSignals(true);

        d->bwFilm->setCurrentId(settings.filmType);
        d->bwFilters->setCurrentId(settings.filterType);
        d->bwTone->setCurrentId(settings.toneType);
        d->cInput->setValue((int)((settings.bcgPrm.contrast - 1.00) * 100.0));
        d->strengthInput->setValue((int)(1.0 + (settings.strength - 1.0) * 3.0));
        d->curvesBox->curves()->setContainer(settings.curvesPrm);
        d->curvesBox->update();

        slotFilterSelected();
        blockSignals(false);
    }

    void BWSepiaSettings::resetToDefault()
    {
        blockSignals(true);

        d->bwFilters->setCurrentId(BWSepiaContainer::BWNoFilter);
        d->bwFilm->setCurrentId(BWSepiaContainer::BWGeneric);
        d->bwTone->setCurrentId(BWSepiaContainer::BWNoTone);

        d->cInput->slotReset();
        d->strengthInput->slotReset();
        d->curvesBox->curves()->curvesChannelReset(LuminosityChannel);
        d->curvesBox->reset();

        blockSignals(false);
        slotFilterSelected();
    }

    BWSepiaContainer BWSepiaSettings::defaultSettings() const
    {
        BWSepiaContainer prm;

        prm.bcgPrm.contrast = ((double)(d->cInput->defaultValue() / 100.0) + 1.00);
        prm.strength        = 1.0 + ((double)d->strengthInput->defaultValue() - 1.0) * (1.0 / 3.0);

        return prm;
    }

    void BWSepiaSettings::readSettings(KConfigGroup& group)
    {
        BWSepiaContainer prm;
        BWSepiaContainer defaultPrm = defaultSettings();

        d->tab->readSettings(group);

        prm.filmType        = group.readEntry(d->configBWFilmEntry,             defaultPrm.filmType);
        prm.filterType      = group.readEntry(d->configBWFilterEntry,           defaultPrm.filterType);
        prm.toneType        = group.readEntry(d->configBWToneEntry,             defaultPrm.toneType);
        prm.bcgPrm.contrast = group.readEntry(d->configContrastAdjustmentEntry, defaultPrm.bcgPrm.contrast);
        prm.strength        = group.readEntry(d->configStrengthAdjustmentEntry, defaultPrm.strength);

        d->curvesBox->readCurveSettings(group, d->configCurveEntry);
        prm.curvesPrm = d->curvesBox->curves()->getContainer(LuminosityChannel);

        setSettings(prm);
    }

    void BWSepiaSettings::writeSettings(KConfigGroup& group)
    {
        BWSepiaContainer prm = settings();

        d->tab->writeSettings(group);

        group.writeEntry(d->configBWFilmEntry,             prm.filmType);
        group.writeEntry(d->configBWFilterEntry,           prm.filterType);
        group.writeEntry(d->configBWToneEntry,             prm.toneType);
        group.writeEntry(d->configContrastAdjustmentEntry, prm.bcgPrm.contrast);
        group.writeEntry(d->configStrengthAdjustmentEntry, prm.strength);

        d->curvesBox->writeCurveSettings(group, d->configCurveEntry);
    }

    void BWSepiaSettings::loadSettings()
    {
        QUrl loadFile = DFileDialog::getOpenFileUrl(qApp->activeWindow(), i18nc("@title:window", "Black & White Settings File to Load"),
                                                    QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)),
                                                    QLatin1String("*"));

        if (loadFile.isEmpty())
        {
            return;
        }

        QFile file(loadFile.toLocalFile());

        if (file.open(QIODevice::ReadOnly))
        {
            QTextStream stream(&file);

            if (stream.readLine() != QLatin1String("# Black & White Configuration File"))
            {
                QMessageBox::critical(qApp->activeWindow(), qApp->applicationName(),
                                      i18n("\"%1\" is not a Black & White settings text file.", loadFile.fileName()));
                file.close();
                return;
            }

            blockSignals(true);

            d->bwFilm->setCurrentId(stream.readLine().toInt());
            d->bwFilters->setCurrentId(stream.readLine().toInt());
            d->bwTone->setCurrentId(stream.readLine().toInt());
            d->cInput->setValue(stream.readLine().toInt());

            for (int i = 0 ; i < 5 ; ++i)
            {
                d->curvesBox->curves()->curvesChannelReset(i);
            }

            d->curvesBox->curves()->setCurveType(d->curvesBox->channel(), ImageCurves::CURVE_SMOOTH);
            d->curvesBox->reset();

            // TODO: cannot we use the kconfig mechanisms provided by CurveWidget here?

            QPoint disable = ImageCurves::getDisabledValue();
            QPoint p;

            for (int j = 0 ; j < ImageCurves::NUMBER_OF_POINTS ; ++j)
            {
                p.setX(stream.readLine().toInt());
                p.setY(stream.readLine().toInt());

                if (d->curvesBox->curves()->isSixteenBits() && (p != disable))
                {
                    p.setX(p.x()*ImageCurves::MULTIPLIER_16BIT);
                    p.setY(p.y()*ImageCurves::MULTIPLIER_16BIT);
                }

                d->curvesBox->curves()->setCurvePoint(LuminosityChannel, j, p);
            }

            d->curvesBox->curves()->curvesCalculateAllCurves();

            blockSignals(false);
        }
        else
        {
            QMessageBox::critical(qApp->activeWindow(), qApp->applicationName(),
                                  i18n("Cannot load settings from the Black & White text file."));
        }

        file.close();
    }

    void BWSepiaSettings::saveAsSettings()
    {
        QUrl saveFile = DFileDialog::getSaveFileUrl(qApp->activeWindow(), i18nc("@title:window", "Black & White Settings File to Save"),
                                                    QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)),
                                                    QLatin1String("*"));

        if (saveFile.isEmpty())
        {
            return;
        }

        QFile file(saveFile.toLocalFile());

        if (file.open(QIODevice::WriteOnly))
        {
            QTextStream stream(&file);
            stream << QLatin1String("# Black & White Configuration File\n");
            stream << d->bwFilm->currentId() << "\n";
            stream << d->bwFilters->currentId() << "\n";
            stream << d->bwTone->currentId() << "\n";
            stream << d->cInput->value() << "\n";

            // TODO: cannot we use the kconfig mechanisms provided by CurveWidget here?

            for (int j = 0 ; j < ImageCurves::NUMBER_OF_POINTS ; ++j)
            {
                QPoint p = d->curvesBox->curves()->getCurvePoint(LuminosityChannel, j);

                if (d->curvesBox->curves()->isSixteenBits())
                {
                    p.setX(p.x() / ImageCurves::MULTIPLIER_16BIT);
                    p.setY(p.y() / ImageCurves::MULTIPLIER_16BIT);
                }

                stream << p.x() << "\n";
                stream << p.y() << "\n";
            }
        }
        else
        {
            QMessageBox::critical(qApp->activeWindow(), qApp->applicationName(),
                                  i18n("Cannot save settings to the Black & White text file."));
        }

        file.close();
    }

    void BWSepiaSettings::setScaleType(HistogramScale scale)
    {
        d->curvesBox->setScale(scale);
    }

    } // namespace Digikam

    #include "moc_bwsepiasettings.cpp"