1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2009-09-16
7  * Description : Dialog to adjust soft proofing settings
8  *
9  * Copyright (C) 2009-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2013-2021 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 "softproofdialog.h"
26 
27 // Qt includes
28 
29 #include <QCheckBox>
30 #include <QGridLayout>
31 #include <QGroupBox>
32 #include <QLabel>
33 #include <QPushButton>
34 #include <QIcon>
35 #include <QDialogButtonBox>
36 #include <QVBoxLayout>
37 #include <QMessageBox>
38 
39 // KDE includes
40 
41 #include <klocalizedstring.h>
42 
43 // Local includes
44 
45 #include "dlayoutbox.h"
46 #include "iccprofilescombobox.h"
47 #include "iccsettingscontainer.h"
48 #include "iccsettings.h"
49 #include "iccprofileinfodlg.h"
50 #include "dexpanderbox.h"
51 #include "dcolorselector.h"
52 
53 namespace Digikam
54 {
55 
56 class Q_DECL_HIDDEN SoftProofDialog::Private
57 {
58 public:
59 
Private()60     explicit Private()
61       : switchOn         (false),
62         deviceProfileBox (nullptr),
63         infoProofProfiles(nullptr),
64         buttons          (nullptr),
65         gamutCheckBox    (nullptr),
66         maskColorLabel   (nullptr),
67         maskColorBtn     (nullptr),
68         proofingIntentBox(nullptr)
69     {
70     }
71 
72     bool                        switchOn;
73 
74     IccProfilesComboBox*        deviceProfileBox;
75     QPushButton*                infoProofProfiles;
76     QDialogButtonBox*           buttons;
77     QCheckBox*                  gamutCheckBox;
78     QLabel*                     maskColorLabel;
79     DColorSelector*             maskColorBtn;
80 
81     IccRenderingIntentComboBox* proofingIntentBox;
82 };
83 
SoftProofDialog(QWidget * const parent)84 SoftProofDialog::SoftProofDialog(QWidget* const parent)
85     : QDialog(parent),
86       d      (new Private)
87 {
88     setModal(true);
89     setWindowTitle(i18n("Soft Proofing Options"));
90 
91     d->buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
92     d->buttons->button(QDialogButtonBox::Ok)->setDefault(true);
93     d->buttons->button(QDialogButtonBox::Ok)->setText(i18n("Soft Proofing On"));
94     d->buttons->button(QDialogButtonBox::Ok)->setToolTip(i18n("Enable soft-proofing color managed view"));
95     d->buttons->button(QDialogButtonBox::Cancel)->setText(i18n("Soft Proofing Off"));
96     d->buttons->button(QDialogButtonBox::Cancel)->setToolTip(i18n("Disable soft-proofing color managed view"));
97 
98     QWidget* const page           = new QWidget(this);
99     QVBoxLayout* const mainLayout = new QVBoxLayout(page);
100 
101     // ---
102 
103     QLabel* const headerLabel    = new QLabel(i18n("<b>Configure the Soft Proofing View</b>"));
104     DLineWidget* const separator = new DLineWidget(Qt::Horizontal);
105 
106     // -------------------------------------------------------------
107 
108     QGridLayout* const profileGrid = new QGridLayout;
109     QLabel* const proofIcon        = new QLabel;
110     proofIcon->setPixmap(QIcon::fromTheme(QLatin1String("document-print")).pixmap(22));
111     QLabel* const proofLabel       = new QLabel(i18n("Profile of the output device to simulate:"));
112     d->deviceProfileBox            = new IccProfilesComboBox;
113     proofLabel->setBuddy(d->deviceProfileBox);
114     d->deviceProfileBox->setWhatsThis(i18n("<p>Select the profile for your output device "
115                                            "(usually, your printer). This profile will be used to do a soft proof, so you will "
116                                            "be able to preview how an image will be rendered via an output device.</p>"));
117 
118     d->infoProofProfiles      = new QPushButton;
119     d->infoProofProfiles->setIcon(QIcon::fromTheme(QLatin1String("dialog-information")));
120     d->infoProofProfiles->setWhatsThis(i18n("<p>Press this button to get detailed "
121                                             "information about the selected proofing profile.</p>"));
122 
123     d->deviceProfileBox->replaceProfilesSqueezed(IccSettings::instance()->outputProfiles());
124 
125     profileGrid->addWidget(proofIcon,            0, 0);
126     profileGrid->addWidget(proofLabel,           0, 1, 1, 2);
127     profileGrid->addWidget(d->deviceProfileBox,  1, 0, 1, 2);
128     profileGrid->addWidget(d->infoProofProfiles, 1, 2);
129     profileGrid->setColumnStretch(1, 10);
130 
131     // --------------------------------------------------------------
132 
133     QGroupBox* const optionsBox    = new QGroupBox;
134     QGridLayout* const optionsGrid = new QGridLayout;
135 
136     QLabel* const intentLabel      = new QLabel(i18n("Rendering intent:"));
137     d->proofingIntentBox           = new IccRenderingIntentComboBox;
138 
139     intentLabel->setBuddy(d->proofingIntentBox);
140 
141     d->gamutCheckBox   = new QCheckBox(i18n("Highlight out-of-gamut colors"));
142     d->maskColorLabel  = new QLabel(i18n("Highlighting color:"));
143     d->maskColorBtn    = new DColorSelector;
144     d->maskColorLabel->setBuddy(d->maskColorBtn);
145 
146     optionsGrid->addWidget(intentLabel,          0, 0, 1, 2);
147     optionsGrid->addWidget(d->proofingIntentBox, 0, 2, 1, 2);
148     optionsGrid->addWidget(d->gamutCheckBox,     1, 0, 1, 4);
149     optionsGrid->addWidget(d->maskColorLabel,    2, 1, 1, 1);
150     optionsGrid->addWidget(d->maskColorBtn,   2, 2, 1, 2, Qt::AlignLeft);
151     optionsGrid->setColumnMinimumWidth(0, 10);
152     optionsGrid->setColumnStretch(2, 1);
153     optionsBox->setLayout(optionsGrid);
154 
155     // -------------------------------------------------------
156 
157     mainLayout->addWidget(headerLabel);
158     mainLayout->addWidget(separator);
159     mainLayout->addLayout(profileGrid);
160     mainLayout->addWidget(optionsBox);
161 
162     QVBoxLayout* const vbx = new QVBoxLayout(this);
163     vbx->addWidget(page);
164     vbx->addWidget(d->buttons);
165     setLayout(vbx);
166 
167     connect(d->deviceProfileBox, SIGNAL(currentIndexChanged(int)),
168             this, SLOT(updateOkButtonState()));
169 
170     connect(d->gamutCheckBox, SIGNAL(toggled(bool)),
171             this, SLOT(updateGamutCheckState()));
172 
173     connect(d->buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
174             this, SLOT(slotOk()));
175 
176     connect(d->buttons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()),
177             this, SLOT(reject()));
178 
179     connect(d->infoProofProfiles, SIGNAL(clicked()),
180             this, SLOT(slotProfileInfo()));
181 
182     readSettings();
183     updateOkButtonState();
184     updateGamutCheckState();
185 }
186 
~SoftProofDialog()187 SoftProofDialog::~SoftProofDialog()
188 {
189     delete d;
190 }
191 
shallEnableSoftProofView() const192 bool SoftProofDialog::shallEnableSoftProofView() const
193 {
194     return d->switchOn;
195 }
196 
updateGamutCheckState()197 void SoftProofDialog::updateGamutCheckState()
198 {
199     bool on = d->gamutCheckBox->isChecked();
200     d->maskColorLabel->setEnabled(on);
201     d->maskColorBtn->setEnabled(on);
202 }
203 
updateOkButtonState()204 void SoftProofDialog::updateOkButtonState()
205 {
206     d->buttons->button(QDialogButtonBox::Ok)->setEnabled(d->deviceProfileBox->currentIndex() != -1);
207 }
208 
readSettings()209 void SoftProofDialog::readSettings()
210 {
211     ICCSettingsContainer settings = IccSettings::instance()->settings();
212     d->deviceProfileBox->setCurrentProfile(IccProfile(settings.defaultProofProfile));
213     d->proofingIntentBox->setIntent(settings.proofingRenderingIntent);
214     d->gamutCheckBox->setChecked(settings.doGamutCheck);
215     d->maskColorBtn->setColor(settings.gamutCheckMaskColor);
216 }
217 
writeSettings()218 void SoftProofDialog::writeSettings()
219 {
220     ICCSettingsContainer settings    = IccSettings::instance()->settings();
221     settings.defaultProofProfile     = d->deviceProfileBox->currentProfile().filePath();
222     settings.proofingRenderingIntent = d->proofingIntentBox->intent();
223     settings.doGamutCheck            = d->gamutCheckBox->isChecked();
224     settings.gamutCheckMaskColor     = d->maskColorBtn->color();
225     IccSettings::instance()->setSettings(settings);
226 }
227 
slotProfileInfo()228 void SoftProofDialog::slotProfileInfo()
229 {
230     IccProfile profile = d->deviceProfileBox->currentProfile();
231 
232     if (profile.isNull())
233     {
234         QMessageBox::critical(this, i18n("Profile Error"), i18n("No profile is selected."));
235         return;
236     }
237 
238     ICCProfileInfoDlg infoDlg(this, profile.filePath(), profile);
239     infoDlg.exec();
240 }
241 
slotOk()242 void SoftProofDialog::slotOk()
243 {
244     d->switchOn = true;
245     writeSettings();
246     accept();
247 }
248 
249 } // namespace Digikam
250