2007-02-25 00:07:59 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2007 by Pino Toscano <pino@kde.org> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "form.h"
|
2007-07-04 11:41:45 +00:00
|
|
|
#include "form_p.h"
|
|
|
|
|
|
|
|
// qt includes
|
2018-08-31 09:23:45 +00:00
|
|
|
#include <QVariant>
|
2007-02-25 00:07:59 +00:00
|
|
|
|
2008-03-20 17:42:17 +00:00
|
|
|
#include "action.h"
|
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
using namespace Okular;
|
|
|
|
|
2007-07-04 11:41:45 +00:00
|
|
|
FormFieldPrivate::FormFieldPrivate(FormField::FieldType type)
|
2017-09-05 21:27:18 +00:00
|
|
|
: m_type(type)
|
|
|
|
, m_activateAction(nullptr)
|
2007-07-03 17:20:38 +00:00
|
|
|
{
|
2007-07-04 11:41:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FormFieldPrivate::~FormFieldPrivate()
|
|
|
|
{
|
2008-03-20 17:42:17 +00:00
|
|
|
delete m_activateAction;
|
2020-02-19 16:31:11 +00:00
|
|
|
qDeleteAll(m_additionalActions);
|
|
|
|
qDeleteAll(m_additionalAnnotActions);
|
2007-07-04 11:41:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FormFieldPrivate::setDefault()
|
|
|
|
{
|
|
|
|
m_default = value();
|
|
|
|
}
|
2007-07-03 17:20:38 +00:00
|
|
|
|
|
|
|
FormField::FormField(FormFieldPrivate &dd)
|
|
|
|
: d_ptr(&dd)
|
2007-02-25 00:07:59 +00:00
|
|
|
{
|
2007-07-04 11:41:45 +00:00
|
|
|
d_ptr->q_ptr = this;
|
2007-02-25 00:07:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FormField::~FormField()
|
|
|
|
{
|
2007-07-03 17:20:38 +00:00
|
|
|
delete d_ptr;
|
2007-02-25 00:07:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FormField::FieldType FormField::type() const
|
|
|
|
{
|
2007-07-03 17:20:38 +00:00
|
|
|
Q_D(const FormField);
|
|
|
|
return d->m_type;
|
2007-02-25 00:07:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FormField::isReadOnly() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-20 21:59:37 +00:00
|
|
|
void FormField::setReadOnly(bool)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
bool FormField::isVisible() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-23 21:47:42 +00:00
|
|
|
void FormField::setVisible(bool)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-28 12:39:02 +00:00
|
|
|
bool FormField::isPrintable() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormField::setPrintable(bool)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-03-20 17:42:17 +00:00
|
|
|
Action *FormField::activationAction() const
|
|
|
|
{
|
|
|
|
Q_D(const FormField);
|
|
|
|
return d->m_activateAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormField::setActivationAction(Action *action)
|
|
|
|
{
|
|
|
|
Q_D(FormField);
|
|
|
|
delete d->m_activateAction;
|
|
|
|
d->m_activateAction = action;
|
|
|
|
}
|
|
|
|
|
2017-03-02 23:41:06 +00:00
|
|
|
Action *FormField::additionalAction(AdditionalActionType type) const
|
|
|
|
{
|
|
|
|
Q_D(const FormField);
|
|
|
|
return d->m_additionalActions.value(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormField::setAdditionalAction(AdditionalActionType type, Action *action)
|
|
|
|
{
|
|
|
|
Q_D(FormField);
|
|
|
|
delete d->m_additionalActions.value(type);
|
|
|
|
d->m_additionalActions[type] = action;
|
|
|
|
}
|
|
|
|
|
2018-05-30 08:04:06 +00:00
|
|
|
Action *FormField::additionalAction(Annotation::AdditionalActionType type) const
|
|
|
|
{
|
|
|
|
Q_D(const FormField);
|
|
|
|
return d->m_additionalAnnotActions.value(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormField::setAdditionalAction(Annotation::AdditionalActionType type, Action *action)
|
|
|
|
{
|
|
|
|
Q_D(FormField);
|
|
|
|
delete d->m_additionalAnnotActions.value(type);
|
|
|
|
d->m_additionalAnnotActions[type] = action;
|
|
|
|
}
|
|
|
|
|
2008-02-11 10:41:04 +00:00
|
|
|
class Okular::FormFieldButtonPrivate : public Okular::FormFieldPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FormFieldButtonPrivate()
|
|
|
|
: FormFieldPrivate(FormField::FormButton)
|
|
|
|
{
|
|
|
|
}
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2008-02-11 10:41:04 +00:00
|
|
|
Q_DECLARE_PUBLIC(FormFieldButton)
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2016-10-29 14:38:19 +00:00
|
|
|
void setValue(const QString &v) override
|
2008-02-11 10:41:04 +00:00
|
|
|
{
|
|
|
|
Q_Q(FormFieldButton);
|
|
|
|
q->setState(QVariant(v).toBool());
|
|
|
|
}
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2016-10-29 14:38:19 +00:00
|
|
|
QString value() const override
|
2008-02-11 10:41:04 +00:00
|
|
|
{
|
|
|
|
Q_Q(const FormFieldButton);
|
2019-09-18 11:41:19 +00:00
|
|
|
return QVariant::fromValue<bool>(q->state()).toString();
|
2008-02-11 10:41:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
FormFieldButton::FormFieldButton()
|
|
|
|
: FormField(*new FormFieldButtonPrivate())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FormFieldButton::~FormFieldButton()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormFieldButton::setState(bool)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-06 15:46:21 +00:00
|
|
|
void FormFieldButton::setIcon(Okular::FormField *)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-07-03 17:20:38 +00:00
|
|
|
class Okular::FormFieldTextPrivate : public Okular::FormFieldPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FormFieldTextPrivate()
|
|
|
|
: FormFieldPrivate(FormField::FormText)
|
|
|
|
{
|
|
|
|
}
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-07-04 11:41:45 +00:00
|
|
|
Q_DECLARE_PUBLIC(FormFieldText)
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2016-10-29 14:38:19 +00:00
|
|
|
void setValue(const QString &v) override
|
2007-07-04 11:41:45 +00:00
|
|
|
{
|
|
|
|
Q_Q(FormFieldText);
|
|
|
|
q->setText(v);
|
|
|
|
}
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2016-10-29 14:38:19 +00:00
|
|
|
QString value() const override
|
2007-07-04 11:41:45 +00:00
|
|
|
{
|
|
|
|
Q_Q(const FormFieldText);
|
|
|
|
return q->text();
|
|
|
|
}
|
2007-07-03 17:20:38 +00:00
|
|
|
};
|
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
FormFieldText::FormFieldText()
|
2007-07-03 17:20:38 +00:00
|
|
|
: FormField(*new FormFieldTextPrivate())
|
2007-02-25 00:07:59 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FormFieldText::~FormFieldText()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormFieldText::setText(const QString &)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FormFieldText::isPassword() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FormFieldText::isRichText() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int FormFieldText::maximumLength() const
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::Alignment FormFieldText::textAlignment() const
|
|
|
|
{
|
|
|
|
return Qt::AlignVCenter | Qt::AlignLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FormFieldText::canBeSpellChecked() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-07-03 17:20:38 +00:00
|
|
|
class Okular::FormFieldChoicePrivate : public Okular::FormFieldPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FormFieldChoicePrivate()
|
|
|
|
: FormFieldPrivate(FormField::FormChoice)
|
|
|
|
{
|
|
|
|
}
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-07-04 11:41:45 +00:00
|
|
|
Q_DECLARE_PUBLIC(FormFieldChoice)
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2016-10-29 14:38:19 +00:00
|
|
|
void setValue(const QString &v) override
|
2007-07-04 11:41:45 +00:00
|
|
|
{
|
|
|
|
Q_Q(FormFieldChoice);
|
2019-12-09 13:16:55 +00:00
|
|
|
const QStringList choices = v.split(QLatin1Char(';'), QString::SkipEmptyParts);
|
2007-07-04 11:41:45 +00:00
|
|
|
QList<int> newchoices;
|
2019-12-09 13:16:55 +00:00
|
|
|
for (const QString &str : choices) {
|
2007-07-04 11:41:45 +00:00
|
|
|
bool ok = true;
|
|
|
|
int val = str.toInt(&ok);
|
|
|
|
if (ok)
|
|
|
|
newchoices.append(val);
|
|
|
|
}
|
|
|
|
if (!newchoices.isEmpty())
|
|
|
|
q->setCurrentChoices(newchoices);
|
2020-07-10 22:15:05 +00:00
|
|
|
}
|
|
|
|
|
2016-10-29 14:38:19 +00:00
|
|
|
QString value() const override
|
2007-07-04 11:41:45 +00:00
|
|
|
{
|
|
|
|
Q_Q(const FormFieldChoice);
|
|
|
|
QList<int> choices = q->currentChoices();
|
2019-03-12 12:13:53 +00:00
|
|
|
std::sort(choices.begin(), choices.end());
|
2007-07-04 11:41:45 +00:00
|
|
|
QStringList list;
|
2019-12-09 13:16:55 +00:00
|
|
|
for (const int c : qAsConst(choices)) {
|
2007-07-04 11:41:45 +00:00
|
|
|
list.append(QString::number(c));
|
|
|
|
}
|
2015-10-29 12:37:11 +00:00
|
|
|
return list.join(QStringLiteral(";"));
|
2020-07-10 22:15:05 +00:00
|
|
|
}
|
2020-03-21 21:39:45 +00:00
|
|
|
|
|
|
|
QMap<QString, QString> exportValues;
|
2007-07-03 17:20:38 +00:00
|
|
|
};
|
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
FormFieldChoice::FormFieldChoice()
|
2007-07-03 17:20:38 +00:00
|
|
|
: FormField(*new FormFieldChoicePrivate())
|
2007-02-25 00:07:59 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FormFieldChoice::~FormFieldChoice()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FormFieldChoice::isEditable() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FormFieldChoice::multiSelect() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormFieldChoice::setCurrentChoices(const QList<int> &)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-31 23:54:14 +00:00
|
|
|
QString FormFieldChoice::editChoice() const
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormFieldChoice::setEditChoice(const QString &)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
Qt::Alignment FormFieldChoice::textAlignment() const
|
|
|
|
{
|
|
|
|
return Qt::AlignVCenter | Qt::AlignLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FormFieldChoice::canBeSpellChecked() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-21 21:39:45 +00:00
|
|
|
void FormFieldChoice::setExportValues(const QMap<QString, QString> &values)
|
|
|
|
{
|
|
|
|
Q_D(FormFieldChoice);
|
|
|
|
d->exportValues = values;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString FormFieldChoice::exportValueForChoice(const QString &choice) const
|
|
|
|
{
|
|
|
|
Q_D(const FormFieldChoice);
|
|
|
|
return d->exportValues.value(choice, choice);
|
|
|
|
}
|
|
|
|
|
2019-01-05 22:30:25 +00:00
|
|
|
class Okular::FormFieldSignaturePrivate : public Okular::FormFieldPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FormFieldSignaturePrivate()
|
|
|
|
: FormFieldPrivate(FormField::FormSignature)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_DECLARE_PUBLIC(FormFieldSignature)
|
|
|
|
|
|
|
|
void setValue(const QString &v) override
|
|
|
|
{
|
|
|
|
Q_UNUSED(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
QString value() const override
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
FormFieldSignature::FormFieldSignature()
|
|
|
|
: FormField(*new FormFieldSignaturePrivate())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FormFieldSignature::~FormFieldSignature()
|
|
|
|
{
|
|
|
|
}
|