File indexing completed on 2025-01-05 03:57:56

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-07-18
0007  * Description : setup Metadata tab.
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 "showfotosetupmetadata.h"
0016 
0017 // Qt includes
0018 
0019 #include <QButtonGroup>
0020 #include <QCheckBox>
0021 #include <QFrame>
0022 #include <QGridLayout>
0023 #include <QGroupBox>
0024 #include <QLabel>
0025 #include <QVBoxLayout>
0026 #include <QTabWidget>
0027 #include <QApplication>
0028 #include <QStyle>
0029 #include <QStandardPaths>
0030 #include <QFontDatabase>
0031 #include <QTimer>
0032 
0033 // KDE includes
0034 
0035 #include <klocalizedstring.h>
0036 
0037 // Local includes
0038 
0039 #include "metaengine.h"
0040 #include "metadatapanel.h"
0041 #include "metaenginesettings.h"
0042 #include "dactivelabel.h"
0043 #include "exiftoolconfpanel.h"
0044 
0045 using namespace Digikam;
0046 
0047 namespace ShowFoto
0048 {
0049 
0050 class Q_DECL_HIDDEN ShowfotoSetupMetadata::Private
0051 {
0052 public:
0053 
0054     explicit Private()
0055       : exifRotateBox        (nullptr),
0056         exifSetOrientationBox(nullptr),
0057         tab                  (nullptr),
0058         tagsCfgPanel         (nullptr),
0059         exifToolView         (nullptr)
0060     {
0061     }
0062 
0063     QCheckBox*         exifRotateBox;
0064     QCheckBox*         exifSetOrientationBox;
0065 
0066     QTabWidget*        tab;
0067 
0068     MetadataPanel*     tagsCfgPanel;
0069     ExifToolConfPanel* exifToolView;
0070 };
0071 
0072 ShowfotoSetupMetadata::ShowfotoSetupMetadata(QWidget* const parent)
0073     : QScrollArea(parent),
0074       d          (new Private)
0075 {
0076     d->tab                        = new QTabWidget(viewport());
0077     setWidget(d->tab);
0078     setWidgetResizable(true);
0079 
0080     const int spacing             = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0081                                          QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0082 
0083     QWidget* const panel          = new QWidget(d->tab);
0084     QVBoxLayout* const mainLayout = new QVBoxLayout(panel);
0085 
0086     // --------------------------------------------------------
0087 
0088     QGroupBox* const   rotationAdvGroup  = new QGroupBox(panel);
0089     QGridLayout* const rotationAdvLayout = new QGridLayout(rotationAdvGroup);
0090 
0091     QLabel* const rotationAdvExpl  = new QLabel(i18nc("@label", "Rotate actions"));
0092     QLabel* const rotationAdvIcon  = new QLabel;
0093     rotationAdvIcon->setPixmap(QIcon::fromTheme(QLatin1String("configure")).pixmap(32));
0094 
0095     d->exifRotateBox         = new QCheckBox(rotationAdvGroup);
0096     d->exifRotateBox->setText(i18nc("@option:check", "Show images/thumbnails &rotated according to orientation tag."));
0097     d->exifSetOrientationBox = new QCheckBox(rotationAdvGroup);
0098     d->exifSetOrientationBox->setText(i18nc("@option:check", "Set orientation tag to normal after rotate/flip."));
0099 
0100     rotationAdvLayout->addWidget(rotationAdvIcon,          0, 0, 1, 1);
0101     rotationAdvLayout->addWidget(rotationAdvExpl,          0, 1, 1, 1);
0102     rotationAdvLayout->addWidget(d->exifRotateBox,         1, 0, 1, 3);
0103     rotationAdvLayout->addWidget(d->exifSetOrientationBox, 2, 0, 1, 3);
0104     rotationAdvLayout->setColumnStretch(2, 10);
0105     rotationAdvGroup->setLayout(rotationAdvLayout);
0106 
0107     // --------------------------------------------------------
0108 
0109     QFrame* const box         = new QFrame(panel);
0110     QGridLayout* const grid   = new QGridLayout(box);
0111     box->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
0112 
0113     QLabel* const explanation = new QLabel(box);
0114     explanation->setOpenExternalLinks(true);
0115     explanation->setWordWrap(true);
0116     QString txt;
0117 
0118     txt.append(QString::fromUtf8("<p><a href='https://en.wikipedia.org/wiki/Exif'>Exif</a> - %1</p>")
0119                .arg(i18nc("@info", "a standard used by most digital cameras today to store technical "
0120                           "information (like aperture and shutter speed) about an image.")));
0121 
0122     txt.append(QString::fromUtf8("<p><a href='https://en.wikipedia.org/wiki/IPTC_Information_Interchange_Model'>IPTC</a> - %1</p>")
0123                .arg(i18nc("@info", "an older standard used in digital photography to store "
0124                           "photographer information in images.")));
0125 
0126     if (Digikam::MetaEngine::supportXmp())
0127     {
0128         txt.append(QString::fromUtf8("<p><a href='https://en.wikipedia.org/wiki/Extensible_Metadata_Platform'>XMP</a> - %1</p>")
0129                    .arg(i18nc("@info", "a new standard used in digital photography, designed to replace IPTC.")));
0130     }
0131 
0132     explanation->setText(txt);
0133     explanation->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
0134 
0135     grid->addWidget(explanation, 0, 0, 1, 1);
0136     grid->setColumnStretch(0, 10);
0137     grid->setRowStretch(0, 10);
0138     grid->setContentsMargins(spacing, spacing, spacing, spacing);
0139     grid->setSpacing(0);
0140 
0141     // --------------------------------------------------------
0142 
0143     mainLayout->setContentsMargins(QMargins());
0144     mainLayout->setSpacing(spacing);
0145     mainLayout->addWidget(rotationAdvGroup);
0146     mainLayout->addSpacing(spacing);
0147     mainLayout->addWidget(box);
0148     mainLayout->addStretch();
0149 
0150     d->tab->insertTab(Behavior, panel, i18nc("@title:tab", "Behavior"));
0151 
0152     // --------------------------------------------------------
0153 
0154     d->tagsCfgPanel = new MetadataPanel(d->tab);
0155 
0156     // --------------------------------------------------------
0157 
0158     d->exifToolView = new ExifToolConfPanel(d->tab);
0159     d->tab->insertTab(ExifTool, d->exifToolView, i18nc("@title:tab", "ExifTool"));
0160 
0161     // --------------------------------------------------------
0162 
0163     readSettings();
0164 
0165     QTimer::singleShot(0, d->exifToolView, SLOT(slotStartFoundExifTool()));
0166 }
0167 
0168 ShowfotoSetupMetadata::~ShowfotoSetupMetadata()
0169 {
0170     delete d;
0171 }
0172 
0173 void ShowfotoSetupMetadata::setActiveTab(MetadataTab tab)
0174 {
0175     d->tab->setCurrentIndex(tab);
0176 }
0177 
0178 ShowfotoSetupMetadata::MetadataTab ShowfotoSetupMetadata::activeTab() const
0179 {
0180     return (MetadataTab)d->tab->currentIndex();
0181 }
0182 
0183 void ShowfotoSetupMetadata::applySettings()
0184 {
0185     MetaEngineSettings* const mSettings = MetaEngineSettings::instance();
0186 
0187     if (!mSettings)
0188     {
0189         return;
0190     }
0191 
0192     MetaEngineSettingsContainer set;
0193 
0194     set.exifRotate         = d->exifRotateBox->isChecked();
0195     set.exifSetOrientation = d->exifSetOrientationBox->isChecked();
0196     set.exifToolPath       = d->exifToolView->exifToolDirectory();
0197     mSettings->setSettings(set);
0198 
0199     d->tagsCfgPanel->applySettings();
0200 }
0201 
0202 void ShowfotoSetupMetadata::readSettings()
0203 {
0204     MetaEngineSettings* const mSettings = MetaEngineSettings::instance();
0205 
0206     if (!mSettings)
0207     {
0208         return;
0209     }
0210 
0211     MetaEngineSettingsContainer set     = mSettings->settings();
0212 
0213     d->exifRotateBox->setChecked(set.exifRotate);
0214     d->exifSetOrientationBox->setChecked(set.exifSetOrientation);
0215     d->exifToolView->setExifToolDirectory(set.exifToolPath);
0216 }
0217 
0218 } // namespace ShowFoto
0219 
0220 #include "moc_showfotosetupmetadata.cpp"