2007-02-25 00:07:59 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2007 by Pino Toscano <pino@kde.org> *
|
2017-11-16 08:57:58 +00:00
|
|
|
* Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group *
|
|
|
|
* company, info@kdab.com. Work sponsored by the *
|
|
|
|
* LiMux project of the city of Munich *
|
2007-02-25 00:07:59 +00:00
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _OKULAR_FORMWIDGETS_H_
|
|
|
|
#define _OKULAR_FORMWIDGETS_H_
|
|
|
|
|
|
|
|
#include "core/area.h"
|
2019-07-30 20:25:35 +00:00
|
|
|
#include "core/form.h"
|
2007-02-25 00:07:59 +00:00
|
|
|
|
2020-07-08 11:54:37 +00:00
|
|
|
#include <KTextEdit>
|
|
|
|
#include <KUrlRequester>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QListWidget>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QRadioButton>
|
2007-02-25 00:07:59 +00:00
|
|
|
|
2013-06-03 20:46:41 +00:00
|
|
|
class ComboEdit;
|
|
|
|
class QMenu;
|
2008-02-11 10:41:04 +00:00
|
|
|
class QButtonGroup;
|
2007-02-25 00:07:59 +00:00
|
|
|
class FormWidgetIface;
|
2007-10-18 22:09:49 +00:00
|
|
|
class PageViewItem;
|
2008-02-11 10:41:04 +00:00
|
|
|
class RadioButtonEdit;
|
2013-06-03 20:46:41 +00:00
|
|
|
class QEvent;
|
2007-02-25 00:07:59 +00:00
|
|
|
|
|
|
|
namespace Okular
|
|
|
|
{
|
2008-03-20 17:45:37 +00:00
|
|
|
class Action;
|
2007-02-25 00:07:59 +00:00
|
|
|
class FormField;
|
2008-02-11 10:41:04 +00:00
|
|
|
class FormFieldButton;
|
2007-02-25 00:07:59 +00:00
|
|
|
class FormFieldChoice;
|
|
|
|
class FormFieldText;
|
2019-01-05 22:30:25 +00:00
|
|
|
class FormFieldSignature;
|
2013-06-03 20:46:41 +00:00
|
|
|
class Document;
|
2007-02-25 00:07:59 +00:00
|
|
|
}
|
|
|
|
|
2008-02-11 10:41:04 +00:00
|
|
|
struct RadioData {
|
|
|
|
RadioData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<int> ids;
|
|
|
|
QButtonGroup *group;
|
|
|
|
};
|
2007-10-18 22:09:49 +00:00
|
|
|
|
|
|
|
class FormWidgetsController : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-09-01 08:25:57 +00:00
|
|
|
explicit FormWidgetsController(Okular::Document *doc);
|
2019-12-18 11:51:13 +00:00
|
|
|
~FormWidgetsController() override;
|
2007-10-18 22:09:49 +00:00
|
|
|
|
2019-08-16 23:15:47 +00:00
|
|
|
void signalAction(Okular::Action *action);
|
|
|
|
|
2017-10-25 14:08:13 +00:00
|
|
|
void processScriptAction(Okular::Action *a, Okular::FormField *field, Okular::Annotation::AdditionalActionType type);
|
2008-02-11 10:41:04 +00:00
|
|
|
|
2019-01-05 22:30:25 +00:00
|
|
|
void registerRadioButton(FormWidgetIface *fwButton, Okular::FormFieldButton *formButton);
|
2008-02-11 10:41:04 +00:00
|
|
|
void dropRadioButtons();
|
2019-01-05 22:30:25 +00:00
|
|
|
bool canUndo();
|
2013-06-03 20:46:41 +00:00
|
|
|
bool canRedo();
|
2019-01-05 22:30:25 +00:00
|
|
|
|
2013-06-03 20:46:41 +00:00
|
|
|
static bool shouldFormWidgetBeShown(Okular::FormField *form);
|
|
|
|
|
2016-07-11 17:30:31 +00:00
|
|
|
Q_SIGNALS:
|
2013-06-03 20:46:41 +00:00
|
|
|
void changed(int pageNumber);
|
|
|
|
void requestUndo();
|
|
|
|
void requestRedo();
|
|
|
|
void canUndoChanged(bool undoAvailable);
|
|
|
|
void canRedoChanged(bool redoAvailable);
|
|
|
|
void formTextChangedByWidget(int pageNumber, Okular::FormFieldText *form, const QString &newContents, int newCursorPos, int prevCursorPos, int prevAnchorPos);
|
|
|
|
|
|
|
|
void formTextChangedByUndoRedo(int pageNumber, Okular::FormFieldText *form, const QString &contents, int cursorPos, int anchorPos);
|
|
|
|
|
|
|
|
void formListChangedByWidget(int pageNumber, Okular::FormFieldChoice *form, const QList<int> &newChoices);
|
|
|
|
|
|
|
|
void formListChangedByUndoRedo(int pageNumber, Okular::FormFieldChoice *form, const QList<int> &choices);
|
|
|
|
|
|
|
|
void formComboChangedByWidget(int pageNumber, Okular::FormFieldChoice *form, const QString &newText, int newCursorPos, int prevCursorPos, int prevAnchorPos);
|
|
|
|
|
|
|
|
void formComboChangedByUndoRedo(int pageNumber, Okular::FormFieldChoice *form, const QString &text, int cursorPos, int anchorPos);
|
|
|
|
|
2017-03-02 19:09:32 +00:00
|
|
|
void formButtonsChangedByWidget(int pageNumber, const QList<Okular::FormFieldButton *> &formButtons, const QList<bool> &newButtonStates);
|
2013-06-03 20:46:41 +00:00
|
|
|
|
2008-03-20 17:45:37 +00:00
|
|
|
void action(Okular::Action *action);
|
2008-02-11 10:41:04 +00:00
|
|
|
|
2019-07-30 20:25:35 +00:00
|
|
|
void focusAction(const Okular::Action *action, Okular::FormFieldText *ff);
|
|
|
|
|
2019-06-26 00:58:28 +00:00
|
|
|
void formatAction(const Okular::Action *action, Okular::FormFieldText *ff);
|
|
|
|
|
2019-07-27 17:53:31 +00:00
|
|
|
void keystrokeAction(const Okular::Action *action, Okular::FormFieldText *ff, bool &ok);
|
|
|
|
|
2019-08-16 23:15:47 +00:00
|
|
|
void validateAction(const Okular::Action *action, Okular::FormFieldText *ff, bool &ok);
|
|
|
|
|
2018-02-21 22:56:43 +00:00
|
|
|
void refreshFormWidget(Okular::FormField *form);
|
|
|
|
|
2016-07-11 17:30:31 +00:00
|
|
|
private Q_SLOTS:
|
2008-03-07 16:07:15 +00:00
|
|
|
void slotButtonClicked(QAbstractButton *button);
|
2013-06-03 20:46:41 +00:00
|
|
|
void slotFormButtonsChangedByUndoRedo(int pageNumber, const QList<Okular::FormFieldButton *> &formButtons);
|
2008-03-07 16:07:15 +00:00
|
|
|
|
2008-02-11 10:41:04 +00:00
|
|
|
private:
|
2013-06-03 20:46:41 +00:00
|
|
|
friend class TextAreaEdit;
|
|
|
|
friend class FormLineEdit;
|
|
|
|
friend class FileEdit;
|
|
|
|
friend class ListEdit;
|
|
|
|
friend class ComboEdit;
|
2019-01-05 22:30:25 +00:00
|
|
|
friend class SignatureEdit;
|
2013-06-03 20:46:41 +00:00
|
|
|
|
2008-02-11 10:41:04 +00:00
|
|
|
QList<RadioData> m_radios;
|
2013-06-03 20:46:41 +00:00
|
|
|
QHash<int, QAbstractButton *> m_buttons;
|
|
|
|
Okular::Document *m_doc;
|
2007-10-18 22:09:49 +00:00
|
|
|
};
|
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
class FormWidgetFactory
|
|
|
|
{
|
|
|
|
public:
|
2017-03-02 19:09:32 +00:00
|
|
|
static FormWidgetIface *createWidget(Okular::FormField *ff, QWidget *parent = nullptr);
|
2007-02-25 00:07:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FormWidgetIface
|
|
|
|
{
|
|
|
|
public:
|
2018-03-20 21:58:58 +00:00
|
|
|
FormWidgetIface(QWidget *w, Okular::FormField *ff);
|
2007-02-25 00:07:59 +00:00
|
|
|
virtual ~FormWidgetIface();
|
|
|
|
|
2020-02-21 15:11:42 +00:00
|
|
|
FormWidgetIface(const FormWidgetIface &) = delete;
|
|
|
|
FormWidgetIface &operator=(const FormWidgetIface &) = delete;
|
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
Okular::NormalizedRect rect() const;
|
|
|
|
void setWidthHeight(int w, int h);
|
|
|
|
void moveTo(int x, int y);
|
2007-02-25 14:59:26 +00:00
|
|
|
bool setVisibility(bool visible);
|
2007-04-28 23:22:20 +00:00
|
|
|
void setCanBeFilled(bool fill);
|
2007-02-25 00:07:59 +00:00
|
|
|
|
2007-10-18 22:09:49 +00:00
|
|
|
void setPageItem(PageViewItem *pageItem);
|
|
|
|
PageViewItem *pageItem() const;
|
2017-10-26 07:47:18 +00:00
|
|
|
void setFormField(Okular::FormField *field);
|
|
|
|
Okular::FormField *formField() const;
|
2007-10-18 22:09:49 +00:00
|
|
|
|
2008-02-11 10:41:04 +00:00
|
|
|
virtual void setFormWidgetsController(FormWidgetsController *controller);
|
2007-10-18 22:09:49 +00:00
|
|
|
|
|
|
|
protected:
|
2018-03-20 21:59:27 +00:00
|
|
|
virtual void slotRefresh(Okular::FormField *form);
|
|
|
|
|
2007-10-18 22:09:49 +00:00
|
|
|
FormWidgetsController *m_controller;
|
2017-10-25 13:12:35 +00:00
|
|
|
Okular::FormField *m_ff;
|
2007-10-18 22:09:49 +00:00
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
private:
|
|
|
|
QWidget *m_widget;
|
2007-10-18 22:09:49 +00:00
|
|
|
PageViewItem *m_pageItem;
|
2007-02-25 00:07:59 +00:00
|
|
|
};
|
|
|
|
|
2018-05-30 08:04:06 +00:00
|
|
|
#define DECLARE_ADDITIONAL_ACTIONS \
|
|
|
|
protected: \
|
|
|
|
virtual void mousePressEvent(QMouseEvent *event) override; \
|
|
|
|
virtual void mouseReleaseEvent(QMouseEvent *event) override; \
|
|
|
|
virtual void focusInEvent(QFocusEvent *event) override; \
|
|
|
|
virtual void focusOutEvent(QFocusEvent *event) override; \
|
|
|
|
virtual void leaveEvent(QEvent *event) override; \
|
|
|
|
virtual void enterEvent(QEvent *event) override;
|
2007-02-25 00:07:59 +00:00
|
|
|
|
2008-02-11 10:41:04 +00:00
|
|
|
class PushButtonEdit : public QPushButton, public FormWidgetIface
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-03-02 19:09:32 +00:00
|
|
|
explicit PushButtonEdit(Okular::FormFieldButton *button, QWidget *parent = nullptr);
|
2008-02-11 10:41:04 +00:00
|
|
|
|
2018-05-30 08:04:06 +00:00
|
|
|
DECLARE_ADDITIONAL_ACTIONS
|
2008-02-11 10:41:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CheckBoxEdit : public QCheckBox, public FormWidgetIface
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-03-02 19:09:32 +00:00
|
|
|
explicit CheckBoxEdit(Okular::FormFieldButton *button, QWidget *parent = nullptr);
|
2008-02-11 10:41:04 +00:00
|
|
|
|
2008-02-12 11:03:04 +00:00
|
|
|
// reimplemented from FormWidgetIface
|
2017-03-02 19:38:50 +00:00
|
|
|
void setFormWidgetsController(FormWidgetsController *controller) override;
|
2008-02-12 11:03:04 +00:00
|
|
|
|
2018-03-20 21:59:42 +00:00
|
|
|
void doActivateAction();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void slotRefresh(Okular::FormField *form) override;
|
2018-05-30 08:04:06 +00:00
|
|
|
DECLARE_ADDITIONAL_ACTIONS
|
2008-02-11 10:41:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class RadioButtonEdit : public QRadioButton, public FormWidgetIface
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-03-02 19:09:32 +00:00
|
|
|
explicit RadioButtonEdit(Okular::FormFieldButton *button, QWidget *parent = nullptr);
|
2008-02-11 10:41:04 +00:00
|
|
|
|
|
|
|
// reimplemented from FormWidgetIface
|
2017-03-02 19:38:50 +00:00
|
|
|
void setFormWidgetsController(FormWidgetsController *controller) override;
|
2018-05-30 08:04:06 +00:00
|
|
|
DECLARE_ADDITIONAL_ACTIONS
|
2008-02-11 10:41:04 +00:00
|
|
|
};
|
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
class FormLineEdit : public QLineEdit, public FormWidgetIface
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-03-02 19:09:32 +00:00
|
|
|
explicit FormLineEdit(Okular::FormFieldText *text, QWidget *parent = nullptr);
|
2017-03-02 19:38:50 +00:00
|
|
|
void setFormWidgetsController(FormWidgetsController *controller) override;
|
|
|
|
bool event(QEvent *e) override;
|
|
|
|
void contextMenuEvent(QContextMenuEvent *event) override;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2016-07-11 17:30:31 +00:00
|
|
|
public Q_SLOTS:
|
2013-06-03 20:46:41 +00:00
|
|
|
void slotHandleTextChangedByUndoRedo(int pageNumber, Okular::FormFieldText *textForm, const QString &contents, int cursorPos, int anchorPos);
|
2016-07-11 17:30:31 +00:00
|
|
|
private Q_SLOTS:
|
2013-06-03 20:46:41 +00:00
|
|
|
void slotChanged();
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2018-03-20 21:59:27 +00:00
|
|
|
protected:
|
|
|
|
void slotRefresh(Okular::FormField *form) override;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
private:
|
2013-06-03 20:46:41 +00:00
|
|
|
int m_prevCursorPos;
|
|
|
|
int m_prevAnchorPos;
|
2019-07-27 17:53:31 +00:00
|
|
|
bool m_editing;
|
2018-05-30 08:04:06 +00:00
|
|
|
DECLARE_ADDITIONAL_ACTIONS
|
2007-02-25 00:07:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class TextAreaEdit : public KTextEdit, public FormWidgetIface
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-03-02 19:09:32 +00:00
|
|
|
explicit TextAreaEdit(Okular::FormFieldText *text, QWidget *parent = nullptr);
|
2019-12-18 11:51:13 +00:00
|
|
|
~TextAreaEdit() override;
|
2017-03-02 19:38:50 +00:00
|
|
|
void setFormWidgetsController(FormWidgetsController *controller) override;
|
|
|
|
bool event(QEvent *e) override;
|
2013-06-03 20:46:41 +00:00
|
|
|
|
2016-07-11 17:30:31 +00:00
|
|
|
public Q_SLOTS:
|
2013-06-03 20:46:41 +00:00
|
|
|
void slotHandleTextChangedByUndoRedo(int pageNumber, Okular::FormFieldText *textForm, const QString &contents, int cursorPos, int anchorPos);
|
|
|
|
void slotUpdateUndoAndRedoInContextMenu(QMenu *menu);
|
|
|
|
|
2016-07-11 17:30:31 +00:00
|
|
|
private Q_SLOTS:
|
2013-06-03 20:46:41 +00:00
|
|
|
void slotChanged();
|
2007-02-25 00:07:59 +00:00
|
|
|
|
2016-07-11 17:30:31 +00:00
|
|
|
protected:
|
2007-02-25 00:07:59 +00:00
|
|
|
void slotRefresh(Okular::FormField *form) override;
|
2018-03-20 21:59:27 +00:00
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
private:
|
2013-06-03 20:46:41 +00:00
|
|
|
int m_prevCursorPos;
|
|
|
|
int m_prevAnchorPos;
|
2019-07-27 17:53:31 +00:00
|
|
|
bool m_editing;
|
2018-05-30 08:04:06 +00:00
|
|
|
DECLARE_ADDITIONAL_ACTIONS
|
2007-02-25 00:07:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FileEdit : public KUrlRequester, public FormWidgetIface
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-03-02 19:09:32 +00:00
|
|
|
explicit FileEdit(Okular::FormFieldText *text, QWidget *parent = nullptr);
|
2017-03-02 19:38:50 +00:00
|
|
|
void setFormWidgetsController(FormWidgetsController *controller) override;
|
2013-06-03 20:46:41 +00:00
|
|
|
|
|
|
|
protected:
|
2017-03-02 19:38:50 +00:00
|
|
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
2007-02-25 00:07:59 +00:00
|
|
|
|
2016-07-11 17:30:31 +00:00
|
|
|
private Q_SLOTS:
|
2013-06-03 20:46:41 +00:00
|
|
|
void slotChanged();
|
|
|
|
void slotHandleFileChangedByUndoRedo(int pageNumber, Okular::FormFieldText *form, const QString &contents, int cursorPos, int anchorPos);
|
2007-02-25 00:07:59 +00:00
|
|
|
|
|
|
|
private:
|
2013-06-03 20:46:41 +00:00
|
|
|
int m_prevCursorPos;
|
|
|
|
int m_prevAnchorPos;
|
2018-05-30 08:04:06 +00:00
|
|
|
DECLARE_ADDITIONAL_ACTIONS
|
2007-02-25 00:07:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ListEdit : public QListWidget, public FormWidgetIface
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-03-02 19:09:32 +00:00
|
|
|
explicit ListEdit(Okular::FormFieldChoice *choice, QWidget *parent = nullptr);
|
2017-03-02 19:38:50 +00:00
|
|
|
void setFormWidgetsController(FormWidgetsController *controller) override;
|
2007-02-25 00:07:59 +00:00
|
|
|
|
2016-07-11 17:30:31 +00:00
|
|
|
private Q_SLOTS:
|
2007-11-24 16:41:57 +00:00
|
|
|
void slotSelectionChanged();
|
2013-06-03 20:46:41 +00:00
|
|
|
void slotHandleFormListChangedByUndoRedo(int pageNumber, Okular::FormFieldChoice *listForm, const QList<int> &choices);
|
2018-05-30 08:04:06 +00:00
|
|
|
DECLARE_ADDITIONAL_ACTIONS
|
2007-02-25 00:07:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ComboEdit : public QComboBox, public FormWidgetIface
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-03-02 19:09:32 +00:00
|
|
|
explicit ComboEdit(Okular::FormFieldChoice *choice, QWidget *parent = nullptr);
|
2017-03-02 19:38:50 +00:00
|
|
|
void setFormWidgetsController(FormWidgetsController *controller) override;
|
|
|
|
bool event(QEvent *e) override;
|
|
|
|
void contextMenuEvent(QContextMenuEvent *event) override;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2016-07-11 17:30:31 +00:00
|
|
|
private Q_SLOTS:
|
2012-10-31 23:54:14 +00:00
|
|
|
void slotValueChanged();
|
2013-06-03 20:46:41 +00:00
|
|
|
void slotHandleFormComboChangedByUndoRedo(int pageNumber, Okular::FormFieldChoice *comboForm, const QString &text, int cursorPos, int anchorPos);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
private:
|
2013-06-03 20:46:41 +00:00
|
|
|
int m_prevCursorPos;
|
|
|
|
int m_prevAnchorPos;
|
2018-05-30 08:04:06 +00:00
|
|
|
DECLARE_ADDITIONAL_ACTIONS
|
2007-02-25 00:07:59 +00:00
|
|
|
};
|
|
|
|
|
2019-01-05 22:30:25 +00:00
|
|
|
class SignatureEdit : public QAbstractButton, public FormWidgetIface
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit SignatureEdit(Okular::FormFieldSignature *signature, QWidget *parent = nullptr);
|
|
|
|
|
|
|
|
// This will be called when an item in signature panel is clicked. Calling it changes the
|
|
|
|
// widget state. If this widget was visible prior to calling this then background
|
|
|
|
// color will change and borders will remain otherwise visibility of this widget will change.
|
|
|
|
// During the change all interactions will be disabled.
|
|
|
|
void setDummyMode(bool set);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool event(QEvent *e) override;
|
|
|
|
void contextMenuEvent(QContextMenuEvent *event) override;
|
|
|
|
void paintEvent(QPaintEvent *event) override;
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void slotViewProperties();
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_widgetPressed;
|
|
|
|
bool m_dummyMode;
|
|
|
|
bool m_wasVisible; // this will help in deciding whether or not to paint border for this widget
|
|
|
|
|
|
|
|
DECLARE_ADDITIONAL_ACTIONS
|
|
|
|
};
|
|
|
|
|
2018-05-30 08:04:06 +00:00
|
|
|
#undef DECLARE_ADDITIONAL_ACTIONS
|
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
#endif
|