Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_meta_data_editor.cc
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2007, 2010 Cyrille Berger <cberger@cberger.net>
3 * SPDX-FileCopyrightText: 2021 L. E. Segovia <amy@amyspark.me>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7
9
10#include <QDomDocument>
11#include <QFile>
12#include <QHeaderView>
13#include <QTableView>
14
15#include <KoResourcePaths.h>
16#include <kis_debug.h>
17#include <kis_icon.h>
18#include <kis_meta_data_entry.h>
21#include <kis_meta_data_store.h>
22#include <kis_meta_data_value.h>
23#include <klocalizedstring.h>
24
25#include "kis_entry_editor.h"
26#include "kis_meta_data_model.h"
27
28
34
35#define GET_VALUE(entryName, wdg, wdgPropertyName, editorSignal) \
36 QString key = schema->generateQualifiedName(#entryName); \
37 KisEntryEditor *ee = new KisEntryEditor(wdg, d->temporaryStorage, key, #wdgPropertyName, QString(), 0); \
38 connect(wdg, editorSignal, ee, &KisEntryEditor::valueEdited); \
39 d->entryHandlers.push_back(ee);
40
41#define GET_ARRAY_VALUE(entryName, arrayIndex, wdg, wdgPropertyName, editorSignal) \
42 QString key = schema->generateQualifiedName(#entryName); \
43 KisEntryEditor *ee = new KisEntryEditor(wdg, d->temporaryStorage, key, #wdgPropertyName, QString(), arrayIndex); \
44 connect(wdg, editorSignal, ee, &KisEntryEditor::valueEdited); \
45 d->entryHandlers.push_back(ee);
46
47#define GET_STRUCTURE_VALUE(entryName, structureField, wdg, wdgPropertyName, editorSignal) \
48 QString key = schema->generateQualifiedName(#entryName); \
49 KisEntryEditor *ee = new KisEntryEditor(wdg, d->temporaryStorage, key, #wdgPropertyName, #structureField, 0); \
50 connect(wdg, editorSignal, ee, &KisEntryEditor::valueEdited); \
51 d->entryHandlers.push_back(ee);
52
53#define GET_DC_VALUE(entryName, wdgPropertyName, editorSignal) { \
54 GET_VALUE(entryName, wdg->entryName, wdgPropertyName, editorSignal) \
55}
56
57#define GET_EXIF_VALUE(entryName, wdgPropertyName, editorSignal) { \
58 GET_VALUE(entryName, wdg->edit##entryName, wdgPropertyName, editorSignal) \
59}
60
61#define GET_EXIF_ARRAY_VALUE(entryName, arrayIndex, wdgPropertyName, editorSignal) { \
62 GET_ARRAY_VALUE(entryName, arrayIndex, wdg->edit##entryName, wdgPropertyName, editorSignal) \
63}
64
65#define GET_EXIF_STRUCTURE_VALUE(entryName, structureField, wdgPropertyName, editorSignal) { \
66 GET_STRUCTURE_VALUE(entryName, structureField, wdg->edit##entryName##structureField, wdgPropertyName, editorSignal) \
67}
68
70 : KPageDialog(parent)
71 , d(new Private)
72{
74 d->store = store;
75
76 // Add the Dublin Core widget
77 {
78 WdgDublinCore *wdg = new WdgDublinCore(this);
79
80 {
81 // copy from dublin core
82 const KisMetaData::Schema *schema =
84
85 Q_ASSERT(schema);
86
87 GET_DC_VALUE(creator, text, &QLineEdit::textEdited);
88 GET_DC_VALUE(publisher, text, &QLineEdit::textEdited);
89 GET_DC_VALUE(rights, text, &QLineEdit::textEdited);
90 GET_DC_VALUE(date, date, &QDateTimeEdit::editingFinished);
91 GET_DC_VALUE(title, text, &QLineEdit::textEdited);
92 GET_DC_VALUE(description, plainText, &QTextEdit::textChanged);
93 }
94
95 wdg->date->setDisplayFormat(QLocale().dateFormat());
96
97 KPageWidgetItem *page = new KPageWidgetItem(wdg, i18n("Dublin Core"));
98 page->setIcon(KisIconUtils::loadIcon("user-identity"));
99 addPage(page);
100 }
101
102 // Add the Exif widget
103 {
104 WdgExif *wdg = new WdgExif(this);
105
106 {
107 // copy from exif
108 const KisMetaData::Schema *schema =
110
111 Q_ASSERT(schema);
112
113 /* exposure tab */
114 GET_EXIF_VALUE(BrightnessValue, text, &QLineEdit::textEdited);
115 GET_EXIF_VALUE(ExposureTime, text, &QLineEdit::textEdited);
116 GET_EXIF_ARRAY_VALUE(ISOSpeedRatings, 0, value, QOverload<int>::of(&KisIntParseSpinBox::valueChanged));
117 GET_EXIF_VALUE(ExposureMode, currentIndex, QOverload<int>::of(&QComboBox::activated));
118 GET_EXIF_VALUE(ExposureProgram, currentIndex, QOverload<int>::of(&QComboBox::activated));
119 GET_EXIF_VALUE(ExposureIndex, text, &QLineEdit::textEdited);
120 GET_EXIF_VALUE(ExposureBiasValue, text, &QLineEdit::textEdited);
121 GET_EXIF_VALUE(ApertureValue, text, &QLineEdit::textEdited);
122 GET_EXIF_VALUE(ShutterSpeedValue, text, &QLineEdit::textEdited);
123 GET_EXIF_VALUE(FNumber, text, &QLineEdit::textEdited);
124 /* lens tab */
125 GET_EXIF_VALUE(FocalLengthIn35mmFilm, value, QOverload<int>::of(&QSpinBox::valueChanged));
126 GET_EXIF_VALUE(FocalLength, value, QOverload<int>::of(&QSpinBox::valueChanged));
127 GET_EXIF_VALUE(MaxApertureValue, text, &QLineEdit::textEdited);
128 /* autofocus tab */
129 GET_EXIF_VALUE(MeteringMode, currentIndex, QOverload<int>::of(&QComboBox::activated));
130 GET_EXIF_VALUE(SubjectDistance, text, &QLineEdit::textEdited);
131 GET_EXIF_VALUE(SubjectDistanceRange, currentIndex, QOverload<int>::of(&QComboBox::activated));
132 /* flash */
133 GET_EXIF_STRUCTURE_VALUE(Flash, Fired, isChecked, QOverload<bool>::of(&QCheckBox::toggled));
134 GET_EXIF_STRUCTURE_VALUE(Flash, StrobeReturn, currentIndex, QOverload<int>::of(&QComboBox::activated));
135 GET_EXIF_STRUCTURE_VALUE(Flash, Mode, currentIndex, QOverload<int>::of(&QComboBox::activated));
136 GET_EXIF_STRUCTURE_VALUE(Flash, Function, isChecked, QOverload<bool>::of(&QCheckBox::toggled));
137 GET_EXIF_STRUCTURE_VALUE(Flash, RedEyeMode, isChecked, QOverload<bool>::of(&QCheckBox::toggled));
138 GET_EXIF_VALUE(FlashEnergy, text, &QLineEdit::textEdited);
139 /* postprocessing tab */
140 GET_EXIF_VALUE(GainControl, currentIndex, QOverload<int>::of(&QComboBox::activated));
141 GET_EXIF_VALUE(LightSource, currentIndex, QOverload<int>::of(&QComboBox::activated));
142 GET_EXIF_VALUE(Sharpness, currentIndex, QOverload<int>::of(&QComboBox::activated));
143 GET_EXIF_VALUE(Contrast, currentIndex, QOverload<int>::of(&QComboBox::activated));
144 GET_EXIF_VALUE(WhiteBalance, currentIndex, QOverload<int>::of(&QComboBox::activated));
145 /* misc tab */
146 GET_EXIF_VALUE(SceneCaptureType, currentIndex, QOverload<int>::of(&QComboBox::activated));
147 GET_EXIF_VALUE(SensingMethod, currentIndex, QOverload<int>::of(&QComboBox::activated));
148 }
149
150 {
151 // copy from exif (tiff schema)
152 const KisMetaData::Schema *schema =
154
155 Q_ASSERT(schema);
156
157 /* misc */
158 GET_EXIF_VALUE(Make, text, &QLineEdit::textEdited);
159 GET_EXIF_VALUE(Model, text, &QLineEdit::textEdited);
160 }
161
162 KPageWidgetItem *page = new KPageWidgetItem(wdg, i18n("Exif"));
163 page->setIcon(KisIconUtils::loadIcon("camera-photo"));
164 addPage(page);
165 }
166
167 {
168 // Add the list page
169 QTableView *tableView = new QTableView;
171 tableView->setModel(model);
172 tableView->verticalHeader()->setVisible(false);
173 tableView->resizeColumnsToContents();
174 KPageWidgetItem *page = new KPageWidgetItem(tableView, i18n("List"));
175 page->setIcon(KisIconUtils::loadIcon("format-list-unordered"));
176 addPage(page);
177 }
178}
179
181{
182 Q_FOREACH (KisEntryEditor *e, d->entryHandlers) {
183 delete e;
184 }
185 delete d->temporaryStorage;
186 delete d;
187}
188
190{
191 KPageDialog::accept();
192
194}
float value(const T *src, size_t ch)
KisMetaDataEditor(QWidget *parent, KisMetaData::Store *store)
static KisMetaData::SchemaRegistry * instance()
const Schema * schemaFromUri(const QString &uri) const
static const QString TIFFSchemaUri
static const QString DublinCoreSchemaUri
static const QString EXIFSchemaUri
void copyFrom(const Store *store)
#define GET_EXIF_STRUCTURE_VALUE(entryName, structureField, wdgPropertyName, editorSignal)
#define GET_EXIF_ARRAY_VALUE(entryName, arrayIndex, wdgPropertyName, editorSignal)
#define GET_DC_VALUE(entryName, wdgPropertyName, editorSignal)
#define GET_EXIF_VALUE(entryName, wdgPropertyName, editorSignal)
QIcon loadIcon(const QString &name)
KisMetaData::Store * temporaryStorage
QList< KisEntryEditor * > entryHandlers