1
/* ============================================================
3
* This file is a part of kipi-plugins project
4
* http://www.kipi-plugins.org
7
* Description : a widget to edit Application2 ObjectAttribute
10
* Copyright (C) 2007-2010 by Gilles Caulier <caulier dot gilles at gmail dot com>
12
* This program is free software; you can redistribute it
13
* and/or modify it under the terms of the GNU General
14
* Public License as published by the Free Software Foundation;
15
* either version 2, or (at your option) any later version.
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.
22
* ============================================================ */
24
#include "objectattributesedit.moc"
29
#include <QPushButton>
31
#include <QGridLayout>
35
#include <kcombobox.h>
37
#include <kiconloader.h>
38
#include <klineedit.h>
39
#include <klistwidget.h>
44
#include <libkdcraw/squeezedcombobox.h>
48
#include "metadatacheckbox.h"
50
using namespace KDcrawIface;
52
namespace KIPIMetadataEditPlugin
55
class ObjectAttributesEditPriv
59
ObjectAttributesEditPriv()
70
QStringList oldValues;
72
QPushButton *addValueButton;
73
QPushButton *delValueButton;
74
QPushButton *repValueButton;
78
KListWidget *valueBox;
80
MetadataCheckBox *valueCheck;
82
SqueezedComboBox *dataList;
85
ObjectAttributesEdit::ObjectAttributesEdit(QWidget* parent, bool ascii, int size)
86
: QWidget(parent), d(new ObjectAttributesEditPriv)
88
QGridLayout *grid = new QGridLayout(this);
90
// IPTC only accept printable Ascii char.
91
QRegExp asciiRx("[\x20-\x7F]+$");
92
QValidator *asciiValidator = new QRegExpValidator(asciiRx, this);
94
// --------------------------------------------------------
96
d->valueCheck = new MetadataCheckBox(i18n("Attribute:"), this);
98
d->addValueButton = new QPushButton(this);
99
d->delValueButton = new QPushButton(this);
100
d->repValueButton = new QPushButton(this);
101
d->addValueButton->setIcon(SmallIcon("list-add"));
102
d->delValueButton->setIcon(SmallIcon("edit-delete"));
103
d->repValueButton->setIcon(SmallIcon("view-refresh"));
104
d->addValueButton->setWhatsThis(i18n("Add a new value to the list"));
105
d->delValueButton->setWhatsThis(i18n("Remove the current selected value from the list"));
106
d->repValueButton->setWhatsThis(i18n("Replace the current selected value from the list"));
107
d->delValueButton->setEnabled(false);
108
d->repValueButton->setEnabled(false);
110
d->valueBox = new KListWidget(this);
111
d->valueBox->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Ignored);
112
d->valueBox->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
114
// --------------------------------------------------------
116
d->dataList = new SqueezedComboBox(this);
117
d->dataList->model()->sort(0);
118
d->dataList->setWhatsThis(i18n("Select here the editorial attribute of content."));
119
d->dataList->addSqueezedItem(QString("001 - ") + i18nc("Content type", "Current"));
120
d->dataList->addSqueezedItem(QString("002 - ") + i18nc("Content type", "Analysis"));
121
d->dataList->addSqueezedItem(QString("003 - ") + i18nc("Content type", "Archive material"));
122
d->dataList->addSqueezedItem(QString("004 - ") + i18nc("Content type", "Background"));
123
d->dataList->addSqueezedItem(QString("005 - ") + i18nc("Content type", "Feature"));
124
d->dataList->addSqueezedItem(QString("006 - ") + i18nc("Content type", "Forecast"));
125
d->dataList->addSqueezedItem(QString("007 - ") + i18nc("Content type", "History"));
126
d->dataList->addSqueezedItem(QString("008 - ") + i18nc("Content type", "Obituary"));
127
d->dataList->addSqueezedItem(QString("009 - ") + i18nc("Content type", "Opinion"));
128
d->dataList->addSqueezedItem(QString("010 - ") + i18nc("Content type", "Polls & Surveys"));
129
d->dataList->addSqueezedItem(QString("011 - ") + i18nc("Content type", "Profile"));
130
d->dataList->addSqueezedItem(QString("012 - ") + i18nc("Content type", "Results Listings & Table"));
131
d->dataList->addSqueezedItem(QString("013 - ") + i18nc("Content type", "Side bar & Supporting information"));
132
d->dataList->addSqueezedItem(QString("014 - ") + i18nc("Content type", "Summary"));
133
d->dataList->addSqueezedItem(QString("015 - ") + i18nc("Content type", "Transcript & Verbatim"));
134
d->dataList->addSqueezedItem(QString("016 - ") + i18nc("Content type", "Interview"));
135
d->dataList->addSqueezedItem(QString("017 - ") + i18nc("Content type", "From the Scene"));
136
d->dataList->addSqueezedItem(QString("018 - ") + i18nc("Content type", "Retrospective"));
137
d->dataList->addSqueezedItem(QString("019 - ") + i18nc("Content type", "Statistics"));
138
d->dataList->addSqueezedItem(QString("020 - ") + i18nc("Content type", "Update"));
139
d->dataList->addSqueezedItem(QString("021 - ") + i18nc("Content type", "Wrap-up"));
140
d->dataList->addSqueezedItem(QString("022 - ") + i18nc("Content type", "Press Release"));
142
// --------------------------------------------------------
144
d->valueEdit = new KLineEdit(this);
145
d->valueEdit->setClearButtonShown(true);
146
QString whatsThis = i18n("Set here the editorial attribute description of "
147
"content. This field is limited to 64 ASCII characters.");
149
if (ascii || size != -1)
151
whatsThis.append(i18n(" This field is limited to:"));
156
d->valueEdit->setValidator(asciiValidator);
157
whatsThis.append(i18n("<p>Printable ASCII characters.</p>"));
162
d->valueEdit->setMaxLength(size);
163
whatsThis.append(i18np("<p>1 character.</p>","<p>%1 characters.</p>", size));
166
d->valueEdit->setWhatsThis(whatsThis);
168
// --------------------------------------------------------
170
grid->setAlignment( Qt::AlignTop );
171
grid->addWidget(d->valueCheck, 0, 0, 1, 1);
172
grid->addWidget(d->addValueButton, 0, 1, 1, 1);
173
grid->addWidget(d->delValueButton, 0, 2, 1, 1);
174
grid->addWidget(d->repValueButton, 0, 3, 1, 1);
175
grid->addWidget(d->valueBox, 0, 4, 4, 1);
176
grid->addWidget(d->dataList, 1, 0, 1, 4);
177
grid->addWidget(d->valueEdit, 2, 0, 1, 4);
178
grid->setRowStretch(3, 10);
179
grid->setColumnStretch(0, 10);
180
grid->setColumnStretch(4, 100);
182
grid->setSpacing(KDialog::spacingHint());
184
// --------------------------------------------------------
186
connect(d->valueBox, SIGNAL(itemSelectionChanged()),
187
this, SLOT(slotSelectionChanged()));
189
connect(d->addValueButton, SIGNAL(clicked()),
190
this, SLOT(slotAddValue()));
192
connect(d->delValueButton, SIGNAL(clicked()),
193
this, SLOT(slotDeleteValue()));
195
connect(d->repValueButton, SIGNAL(clicked()),
196
this, SLOT(slotReplaceValue()));
198
// --------------------------------------------------------
200
connect(d->valueCheck, SIGNAL(toggled(bool)),
201
d->valueEdit, SLOT(setEnabled(bool)));
203
connect(d->valueCheck, SIGNAL(toggled(bool)),
204
d->dataList, SLOT(setEnabled(bool)));
206
connect(d->valueCheck, SIGNAL(toggled(bool)),
207
d->addValueButton, SLOT(setEnabled(bool)));
209
connect(d->valueCheck, SIGNAL(toggled(bool)),
210
d->delValueButton, SLOT(setEnabled(bool)));
212
connect(d->valueCheck, SIGNAL(toggled(bool)),
213
d->repValueButton, SLOT(setEnabled(bool)));
215
connect(d->valueCheck, SIGNAL(toggled(bool)),
216
d->valueBox, SLOT(setEnabled(bool)));
218
// --------------------------------------------------------
220
connect(d->valueCheck, SIGNAL(toggled(bool)),
221
this, SIGNAL(signalModified()));
223
connect(d->addValueButton, SIGNAL(clicked()),
224
this, SIGNAL(signalModified()));
226
connect(d->delValueButton, SIGNAL(clicked()),
227
this, SIGNAL(signalModified()));
229
connect(d->repValueButton, SIGNAL(clicked()),
230
this, SIGNAL(signalModified()));
233
ObjectAttributesEdit::~ObjectAttributesEdit()
238
void ObjectAttributesEdit::slotDeleteValue()
240
QListWidgetItem *item = d->valueBox->currentItem();
242
d->valueBox->takeItem(d->valueBox->row(item));
246
void ObjectAttributesEdit::slotReplaceValue()
248
QString newValue = d->dataList->itemHighlighted().left(3);
249
newValue.append(QString(":%1").arg(d->valueEdit->text()));
251
if (!d->valueBox->selectedItems().isEmpty())
252
d->valueBox->selectedItems()[0]->setText(newValue);
255
void ObjectAttributesEdit::slotSelectionChanged()
257
if (!d->valueBox->selectedItems().isEmpty())
260
int index = d->valueBox->selectedItems()[0]->text().section(':', 0, 0).toInt(&ok);
263
d->dataList->setCurrentIndex(index-1);
264
d->valueEdit->setText(d->valueBox->selectedItems()[0]->text().section(':', -1));
265
d->delValueButton->setEnabled(true);
266
d->repValueButton->setEnabled(true);
271
d->delValueButton->setEnabled(false);
272
d->repValueButton->setEnabled(false);
275
void ObjectAttributesEdit::slotAddValue()
277
QString newValue = d->dataList->itemHighlighted().left(3);
278
newValue.append(QString(":%1").arg(d->valueEdit->text()));
281
for (int i = 0 ; i < d->valueBox->count(); i++)
283
QListWidgetItem *item = d->valueBox->item(i);
284
if (newValue == item->text())
292
d->valueBox->insertItem(d->valueBox->count(), newValue);
295
void ObjectAttributesEdit::setValues(const QStringList& values)
298
d->oldValues = values;
300
d->valueBox->clear();
301
d->valueCheck->setChecked(false);
302
if (!d->oldValues.isEmpty())
304
d->valueBox->insertItems(0, d->oldValues);
305
d->valueCheck->setChecked(true);
307
d->dataList->setEnabled(d->valueCheck->isChecked());
308
d->valueBox->setEnabled(d->valueCheck->isChecked());
309
d->addValueButton->setEnabled(d->valueCheck->isChecked());
310
d->delValueButton->setEnabled(d->valueCheck->isChecked());
315
bool ObjectAttributesEdit::getValues(QStringList& oldValues, QStringList& newValues)
317
oldValues = d->oldValues;
320
for (int i = 0 ; i < d->valueBox->count(); i++)
322
QListWidgetItem *item = d->valueBox->item(i);
323
newValues.append(item->text());
326
return d->valueCheck->isChecked();
329
void ObjectAttributesEdit::setValid(bool v)
331
d->valueCheck->setValid(v);
334
bool ObjectAttributesEdit::isValid() const
336
return d->valueCheck->isValid();
339
} // namespace KIPIMetadataEditPlugin