1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2009-07-18
7 * Description : setup Metadata tab.
8 *
9 * Copyright (C) 2009-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10 *
11 * This program is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General
13 * Public License as published by the Free Software Foundation;
14 * either version 2, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * ============================================================ */
23
24 #include "showfotosetupmetadata.h"
25
26 // Qt includes
27
28 #include <QButtonGroup>
29 #include <QCheckBox>
30 #include <QFrame>
31 #include <QGridLayout>
32 #include <QGroupBox>
33 #include <QLabel>
34 #include <QVBoxLayout>
35 #include <QTabWidget>
36 #include <QApplication>
37 #include <QStyle>
38 #include <QStandardPaths>
39 #include <QFontDatabase>
40
41 // KDE includes
42
43 #include <klocalizedstring.h>
44
45 // Local includes
46
47 #include "metaengine.h"
48 #include "metadatapanel.h"
49 #include "metaenginesettings.h"
50 #include "dactivelabel.h"
51 #include "exiftoolconfpanel.h"
52
53 using namespace Digikam;
54
55 namespace ShowFoto
56 {
57
58 class Q_DECL_HIDDEN ShowfotoSetupMetadata::Private
59 {
60 public:
61
Private()62 explicit Private()
63 : exifRotateBox (nullptr),
64 exifSetOrientationBox(nullptr),
65 tab (nullptr),
66 tagsCfgPanel (nullptr),
67 exifToolView (nullptr)
68 {
69 }
70
71 QCheckBox* exifRotateBox;
72 QCheckBox* exifSetOrientationBox;
73
74 QTabWidget* tab;
75
76 MetadataPanel* tagsCfgPanel;
77 ExifToolConfPanel* exifToolView;
78 };
79
ShowfotoSetupMetadata(QWidget * const parent)80 ShowfotoSetupMetadata::ShowfotoSetupMetadata(QWidget* const parent)
81 : QScrollArea(parent),
82 d (new Private)
83 {
84 d->tab = new QTabWidget(viewport());
85 setWidget(d->tab);
86 setWidgetResizable(true);
87
88 const int spacing = QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing);
89
90 QWidget* const panel = new QWidget(d->tab);
91 QVBoxLayout* const mainLayout = new QVBoxLayout(panel);
92
93 // --------------------------------------------------------
94
95 QGroupBox* const rotationAdvGroup = new QGroupBox(panel);
96 QGridLayout* const rotationAdvLayout = new QGridLayout(rotationAdvGroup);
97
98 QLabel* const rotationAdvExpl = new QLabel(i18nc("@label", "Rotate actions"));
99 QLabel* const rotationAdvIcon = new QLabel;
100 rotationAdvIcon->setPixmap(QIcon::fromTheme(QLatin1String("configure")).pixmap(32));
101
102 d->exifRotateBox = new QCheckBox(rotationAdvGroup);
103 d->exifRotateBox->setText(i18nc("@option:check", "Show images/thumbnails &rotated according to orientation tag."));
104 d->exifSetOrientationBox = new QCheckBox(rotationAdvGroup);
105 d->exifSetOrientationBox->setText(i18nc("@option:check", "Set orientation tag to normal after rotate/flip."));
106
107 rotationAdvLayout->addWidget(rotationAdvIcon, 0, 0, 1, 1);
108 rotationAdvLayout->addWidget(rotationAdvExpl, 0, 1, 1, 1);
109 rotationAdvLayout->addWidget(d->exifRotateBox, 1, 0, 1, 3);
110 rotationAdvLayout->addWidget(d->exifSetOrientationBox, 2, 0, 1, 3);
111 rotationAdvLayout->setColumnStretch(2, 10);
112 rotationAdvGroup->setLayout(rotationAdvLayout);
113
114 // --------------------------------------------------------
115
116 QFrame* const box = new QFrame(panel);
117 QGridLayout* const grid = new QGridLayout(box);
118 box->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
119
120 DActiveLabel* const exiv2LogoLabel = new DActiveLabel(QUrl(QLatin1String("https://www.exiv2.org")),
121 QStandardPaths::locate(QStandardPaths::GenericDataLocation,
122 QLatin1String("digikam/data/logo-exiv2.png")),
123 box);
124 exiv2LogoLabel->setWhatsThis(i18nc("@info:whatsthis", "Visit Exiv2 project website"));
125
126 QLabel* const explanation = new QLabel(box);
127 explanation->setOpenExternalLinks(true);
128 explanation->setWordWrap(true);
129 QString txt;
130
131 txt.append(QString::fromUtf8("<p><a href='https://en.wikipedia.org/wiki/Exif'>Exif</a> - %1</p>")
132 .arg(i18nc("@info", "a standard used by most digital cameras today to store technical "
133 "information (like aperture and shutter speed) about an image.")));
134
135 txt.append(QString::fromUtf8("<p><a href='https://en.wikipedia.org/wiki/IPTC_Information_Interchange_Model'>IPTC</a> - %1</p>")
136 .arg(i18nc("@info", "an older standard used in digital photography to store "
137 "photographer information in images.")));
138
139 if (Digikam::MetaEngine::supportXmp())
140 {
141 txt.append(QString::fromUtf8("<p><a href='https://en.wikipedia.org/wiki/Extensible_Metadata_Platform'>XMP</a> - %1</p>")
142 .arg(i18nc("@info", "a new standard used in digital photography, designed to replace IPTC.")));
143 }
144
145 explanation->setText(txt);
146 explanation->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
147
148 grid->addWidget(exiv2LogoLabel, 0, 0, 1, 1);
149 grid->addWidget(explanation, 0, 1, 1, 2);
150 grid->setColumnStretch(1, 10);
151 grid->setContentsMargins(spacing, spacing, spacing, spacing);
152 grid->setSpacing(0);
153
154 // --------------------------------------------------------
155
156 mainLayout->setContentsMargins(QMargins());
157 mainLayout->setSpacing(spacing);
158 mainLayout->addWidget(rotationAdvGroup);
159 mainLayout->addSpacing(spacing);
160 mainLayout->addWidget(box);
161 mainLayout->addStretch();
162
163 d->tab->insertTab(Behavior, panel, i18nc("@title:tab", "Behavior"));
164
165 // --------------------------------------------------------
166
167 d->tagsCfgPanel = new MetadataPanel(d->tab);
168
169 // --------------------------------------------------------
170
171 d->exifToolView = new ExifToolConfPanel(d->tab);
172 d->tab->insertTab(ExifTool, d->exifToolView, i18nc("@title:tab", "ExifTool"));
173
174 // --------------------------------------------------------
175
176 readSettings();
177 }
178
~ShowfotoSetupMetadata()179 ShowfotoSetupMetadata::~ShowfotoSetupMetadata()
180 {
181 delete d;
182 }
183
applySettings()184 void ShowfotoSetupMetadata::applySettings()
185 {
186 MetaEngineSettings* const mSettings = MetaEngineSettings::instance();
187
188 if (!mSettings)
189 {
190 return;
191 }
192
193 MetaEngineSettingsContainer set;
194
195 set.exifRotate = d->exifRotateBox->isChecked();
196 set.exifSetOrientation = d->exifSetOrientationBox->isChecked();
197 set.exifToolPath = d->exifToolView->exifToolDirectory();
198 mSettings->setSettings(set);
199
200 d->tagsCfgPanel->applySettings();
201 }
202
readSettings()203 void ShowfotoSetupMetadata::readSettings()
204 {
205 MetaEngineSettings* const mSettings = MetaEngineSettings::instance();
206
207 if (!mSettings)
208 {
209 return;
210 }
211
212 MetaEngineSettingsContainer set = mSettings->settings();
213
214 d->exifRotateBox->setChecked(set.exifRotate);
215 d->exifSetOrientationBox->setChecked(set.exifSetOrientation);
216 d->exifToolView->setExifToolDirectory(set.exifToolPath);
217 }
218
setActiveTab(MetadataTab tab)219 void ShowfotoSetupMetadata::setActiveTab(MetadataTab tab)
220 {
221 d->tab->setCurrentIndex(tab);
222 }
223
224 } // namespace ShowFoto
225