File indexing completed on 2025-01-19 03:51:00

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2007-08-02
0007  * Description : JPEG-2000 image export settings widget.
0008  *
0009  * SPDX-FileCopyrightText: 2007-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "dimgjpeg2000exportsettings.h"
0016 
0017 // Qt includes
0018 
0019 #include <QString>
0020 #include <QLabel>
0021 #include <QCheckBox>
0022 #include <QLayout>
0023 #include <QGridLayout>
0024 #include <QApplication>
0025 #include <QStyle>
0026 
0027 // KDE includes
0028 
0029 #include <klocalizedstring.h>
0030 
0031 // Local includes
0032 
0033 #include "dnuminput.h"
0034 
0035 namespace Digikam
0036 {
0037 
0038 class Q_DECL_HIDDEN DImgJPEG2000ExportSettings::Private
0039 {
0040 
0041 public:
0042 
0043     explicit Private()
0044       : JPEG2000Grid            (nullptr),
0045         labelJPEG2000compression(nullptr),
0046         JPEG2000LossLess        (nullptr),
0047         JPEG2000compression     (nullptr)
0048     {
0049     }
0050 
0051     QGridLayout*  JPEG2000Grid;
0052 
0053     QLabel*       labelJPEG2000compression;
0054 
0055     QCheckBox*    JPEG2000LossLess;
0056 
0057     DIntNumInput* JPEG2000compression;
0058 };
0059 
0060 DImgJPEG2000ExportSettings::DImgJPEG2000ExportSettings(QWidget* const parent)
0061     : DImgLoaderSettings(parent),
0062       d                 (new Private)
0063 {
0064     const int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0065                              QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0066 
0067     d->JPEG2000Grid     = new QGridLayout(this);
0068     d->JPEG2000LossLess = new QCheckBox(i18n("Lossless JPEG 2000 files"), this);
0069 
0070     d->JPEG2000LossLess->setWhatsThis(i18n("<p>Toggle lossless compression for JPEG 2000 images.</p>"
0071                                            "<p>If this option is enabled, a lossless method will be used "
0072                                            "to compress JPEG 2000 pictures.</p>"));
0073 
0074     d->JPEG2000compression = new DIntNumInput(this);
0075     d->JPEG2000compression->setDefaultValue(75);
0076     d->JPEG2000compression->setRange(1, 100, 1);
0077     d->labelJPEG2000compression = new QLabel(i18n("JPEG 2000 quality:"), this);
0078 
0079     d->JPEG2000compression->setWhatsThis(i18n("<p>The quality value for JPEG 2000 images:</p>"
0080                                               "<p><b>1</b>: low quality (high compression and small "
0081                                               "file size)<br/>"
0082                                               "<b>50</b>: medium quality<br/>"
0083                                               "<b>75</b>: good quality (default)<br/>"
0084                                               "<b>100</b>: high quality (no compression and "
0085                                               "large file size)</p>"
0086                                               "<p><b>Note: JPEG 2000 is not a lossless image "
0087                                               "compression format when you use this setting.</b></p>"));
0088 
0089     d->JPEG2000Grid->addWidget(d->JPEG2000LossLess,         0, 0, 1, 2);
0090     d->JPEG2000Grid->addWidget(d->labelJPEG2000compression, 1, 0, 1, 2);
0091     d->JPEG2000Grid->addWidget(d->JPEG2000compression,      2, 0, 1, 2);
0092     d->JPEG2000Grid->setColumnStretch(1, 10);
0093     d->JPEG2000Grid->setRowStretch(3, 10);
0094     d->JPEG2000Grid->setContentsMargins(spacing, spacing, spacing, spacing);
0095     d->JPEG2000Grid->setSpacing(spacing);
0096 
0097     connect(d->JPEG2000LossLess, SIGNAL(toggled(bool)),
0098             this, SLOT(slotToggleJPEG2000LossLess(bool)));
0099 
0100     connect(d->JPEG2000LossLess, SIGNAL(toggled(bool)),
0101             this, SIGNAL(signalSettingsChanged()));
0102 
0103     connect(d->JPEG2000compression, SIGNAL(valueChanged(int)),
0104             this, SIGNAL(signalSettingsChanged()));
0105 }
0106 
0107 DImgJPEG2000ExportSettings::~DImgJPEG2000ExportSettings()
0108 {
0109     delete d;
0110 }
0111 
0112 void DImgJPEG2000ExportSettings::setSettings(const DImgLoaderPrms& set)
0113 {
0114     for (DImgLoaderPrms::const_iterator it = set.constBegin() ; it != set.constEnd() ; ++it)
0115     {
0116         if      (it.key() == QLatin1String("quality"))
0117         {
0118             d->JPEG2000compression->setValue(it.value().toInt());
0119         }
0120         else if (it.key() == QLatin1String("lossless"))
0121         {
0122             d->JPEG2000LossLess->setChecked(it.value().toBool());
0123         }
0124     }
0125 
0126     slotToggleJPEG2000LossLess(d->JPEG2000LossLess->isChecked());
0127 }
0128 
0129 DImgLoaderPrms DImgJPEG2000ExportSettings::settings() const
0130 {
0131     DImgLoaderPrms set;
0132     set.insert(QLatin1String("quality"),  d->JPEG2000compression->value());
0133     set.insert(QLatin1String("lossless"), d->JPEG2000LossLess->isChecked());
0134 
0135     return set;
0136 }
0137 
0138 void DImgJPEG2000ExportSettings::slotToggleJPEG2000LossLess(bool b)
0139 {
0140     d->JPEG2000compression->setEnabled(!b);
0141     d->labelJPEG2000compression->setEnabled(!b);
0142 }
0143 
0144 } // namespace Digikam
0145 
0146 #include "moc_dimgjpeg2000exportsettings.cpp"