diff --git a/ui/formwidgets.h b/ui/formwidgets.h --- a/ui/formwidgets.h +++ b/ui/formwidgets.h @@ -38,6 +38,7 @@ class FormFieldButton; class FormFieldChoice; class FormFieldText; +class FormFieldSignature; class Document; } @@ -332,4 +333,25 @@ int m_prevAnchorPos; }; +class SignatureEdit : public QAbstractButton, public FormWidgetIface +{ + Q_OBJECT + + public: + explicit SignatureEdit( Okular::FormFieldSignature * signature, QWidget * parent = nullptr ); + + protected: + void mousePressEvent( QMouseEvent * e) override; + void mouseReleaseEvent(QMouseEvent * e) override; + void contextMenuEvent( QContextMenuEvent * e ) override; + void paintEvent( QPaintEvent * e ) override; + + private Q_SLOTS: + void slotValidateSignature(); + void slotShowProperties(); + + private: + bool m_lefMouseButtonPressed; +}; + #endif diff --git a/ui/formwidgets.cpp b/ui/formwidgets.cpp --- a/ui/formwidgets.cpp +++ b/ui/formwidgets.cpp @@ -22,6 +22,7 @@ #include #include #include +#include // local includes #include "core/form.h" @@ -275,6 +276,13 @@ } break; } + case Okular::FormField::FormSignature: + { + Okular::FormFieldSignature * ffs = static_cast< Okular::FormFieldSignature * >( ff ); + if ( ffs->isVisible() ) + widget = new SignatureEdit( ffs, parent ); + break; + } default: ; } @@ -1056,4 +1064,71 @@ return QComboBox::event( e ); } +SignatureEdit::SignatureEdit( Okular::FormFieldSignature * signature, QWidget * parent ) + : QAbstractButton( parent ), FormWidgetIface( this, signature ), m_lefMouseButtonPressed( false ) +{ + setCheckable( false ); + setCursor( Qt::PointingHandCursor ); + connect( this, &SignatureEdit::clicked, this, &SignatureEdit::slotValidateSignature ); +} + +void SignatureEdit::mousePressEvent( QMouseEvent * e ) +{ + if ( e->button() == Qt::LeftButton ) + { + m_lefMouseButtonPressed = true; + update(); + } +} + +void SignatureEdit::mouseReleaseEvent( QMouseEvent * e ) +{ + m_lefMouseButtonPressed = false; + if ( e->button() == Qt::LeftButton) + { + emit clicked(); + update(); + } +} + +void SignatureEdit::contextMenuEvent( QContextMenuEvent * e ) +{ + QMenu *menu = new QMenu( this ); + QAction *sigVal = new QAction( i18n("Validate Signature"), this ); + QAction *sigProp = new QAction( i18n("Show Signature Properties"), this ); + sigVal->setEnabled( false ); + sigProp->setEnabled( false ); + menu->addAction( sigVal ); + menu->addAction( sigProp ); + connect( sigVal, &QAction::triggered, this, &SignatureEdit::slotValidateSignature ); + connect( sigProp, &QAction::triggered, this, &SignatureEdit::slotShowProperties ); + menu->exec( e->globalPos() ); + delete menu; +} + +void SignatureEdit::paintEvent( QPaintEvent * ) +{ + QPainter painter( this ); + painter.setPen( Qt::black ); + if ( m_lefMouseButtonPressed ) + { + QColor col = palette().color( QPalette::Active, QPalette::Highlight ); + col.setAlpha(50); + painter.setBrush( col ); + } + else + painter.setBrush( Qt::transparent ); + painter.drawRect( 0, 0, width()-2, height()-2 ); +} + +void SignatureEdit::slotValidateSignature() +{ + //validate signature +} + +void SignatureEdit::slotShowProperties() +{ + //show signature properties +} + #include "moc_formwidgets.cpp"