File indexing completed on 2025-01-05 04:00:11
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2006-01-23 0007 * Description : setup image editor output files settings. 0008 * 0009 * SPDX-FileCopyrightText: 2006-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 "setupiofiles.h" 0016 0017 // Qt includes 0018 0019 #include <QCheckBox> 0020 #include <QGroupBox> 0021 #include <QVBoxLayout> 0022 0023 // KDE includes 0024 0025 #include <kconfiggroup.h> 0026 #include <ksharedconfig.h> 0027 #include <klocalizedstring.h> 0028 0029 // Local includes 0030 0031 #include "digikam_config.h" 0032 #include "dpluginloader.h" 0033 0034 namespace Digikam 0035 { 0036 0037 class Q_DECL_HIDDEN SetupIOFiles::Private 0038 { 0039 public: 0040 0041 explicit Private() 0042 : JPEGOptions (nullptr), 0043 PNGOptions (nullptr), 0044 TIFFOptions (nullptr), 0045 0046 #ifdef HAVE_JASPER 0047 0048 JPEG2000Options (nullptr), 0049 0050 #endif // HAVE_JASPER 0051 0052 PGFOptions (nullptr), 0053 0054 #ifdef HAVE_X265 0055 0056 HEIFOptions (nullptr), 0057 0058 #endif // HAVE_X265 0059 0060 JXLOptions (nullptr), 0061 WEBPOptions (nullptr), 0062 AVIFOptions (nullptr), 0063 showImageSettingsDialog (nullptr) 0064 { 0065 } 0066 0067 QWidget* createGroupBox(QWidget* const w) const 0068 { 0069 QGroupBox* const box = new QGroupBox; 0070 QVBoxLayout* const layout = new QVBoxLayout; 0071 layout->addWidget(w); 0072 box->setLayout(layout); 0073 0074 return box; 0075 } 0076 0077 public: 0078 0079 static const QString configGroupName; 0080 static const QString configJPEGCompressionEntry; 0081 static const QString configJPEGSubSamplingEntry; 0082 static const QString configPNGCompressionEntry; 0083 static const QString configTIFFCompressionEntry; 0084 static const QString configJPEG2000CompressionEntry; 0085 static const QString configJPEG2000LossLessEntry; 0086 static const QString configPGFCompressionEntry; 0087 static const QString configPGFLossLessEntry; 0088 static const QString configHEIFCompressionEntry; 0089 static const QString configHEIFLossLessEntry; 0090 static const QString configShowImageSettingsDialog; 0091 static const QString configJXLCompressionEntry; 0092 static const QString configJXLLossLessEntry; 0093 static const QString configWEBPCompressionEntry; 0094 static const QString configWEBPLossLessEntry; 0095 static const QString configAVIFCompressionEntry; 0096 static const QString configAVIFLossLessEntry; 0097 0098 DImgLoaderSettings* JPEGOptions; 0099 DImgLoaderSettings* PNGOptions; 0100 DImgLoaderSettings* TIFFOptions; 0101 0102 #ifdef HAVE_JASPER 0103 0104 DImgLoaderSettings* JPEG2000Options; 0105 0106 #endif // HAVE_JASPER 0107 0108 DImgLoaderSettings* PGFOptions; 0109 0110 #ifdef HAVE_X265 0111 0112 DImgLoaderSettings* HEIFOptions; 0113 0114 #endif // HAVE_X265 0115 0116 DImgLoaderSettings* JXLOptions; 0117 DImgLoaderSettings* WEBPOptions; 0118 DImgLoaderSettings* AVIFOptions; 0119 QCheckBox* showImageSettingsDialog; 0120 }; 0121 0122 const QString SetupIOFiles::Private::configGroupName(QLatin1String("ImageViewer Settings")); 0123 const QString SetupIOFiles::Private::configJPEGCompressionEntry(QLatin1String("JPEGCompression")); 0124 const QString SetupIOFiles::Private::configJPEGSubSamplingEntry(QLatin1String("JPEGSubSampling")); 0125 const QString SetupIOFiles::Private::configPNGCompressionEntry(QLatin1String("PNGCompression")); 0126 const QString SetupIOFiles::Private::configTIFFCompressionEntry(QLatin1String("TIFFCompression")); 0127 const QString SetupIOFiles::Private::configJPEG2000CompressionEntry(QLatin1String("JPEG2000Compression")); 0128 const QString SetupIOFiles::Private::configJPEG2000LossLessEntry(QLatin1String("JPEG2000LossLess")); 0129 const QString SetupIOFiles::Private::configPGFCompressionEntry(QLatin1String("PGFCompression")); 0130 const QString SetupIOFiles::Private::configPGFLossLessEntry(QLatin1String("PGFLossLess")); 0131 const QString SetupIOFiles::Private::configHEIFCompressionEntry(QLatin1String("HEIFCompression")); 0132 const QString SetupIOFiles::Private::configHEIFLossLessEntry(QLatin1String("HEIFLossLess")); 0133 const QString SetupIOFiles::Private::configShowImageSettingsDialog(QLatin1String("ShowImageSettingsDialog")); 0134 const QString SetupIOFiles::Private::configJXLCompressionEntry(QLatin1String("JXLCompression")); 0135 const QString SetupIOFiles::Private::configJXLLossLessEntry(QLatin1String("JXLLossLess")); 0136 const QString SetupIOFiles::Private::configWEBPCompressionEntry(QLatin1String("WEBPCompression")); 0137 const QString SetupIOFiles::Private::configWEBPLossLessEntry(QLatin1String("WEBPLossLess")); 0138 const QString SetupIOFiles::Private::configAVIFCompressionEntry(QLatin1String("AVIFCompression")); 0139 const QString SetupIOFiles::Private::configAVIFLossLessEntry(QLatin1String("AVIFLossLess")); 0140 0141 // -------------------------------------------------------- 0142 0143 SetupIOFiles::SetupIOFiles(QWidget* const parent) 0144 : QScrollArea(parent), 0145 d (new Private) 0146 { 0147 QWidget* const panel = new QWidget; 0148 QVBoxLayout* const vbox = new QVBoxLayout; 0149 DPluginLoader* const ploader = DPluginLoader::instance(); 0150 0151 d->JPEGOptions = ploader->exportWidget(QLatin1String("JPEG")); 0152 0153 if (d->JPEGOptions) 0154 { 0155 d->JPEGOptions->setParent(this); 0156 } 0157 0158 d->PNGOptions = ploader->exportWidget(QLatin1String("PNG")); 0159 0160 if (d->PNGOptions) 0161 { 0162 d->PNGOptions->setParent(this); 0163 } 0164 0165 d->TIFFOptions = ploader->exportWidget(QLatin1String("TIFF")); 0166 0167 if (d->TIFFOptions) 0168 { 0169 d->TIFFOptions->setParent(this); 0170 } 0171 0172 #ifdef HAVE_JASPER 0173 0174 d->JPEG2000Options = ploader->exportWidget(QLatin1String("JP2")); 0175 0176 if (d->JPEG2000Options) 0177 { 0178 d->JPEG2000Options->setParent(this); 0179 } 0180 0181 #endif // HAVE_JASPER 0182 0183 d->PGFOptions = ploader->exportWidget(QLatin1String("PGF")); 0184 0185 if (d->PGFOptions) 0186 { 0187 d->PGFOptions->setParent(this); 0188 } 0189 0190 #ifdef HAVE_X265 0191 0192 d->HEIFOptions = ploader->exportWidget(QLatin1String("HEIF")); 0193 0194 if (d->HEIFOptions) 0195 { 0196 d->HEIFOptions->setParent(this); 0197 } 0198 0199 #endif // HAVE_X265 0200 0201 d->JXLOptions = ploader->exportWidget(QLatin1String("JXL")); 0202 0203 if (d->JXLOptions) 0204 { 0205 d->JXLOptions->setParent(this); 0206 } 0207 0208 d->WEBPOptions = ploader->exportWidget(QLatin1String("WEBP")); 0209 0210 if (d->WEBPOptions) 0211 { 0212 d->WEBPOptions->setParent(this); 0213 } 0214 0215 d->AVIFOptions = ploader->exportWidget(QLatin1String("AVIF")); 0216 0217 if (d->AVIFOptions) 0218 { 0219 d->AVIFOptions->setParent(this); 0220 } 0221 0222 // Show Settings Dialog Option 0223 0224 d->showImageSettingsDialog = new QCheckBox(panel); 0225 d->showImageSettingsDialog->setText(i18n("Show Settings Dialog when Saving Image Files")); 0226 d->showImageSettingsDialog->setWhatsThis(i18n("<ul><li>Checked: A dialog where settings can be changed when saving image files</li>" 0227 "<li>Unchecked: Default settings are used when saving image files</li></ul>")); 0228 0229 if (d->JPEGOptions) 0230 { 0231 vbox->addWidget(d->createGroupBox(d->JPEGOptions)); 0232 } 0233 0234 if (d->PNGOptions) 0235 { 0236 vbox->addWidget(d->createGroupBox(d->PNGOptions)); 0237 } 0238 0239 if (d->TIFFOptions) 0240 { 0241 vbox->addWidget(d->createGroupBox(d->TIFFOptions)); 0242 } 0243 0244 #ifdef HAVE_JASPER 0245 0246 if (d->JPEG2000Options) 0247 { 0248 vbox->addWidget(d->createGroupBox(d->JPEG2000Options)); 0249 } 0250 0251 #endif // HAVE_JASPER 0252 0253 if (d->PGFOptions) 0254 { 0255 vbox->addWidget(d->createGroupBox(d->PGFOptions)); 0256 } 0257 0258 #ifdef HAVE_X265 0259 0260 if (d->HEIFOptions) 0261 { 0262 vbox->addWidget(d->createGroupBox(d->HEIFOptions)); 0263 } 0264 0265 #endif // HAVE_265 0266 0267 if (d->JXLOptions) 0268 { 0269 vbox->addWidget(d->createGroupBox(d->JXLOptions)); 0270 } 0271 0272 if (d->WEBPOptions) 0273 { 0274 vbox->addWidget(d->createGroupBox(d->WEBPOptions)); 0275 } 0276 0277 if (d->AVIFOptions) 0278 { 0279 vbox->addWidget(d->createGroupBox(d->AVIFOptions)); 0280 } 0281 0282 vbox->addWidget(d->createGroupBox(d->showImageSettingsDialog)); 0283 vbox->addStretch(); 0284 0285 panel->setLayout(vbox); 0286 setWidget(panel); 0287 setWidgetResizable(true); 0288 0289 // -------------------------------------------------------- 0290 0291 readSettings(); 0292 } 0293 0294 SetupIOFiles::~SetupIOFiles() 0295 { 0296 delete d; 0297 } 0298 0299 void SetupIOFiles::applySettings() 0300 { 0301 KSharedConfig::Ptr config = KSharedConfig::openConfig(); 0302 KConfigGroup group = config->group(d->configGroupName); 0303 0304 if (d->JPEGOptions) 0305 { 0306 group.writeEntry(d->configJPEGCompressionEntry, d->JPEGOptions->settings()[QLatin1String("quality")].toInt()); 0307 group.writeEntry(d->configJPEGSubSamplingEntry, d->JPEGOptions->settings()[QLatin1String("subsampling")].toInt()); 0308 } 0309 0310 // --- 0311 0312 if (d->PNGOptions) 0313 { 0314 group.writeEntry(d->configPNGCompressionEntry, d->PNGOptions->settings()[QLatin1String("quality")].toInt()); 0315 } 0316 0317 // --- 0318 0319 if (d->TIFFOptions) 0320 { 0321 group.writeEntry(d->configTIFFCompressionEntry, d->TIFFOptions->settings()[QLatin1String("compress")].toBool()); 0322 } 0323 0324 #ifdef HAVE_JASPER 0325 0326 if (d->JPEG2000Options) 0327 { 0328 group.writeEntry(d->configJPEG2000CompressionEntry, d->JPEG2000Options->settings()[QLatin1String("quality")].toInt()); 0329 group.writeEntry(d->configJPEG2000LossLessEntry, d->JPEG2000Options->settings()[QLatin1String("lossless")].toBool()); 0330 } 0331 0332 #endif // HAVE_JASPER 0333 0334 if (d->PGFOptions) 0335 { 0336 group.writeEntry(d->configPGFCompressionEntry, d->PGFOptions->settings()[QLatin1String("quality")].toInt()); 0337 group.writeEntry(d->configPGFLossLessEntry, d->PGFOptions->settings()[QLatin1String("lossless")].toBool()); 0338 } 0339 0340 #ifdef HAVE_X265 0341 0342 if (d->HEIFOptions) 0343 { 0344 group.writeEntry(d->configHEIFCompressionEntry, d->HEIFOptions->settings()[QLatin1String("quality")].toInt()); 0345 group.writeEntry(d->configHEIFLossLessEntry, d->HEIFOptions->settings()[QLatin1String("lossless")].toBool()); 0346 } 0347 0348 #endif // HAVE_X265 0349 0350 if (d->JXLOptions) 0351 { 0352 group.writeEntry(d->configJXLCompressionEntry, d->JXLOptions->settings()[QLatin1String("quality")].toInt()); 0353 group.writeEntry(d->configJXLLossLessEntry, d->JXLOptions->settings()[QLatin1String("lossless")].toBool()); 0354 } 0355 0356 if (d->WEBPOptions) 0357 { 0358 group.writeEntry(d->configWEBPCompressionEntry, d->WEBPOptions->settings()[QLatin1String("quality")].toInt()); 0359 group.writeEntry(d->configWEBPLossLessEntry, d->WEBPOptions->settings()[QLatin1String("lossless")].toBool()); 0360 } 0361 0362 if (d->AVIFOptions) 0363 { 0364 group.writeEntry(d->configAVIFCompressionEntry, d->AVIFOptions->settings()[QLatin1String("quality")].toInt()); 0365 group.writeEntry(d->configAVIFLossLessEntry, d->AVIFOptions->settings()[QLatin1String("lossless")].toBool()); 0366 } 0367 0368 group.writeEntry(d->configShowImageSettingsDialog, d->showImageSettingsDialog->isChecked()); 0369 config->sync(); 0370 } 0371 0372 void SetupIOFiles::readSettings() 0373 { 0374 DImgLoaderPrms set; 0375 0376 KSharedConfig::Ptr config = KSharedConfig::openConfig(); 0377 KConfigGroup group = config->group(d->configGroupName); 0378 0379 if (d->JPEGOptions) 0380 { 0381 set.clear(); 0382 set.insert(QLatin1String("quality"), group.readEntry(d->configJPEGCompressionEntry, 75)); 0383 set.insert(QLatin1String("subsampling"), group.readEntry(d->configJPEGSubSamplingEntry, 1)); // Medium sub-sampling 0384 d->JPEGOptions->setSettings(set); 0385 } 0386 0387 // --- 0388 0389 if (d->PNGOptions) 0390 { 0391 set.clear(); 0392 set.insert(QLatin1String("quality"), group.readEntry(d->configPNGCompressionEntry, 9)); 0393 d->PNGOptions->setSettings(set); 0394 } 0395 0396 // --- 0397 0398 if (d->TIFFOptions) 0399 { 0400 set.clear(); 0401 set.insert(QLatin1String("compress"), group.readEntry(d->configTIFFCompressionEntry, false)); 0402 d->TIFFOptions->setSettings(set); 0403 } 0404 0405 #ifdef HAVE_JASPER 0406 0407 if (d->JPEG2000Options) 0408 { 0409 set.clear(); 0410 set.insert(QLatin1String("quality"), group.readEntry(d->configJPEG2000CompressionEntry, 75)); 0411 set.insert(QLatin1String("lossless"), group.readEntry(d->configJPEG2000LossLessEntry, true)); 0412 d->JPEG2000Options->setSettings(set); 0413 } 0414 0415 #endif // HAVE_JASPER 0416 0417 if (d->PGFOptions) 0418 { 0419 set.clear(); 0420 set.insert(QLatin1String("quality"), group.readEntry(d->configPGFCompressionEntry, 3)); 0421 set.insert(QLatin1String("lossless"), group.readEntry(d->configPGFLossLessEntry, true)); 0422 d->PGFOptions->setSettings(set); 0423 } 0424 0425 #ifdef HAVE_X265 0426 0427 if (d->HEIFOptions) 0428 { 0429 set.clear(); 0430 set.insert(QLatin1String("quality"), group.readEntry(d->configHEIFCompressionEntry, 75)); 0431 set.insert(QLatin1String("lossless"), group.readEntry(d->configHEIFLossLessEntry, true)); 0432 d->HEIFOptions->setSettings(set); 0433 } 0434 0435 #endif // HAVE_X265 0436 0437 if (d->JXLOptions) 0438 { 0439 set.clear(); 0440 set.insert(QLatin1String("quality"), group.readEntry(d->configJXLCompressionEntry, 75)); 0441 set.insert(QLatin1String("lossless"), group.readEntry(d->configJXLLossLessEntry, true)); 0442 d->JXLOptions->setSettings(set); 0443 } 0444 0445 if (d->WEBPOptions) 0446 { 0447 set.clear(); 0448 set.insert(QLatin1String("quality"), group.readEntry(d->configWEBPCompressionEntry, 75)); 0449 set.insert(QLatin1String("lossless"), group.readEntry(d->configWEBPLossLessEntry, true)); 0450 d->WEBPOptions->setSettings(set); 0451 } 0452 0453 if (d->AVIFOptions) 0454 { 0455 set.clear(); 0456 set.insert(QLatin1String("quality"), group.readEntry(d->configAVIFCompressionEntry, 75)); 0457 set.insert(QLatin1String("lossless"), group.readEntry(d->configAVIFLossLessEntry, true)); 0458 d->AVIFOptions->setSettings(set); 0459 } 0460 0461 d->showImageSettingsDialog->setChecked(group.readEntry(d->configShowImageSettingsDialog, true)); 0462 } 0463 0464 } // namespace Digikam 0465 0466 #include "moc_setupiofiles.cpp"