File indexing completed on 2025-01-19 03:50:59
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-02-10 0007 * Description : flip image batch tool. 0008 * 0009 * SPDX-FileCopyrightText: 2009-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 "flip.h" 0016 0017 // Qt includes 0018 0019 #include <QLabel> 0020 #include <QWidget> 0021 #include <QComboBox> 0022 0023 // KDE includes 0024 0025 #include <klocalizedstring.h> 0026 0027 // Local includes 0028 0029 #include "dlayoutbox.h" 0030 #include "digikam_debug.h" 0031 #include "dimg.h" 0032 #include "dimgbuiltinfilter.h" 0033 #include "jpegutils.h" 0034 0035 namespace DigikamBqmFlipPlugin 0036 { 0037 0038 Flip::Flip(QObject* const parent) 0039 : BatchTool(QLatin1String("Flip"), TransformTool, parent), 0040 m_comboBox(nullptr) 0041 { 0042 } 0043 0044 Flip::~Flip() 0045 { 0046 } 0047 0048 BatchTool* Flip::clone(QObject* const parent) const 0049 { 0050 return new Flip(parent); 0051 } 0052 0053 void Flip::registerSettingsWidget() 0054 { 0055 DVBox* const vbox = new DVBox; 0056 QLabel* const label = new QLabel(vbox); 0057 m_comboBox = new QComboBox(vbox); 0058 m_comboBox->insertItem(DImg::HORIZONTAL, i18nc("@item: orientation", "Horizontal")); 0059 m_comboBox->insertItem(DImg::VERTICAL, i18nc("@item: orientation", "Vertical")); 0060 label->setText(i18nc("@label", "Flip:")); 0061 QLabel* const space = new QLabel(vbox); 0062 vbox->setStretchFactor(space, 10); 0063 0064 m_settingsWidget = vbox; 0065 0066 setNeedResetExifOrientation(true); 0067 0068 connect(m_comboBox, SIGNAL(activated(int)), 0069 this, SLOT(slotSettingsChanged())); 0070 0071 BatchTool::registerSettingsWidget(); 0072 } 0073 0074 BatchToolSettings Flip::defaultSettings() 0075 { 0076 BatchToolSettings settings; 0077 settings.insert(QLatin1String("Flip"), DImg::HORIZONTAL); 0078 0079 return settings; 0080 } 0081 0082 void Flip::slotAssignSettings2Widget() 0083 { 0084 m_comboBox->setCurrentIndex(settings()[QLatin1String("Flip")].toInt()); 0085 } 0086 0087 void Flip::slotSettingsChanged() 0088 { 0089 BatchToolSettings settings; 0090 settings.insert(QLatin1String("Flip"), m_comboBox->currentIndex()); 0091 BatchTool::slotSettingsChanged(settings); 0092 } 0093 0094 bool Flip::toolOperations() 0095 { 0096 DImg::FLIP flip = (DImg::FLIP)(settings()[QLatin1String("Flip")].toInt()); 0097 0098 if (JPEGUtils::isJpegImage(inputUrl().toLocalFile()) && image().isNull()) 0099 { 0100 JPEGUtils::JpegRotator rotator(inputUrl().toLocalFile()); 0101 rotator.setDestinationFile(outputUrl().toLocalFile()); 0102 0103 switch (flip) 0104 { 0105 case DImg::HORIZONTAL: 0106 { 0107 return rotator.exifTransform(MetaEngineRotation::FlipHorizontal); 0108 } 0109 0110 case DImg::VERTICAL: 0111 { 0112 return rotator.exifTransform(MetaEngineRotation::FlipVertical); 0113 } 0114 0115 default: 0116 { 0117 qCDebug(DIGIKAM_DPLUGIN_BQM_LOG) << "Unknown flip action"; 0118 return false; 0119 } 0120 } 0121 } 0122 0123 if (!loadToDImg()) 0124 { 0125 return false; 0126 } 0127 0128 DImgBuiltinFilter filter; 0129 0130 switch (flip) 0131 { 0132 case DImg::HORIZONTAL: 0133 { 0134 filter = DImgBuiltinFilter(DImgBuiltinFilter::FlipHorizontally); 0135 break; 0136 } 0137 0138 case DImg::VERTICAL: 0139 { 0140 filter = DImgBuiltinFilter(DImgBuiltinFilter::FlipVertically); 0141 break; 0142 } 0143 } 0144 0145 applyFilter(&filter); 0146 0147 return (savefromDImg()); 0148 } 0149 0150 } // namespace DigikamBqmFlipPlugin 0151 0152 #include "moc_flip.cpp"