~ubuntu-branches/ubuntu/trusty/digikam/trusty

« back to all changes in this revision

Viewing changes to core/utilities/imageeditor/canvas/colorcorrectiondlg.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2012-11-26 18:24:20 UTC
  • mfrom: (1.9.1) (3.1.23 experimental)
  • Revision ID: package-import@ubuntu.com-20121126182420-qoy6z0nx4ai0wzcl
Tags: 4:3.0.0~beta3-0ubuntu1
* New upstream release
  - Add build-deps :  libhupnp-dev, libqtgstreamer-dev, libmagickcore-dev
* Merge from debian, remaining changes:
  - Make sure libqt4-opengl-dev, libgl1-mesa-dev and libglu1-mesa-dev only
    install on i386,amd64 and powerpc
  - Depend on libtiff-dev instead of libtiff4-dev
  - Drop digikam breaks/replaces kipi-plugins-common since we're past the
    LTS release now
  - digikam to recommend mplayerthumbs | ffmpegthumbs. We currently only
    have latter in the archives, even though former is also supposed to
    be part of kdemultimedia. (LP: #890059)
  - kipi-plugins to recommend www-browser rather than konqueror directly
    since 2.8 no direct usage of konqueror is present in the flickr
    plugin anymore (LP: #1011211)
  - Keep kubuntu_mysqld_executable_name.diff
  - Don't install libkipi translations
  - Keep deps on libcv-dev, libcvaux-dev
  - Keep split packaging of libraries
  - Replace icons from KDE 3 time in debian/xpm.d/*.xpm with the new
    versions (LP: #658047)
* Update debian/not-installed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ============================================================
2
 
 *
3
 
 * This file is a part of digiKam project
4
 
 * http://www.digikam.org
5
 
 *
6
 
 * Date        : 2006-05-15
7
 
 * Description : a dialog to see preview ICC color correction
8
 
 *               before to apply color profile.
9
 
 *
10
 
 * Copyright (C) 2006-2011 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
 
 *
12
 
 * This program is free software; you can redistribute it
13
 
 * and/or modify it under the terms of the GNU General
14
 
 * Public License as published by the Free Software Foundation;
15
 
 * either version 2, or (at your option)
16
 
 * any later version.
17
 
 *
18
 
 * This program is distributed in the hope that it will be useful,
19
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 
 * GNU General Public License for more details.
22
 
 *
23
 
 * ============================================================ */
24
 
 
25
 
#include "colorcorrectiondlg.moc"
26
 
 
27
 
// Qt includes
28
 
 
29
 
#include <QCheckBox>
30
 
#include <QFrame>
31
 
#include <QFileInfo>
32
 
#include <QGridLayout>
33
 
#include <QGroupBox>
34
 
#include <QHBoxLayout>
35
 
#include <QLabel>
36
 
#include <QPushButton>
37
 
#include <QRadioButton>
38
 
#include <QVBoxLayout>
39
 
 
40
 
// KDE includes
41
 
 
42
 
 
43
 
#include <klocale.h>
44
 
#include <kiconloader.h>
45
 
#include <kapplication.h>
46
 
#include <kseparator.h>
47
 
#include <kstandarddirs.h>
48
 
 
49
 
// Local includes
50
 
 
51
 
#include "dimg.h"
52
 
#include "iccmanager.h"
53
 
#include "iccsettings.h"
54
 
#include "icctransform.h"
55
 
#include "iccprofileinfodlg.h"
56
 
#include "iccprofilescombobox.h"
57
 
 
58
 
namespace Digikam
59
 
{
60
 
 
61
 
class ColorCorrectionDlg::ColorCorrectionDlgPriv
62
 
{
63
 
public:
64
 
 
65
 
    ColorCorrectionDlgPriv() :
66
 
        imageProfileTitle(0),
67
 
        imageProfileDesc(0),
68
 
        previewTarget(0),
69
 
        keepProfile(0),
70
 
        convertToWorkingSpace(0),
71
 
        thirdOption(0),
72
 
        thirdCheckBox(0),
73
 
        imageSRGB(0),
74
 
        imageWorkingSpace(0),
75
 
        imageOtherSpace(0),
76
 
        otherProfileBox(0),
77
 
        imageProfileBox(0),
78
 
        mode(ColorCorrectionDlg::ProfileMismatch)
79
 
    {
80
 
    }
81
 
 
82
 
    DImg                     preview;
83
 
    QString                  filePath;
84
 
 
85
 
    QLabel*                  imageProfileTitle;
86
 
    QLabel*                  imageProfileDesc;
87
 
    QLabel*                  previewTarget;
88
 
 
89
 
    QRadioButton*            keepProfile;
90
 
    QRadioButton*            convertToWorkingSpace;
91
 
    QRadioButton*            thirdOption;
92
 
    QCheckBox*               thirdCheckBox;
93
 
 
94
 
    QRadioButton*            imageSRGB;
95
 
    QRadioButton*            imageWorkingSpace;
96
 
    QRadioButton*            imageOtherSpace;
97
 
 
98
 
    IccProfilesComboBox*     otherProfileBox;
99
 
    IccProfilesComboBox*     imageProfileBox;
100
 
 
101
 
    ColorCorrectionDlg::Mode mode;
102
 
 
103
 
    IccProfile               workspaceProfile;
104
 
    IccProfile               imageProfile;
105
 
    IccProfile               outputProfile;
106
 
};
107
 
 
108
 
ColorCorrectionDlg::ColorCorrectionDlg(Mode mode, const DImg& preview,
109
 
                                       const QString& file, QWidget* parent)
110
 
    : KDialog(parent), d(new ColorCorrectionDlgPriv)
111
 
{
112
 
    d->mode                          = mode;
113
 
    d->preview                       = preview;
114
 
    d->filePath                      = file;
115
 
    ICCSettingsContainer iccSettings = IccSettings::instance()->settings();
116
 
    d->workspaceProfile              = IccProfile(iccSettings.workspaceProfile);
117
 
 
118
 
    QString caption;
119
 
 
120
 
    if (d->mode == ProfileMismatch)
121
 
    {
122
 
        caption = i18n("Color Profile Mismatch");
123
 
    }
124
 
    else if (d->mode == MissingProfile)
125
 
    {
126
 
        caption = i18n("Missing Color Profile");
127
 
    }
128
 
    else if (d->mode == UncalibratedColor)
129
 
    {
130
 
        caption = i18n("Image with Uncalibrated Color");
131
 
    }
132
 
 
133
 
    if (!file.isNull())
134
 
    {
135
 
        QFileInfo fi(file);
136
 
        caption = i18nc("<Problem> - <filename>", "%1 - %2", caption, fi.fileName());
137
 
    }
138
 
 
139
 
    setCaption(caption);
140
 
 
141
 
    setButtons(Help | Ok | Cancel);
142
 
    setDefaultButton(Ok);
143
 
    setButtonFocus(Ok);
144
 
    setModal(true);
145
 
    setHelp("iccprofile.anchor", "digikam");
146
 
    setButtonText(Cancel,    i18n("Don't know"));
147
 
    setButtonToolTip(Cancel, i18n("Take the safest and most appropriate action"));
148
 
 
149
 
    QWidget* page     = new QWidget(this);
150
 
    QGridLayout* grid = new QGridLayout(page);
151
 
    setMainWidget(page);
152
 
 
153
 
 
154
 
    if (d->mode == ProfileMismatch)
155
 
    {
156
 
        grid->addLayout(createHeading(),       0, 0, 1, 2);
157
 
        grid->addLayout(createProfilesInfo(),  1, 0);
158
 
        grid->addLayout(createPreviews(),      1, 1, 2, 1);
159
 
        grid->addWidget(createOptions(),       3, 0, 1, 2);
160
 
    }
161
 
    else if (d->mode == MissingProfile)
162
 
    {
163
 
        QVBoxLayout* vbox = new QVBoxLayout;
164
 
        vbox->addWidget(createAssumeOptions());
165
 
        vbox->addLayout(createProfilesInfo());
166
 
        vbox->addStretch(1);
167
 
 
168
 
        grid->addLayout(createHeading(),       0, 0, 1, 2);
169
 
        grid->addLayout(vbox,                  1, 0);
170
 
        grid->addLayout(createPreviews(),      1, 1, 2, 1);
171
 
        grid->addWidget(createOptions(),       3, 0, 1, 2);
172
 
        grid->setRowStretch(1, 1);
173
 
        grid->setRowStretch(3, 1);
174
 
    }
175
 
    else if (d->mode == UncalibratedColor)
176
 
    {
177
 
        grid->addLayout(createHeading(),       0, 0, 1, 2);
178
 
        grid->addLayout(createProfilesInfo(),  1, 0,       Qt::AlignTop);
179
 
        grid->addLayout(createPreviews(),      1, 1, 2, 1);
180
 
        grid->addWidget(createAssumeOptions(), 3, 0, 1, 2);
181
 
    }
182
 
 
183
 
    page->setLayout(grid);
184
 
 
185
 
    readSettings();
186
 
    updateImageProfileUI();
187
 
    updateUsedProfileUI();
188
 
    updateInfo();
189
 
}
190
 
 
191
 
ColorCorrectionDlg::~ColorCorrectionDlg()
192
 
{
193
 
    delete d;
194
 
}
195
 
 
196
 
QLayout* ColorCorrectionDlg::createHeading() const
197
 
{
198
 
    QLabel* icon = new QLabel;
199
 
    icon->setPixmap(SmallIcon("fill-color", KIconLoader::SizeMedium));
200
 
 
201
 
    QLabel* message = new QLabel;
202
 
 
203
 
    if (d->mode == ProfileMismatch)
204
 
    {
205
 
        message->setText(i18n("<p>This image has an <b>embedded color profile</b><br/> "
206
 
                              "which does not match your working space color profile.<br/>"
207
 
                              "How do you want to proceed?</p>"));
208
 
    }
209
 
    else if (d->mode == MissingProfile)
210
 
    {
211
 
        message->setText(i18n("<p>This image has <b>no information about the color space</b><br/>"
212
 
                              "that was used when creating the image. <br/>"
213
 
                              "How do you want to proceed?</p>"));
214
 
 
215
 
    }
216
 
    else if (d->mode == UncalibratedColor)
217
 
    {
218
 
        message->setText(i18n("<p>The color information of this image is uncalibrated.<br/>"
219
 
                              "How do you want to proceed?</p>"));
220
 
    }
221
 
 
222
 
    message->setWordWrap(true);
223
 
 
224
 
    QLabel* logo      = new QLabel;
225
 
    logo->setPixmap(QPixmap(KStandardDirs::locate("data", "digikam/data/logo-digikam.png"))
226
 
                    .scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
227
 
 
228
 
    KSeparator* line  = new KSeparator(Qt::Horizontal);
229
 
 
230
 
    QGridLayout* grid = new QGridLayout;
231
 
    grid->addWidget(icon,    0, 0);
232
 
    grid->addWidget(message, 0, 1);
233
 
    grid->addWidget(logo,    0, 2);
234
 
    grid->addWidget(line,    1, 0, 1, 3);
235
 
    grid->setColumnStretch(1, 1);
236
 
    return grid;
237
 
}
238
 
 
239
 
QLayout* ColorCorrectionDlg::createProfilesInfo() const
240
 
{
241
 
    QVBoxLayout* vbox = new QVBoxLayout;
242
 
 
243
 
    if (d->mode == ProfileMismatch || d->mode == UncalibratedColor)
244
 
    {
245
 
        d->imageProfileTitle = new QLabel;
246
 
 
247
 
        if (d->mode == ProfileMismatch)
248
 
        {
249
 
            d->imageProfileTitle->setText(i18n("Embedded Color Profile:"));
250
 
        }
251
 
        //else if (d->mode == MissingProfile)
252
 
        //  d->imageProfileTitle->setText(i18n("Image Color Profile:"));
253
 
        else if (d->mode == UncalibratedColor)
254
 
        {
255
 
            d->imageProfileTitle->setText(i18n("Input Color Profile:"));
256
 
        }
257
 
 
258
 
        d->imageProfileDesc        = new QLabel;
259
 
        QPushButton* imageProfInfo = new QPushButton(i18n("Info..."));
260
 
        //d->imageProfileTitle->setWordWrap(true);
261
 
        d->imageProfileDesc->setWordWrap(true);
262
 
 
263
 
        vbox->addWidget(d->imageProfileTitle);
264
 
        vbox->addWidget(d->imageProfileDesc);
265
 
        vbox->addWidget(imageProfInfo, 0, Qt::AlignLeft);
266
 
 
267
 
        connect(imageProfInfo, SIGNAL(clicked()),
268
 
                this, SLOT(slotImageProfInfo()));
269
 
    }
270
 
 
271
 
    QLabel* workspaceProfileTitle   = new QLabel(i18n("Working Color Space:"));
272
 
    QLabel* workspaceProfileDesc    = new QLabel(QString("<b>%1</b>").arg(d->workspaceProfile.description()));
273
 
    QPushButton* workspaceProfInfo  = new QPushButton(i18n("Info..."));
274
 
    //workspaceProfileTitle->setWordWrap(true);
275
 
    workspaceProfileDesc->setWordWrap(true);
276
 
 
277
 
    vbox->addWidget(workspaceProfileTitle);
278
 
    vbox->addWidget(workspaceProfileDesc);
279
 
    vbox->addWidget(workspaceProfInfo, 0, Qt::AlignLeft);
280
 
 
281
 
    connect(workspaceProfInfo, SIGNAL(clicked()),
282
 
            this, SLOT(slotWorkspaceProfInfo()));
283
 
 
284
 
    return vbox;
285
 
}
286
 
 
287
 
QLayout* ColorCorrectionDlg::createPreviews() const
288
 
{
289
 
    QGridLayout* grid     = new QGridLayout;
290
 
    QLabel* originalTitle = new QLabel;
291
 
 
292
 
    if (d->mode == ProfileMismatch)
293
 
    {
294
 
        originalTitle->setText(i18n("Original Colors:"));
295
 
    }
296
 
    else if (d->mode == MissingProfile)
297
 
    {
298
 
        originalTitle->setText(i18n("Uncorrected Colors:"));
299
 
    }
300
 
    else if (d->mode == UncalibratedColor)
301
 
    {
302
 
        originalTitle->setText(i18n("Raw Colors:"));
303
 
    }
304
 
 
305
 
    originalTitle->setWordWrap(true);
306
 
 
307
 
    QLabel* previewOriginal = new QLabel;
308
 
    DImg copyOriginal       = d->preview.copy();
309
 
    IccManager manager(copyOriginal);
310
 
    manager.transformForDisplay();
311
 
    previewOriginal->setPixmap(copyOriginal.convertToPixmap());
312
 
 
313
 
    QLabel* targetTitle = new QLabel;
314
 
 
315
 
    if (d->mode == ProfileMismatch)
316
 
    {
317
 
        targetTitle->setText(i18n("Resulting Colors:"));
318
 
    }
319
 
    else if (d->mode == MissingProfile)
320
 
    {
321
 
        targetTitle->setText(i18n("Correction Applied:"));
322
 
    }
323
 
    else if (d->mode == UncalibratedColor)
324
 
    {
325
 
        targetTitle->setText(i18n("Corrected Colors:"));
326
 
    }
327
 
 
328
 
    targetTitle->setWordWrap(true);
329
 
 
330
 
    d->previewTarget = new QLabel;
331
 
 
332
 
    if (d->preview.width() > d->preview.height())
333
 
    {
334
 
        grid->addWidget(originalTitle,    0, 0, Qt::AlignTop);
335
 
        grid->addWidget(previewOriginal,  1, 0);
336
 
        grid->addWidget(targetTitle,      2, 0, Qt::AlignTop);
337
 
        grid->addWidget(d->previewTarget, 3, 0);
338
 
    }
339
 
    else
340
 
    {
341
 
        grid->addWidget(originalTitle,    0, 0, Qt::AlignTop);
342
 
        grid->addWidget(previewOriginal,  1, 0);
343
 
        grid->addWidget(targetTitle,      0, 1, Qt::AlignTop);
344
 
        grid->addWidget(d->previewTarget, 1, 1);
345
 
    }
346
 
 
347
 
    return grid;
348
 
}
349
 
 
350
 
QWidget* ColorCorrectionDlg::createOptions() const
351
 
{
352
 
    QGroupBox* box    = new QGroupBox;
353
 
    QVBoxLayout* vbox = new QVBoxLayout(box);
354
 
 
355
 
    if (d->mode == ProfileMismatch)
356
 
    {
357
 
        d->keepProfile           = new QRadioButton(i18n("Keep the embedded profile, do not convert"));
358
 
        d->convertToWorkingSpace = new QRadioButton(i18n("Convert to working color space"));
359
 
        d->thirdOption           = new QRadioButton(i18n("Ignore embedded profile, assign this profile:"));
360
 
        d->otherProfileBox       = new IccProfilesComboBox;
361
 
        d->otherProfileBox->addProfilesSqueezed(IccSettings::instance()->workspaceProfiles());
362
 
        d->thirdCheckBox         = new QCheckBox(i18n("and then convert to working space"));
363
 
 
364
 
        d->keepProfile->setChecked(true);
365
 
        d->otherProfileBox->setCurrentProfile(IccProfile::adobeRGB());
366
 
        d->otherProfileBox->setNoProfileIfEmpty(i18n("No Profile Available"));
367
 
 
368
 
        if (d->otherProfileBox->count() == 0) // disable if empty
369
 
        {
370
 
            d->thirdOption->setEnabled(false);
371
 
            d->otherProfileBox->setEnabled(false);
372
 
        }
373
 
 
374
 
        QHBoxLayout* hboxAssign = new QHBoxLayout;
375
 
        hboxAssign->addSpacing(10);
376
 
        hboxAssign->addWidget(d->otherProfileBox);
377
 
        hboxAssign->addWidget(d->thirdCheckBox);
378
 
        hboxAssign->setSpacing(0);
379
 
 
380
 
        vbox->addWidget(d->keepProfile);
381
 
        vbox->addWidget(d->convertToWorkingSpace);
382
 
        vbox->addWidget(d->thirdOption);
383
 
        vbox->addLayout(hboxAssign);
384
 
 
385
 
        connect(d->keepProfile, SIGNAL(toggled(bool)),
386
 
                this, SLOT(imageProfileToggled(bool)));
387
 
 
388
 
        connect(d->convertToWorkingSpace, SIGNAL(toggled(bool)),
389
 
                this, SLOT(imageProfileToggled(bool)));
390
 
 
391
 
        connect(d->thirdOption, SIGNAL(toggled(bool)),
392
 
                this, SLOT(imageProfileToggled(bool)));
393
 
 
394
 
        connect(d->thirdCheckBox, SIGNAL(toggled(bool)),
395
 
                this, SLOT(imageProfileToggled(bool)));
396
 
 
397
 
        connect(d->otherProfileBox, SIGNAL(currentIndexChanged(int)),
398
 
                this, SLOT(imageProfileChanged()));
399
 
    }
400
 
    else if (d->mode == MissingProfile)
401
 
    {
402
 
        d->convertToWorkingSpace = new QRadioButton(i18n("Assign profile and convert to working color space"));
403
 
        d->keepProfile           = new QRadioButton(i18n("Assign and keep color profile"));
404
 
        d->thirdOption           = new QRadioButton(i18n("Leave the file untagged, do not color manage"));
405
 
 
406
 
        d->convertToWorkingSpace->setChecked(true);
407
 
 
408
 
        vbox->addWidget(d->convertToWorkingSpace);
409
 
        vbox->addWidget(d->keepProfile);
410
 
        vbox->addWidget(d->thirdOption);
411
 
 
412
 
        connect(d->keepProfile, SIGNAL(toggled(bool)),
413
 
                this, SLOT(missingProfileToggled(bool)));
414
 
 
415
 
        connect(d->convertToWorkingSpace, SIGNAL(toggled(bool)),
416
 
                this, SLOT(missingProfileToggled(bool)));
417
 
 
418
 
        connect(d->thirdOption, SIGNAL(toggled(bool)),
419
 
                this, SLOT(missingProfileToggled(bool)));
420
 
    }
421
 
    else if (d->mode == UncalibratedColor)
422
 
    {
423
 
        // empty
424
 
        /*
425
 
        d->convertToWorkingSpace = new QRadioButton(i18n("Convert to working color space"));
426
 
        d->thirdOption         = new QRadioButton(i18n("Convert to this profile:"));
427
 
        d->otherProfileBox       = new IccProfilesComboBox;
428
 
        d->otherProfileBox->addProfilesSqueezed(IccSettings::instance()->workspaceProfiles());
429
 
 
430
 
        vbox->addWidget(d->convertToWorkingSpace);
431
 
        vbox->addWidget(d->thirdOption);
432
 
        vbox->addWidget(d->otherProfileBox);
433
 
        */
434
 
    }
435
 
 
436
 
    return box;
437
 
}
438
 
 
439
 
QWidget* ColorCorrectionDlg::createAssumeOptions() const
440
 
{
441
 
    QGroupBox*   box  = new QGroupBox;
442
 
    QGridLayout* grid = new QGridLayout(box);
443
 
 
444
 
    if (d->mode == ProfileMismatch)
445
 
    {
446
 
        // unused
447
 
    }
448
 
    else if (d->mode == MissingProfile)
449
 
    {
450
 
        QLabel* label = new QLabel(i18n("Which color space shall be used to interpret the colors of this image?"));
451
 
        label->setWordWrap(true);
452
 
 
453
 
        d->imageSRGB         = new QRadioButton(i18n("sRGB (Internet standard)"));
454
 
        d->imageWorkingSpace = new QRadioButton(i18n("Current working color space"));
455
 
        d->imageOtherSpace   = new QRadioButton(i18n("This profile:"));
456
 
        d->imageProfileBox   = new IccProfilesComboBox;
457
 
        d->imageProfileBox->addProfilesSqueezed(IccSettings::instance()->workspaceProfiles()
458
 
                                                << IccSettings::instance()->inputProfiles());
459
 
        QPushButton* usedProfInfo = new QPushButton(i18n("Info..."));
460
 
 
461
 
        d->imageSRGB->setChecked(true);
462
 
        d->imageProfileBox->setCurrentProfile(IccProfile::adobeRGB());
463
 
        d->imageProfileBox->setNoProfileIfEmpty(i18n("No Profile Available"));
464
 
 
465
 
        if (d->imageProfileBox->count() == 0) // disable if empty
466
 
        {
467
 
            d->imageOtherSpace->setEnabled(false);
468
 
            d->imageProfileBox->setEnabled(false);
469
 
        }
470
 
 
471
 
        grid->addWidget(label,                0, 0, 1, 2);
472
 
        grid->addWidget(d->imageSRGB,         1, 0, 1, 2);
473
 
        grid->addWidget(d->imageWorkingSpace, 2, 0, 1, 2);
474
 
        grid->addWidget(d->imageOtherSpace,   3, 0, 1, 2);
475
 
        grid->addWidget(d->imageProfileBox,   4, 1);
476
 
        grid->addWidget(usedProfInfo,         5, 0, 1, 2, Qt::AlignLeft);
477
 
        grid->setColumnMinimumWidth(0, 10);
478
 
        grid->setColumnStretch(1, 1);
479
 
 
480
 
        connect(d->imageProfileBox, SIGNAL(currentIndexChanged(int)),
481
 
                this, SLOT(usedProfileChanged()));
482
 
 
483
 
        connect(d->imageSRGB, SIGNAL(toggled(bool)),
484
 
                this, SLOT(usedProfileToggled(bool)));
485
 
 
486
 
        connect(d->imageWorkingSpace, SIGNAL(toggled(bool)),
487
 
                this, SLOT(usedProfileToggled(bool)));
488
 
 
489
 
        connect(d->imageOtherSpace, SIGNAL(toggled(bool)),
490
 
                this, SLOT(usedProfileToggled(bool)));
491
 
 
492
 
        connect(usedProfInfo, SIGNAL(clicked()),
493
 
                this, SLOT(slotImageProfInfo()));
494
 
    }
495
 
    else if (d->mode == UncalibratedColor)
496
 
    {
497
 
        QLabel* label = new QLabel(i18n("Please select the input color profile of the device (camera) used to create this image:"));
498
 
        label->setWordWrap(true);
499
 
 
500
 
        d->imageProfileBox = new IccProfilesComboBox;
501
 
        d->imageProfileBox->addProfilesSqueezed(IccSettings::instance()->inputProfiles());
502
 
        d->imageProfileBox->setCurrentProfile(IccSettings::instance()->settings().defaultInputProfile);
503
 
        d->imageProfileBox->setNoProfileIfEmpty(i18n("No Input Profile Available"));
504
 
 
505
 
        grid->addWidget(label);
506
 
        grid->addWidget(d->imageProfileBox);
507
 
 
508
 
        connect(d->imageProfileBox, SIGNAL(currentIndexChanged(int)),
509
 
                this, SLOT(inputProfileChanged()));
510
 
    }
511
 
 
512
 
    return box;
513
 
}
514
 
 
515
 
void ColorCorrectionDlg::imageProfileToggled(bool on)
516
 
{
517
 
    if (!on)
518
 
    {
519
 
        return;
520
 
    }
521
 
 
522
 
    imageProfileChanged();
523
 
}
524
 
 
525
 
void ColorCorrectionDlg::imageProfileChanged()
526
 
{
527
 
    updateImageProfileUI();
528
 
    updateInfo();
529
 
}
530
 
 
531
 
void ColorCorrectionDlg::updateImageProfileUI()
532
 
{
533
 
    if (d->otherProfileBox)
534
 
    {
535
 
        d->otherProfileBox->setEnabled(d->thirdOption->isChecked());
536
 
    }
537
 
 
538
 
    if (d->thirdCheckBox)
539
 
    {
540
 
        d->thirdCheckBox->setEnabled(d->thirdOption->isChecked());
541
 
    }
542
 
}
543
 
 
544
 
void ColorCorrectionDlg::missingProfileToggled(bool on)
545
 
{
546
 
    if (!on)
547
 
    {
548
 
        return;
549
 
    }
550
 
 
551
 
    missingProfileChanged();
552
 
}
553
 
 
554
 
void ColorCorrectionDlg::missingProfileChanged()
555
 
{
556
 
    updateInfo();
557
 
}
558
 
 
559
 
void ColorCorrectionDlg::usedProfileToggled(bool on)
560
 
{
561
 
    if (!on)
562
 
    {
563
 
        return;
564
 
    }
565
 
 
566
 
    usedProfileChanged();
567
 
}
568
 
 
569
 
void ColorCorrectionDlg::usedProfileChanged()
570
 
{
571
 
    updateUsedProfileUI();
572
 
    updateInfo();
573
 
}
574
 
 
575
 
void ColorCorrectionDlg::updateUsedProfileUI()
576
 
{
577
 
    if (d->imageProfileBox && d->imageOtherSpace)
578
 
    {
579
 
        d->imageProfileBox->setEnabled(d->imageOtherSpace->isChecked());
580
 
    }
581
 
}
582
 
 
583
 
void ColorCorrectionDlg::inputProfileChanged()
584
 
{
585
 
    updateInfo();
586
 
}
587
 
 
588
 
void ColorCorrectionDlg::updateInfo()
589
 
{
590
 
    setCursor(Qt::WaitCursor);
591
 
 
592
 
    DImg colorPreview                = d->preview.copy();
593
 
    IccManager manager(colorPreview);
594
 
    ICCSettingsContainer::Behavior b = currentBehavior();
595
 
    d->imageProfile                  = manager.imageProfile(b, specifiedProfile());
596
 
 
597
 
    if (d->mode == ProfileMismatch)
598
 
    {
599
 
        if (b & ICCSettingsContainer::UseSpecifiedProfile)
600
 
        {
601
 
            d->imageProfileTitle->setText(i18n("Assigned Color Profile:"));
602
 
        }
603
 
        else
604
 
        {
605
 
            d->imageProfileTitle->setText(i18n("Embedded Color Profile:"));
606
 
        }
607
 
    }
608
 
 
609
 
    if (d->mode == ProfileMismatch || d->mode == UncalibratedColor)
610
 
    {
611
 
        QString description = d->imageProfile.description();
612
 
 
613
 
        if (description.isEmpty())
614
 
        {
615
 
            d->imageProfileDesc->setText(i18n("<b>No Profile</b>"));
616
 
        }
617
 
        else
618
 
        {
619
 
            d->imageProfileDesc->setText(QString("<b>%1</b>").arg(description));
620
 
        }
621
 
    }
622
 
 
623
 
    manager.transform(currentBehavior(), specifiedProfile());
624
 
    manager.transformForDisplay(this);
625
 
    d->previewTarget->setPixmap(colorPreview.convertToPixmap());
626
 
 
627
 
    unsetCursor();
628
 
}
629
 
 
630
 
void ColorCorrectionDlg::slotWorkspaceProfInfo()
631
 
{
632
 
    ICCProfileInfoDlg infoDlg(parentWidget(), QString(), d->workspaceProfile);
633
 
    infoDlg.exec();
634
 
}
635
 
 
636
 
void ColorCorrectionDlg::slotImageProfInfo()
637
 
{
638
 
    if (d->imageProfile.isNull())
639
 
    {
640
 
        return;
641
 
    }
642
 
 
643
 
    ICCProfileInfoDlg infoDlg(parentWidget(), QString(), d->imageProfile);
644
 
    infoDlg.exec();
645
 
}
646
 
 
647
 
ICCSettingsContainer::Behavior ColorCorrectionDlg::behavior() const
648
 
{
649
 
    if (result() == QDialog::Rejected)
650
 
    {
651
 
        return ICCSettingsContainer::SafestBestAction;
652
 
    }
653
 
 
654
 
    return currentBehavior();
655
 
}
656
 
 
657
 
ICCSettingsContainer::Behavior ColorCorrectionDlg::currentBehavior() const
658
 
{
659
 
    if (d->mode == ProfileMismatch)
660
 
    {
661
 
        if (d->keepProfile->isChecked())
662
 
        {
663
 
            return ICCSettingsContainer::PreserveEmbeddedProfile;
664
 
        }
665
 
        else if (d->convertToWorkingSpace->isChecked())
666
 
        {
667
 
            return ICCSettingsContainer::EmbeddedToWorkspace;
668
 
        }
669
 
        else if (d->thirdOption->isChecked())
670
 
        {
671
 
            if (d->thirdCheckBox->isChecked())
672
 
            {
673
 
                return ICCSettingsContainer::UseSpecifiedProfile | ICCSettingsContainer::ConvertToWorkspace;
674
 
            }
675
 
            else
676
 
            {
677
 
                return ICCSettingsContainer::UseSpecifiedProfile | ICCSettingsContainer::KeepProfile;
678
 
            }
679
 
        }
680
 
    }
681
 
    else if (d->mode == MissingProfile)
682
 
    {
683
 
        if (d->thirdOption->isChecked())
684
 
        {
685
 
            return ICCSettingsContainer::NoColorManagement;
686
 
        }
687
 
 
688
 
        ICCSettingsContainer::Behavior behavior;
689
 
 
690
 
        if (d->keepProfile->isChecked())
691
 
        {
692
 
            behavior |= ICCSettingsContainer::KeepProfile;
693
 
        }
694
 
        else if (d->convertToWorkingSpace->isChecked())
695
 
        {
696
 
            behavior |= ICCSettingsContainer::ConvertToWorkspace;
697
 
        }
698
 
 
699
 
        if (d->imageSRGB->isChecked())
700
 
        {
701
 
            behavior |= ICCSettingsContainer::UseSRGB;
702
 
        }
703
 
        else if (d->imageWorkingSpace->isChecked())
704
 
        {
705
 
            behavior |= ICCSettingsContainer::UseWorkspace;
706
 
        }
707
 
        else if (d->imageOtherSpace->isChecked())
708
 
        {
709
 
            behavior |= ICCSettingsContainer::UseSpecifiedProfile;
710
 
        }
711
 
 
712
 
        return behavior;
713
 
    }
714
 
    else if (d->mode == UncalibratedColor)
715
 
    {
716
 
        return ICCSettingsContainer::ConvertToWorkspace | ICCSettingsContainer::UseSpecifiedProfile;
717
 
    }
718
 
 
719
 
    return ICCSettingsContainer::SafestBestAction;
720
 
}
721
 
 
722
 
IccProfile ColorCorrectionDlg::specifiedProfile() const
723
 
{
724
 
    if (d->mode == ProfileMismatch)
725
 
    {
726
 
        return d->otherProfileBox->currentProfile();
727
 
    }
728
 
    else if (d->mode == MissingProfile || d->mode == UncalibratedColor)
729
 
    {
730
 
        return d->imageProfileBox->currentProfile();
731
 
    }
732
 
 
733
 
    return IccProfile();
734
 
}
735
 
 
736
 
void ColorCorrectionDlg::readSettings()
737
 
{
738
 
    ICCSettingsContainer settings = IccSettings::instance()->settings();
739
 
 
740
 
    if (d->mode == ProfileMismatch)
741
 
    {
742
 
        if ((settings.lastMismatchBehavior & ICCSettingsContainer::UseSpecifiedProfile) &&
743
 
            d->otherProfileBox->count() > 0)
744
 
        {
745
 
            d->thirdOption->setChecked(true);
746
 
            d->thirdCheckBox->setChecked(settings.lastMismatchBehavior & ICCSettingsContainer::ConvertToWorkspace);
747
 
            d->thirdOption->setFocus();
748
 
        }
749
 
        else
750
 
        {
751
 
            if (settings.lastMismatchBehavior & ICCSettingsContainer::KeepProfile)
752
 
            {
753
 
                d->keepProfile->setChecked(true);
754
 
                d->keepProfile->setFocus();
755
 
            }
756
 
            else if (settings.lastMismatchBehavior & ICCSettingsContainer::ConvertToWorkspace)
757
 
            {
758
 
                d->convertToWorkingSpace->setChecked(true);
759
 
                d->convertToWorkingSpace->setFocus();
760
 
            }
761
 
        }
762
 
 
763
 
        if (!settings.lastSpecifiedAssignProfile.isEmpty())
764
 
        {
765
 
            d->otherProfileBox->setCurrentProfile(settings.lastSpecifiedAssignProfile);
766
 
        }
767
 
    }
768
 
    else if (d->mode == MissingProfile)
769
 
    {
770
 
        if (settings.lastMissingProfileBehavior == ICCSettingsContainer::NoColorManagement)
771
 
        {
772
 
            d->imageSRGB->setChecked(true); // ?
773
 
            d->thirdOption->setChecked(true);
774
 
            d->thirdOption->setFocus();
775
 
        }
776
 
        else
777
 
        {
778
 
            if (settings.lastMissingProfileBehavior & ICCSettingsContainer::KeepProfile)
779
 
            {
780
 
                d->keepProfile->setChecked(true);
781
 
                d->keepProfile->setFocus();
782
 
            }
783
 
            else if (settings.lastMissingProfileBehavior & ICCSettingsContainer::ConvertToWorkspace)
784
 
            {
785
 
                d->convertToWorkingSpace->setChecked(true);
786
 
                d->convertToWorkingSpace->setFocus();
787
 
            }
788
 
 
789
 
            if (settings.lastMissingProfileBehavior & ICCSettingsContainer::UseSRGB)
790
 
            {
791
 
                d->imageSRGB->setChecked(true);
792
 
            }
793
 
 
794
 
            if (settings.lastMissingProfileBehavior & ICCSettingsContainer::UseWorkspace)
795
 
            {
796
 
                d->imageWorkingSpace->setChecked(true);
797
 
            }
798
 
 
799
 
            if ((settings.lastMissingProfileBehavior & ICCSettingsContainer::UseSpecifiedProfile)
800
 
                && d->imageProfileBox->count() > 0)
801
 
            {
802
 
                d->imageOtherSpace->setChecked(true);
803
 
            }
804
 
        }
805
 
 
806
 
        if (!settings.lastSpecifiedInputProfile.isEmpty())
807
 
        {
808
 
            d->imageProfileBox->setCurrentProfile(settings.lastSpecifiedInputProfile);
809
 
        }
810
 
    }
811
 
    else if (d->mode == UncalibratedColor)
812
 
    {
813
 
        d->imageProfileBox->setCurrentProfile(settings.lastSpecifiedInputProfile);
814
 
        d->imageProfileBox->setFocus();
815
 
    }
816
 
}
817
 
 
818
 
void ColorCorrectionDlg::setSettings()
819
 
{
820
 
    ICCSettingsContainer settings = IccSettings::instance()->settings();
821
 
 
822
 
    if (d->mode == ProfileMismatch)
823
 
    {
824
 
        settings.lastMismatchBehavior = currentBehavior();
825
 
        settings.lastSpecifiedAssignProfile = specifiedProfile().filePath();
826
 
    }
827
 
    else if (d->mode == MissingProfile)
828
 
    {
829
 
        settings.lastMissingProfileBehavior = currentBehavior();
830
 
        settings.lastSpecifiedInputProfile = specifiedProfile().filePath();
831
 
    }
832
 
    else if (d->mode == UncalibratedColor)
833
 
    {
834
 
        settings.lastUncalibratedBehavior = currentBehavior();
835
 
        settings.lastSpecifiedInputProfile = specifiedProfile().filePath();
836
 
    }
837
 
 
838
 
    IccSettings::instance()->setSettings(settings);
839
 
}
840
 
 
841
 
void ColorCorrectionDlg::accept()
842
 
{
843
 
    KDialog::accept();
844
 
 
845
 
    setSettings();
846
 
}
847
 
 
848
 
}  // namespace Digikam