diff --git a/core/form.h b/core/form.h --- a/core/form.h +++ b/core/form.h @@ -118,6 +118,12 @@ FormatField, ///< An action to be performed before the field is formatted to display its value ValidateField, ///< An action to be performed when the field value changes CalculateField, ///< An action to be performed when the field needs to be recalculated + CursorEntering, ///< Performed when the cursor enters the annotation's active area @since 1.5 + CursorLeaving, ///< Performed when the cursor exists the annotation's active area @since 1.5 + MousePressed, ///< Performed when the mouse button is pressed inside the annotation's active area @since 1.5 + MouseReleased, ///< Performed when the mouse button is released inside the annotation's active area @since 1.5 + FocusIn, ///< Performed when the annotation receives the input focus @since 1.5 + FocusOut, ///< Performed when the annotation loses the input focus @since 1.5 }; /** diff --git a/generators/poppler/CMakeLists.txt b/generators/poppler/CMakeLists.txt --- a/generators/poppler/CMakeLists.txt +++ b/generators/poppler/CMakeLists.txt @@ -83,6 +83,7 @@ f->setVisible(true); Poppler::Link *l; l->nextLinks(); + f->additionalAction(Poppler::FormField::CursorEntering); } " HAVE_POPPLER_0_64) diff --git a/generators/poppler/formfields.cpp b/generators/poppler/formfields.cpp --- a/generators/poppler/formfields.cpp +++ b/generators/poppler/formfields.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (C) 2007 by Pino Toscano * + * Copyright (C) 2018 by Andre Heinecke * * * * 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 * @@ -16,14 +17,26 @@ #include extern Okular::Action* createLinkFromPopplerLink(const Poppler::Link *popplerLink, bool deletePopplerLink = true); +#ifdef HAVE_POPPLER_0_64 +# define SET_WIDGET_ACTIONS \ + setAdditionalAction( Okular::FormField::CursorEntering, createLinkFromPopplerLink( field->additionalAction( Poppler::FormField::CursorEntering ) ) ); \ + setAdditionalAction( Okular::FormField::CursorLeaving, createLinkFromPopplerLink( field->additionalAction( Poppler::FormField::CursorLeaving ) ) ); \ + setAdditionalAction( Okular::FormField::MousePressed, createLinkFromPopplerLink( field->additionalAction( Poppler::FormField::MousePressed ) ) ); \ + setAdditionalAction( Okular::FormField::MouseReleased, createLinkFromPopplerLink( field->additionalAction( Poppler::FormField::MouseReleased ) ) ); \ + setAdditionalAction( Okular::FormField::FocusIn, createLinkFromPopplerLink( field->additionalAction( Poppler::FormField::FocusIn ) ) ); \ + setAdditionalAction( Okular::FormField::FocusOut, createLinkFromPopplerLink( field->additionalAction( Poppler::FormField::FocusOut ) ) ); +#else +# define SET_WIDGET_ACTIONS +#endif #ifdef HAVE_POPPLER_0_53 #define SET_ACTIONS \ setActivationAction( createLinkFromPopplerLink( field->activationAction() ) ); \ setAdditionalAction( Okular::FormField::FieldModified, createLinkFromPopplerLink( field->additionalAction( Poppler::FormField::FieldModified ) ) ); \ setAdditionalAction( Okular::FormField::FormatField, createLinkFromPopplerLink( field->additionalAction( Poppler::FormField::FormatField ) ) ); \ setAdditionalAction( Okular::FormField::ValidateField, createLinkFromPopplerLink( field->additionalAction( Poppler::FormField::ValidateField ) ) ); \ - setAdditionalAction( Okular::FormField::CalculateField, createLinkFromPopplerLink( field->additionalAction( Poppler::FormField::CalculateField ) ) ); + setAdditionalAction( Okular::FormField::CalculateField, createLinkFromPopplerLink( field->additionalAction( Poppler::FormField::CalculateField ) ) ); \ + SET_WIDGET_ACTIONS #else #define SET_ACTIONS \ setActivationAction( createLinkFromPopplerLink( field->activationAction() ) ); diff --git a/ui/formwidgets.h b/ui/formwidgets.h --- a/ui/formwidgets.h +++ b/ui/formwidgets.h @@ -170,6 +170,14 @@ PageViewItem * m_pageItem; }; +#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; class PushButtonEdit : public QPushButton, public FormWidgetIface { @@ -180,6 +188,7 @@ private Q_SLOTS: void slotClicked(); + DECLARE_ADDITIONAL_ACTIONS }; class CheckBoxEdit : public QCheckBox, public FormWidgetIface @@ -196,6 +205,7 @@ protected: void slotRefresh( Okular::FormField *form ) override; + DECLARE_ADDITIONAL_ACTIONS }; class RadioButtonEdit : public QRadioButton, public FormWidgetIface @@ -207,6 +217,7 @@ // reimplemented from FormWidgetIface void setFormWidgetsController( FormWidgetsController *controller ) override; + DECLARE_ADDITIONAL_ACTIONS }; class FormLineEdit : public QLineEdit, public FormWidgetIface @@ -235,6 +246,7 @@ private: int m_prevCursorPos; int m_prevAnchorPos; + DECLARE_ADDITIONAL_ACTIONS }; class TextAreaEdit : public KTextEdit, public FormWidgetIface @@ -264,6 +276,7 @@ private: int m_prevCursorPos; int m_prevAnchorPos; + DECLARE_ADDITIONAL_ACTIONS }; @@ -289,6 +302,7 @@ private: int m_prevCursorPos; int m_prevAnchorPos; + DECLARE_ADDITIONAL_ACTIONS }; @@ -305,6 +319,7 @@ void slotHandleFormListChangedByUndoRedo( int pageNumber, Okular::FormFieldChoice * listForm, const QList< int > & choices ); + DECLARE_ADDITIONAL_ACTIONS }; @@ -330,6 +345,9 @@ private: int m_prevCursorPos; int m_prevAnchorPos; + DECLARE_ADDITIONAL_ACTIONS }; +#undef DECLARE_ADDITIONAL_ACTIONS + #endif diff --git a/ui/formwidgets.cpp b/ui/formwidgets.cpp --- a/ui/formwidgets.cpp +++ b/ui/formwidgets.cpp @@ -1056,4 +1056,74 @@ return QComboBox::event( e ); } +// Code for additional action handling. +// Challenge: Change preprocessor magic to C++ magic! + +#define DEFINE_ADDITIONAL_ACTIONS(FormClass, BaseClass) \ + void FormClass::mousePressEvent( QMouseEvent *event ) \ + { \ + Okular::Action *act = m_ff->additionalAction( Okular::FormField::MousePressed ); \ + if (act) \ + { \ + emit m_controller->signalAction( act ); \ + } \ + BaseClass::mousePressEvent( event ); \ + } \ + void FormClass::mouseReleaseEvent( QMouseEvent *event ) \ + { \ + Okular::Action *act = m_ff->additionalAction( Okular::FormField::MouseReleased ); \ + if (act) \ + { \ + emit m_controller->signalAction( act ); \ + } \ + BaseClass::mouseReleaseEvent( event ); \ + } \ + void FormClass::focusInEvent( QFocusEvent *event ) \ + { \ + Okular::Action *act = m_ff->additionalAction( Okular::FormField::FocusIn ); \ + if (act) \ + { \ + emit m_controller->signalAction( act ); \ + } \ + BaseClass::focusInEvent( event ); \ + } \ + void FormClass::focusOutEvent( QFocusEvent *event ) \ + { \ + Okular::Action *act = m_ff->additionalAction( Okular::FormField::FocusOut ); \ + if (act) \ + { \ + emit m_controller->signalAction( act ); \ + } \ + BaseClass::focusOutEvent( event ); \ + } \ + void FormClass::leaveEvent( QEvent *event ) \ + { \ + Okular::Action *act = m_ff->additionalAction( Okular::FormField::CursorLeaving ); \ + if (act) \ + { \ + emit m_controller->signalAction( act ); \ + } \ + BaseClass::leaveEvent( event ); \ + } \ + void FormClass::enterEvent( QEvent *event ) \ + { \ + Okular::Action *act = m_ff->additionalAction( Okular::FormField::CursorEntering ); \ + if (act) \ + { \ + emit m_controller->signalAction( act ); \ + } \ + BaseClass::enterEvent( event ); \ + } + +DEFINE_ADDITIONAL_ACTIONS(PushButtonEdit, QPushButton) +DEFINE_ADDITIONAL_ACTIONS(CheckBoxEdit, QCheckBox) +DEFINE_ADDITIONAL_ACTIONS(RadioButtonEdit, QRadioButton) +DEFINE_ADDITIONAL_ACTIONS(FormLineEdit, QLineEdit) +DEFINE_ADDITIONAL_ACTIONS(TextAreaEdit, KTextEdit) +DEFINE_ADDITIONAL_ACTIONS(FileEdit, KUrlRequester) +DEFINE_ADDITIONAL_ACTIONS(ListEdit, QListWidget) +DEFINE_ADDITIONAL_ACTIONS(ComboEdit, QComboBox) + +#undef DEFINE_ADDITIONAL_ACTIONS + #include "moc_formwidgets.cpp"