File indexing completed on 2025-01-05 03:59:39

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-09-16
0007  * Description : Dialog to adjust soft proofing settings
0008  *
0009  * SPDX-FileCopyrightText: 2009-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  * SPDX-FileCopyrightText: 2013-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "softproofdialog.h"
0017 
0018 // Qt includes
0019 
0020 #include <QCheckBox>
0021 #include <QGridLayout>
0022 #include <QGroupBox>
0023 #include <QLabel>
0024 #include <QPushButton>
0025 #include <QIcon>
0026 #include <QDialogButtonBox>
0027 #include <QVBoxLayout>
0028 #include <QMessageBox>
0029 
0030 // KDE includes
0031 
0032 #include <klocalizedstring.h>
0033 
0034 // Local includes
0035 
0036 #include "dlayoutbox.h"
0037 #include "iccprofilescombobox.h"
0038 #include "iccsettings.h"
0039 #include "iccprofileinfodlg.h"
0040 #include "dexpanderbox.h"
0041 #include "dcolorselector.h"
0042 #include "dxmlguiwindow.h"
0043 
0044 namespace Digikam
0045 {
0046 
0047 class Q_DECL_HIDDEN SoftProofDialog::Private
0048 {
0049 public:
0050 
0051     explicit Private()
0052       : switchOn         (false),
0053         deviceProfileBox (nullptr),
0054         infoProofProfiles(nullptr),
0055         buttons          (nullptr),
0056         gamutCheckBox    (nullptr),
0057         maskColorLabel   (nullptr),
0058         maskColorBtn     (nullptr),
0059         proofingIntentBox(nullptr)
0060     {
0061     }
0062 
0063     bool                        switchOn;
0064 
0065     IccProfilesComboBox*        deviceProfileBox;
0066     QPushButton*                infoProofProfiles;
0067     QDialogButtonBox*           buttons;
0068     QCheckBox*                  gamutCheckBox;
0069     QLabel*                     maskColorLabel;
0070     DColorSelector*             maskColorBtn;
0071 
0072     IccRenderingIntentComboBox* proofingIntentBox;
0073 };
0074 
0075 SoftProofDialog::SoftProofDialog(QWidget* const parent)
0076     : QDialog(parent),
0077       d      (new Private)
0078 {
0079     setModal(true);
0080     setWindowTitle(i18nc("@title:window", "Soft Proofing Options"));
0081 
0082     d->buttons = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0083     d->buttons->button(QDialogButtonBox::Ok)->setDefault(true);
0084     d->buttons->button(QDialogButtonBox::Ok)->setText(i18n("Soft Proofing On"));
0085     d->buttons->button(QDialogButtonBox::Ok)->setToolTip(i18n("Enable soft-proofing color managed view"));
0086     d->buttons->button(QDialogButtonBox::Cancel)->setText(i18n("Soft Proofing Off"));
0087     d->buttons->button(QDialogButtonBox::Cancel)->setToolTip(i18n("Disable soft-proofing color managed view"));
0088 
0089     QWidget* const page           = new QWidget(this);
0090     QVBoxLayout* const mainLayout = new QVBoxLayout(page);
0091 
0092     // ---
0093 
0094     QLabel* const headerLabel    = new QLabel(i18n("<b>Configure the Soft Proofing View</b>"));
0095     DLineWidget* const separator = new DLineWidget(Qt::Horizontal);
0096 
0097     // -------------------------------------------------------------
0098 
0099     QGridLayout* const profileGrid = new QGridLayout;
0100     QLabel* const proofIcon        = new QLabel;
0101     proofIcon->setPixmap(QIcon::fromTheme(QLatin1String("document-print")).pixmap(22));
0102     QLabel* const proofLabel       = new QLabel(i18n("Profile of the output device to simulate:"));
0103     d->deviceProfileBox            = new IccProfilesComboBox;
0104     proofLabel->setBuddy(d->deviceProfileBox);
0105     d->deviceProfileBox->setWhatsThis(i18n("<p>Select the profile for your output device "
0106                                            "(usually, your printer). This profile will be used to do a soft proof, so you will "
0107                                            "be able to preview how an image will be rendered via an output device.</p>"));
0108 
0109     d->infoProofProfiles      = new QPushButton;
0110     d->infoProofProfiles->setIcon(QIcon::fromTheme(QLatin1String("dialog-information")));
0111     d->infoProofProfiles->setWhatsThis(i18n("<p>Press this button to get detailed "
0112                                             "information about the selected proofing profile.</p>"));
0113 
0114     d->deviceProfileBox->replaceProfilesSqueezed(IccSettings::instance()->outputProfiles());
0115 
0116     profileGrid->addWidget(proofIcon,            0, 0);
0117     profileGrid->addWidget(proofLabel,           0, 1, 1, 2);
0118     profileGrid->addWidget(d->deviceProfileBox,  1, 0, 1, 2);
0119     profileGrid->addWidget(d->infoProofProfiles, 1, 2);
0120     profileGrid->setColumnStretch(1, 10);
0121 
0122     // --------------------------------------------------------------
0123 
0124     QGroupBox* const optionsBox    = new QGroupBox;
0125     QGridLayout* const optionsGrid = new QGridLayout;
0126 
0127     QLabel* const intentLabel      = new QLabel(i18n("Rendering intent:"));
0128     d->proofingIntentBox           = new IccRenderingIntentComboBox;
0129 
0130     intentLabel->setBuddy(d->proofingIntentBox);
0131 
0132     d->gamutCheckBox   = new QCheckBox(i18n("Highlight out-of-gamut colors"));
0133     d->maskColorLabel  = new QLabel(i18n("Highlighting color:"));
0134     d->maskColorBtn    = new DColorSelector;
0135     d->maskColorLabel->setBuddy(d->maskColorBtn);
0136 
0137     optionsGrid->addWidget(intentLabel,          0, 0, 1, 2);
0138     optionsGrid->addWidget(d->proofingIntentBox, 0, 2, 1, 2);
0139     optionsGrid->addWidget(d->gamutCheckBox,     1, 0, 1, 4);
0140     optionsGrid->addWidget(d->maskColorLabel,    2, 1, 1, 1);
0141     optionsGrid->addWidget(d->maskColorBtn,   2, 2, 1, 2, Qt::AlignLeft);
0142     optionsGrid->setColumnMinimumWidth(0, 10);
0143     optionsGrid->setColumnStretch(2, 1);
0144     optionsBox->setLayout(optionsGrid);
0145 
0146     // -------------------------------------------------------
0147 
0148     mainLayout->addWidget(headerLabel);
0149     mainLayout->addWidget(separator);
0150     mainLayout->addLayout(profileGrid);
0151     mainLayout->addWidget(optionsBox);
0152 
0153     QVBoxLayout* const vbx = new QVBoxLayout(this);
0154     vbx->addWidget(page);
0155     vbx->addWidget(d->buttons);
0156     setLayout(vbx);
0157 
0158     connect(d->deviceProfileBox, SIGNAL(currentIndexChanged(int)),
0159             this, SLOT(updateOkButtonState()));
0160 
0161     connect(d->gamutCheckBox, SIGNAL(toggled(bool)),
0162             this, SLOT(updateGamutCheckState()));
0163 
0164     connect(d->buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
0165             this, SLOT(slotOk()));
0166 
0167     connect(d->buttons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()),
0168             this, SLOT(reject()));
0169 
0170     connect(d->buttons->button(QDialogButtonBox::Help), SIGNAL(clicked()),
0171             this, SLOT(slotHelp()));
0172 
0173     connect(d->infoProofProfiles, SIGNAL(clicked()),
0174             this, SLOT(slotProfileInfo()));
0175 
0176     readSettings();
0177     updateOkButtonState();
0178     updateGamutCheckState();
0179 }
0180 
0181 SoftProofDialog::~SoftProofDialog()
0182 {
0183     delete d;
0184 }
0185 
0186 bool SoftProofDialog::shallEnableSoftProofView() const
0187 {
0188     return d->switchOn;
0189 }
0190 
0191 void SoftProofDialog::updateGamutCheckState()
0192 {
0193     bool on = d->gamutCheckBox->isChecked();
0194     d->maskColorLabel->setEnabled(on);
0195     d->maskColorBtn->setEnabled(on);
0196 }
0197 
0198 void SoftProofDialog::updateOkButtonState()
0199 {
0200     d->buttons->button(QDialogButtonBox::Ok)->setEnabled(d->deviceProfileBox->currentIndex() != -1);
0201 }
0202 
0203 void SoftProofDialog::readSettings()
0204 {
0205     ICCSettingsContainer settings = IccSettings::instance()->settings();
0206     d->deviceProfileBox->setCurrentProfile(IccProfile(settings.defaultProofProfile));
0207     d->proofingIntentBox->setIntent(settings.proofingRenderingIntent);
0208     d->gamutCheckBox->setChecked(settings.doGamutCheck);
0209     d->maskColorBtn->setColor(settings.gamutCheckMaskColor);
0210 }
0211 
0212 void SoftProofDialog::writeSettings()
0213 {
0214     ICCSettingsContainer settings    = IccSettings::instance()->settings();
0215     settings.defaultProofProfile     = d->deviceProfileBox->currentProfile().filePath();
0216     settings.proofingRenderingIntent = d->proofingIntentBox->intent();
0217     settings.doGamutCheck            = d->gamutCheckBox->isChecked();
0218     settings.gamutCheckMaskColor     = d->maskColorBtn->color();
0219     IccSettings::instance()->setSettings(settings);
0220 }
0221 
0222 void SoftProofDialog::slotProfileInfo()
0223 {
0224     IccProfile profile = d->deviceProfileBox->currentProfile();
0225 
0226     if (profile.isNull())
0227     {
0228         QMessageBox::critical(this, i18nc("@title:window", "Profile Error"), i18n("No profile is selected."));
0229         return;
0230     }
0231 
0232     ICCProfileInfoDlg infoDlg(this, profile.filePath(), profile);
0233     infoDlg.exec();
0234 }
0235 
0236 void SoftProofDialog::slotOk()
0237 {
0238     d->switchOn = true;
0239     writeSettings();
0240     accept();
0241 }
0242 
0243 void SoftProofDialog::slotHelp()
0244 {
0245     openOnlineDocumentation(QLatin1String("color_management"), QLatin1String("printer_profiles"));
0246 }
0247 
0248 } // namespace Digikam
0249 
0250 #include "moc_softproofdialog.cpp"