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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2007-08-02
0007  * Description : PNG 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 "dimgpngexportsettings.h"
0016 
0017 // Qt includes
0018 
0019 #include <QApplication>
0020 #include <QStyle>
0021 #include <QString>
0022 #include <QLabel>
0023 #include <QLayout>
0024 #include <QGridLayout>
0025 
0026 // KDE includes
0027 
0028 #include <klocalizedstring.h>
0029 
0030 // Local includes
0031 
0032 #include "dnuminput.h"
0033 
0034 namespace Digikam
0035 {
0036 
0037 class Q_DECL_HIDDEN DImgPNGExportSettings::Private
0038 {
0039 
0040 public:
0041 
0042     explicit Private()
0043       : PNGGrid            (nullptr),
0044         labelPNGcompression(nullptr),
0045         PNGcompression     (nullptr)
0046     {
0047     }
0048 
0049     QGridLayout*  PNGGrid;
0050 
0051     QLabel*       labelPNGcompression;
0052 
0053     DIntNumInput* PNGcompression;
0054 };
0055 
0056 DImgPNGExportSettings::DImgPNGExportSettings(QWidget* parent)
0057     : DImgLoaderSettings(parent),
0058       d                 (new Private)
0059 {
0060     const int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0061                              QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0062 
0063     d->PNGGrid        = new QGridLayout(this);
0064     d->PNGcompression = new DIntNumInput(this);
0065     d->PNGcompression->setDefaultValue(6);
0066     d->PNGcompression->setRange(1, 9, 1);
0067     d->labelPNGcompression = new QLabel(i18n("PNG compression:"), this);
0068 
0069     d->PNGcompression->setWhatsThis(i18n("<p>The compression value for PNG images:</p>"
0070                                          "<p><b>1</b>: low compression (large file size but "
0071                                          "short compression duration - default)<br/>"
0072                                          "<b>5</b>: medium compression<br/>"
0073                                          "<b>9</b>: high compression (small file size but "
0074                                          "long compression duration)</p>"
0075                                          "<p><b>Note: PNG is always a lossless image "
0076                                          "compression format.</b></p>"));
0077 
0078     d->PNGGrid->addWidget(d->labelPNGcompression, 0, 0, 1, 2);
0079     d->PNGGrid->addWidget(d->PNGcompression,      1, 1, 1, 2);
0080     d->PNGGrid->setColumnStretch(1, 10);
0081     d->PNGGrid->setRowStretch(2, 10);
0082     d->PNGGrid->setContentsMargins(spacing, spacing, spacing, spacing);
0083     d->PNGGrid->setSpacing(spacing);
0084 
0085     connect(d->PNGcompression, SIGNAL(valueChanged(int)),
0086             this, SIGNAL(signalSettingsChanged()));
0087 }
0088 
0089 DImgPNGExportSettings::~DImgPNGExportSettings()
0090 {
0091     delete d;
0092 }
0093 
0094 void DImgPNGExportSettings::setSettings(const DImgLoaderPrms& set)
0095 {
0096     for (DImgLoaderPrms::const_iterator it = set.constBegin() ; it != set.constEnd() ; ++it)
0097     {
0098         if (it.key() == QLatin1String("quality"))
0099         {
0100             d->PNGcompression->setValue(it.value().toInt());
0101         }
0102     }
0103 }
0104 
0105 DImgLoaderPrms DImgPNGExportSettings::settings() const
0106 {
0107     DImgLoaderPrms set;
0108     set.insert(QLatin1String("quality"),  d->PNGcompression->value());
0109 
0110     return set;
0111 }
0112 
0113 } // namespace Digikam
0114 
0115 #include "moc_dimgpngexportsettings.cpp"