summaryrefslogtreecommitdiffstats
path: root/digikam/utilities/imageeditor/canvas/colorcorrectiondlg.cpp
blob: 1d098b22f97ed339994acde079faebe0dedbcea1 (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
/* ============================================================
 *
 * This file is a part of digiKam project
 * http://www.digikam.org
 * 
 * Date        : 2006-05-15
 * Description : a dialog to see preview ICC color correction 
 *               before to apply color profile.
 * 
 * Copyright (C) 2006-2007 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 <tqlabel.h>
#include <tqwhatsthis.h>
#include <tqlayout.h>
#include <tqframe.h>
#include <tqstring.h>
#include <tqfileinfo.h>
#include <tqpushbutton.h>

// KDE includes.

#include <tdelocale.h>
#include <kiconloader.h>
#include <tdeapplication.h>
#include <kseparator.h>

// Local includes.

#include "ddebug.h"
#include "dimg.h"
#include "icctransform.h"
#include "iccprofileinfodlg.h"
#include "colorcorrectiondlg.h"
#include "colorcorrectiondlg.moc"

namespace Digikam
{

ColorCorrectionDlg::ColorCorrectionDlg(TQWidget* parent, DImg *preview, 
                                       IccTransform *iccTrans, const TQString& file)
                  : KDialogBase(parent, "", true, TQString(),
                                Help|Ok|Apply|Cancel, Ok, true)
{
    m_iccTrans = iccTrans;
    m_parent   = parent;
    setHelp("iccprofile.anchor", "digikam");
    setButtonText(Ok,     i18n("Convert"));
    setButtonTip(Ok,      i18n("Apply the default color workspace profile to the image"));
    setButtonText(Cancel, i18n("Do Nothing"));
    setButtonTip(Cancel,  i18n("Do not change the image"));
    setButtonText(Apply,  i18n("Assign"));
    setButtonTip(Apply,   i18n("Only embed the color workspace profile in the image, don't change the image"));

    TQFileInfo fi(file);
    setCaption(fi.fileName());
    
    TQWidget *page     = new TQWidget(this);
    TQGridLayout* grid = new TQGridLayout(page, 3, 2, 0, KDialog::spacingHint());
        
    TQLabel *originalTitle         = new TQLabel(i18n("Original Image:"), page);
    TQLabel *previewOriginal       = new TQLabel(page);
    TQLabel *targetTitle           = new TQLabel(i18n("Corrected Image:"), page);
    TQLabel *previewTarget         = new TQLabel(page);
    TQLabel *logo                  = new TQLabel(page);
    TQLabel *message               = new TQLabel(page);
    TQLabel *currentProfileTitle   = new TQLabel(i18n("Current workspace color profile:"), page);
    TQLabel *currentProfileDesc    = new TQLabel(TQString("<b>%1</b>").arg(m_iccTrans->getOutpoutProfileDescriptor()), page);
    TQPushButton *currentProfInfo  = new TQPushButton(i18n("Info..."), page);
    TQLabel *embeddedProfileTitle  = new TQLabel(i18n("Embedded color profile:"), page);
    TQLabel *embeddedProfileDesc   = new TQLabel(TQString("<b>%1</b>").arg(m_iccTrans->getEmbeddedProfileDescriptor()), page);
    TQPushButton *embeddedProfInfo = new TQPushButton(i18n("Info..."), page);
    KSeparator *line              = new KSeparator(TQt::Horizontal, page);
    
    if (m_iccTrans->embeddedProfile().isEmpty())
    {
        message->setText(i18n("<p>This image has not been assigned a color profile.</p>"
                              "<p>Do you want to convert it to your workspace color profile?</p>"));
                              
        line->hide();
        embeddedProfileTitle->hide();
        embeddedProfileDesc->hide();
        embeddedProfInfo->hide();
    }
    else
    {
        message->setText(i18n("<p>This image has been assigned to a color profile that does not "
                              "match your default workspace color profile.</p>"
                              "<p>Do you want to convert it to your workspace color profile?</p>"));
    }
    
    previewOriginal->setPixmap(preview->convertToPixmap());
    previewTarget->setPixmap(preview->convertToPixmap(m_iccTrans));
    TDEIconLoader* iconLoader = TDEApplication::kApplication()->iconLoader();
    logo->setPixmap(iconLoader->loadIcon("digikam", TDEIcon::NoGroup, 128, TDEIcon::DefaultState, 0, true));    
    
    grid->addMultiCellWidget(originalTitle, 0, 0, 0, 0);
    grid->addMultiCellWidget(previewOriginal, 1, 1, 0, 0);
    grid->addMultiCellWidget(targetTitle, 2, 2, 0, 0);
    grid->addMultiCellWidget(previewTarget, 3, 3, 0, 0);
    
    TQVBoxLayout *vlay = new TQVBoxLayout( KDialog::spacingHint() );
    vlay->addWidget(logo);
    vlay->addWidget(message);
    
    vlay->addWidget(new KSeparator(TQt::Horizontal, page));
    vlay->addWidget(currentProfileTitle);
    vlay->addWidget(currentProfileDesc);
    
    TQHBoxLayout *hlay1 = new TQHBoxLayout( KDialog::spacingHint() );
    hlay1->addWidget(currentProfInfo);
    hlay1->addStretch();
    vlay->addLayout(hlay1);
    
    vlay->addWidget(line);
    vlay->addWidget(embeddedProfileTitle);
    vlay->addWidget(embeddedProfileDesc);    
    
    TQHBoxLayout *hlay2 = new TQHBoxLayout( KDialog::spacingHint() );
    hlay2->addWidget(embeddedProfInfo);
    hlay2->addStretch();
    vlay->addLayout(hlay2);
    vlay->addStretch();
    
    grid->addMultiCell(new TQSpacerItem(KDialog::spacingHint(), KDialog::spacingHint(), 
                       TQSizePolicy::Minimum, TQSizePolicy::Expanding), 0, 3, 1, 1);
    grid->addMultiCellLayout(vlay, 0, 3, 2, 2);
    
    setMainWidget(page);
    
    // --------------------------------------------------------------------
    
    connect(currentProfInfo, TQT_SIGNAL(clicked()),
            this, TQT_SLOT(slotCurrentProfInfo()) );
    
    connect(embeddedProfInfo, TQT_SIGNAL(clicked()),
            this, TQT_SLOT(slotEmbeddedProfInfo()) );
            
    connect(this, TQT_SIGNAL(applyClicked()), 
            this, TQT_SLOT(slotApplyClicked()));
}

ColorCorrectionDlg::~ColorCorrectionDlg()
{
}

void ColorCorrectionDlg::slotCurrentProfInfo()
{
    if (m_iccTrans->outputProfile().isEmpty())
        return;

    ICCProfileInfoDlg infoDlg(m_parent, TQString(), m_iccTrans->outputProfile());
    infoDlg.exec();
}

void ColorCorrectionDlg::slotEmbeddedProfInfo()
{
    if (m_iccTrans->embeddedProfile().isEmpty())
        return;

    ICCProfileInfoDlg infoDlg(m_parent, TQString(), m_iccTrans->embeddedProfile());
    infoDlg.exec();
}

void ColorCorrectionDlg::slotApplyClicked()
{
    DDebug() << "colorcorrectiondlg: Apply pressed" << endl;
    done(-1);
}

}  // NameSpace Digikam