summaryrefslogtreecommitdiffstats
path: root/digikam/utilities/imageeditor/rawimport/rawsettingsbox.cpp
blob: 430ebec302c2dcff8973be3564ab0b30f50e2921 (plain)
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
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
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
733
734
735
736
737
738
739
740
741
/* ============================================================
 *
 * This file is a part of digiKam project
 * http://www.digikam.org
 *
 * Date        : 2008-08-11
 * Description : Raw import settings box
 *
 * Copyright (C) 2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * 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, 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.
 *
 * ============================================================ */

// TQt includes.

#include <tqstring.h>
#include <layout.h>
#include <tqtooltip.h>
#include <tqwhatsthis.h>
#include <tqhbuttongroup.h>
#include <tqcombobox.h>
#include <tqlabel.h>
#include <tqvbox.h>
#include <tqtoolbutton.h>
#include <tqtoolbox.h>
#include <tqpushbutton.h>

// KDE includes.

#include <kapplication.h>
#include <ktabwidget.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kconfig.h>
#include <kstandarddirs.h>
#include <kfiledialog.h>

// LibKDcraw includes.

#include <libkdcraw/dcrawsettingswidget.h>
#include <libkdcraw/rnuminput.h>

// Local includes.

#include "ddebug.h"
#include "imagedialog.h"
#include "imagehistogram.h"
#include "imagecurves.h"
#include "iccpreviewwidget.h"
#include "histogramwidget.h"
#include "curveswidget.h"
#include "colorgradientwidget.h"
#include "rawsettingsbox.h"
#include "rawsettingsbox.moc"

using namespace KDcrawIface;

namespace Digikam
{

class RawSettingsBoxPriv
{
public:

    enum ColorChannel
    {
        LuminosityChannel=0,
        RedChannel,
        GreenChannel,
        BlueChannel,
        ColorChannels
    };

    enum AllColorsColorType
    {
        AllColorsRed=0,
        AllColorsGreen,
        AllColorsBlue
    };

public:

    RawSettingsBoxPriv()
    {
        channelCB              = 0;
        colorsCB               = 0;
        scaleBG                = 0;
        hGradient              = 0;
        histogramWidget        = 0;
        infoBox                = 0;
        advExposureBox         = 0;
        gammaLabel             = 0;
        gammaInput             = 0;
        saturationLabel        = 0;
        saturationInput        = 0;
        fineExposureLabel      = 0;
        fineExposureInput      = 0;
        contrastInput          = 0;
        contrastLabel          = 0;
        curveBox               = 0;
        curveWidget            = 0;
        resetCurveBtn          = 0;
        decodingSettingsBox    = 0;
        postProcessSettingsBox = 0;
        tabView                = 0;
        abortBtn               = 0;
        updateBtn              = 0;
        rawdecodingBox         = 0;
        brightnessLabel        = 0;
        brightnessInput        = 0;
    }

    TQWidget             *advExposureBox;
    TQWidget             *curveBox;
    TQWidget             *rawdecodingBox;

    TQComboBox           *channelCB;
    TQComboBox           *colorsCB;

    TQLabel              *brightnessLabel;
    TQLabel              *contrastLabel;
    TQLabel              *gammaLabel;
    TQLabel              *saturationLabel;
    TQLabel              *fineExposureLabel;

    TQHButtonGroup       *scaleBG;

    TQPushButton         *abortBtn;
    TQPushButton         *updateBtn;

    TQToolButton         *resetCurveBtn;

    TQToolBox            *postProcessSettingsBox;

    KTabWidget          *tabView;

    ColorGradientWidget *hGradient;

    CurvesWidget        *curveWidget;

    HistogramWidget     *histogramWidget;

    ImageDialogPreview  *infoBox;

    RIntNumInput        *contrastInput;
    RIntNumInput        *brightnessInput;

    RDoubleNumInput     *gammaInput;
    RDoubleNumInput     *saturationInput;
    RDoubleNumInput     *fineExposureInput;

    DcrawSettingsWidget *decodingSettingsBox;
};

RawSettingsBox::RawSettingsBox(const KURL& url, TQWidget *parent)
              : EditorToolSettings(Default|Ok|Cancel, NoTool, parent)
{
    d = new RawSettingsBoxPriv;

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

    TQGridLayout* gridSettings = new TQGridLayout(plainPage(), 5, 4);

    TQLabel *label1 = new TQLabel(i18n("Channel:"), plainPage());
    label1->setAlignment( TQt::AlignRight | TQt::AlignVCenter );
    d->channelCB   = new TQComboBox(false, plainPage());
    d->channelCB->insertItem( i18n("Luminosity") );
    d->channelCB->insertItem( i18n("Red") );
    d->channelCB->insertItem( i18n("Green") );
    d->channelCB->insertItem( i18n("Blue") );
    d->channelCB->insertItem( i18n("Colors") );
    TQWhatsThis::add(d->channelCB, i18n("<p>Select the histogram channel to display here:<p>"
                                       "<b>Luminosity</b>: display the image's luminosity values.<p>"
                                       "<b>Red</b>: display the red image-channel values.<p>"
                                       "<b>Green</b>: display the green image-channel values.<p>"
                                       "<b>Blue</b>: display the blue image-channel values.<p>"
                                       "<b>Colors</b>: Display all color channel values at the same time."));

    d->scaleBG = new TQHButtonGroup(plainPage());
    d->scaleBG->setExclusive(true);
    d->scaleBG->setFrameShape(TQFrame::NoFrame);
    d->scaleBG->setInsideMargin( 0 );
    TQWhatsThis::add(d->scaleBG, i18n("<p>Select the histogram scale here.<p>"
                                     "If the image's maximal counts are small, you can use the linear scale.<p>"
                                     "Logarithmic scale can be used when the maximal counts are big; "
                                     "if it is used, all values (small and large) will be visible on the graph."));

    TQPushButton *linHistoButton = new TQPushButton( d->scaleBG );
    TQToolTip::add( linHistoButton, i18n( "<p>Linear" ) );
    d->scaleBG->insert(linHistoButton, HistogramWidget::LinScaleHistogram);
    KGlobal::dirs()->addResourceType("histogram-lin", KGlobal::dirs()->kde_default("data") + "digikam/data");
    TQString directory = KGlobal::dirs()->findResourceDir("histogram-lin", "histogram-lin.png");
    linHistoButton->setPixmap( TQPixmap( directory + "histogram-lin.png" ) );
    linHistoButton->setToggleButton(true);

    TQPushButton *logHistoButton = new TQPushButton( d->scaleBG );
    TQToolTip::add( logHistoButton, i18n( "<p>Logarithmic" ) );
    d->scaleBG->insert(logHistoButton, HistogramWidget::LogScaleHistogram);
    KGlobal::dirs()->addResourceType("histogram-log", KGlobal::dirs()->kde_default("data") + "digikam/data");
    directory = KGlobal::dirs()->findResourceDir("histogram-log", "histogram-log.png");
    logHistoButton->setPixmap( TQPixmap( directory + "histogram-log.png" ) );
    logHistoButton->setToggleButton(true);

    TQLabel *label10 = new TQLabel(i18n("Colors:"), plainPage());
    label10->setAlignment( TQt::AlignRight | TQt::AlignVCenter );
    d->colorsCB = new TQComboBox(false, plainPage());
    d->colorsCB->insertItem( i18n("Red") );
    d->colorsCB->insertItem( i18n("Green") );
    d->colorsCB->insertItem( i18n("Blue") );
    d->colorsCB->setEnabled( false );
    TQWhatsThis::add( d->colorsCB, i18n("<p>Select the main color displayed with Colors Channel mode here:<p>"
                                       "<b>Red</b>: Draw the red image channel in the foreground.<p>"
                                       "<b>Green</b>: Draw the green image channel in the foreground.<p>"
                                       "<b>Blue</b>: Draw the blue image channel in the foreground.<p>"));

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

    TQVBox *histoBox    = new TQVBox(plainPage());
    d->histogramWidget = new HistogramWidget(256, 140, histoBox, false, true, true);
    TQWhatsThis::add(d->histogramWidget, i18n("<p>Here you can see the target preview image histogram drawing "
                                             "of the selected image channel. This one is re-computed at any "
                                             "settings changes."));
    TQLabel *space = new TQLabel(histoBox);
    space->setFixedHeight(1);
    d->hGradient  = new ColorGradientWidget( ColorGradientWidget::Horizontal, 10, histoBox );
    d->hGradient->setColors( TQColor( "black" ), TQColor( "white" ) );

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

    d->tabView             = new KTabWidget(plainPage());
    d->rawdecodingBox      = new TQWidget(d->tabView);
    TQGridLayout* rawGrid   = new TQGridLayout(d->rawdecodingBox, 1, 2);
    d->decodingSettingsBox = new DcrawSettingsWidget(d->rawdecodingBox, true, true, false);

    KFileDialog *inputDlg  = d->decodingSettingsBox->inputProfileUrlEdit()->fileDialog();
    inputDlg->setPreviewWidget(new ICCPreviewWidget(inputDlg));

    KFileDialog *outputDlg = d->decodingSettingsBox->outputProfileUrlEdit()->fileDialog();
    outputDlg->setPreviewWidget(new ICCPreviewWidget(outputDlg));

    d->abortBtn = new TQPushButton(d->rawdecodingBox);
    d->abortBtn->setText(i18n("Abort"));
    d->abortBtn->setIconSet(SmallIconSet("stop"));
    d->abortBtn->setEnabled(false);
    TQToolTip::add(d->abortBtn, i18n("Abort the current Raw image preview."));

    d->updateBtn = new TQPushButton(d->rawdecodingBox);
    d->updateBtn->setText(i18n("Update"));
    d->updateBtn->setIconSet(SmallIconSet("reload_page"));
    d->updateBtn->setEnabled(false);
    TQToolTip::add(d->updateBtn, i18n("Generate a Raw image preview using current settings."));

    rawGrid->addMultiCellWidget(d->decodingSettingsBox, 0, 0, 0, 2);
    rawGrid->addMultiCellWidget(d->abortBtn,            1, 1, 0, 0);
    rawGrid->addMultiCellWidget(d->updateBtn,           1, 1, 2, 2);
    rawGrid->setColStretch(1, 10);
    rawGrid->setSpacing(spacingHint());
    rawGrid->setMargin(spacingHint());

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

    d->postProcessSettingsBox = new TQToolBox(d->tabView);
    d->infoBox                = new ImageDialogPreview(d->postProcessSettingsBox);
    d->infoBox->showPreview(url);

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

    d->advExposureBox              = new TQWidget(d->postProcessSettingsBox);
    TQGridLayout* advExposureLayout = new TQGridLayout(d->advExposureBox, 5, 2);

    d->brightnessLabel = new TQLabel(i18n("Brightness:"), d->advExposureBox);
    d->brightnessInput = new RIntNumInput(d->advExposureBox);
    d->brightnessInput->setRange(-100, 100, 1);
    d->brightnessInput->setDefaultValue(0);
    TQWhatsThis::add(d->brightnessInput->input(), i18n("<p>Set here the brightness adjustment of the image."));

    d->contrastLabel = new TQLabel(i18n("Contrast:"), d->advExposureBox);
    d->contrastInput = new RIntNumInput(d->advExposureBox);
    d->contrastInput->setRange(-100, 100, 1);
    d->contrastInput->setDefaultValue(0);
    TQWhatsThis::add(d->contrastInput->input(), i18n("<p>Set here the contrast adjustment of the image."));

    d->gammaLabel = new TQLabel(i18n("Gamma:"), d->advExposureBox);
    d->gammaInput = new RDoubleNumInput(d->advExposureBox);
    d->gammaInput->setPrecision(2);
    d->gammaInput->setRange(0.1, 3.0, 0.01);
    d->gammaInput->setDefaultValue(1.0);
    TQWhatsThis::add(d->gammaInput->input(), i18n("Set here the gamma adjustement of the image"));

    d->saturationLabel = new TQLabel(i18n("Saturation:"), d->advExposureBox);
    d->saturationInput = new RDoubleNumInput(d->advExposureBox);
    d->saturationInput->setPrecision(2);
    d->saturationInput->setRange(0.0, 2.0, 0.01);
    d->saturationInput->setDefaultValue(1.0);
    TQWhatsThis::add(d->saturationInput->input(), i18n("<p>Set here the color saturation correction."));

    d->fineExposureLabel = new TQLabel(i18n("Exposure (E.V):"), d->advExposureBox);
    d->fineExposureInput = new RDoubleNumInput(d->advExposureBox);
    d->fineExposureInput->setPrecision(2);
    d->fineExposureInput->setRange(-3.0, 3.0, 0.1);
    d->fineExposureInput->setDefaultValue(0.0);
    TQWhatsThis::add(d->fineExposureInput->input(), i18n("<p>This value in E.V will be used to perform "
                                                        "an exposure compensation of the image."));

    advExposureLayout->addMultiCellWidget(d->brightnessLabel,   0, 0, 0, 0);
    advExposureLayout->addMultiCellWidget(d->brightnessInput,   0, 0, 1, 2);
    advExposureLayout->addMultiCellWidget(d->contrastLabel,     1, 1, 0, 0);
    advExposureLayout->addMultiCellWidget(d->contrastInput,     1, 1, 1, 2);
    advExposureLayout->addMultiCellWidget(d->gammaLabel,        2, 2, 0, 0);
    advExposureLayout->addMultiCellWidget(d->gammaInput,        2, 2, 1, 2);
    advExposureLayout->addMultiCellWidget(d->saturationLabel,   3, 3, 0, 0);
    advExposureLayout->addMultiCellWidget(d->saturationInput,   3, 3, 1, 2);
    advExposureLayout->addMultiCellWidget(d->fineExposureLabel, 4, 4, 0, 0);
    advExposureLayout->addMultiCellWidget(d->fineExposureInput, 4, 4, 1, 2);
    advExposureLayout->setRowStretch(5, 10);
    advExposureLayout->setSpacing(0);
    advExposureLayout->setMargin(spacingHint());

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

    d->curveBox              = new TQWidget(d->postProcessSettingsBox);
    TQGridLayout* curveLayout = new TQGridLayout(d->curveBox, 3, 2);

    ColorGradientWidget* vGradient = new ColorGradientWidget(ColorGradientWidget::Vertical, 10, d->curveBox);
    vGradient->setColors( TQColor( "white" ), TQColor( "black" ) );

    TQLabel *spacev = new TQLabel(d->curveBox);
    spacev->setFixedWidth(1);

    d->curveWidget = new CurvesWidget(256, 192, d->curveBox);
    TQWhatsThis::add(d->curveWidget, i18n("<p>This is the curve adjustment of the image luminosity"));

    d->resetCurveBtn = new TQToolButton(d->curveBox);
    d->resetCurveBtn->setFixedSize(11, 11);
    d->resetCurveBtn->setIconSet(SmallIconSet("reload_page", 8));
    d->resetCurveBtn->setFocusPolicy(TQ_NoFocus);
    d->resetCurveBtn->setAutoRaise(true);
    TQToolTip::add(d->resetCurveBtn, i18n("Reset curve to linear"));

    TQLabel *spaceh = new TQLabel(d->curveBox);
    spaceh->setFixedHeight(1);

    ColorGradientWidget *hGradient = new ColorGradientWidget(ColorGradientWidget::Horizontal, 10, d->curveBox);
    hGradient->setColors( TQColor( "black" ), TQColor( "white" ) );

    curveLayout->addMultiCellWidget(vGradient,        0, 0, 0, 0);
    curveLayout->addMultiCellWidget(spacev,           0, 0, 1, 1);
    curveLayout->addMultiCellWidget(d->curveWidget,   0, 0, 2, 2);
    curveLayout->addMultiCellWidget(spaceh,           1, 1, 2, 2);
    curveLayout->addMultiCellWidget(d->resetCurveBtn, 1, 2, 0, 1);
    curveLayout->addMultiCellWidget(hGradient,        2, 2, 2, 2);
    curveLayout->setRowStretch(3, 10);
    curveLayout->setSpacing(0);
    curveLayout->setMargin(spacingHint());

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

    d->postProcessSettingsBox->addItem(d->advExposureBox, i18n("Exposure"));
    d->postProcessSettingsBox->addItem(d->curveBox,       i18n("Luminosity Curve"));
    d->postProcessSettingsBox->setItemIconSet(0, SmallIconSet("contrast"));
    d->postProcessSettingsBox->setItemIconSet(1, SmallIconSet("adjustcurves"));

    d->decodingSettingsBox->setItemIconSet(DcrawSettingsWidget::DEMOSAICING,     SmallIconSet("kdcraw"));
    d->decodingSettingsBox->setItemIconSet(DcrawSettingsWidget::WHITEBALANCE,    SmallIconSet("whitebalance"));
    d->decodingSettingsBox->setItemIconSet(DcrawSettingsWidget::CORRECTIONS,     SmallIconSet("lensdistortion"));
    d->decodingSettingsBox->setItemIconSet(DcrawSettingsWidget::COLORMANAGEMENT, SmallIconSet("colormanagement"));
    d->decodingSettingsBox->updateMinimumWidth();

    d->tabView->insertTab(d->rawdecodingBox,         i18n("Raw Decoding"),    0);
    d->tabView->insertTab(d->postProcessSettingsBox, i18n("Post Processing"), 1);
    d->tabView->insertTab(d->infoBox,                i18n("Info"),            2);

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

    button(Default)->setText(i18n("Reset"));
    button(Default)->setIconSet(SmallIconSet("reload_page"));
    TQToolTip::add(button(Default), i18n("<p>Reset all settings to default values."));

    button(Ok)->setText(i18n("Import"));
    button(Ok)->setIconSet(SmallIconSet("ok"));
    TQToolTip::add(button(Ok), i18n("<p>Import image to editor using current settings."));

    button(Cancel)->setText(i18n("Use Default"));
    button(Cancel)->setIconSet(SmallIconSet("gohome"));
    TQToolTip::add(button(Cancel), i18n("<p>Use general Raw decoding settings to load this image in editor."));

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

    gridSettings->addMultiCellWidget(label1,       0, 0, 0, 0);
    gridSettings->addMultiCellWidget(d->channelCB, 0, 0, 1, 1);
    gridSettings->addMultiCellWidget(d->scaleBG,   0, 0, 4, 4);
    gridSettings->addMultiCellWidget(label10,      1, 1, 0, 0);
    gridSettings->addMultiCellWidget(d->colorsCB,  1, 1, 1, 1);
    gridSettings->addMultiCellWidget(histoBox,     2, 3, 0, 4);
    gridSettings->addMultiCellWidget(d->tabView,   4, 4, 0, 4);
    gridSettings->setRowStretch(5, 10);
    gridSettings->setColStretch(2, 10);
    gridSettings->setSpacing(spacingHint());
    gridSettings->setMargin(0);

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

    connect(d->channelCB, TQT_SIGNAL(activated(int)),
            this, TQT_SLOT(slotChannelChanged(int)));

    connect(d->scaleBG, TQT_SIGNAL(released(int)),
            this, TQT_SLOT(slotScaleChanged(int)));

    connect(d->colorsCB, TQT_SIGNAL(activated(int)),
            this, TQT_SLOT(slotColorsChanged(int)));

    connect(d->resetCurveBtn, TQT_SIGNAL(clicked()),
            this, TQT_SLOT(slotResetCurve()));

    connect(d->updateBtn, TQT_SIGNAL(clicked()),
            this, TQT_SIGNAL(signalUpdatePreview()));

    connect(d->abortBtn, TQT_SIGNAL(clicked()),
            this, TQT_SIGNAL(signalAbortPreview()));

    connect(d->decodingSettingsBox, TQT_SIGNAL(signalSettingsChanged()),
            this, TQT_SIGNAL(signalDemosaicingChanged()));

    connect(d->curveWidget, TQT_SIGNAL(signalCurvesChanged()),
            this, TQT_SIGNAL(signalPostProcessingChanged()));

    connect(d->brightnessInput, TQT_SIGNAL(valueChanged(int)),
            this, TQT_SIGNAL(signalPostProcessingChanged()));

    connect(d->contrastInput, TQT_SIGNAL(valueChanged(int)),
            this, TQT_SIGNAL(signalPostProcessingChanged()));

    connect(d->gammaInput, TQT_SIGNAL(valueChanged(double)),
            this, TQT_SIGNAL(signalPostProcessingChanged()));

    connect(d->saturationInput, TQT_SIGNAL(valueChanged(double)),
            this, TQT_SIGNAL(signalPostProcessingChanged()));

    connect(d->fineExposureInput, TQT_SIGNAL(valueChanged(double)),
            this, TQT_SIGNAL(signalPostProcessingChanged()));
}

RawSettingsBox::~RawSettingsBox()
{
    delete d->curveWidget;
    delete d;
}

void RawSettingsBox::enableUpdateBtn(bool b)
{
    d->updateBtn->setEnabled(b);
}

void RawSettingsBox::setBusy(bool b)
{
    d->decodingSettingsBox->setEnabled(!b);
    d->abortBtn->setEnabled(b);
}

void RawSettingsBox::setDemosaicedImage(DImg& img)
{
    d->curveWidget->stopHistogramComputation();
    d->curveWidget->updateData(img.bits(), img.width(), img.height(), img.sixteenBit());
}

void RawSettingsBox::setPostProcessedImage(DImg& img)
{
    d->histogramWidget->stopHistogramComputation();
    d->histogramWidget->updateData(img.bits(), img.width(), img.height(), img.sixteenBit());
}

void RawSettingsBox::resetSettings()
{
    d->decodingSettingsBox->setDefaultSettings();
    d->brightnessInput->slotReset();
    d->contrastInput->slotReset();
    d->gammaInput->slotReset();
    d->saturationInput->slotReset();
    d->fineExposureInput->slotReset();
    slotResetCurve();
}

void RawSettingsBox::slotResetCurve()
{
    d->curveWidget->reset();
    emit signalPostProcessingChanged();
}

HistogramWidget* RawSettingsBox::histogram() const
{
   return d->histogramWidget;
}

CurvesWidget* RawSettingsBox::curve() const
{
    return d->curveWidget;
}

void RawSettingsBox::readSettings()
{
    KConfig* config = kapp->config();
    config->setGroup("RAW Import Settings");

    d->channelCB->setCurrentItem(config->readNumEntry("Histogram Channel", RawSettingsBoxPriv::LuminosityChannel));
    d->scaleBG->setButton(config->readNumEntry("Histogram Scale", HistogramWidget::LogScaleHistogram));
    d->colorsCB->setCurrentItem(config->readNumEntry("Histogram Color", RawSettingsBoxPriv::AllColorsRed));

    d->decodingSettingsBox->setSixteenBits(config->readBoolEntry("SixteenBitsImage", false));
    d->decodingSettingsBox->setWhiteBalance((DRawDecoding::WhiteBalance)
                                            config->readNumEntry("White Balance",
                                            DRawDecoding::CAMERA));
    d->decodingSettingsBox->setCustomWhiteBalance(config->readNumEntry("Custom White Balance", 6500));
    d->decodingSettingsBox->setCustomWhiteBalanceGreen(config->readDoubleNumEntry("Custom White Balance Green", 1.0));
    d->decodingSettingsBox->setFourColor(config->readBoolEntry("Four Color RGB", false));
    d->decodingSettingsBox->setUnclipColor(config->readNumEntry("Unclip Color", 0));
    d->decodingSettingsBox->setDontStretchPixels(config->readBoolEntry("Dont Stretch Pixels", false));
    d->decodingSettingsBox->setNoiseReduction(config->readBoolEntry("Use Noise Reduction", false));
    d->decodingSettingsBox->setUseBlackPoint(config->readBoolEntry("Use Black Point", false));
    d->decodingSettingsBox->setBlackPoint(config->readNumEntry("Black Point", 0));
    d->decodingSettingsBox->setUseWhitePoint(config->readBoolEntry("Use White Point", false));
    d->decodingSettingsBox->setWhitePoint(config->readNumEntry("White Point", 0));
    d->decodingSettingsBox->setMedianFilterPasses(config->readNumEntry("Median Filter Passes", 0));
    d->decodingSettingsBox->setNRThreshold(config->readNumEntry("NR Threshold", 100));
    d->decodingSettingsBox->setUseCACorrection(config->readBoolEntry("EnableCACorrection", false));
    d->decodingSettingsBox->setcaRedMultiplier(config->readDoubleNumEntry("caRedMultiplier", 1.0));
    d->decodingSettingsBox->setcaBlueMultiplier(config->readDoubleNumEntry("caBlueMultiplier", 1.0));

    d->decodingSettingsBox->setQuality(
        (DRawDecoding::DecodingQuality)config->readNumEntry("Decoding Quality",
            (int)(DRawDecoding::BILINEAR)));

    d->decodingSettingsBox->setInputColorSpace(
        (DRawDecoding::InputColorSpace)config->readNumEntry("Input Color Space",
            (int)(DRawDecoding::NOINPUTCS)));

    d->decodingSettingsBox->setOutputColorSpace(
        (DRawDecoding::OutputColorSpace)config->readNumEntry("Output Color Space",
            (int)(DRawDecoding::SRGB)));

    d->decodingSettingsBox->setInputColorProfile(config->readPathEntry("Input Color Profile", TQString()));
    d->decodingSettingsBox->setOutputColorProfile(config->readPathEntry("Output Color Profile", TQString()));

    d->brightnessInput->setValue(config->readNumEntry("Brightness", 0));
    d->contrastInput->setValue(config->readNumEntry("Contrast", 0));
    d->gammaInput->setValue(config->readDoubleNumEntry("Gamma", 1.0));
    d->saturationInput->setValue(config->readDoubleNumEntry("Saturation", 1.0));
    d->fineExposureInput->setValue(config->readDoubleNumEntry("FineExposure", 0.0));

    d->curveWidget->reset();

    for (int j = 0 ; j <= 17 ; j++)
    {
        TQPoint disable(-1, -1);
        TQPoint p = config->readPointEntry(TQString("CurveAjustmentPoint%1").arg(j), &disable);
        if (!d->decodingSettingsBox->sixteenBits() && p != disable)
        {
            // Restore point as 16 bits depth.
            p.setX(p.x()/255);
            p.setY(p.y()/255);
        }
        d->curveWidget->curves()->setCurvePoint(ImageHistogram::ValueChannel, j, p);
    }
    d->curveWidget->curves()->curvesCalculateCurve(ImageHistogram::ValueChannel);

    d->tabView->setCurrentPage(config->readNumEntry("Settings Page", 0));
    d->decodingSettingsBox->setCurrentIndex(config->readNumEntry("Decoding Settings Tab", DcrawSettingsWidget::DEMOSAICING));
    d->postProcessSettingsBox->setCurrentIndex(config->readNumEntry("Post Processing Settings Tab", 0));

    slotChannelChanged(d->channelCB->currentItem());
    slotScaleChanged(d->scaleBG->selectedId());
    slotColorsChanged(d->colorsCB->currentItem());
}

void RawSettingsBox::writeSettings()
{
    KConfig* config = kapp->config();
    config->setGroup("RAW Import Settings");

    config->writeEntry("Histogram Channel",          d->channelCB->currentItem());
    config->writeEntry("Histogram Scale",            d->scaleBG->selectedId());
    config->writeEntry("Histogram Color",            d->colorsCB->currentItem());

    config->writeEntry("SixteenBitsImage",           d->decodingSettingsBox->sixteenBits());
    config->writeEntry("White Balance",              d->decodingSettingsBox->whiteBalance());
    config->writeEntry("Custom White Balance",       d->decodingSettingsBox->customWhiteBalance());
    config->writeEntry("Custom White Balance Green", d->decodingSettingsBox->customWhiteBalanceGreen());
    config->writeEntry("Four Color RGB",             d->decodingSettingsBox->useFourColor());
    config->writeEntry("Unclip Color",               d->decodingSettingsBox->unclipColor());
    config->writeEntry("Dont Stretch Pixels",        d->decodingSettingsBox->useDontStretchPixels());
    config->writeEntry("Use Noise Reduction",        d->decodingSettingsBox->useNoiseReduction());
    config->writeEntry("Use Black Point",            d->decodingSettingsBox->useBlackPoint());
    config->writeEntry("Black Point",                d->decodingSettingsBox->blackPoint());
    config->writeEntry("Use White Point",            d->decodingSettingsBox->useWhitePoint());
    config->writeEntry("White Point",                d->decodingSettingsBox->whitePoint());
    config->writeEntry("MedianFilterPasses",         d->decodingSettingsBox->medianFilterPasses());
    config->writeEntry("NR Threshold",               d->decodingSettingsBox->NRThreshold());
    config->writeEntry("EnableCACorrection",         d->decodingSettingsBox->useCACorrection());
    config->writeEntry("caRedMultiplier",            d->decodingSettingsBox->caRedMultiplier());
    config->writeEntry("caBlueMultiplier",           d->decodingSettingsBox->caBlueMultiplier());
    config->writeEntry("Decoding Quality",           (int)d->decodingSettingsBox->quality());
    config->writeEntry("Input Color Space",          (int)d->decodingSettingsBox->inputColorSpace());
    config->writeEntry("Output Color Space",         (int)d->decodingSettingsBox->outputColorSpace());
    config->writeEntry("Input Color Profile",        d->decodingSettingsBox->inputColorProfile());
    config->writeEntry("Output Color Profile",       d->decodingSettingsBox->outputColorProfile());

    config->writeEntry("Brightness",                 d->brightnessInput->value());
    config->writeEntry("Contrast",                   d->contrastInput->value());
    config->writeEntry("Gamma",                      d->gammaInput->value());
    config->writeEntry("Saturation",                 d->saturationInput->value());
    config->writeEntry("FineExposure",               d->fineExposureInput->value());

    for (int j = 0 ; j <= 17 ; j++)
    {
        TQPoint p = d->curveWidget->curves()->getCurvePoint(ImageHistogram::ValueChannel, j);
        if (!d->curveWidget->curves()->isSixteenBits())
        {
            // Store point as 16 bits depth.
            p.setX(p.x()*255);
            p.setY(p.y()*255);
        }
        config->writeEntry(TQString("CurveAjustmentPoint%1").arg(j), p);
    }

    config->writeEntry("Settings Page", d->tabView->currentPage());
    config->writeEntry("Decoding Settings Tab", d->decodingSettingsBox->currentIndex());
    config->writeEntry("Post Processing Settings Tab", d->postProcessSettingsBox->currentIndex());
    config->sync();
}

DRawDecoding RawSettingsBox::settings()
{
    DRawDecoding settings;
    settings.sixteenBitsImage        = d->decodingSettingsBox->sixteenBits();
    settings.whiteBalance            = d->decodingSettingsBox->whiteBalance();
    settings.customWhiteBalance      = d->decodingSettingsBox->customWhiteBalance();
    settings.customWhiteBalanceGreen = d->decodingSettingsBox->customWhiteBalanceGreen();
    settings.RGBInterpolate4Colors   = d->decodingSettingsBox->useFourColor();
    settings.unclipColors            = d->decodingSettingsBox->unclipColor();
    settings.DontStretchPixels       = d->decodingSettingsBox->useDontStretchPixels();
    settings.enableNoiseReduction    = d->decodingSettingsBox->useNoiseReduction();
    settings.enableBlackPoint        = d->decodingSettingsBox->useBlackPoint();
    settings.blackPoint              = d->decodingSettingsBox->blackPoint();
    settings.enableWhitePoint        = d->decodingSettingsBox->useWhitePoint();
    settings.whitePoint              = d->decodingSettingsBox->whitePoint();
    settings.medianFilterPasses      = d->decodingSettingsBox->medianFilterPasses();
    settings.NRThreshold             = d->decodingSettingsBox->NRThreshold();
    settings.enableCACorrection      = d->decodingSettingsBox->useCACorrection();
    settings.caMultiplier[0]         = d->decodingSettingsBox->caRedMultiplier();
    settings.caMultiplier[1]         = d->decodingSettingsBox->caBlueMultiplier();
    settings.RAWQuality              = d->decodingSettingsBox->quality();
    settings.inputColorSpace         = d->decodingSettingsBox->inputColorSpace();
    settings.outputColorSpace        = d->decodingSettingsBox->outputColorSpace();
    settings.inputProfile            = d->decodingSettingsBox->inputColorProfile();
    settings.outputProfile           = d->decodingSettingsBox->outputColorProfile();

    settings.lightness               = (double)d->brightnessInput->value()/250.0;
    settings.contrast                = (double)(d->contrastInput->value()/100.0) + 1.00;
    settings.gamma                   = d->gammaInput->value();
    settings.saturation              = d->saturationInput->value();
    settings.exposureComp            = d->fineExposureInput->value();

    if (d->curveWidget->curves()->isDirty())
        settings.curveAdjust         = d->curveWidget->curves()->getCurvePoints(ImageHistogram::ValueChannel);

    return settings;
}

void RawSettingsBox::slotChannelChanged(int channel)
{
    switch(channel)
    {
        case RawSettingsBoxPriv::LuminosityChannel:
            d->histogramWidget->m_channelType = HistogramWidget::ValueHistogram;
            d->hGradient->setColors( TQColor( "black" ), TQColor( "white" ) );
            d->colorsCB->setEnabled(false);
            break;

        case RawSettingsBoxPriv::RedChannel:
            d->histogramWidget->m_channelType = HistogramWidget::RedChannelHistogram;
            d->hGradient->setColors( TQColor( "black" ), TQColor( "red" ) );
            d->colorsCB->setEnabled(false);
            break;

        case RawSettingsBoxPriv::GreenChannel:
            d->histogramWidget->m_channelType = HistogramWidget::GreenChannelHistogram;
            d->hGradient->setColors( TQColor( "black" ), TQColor( "green" ) );
            d->colorsCB->setEnabled(false);
            break;

        case RawSettingsBoxPriv::BlueChannel:
            d->histogramWidget->m_channelType = HistogramWidget::BlueChannelHistogram;
            d->hGradient->setColors( TQColor( "black" ), TQColor( "blue" ) );
            d->colorsCB->setEnabled(false);
            break;

        case RawSettingsBoxPriv::ColorChannels:
            d->histogramWidget->m_channelType = HistogramWidget::ColorChannelsHistogram;
            d->hGradient->setColors( TQColor( "black" ), TQColor( "white" ) );
            d->colorsCB->setEnabled(true);
            break;
    }

    d->histogramWidget->repaint(false);
}

void RawSettingsBox::slotScaleChanged(int scale)
{
    d->histogramWidget->m_scaleType = scale;
    d->histogramWidget->repaint(false);
}

void RawSettingsBox::slotColorsChanged(int color)
{
    switch(color)
    {
        case RawSettingsBoxPriv::AllColorsGreen:
            d->histogramWidget->m_colorType = HistogramWidget::GreenColor;
            break;

        case RawSettingsBoxPriv::AllColorsBlue:
            d->histogramWidget->m_colorType = HistogramWidget::BlueColor;
            break;

        default:          // Red.
            d->histogramWidget->m_colorType = HistogramWidget::RedColor;
            break;
    }

    d->histogramWidget->repaint(false);
}

} // NameSpace Digikam