Commit df65fdbe authored by Joao Oliveira's avatar Joao Oliveira

Made enter key process actions in formTextFields and processKeystrokeAction...

Made enter key process actions in formTextFields and processKeystrokeAction now changes the formText
parent d95b7c53
Pipeline #6972 passed with stage
in 14 minutes and 39 seconds
......@@ -4311,7 +4311,7 @@ void Document::processFormatAction( const Action * action, Okular::FormFieldText
}
}
void Document::processKeystrokeAction( const Action * action, Okular::FormFieldText *fft, bool &returnCode )
void Document::processKeystrokeAction( const Action * action, Okular::FormFieldText *fft, bool &returnCode, const bool changeFormText )
{
if ( action->actionType() != Action::Script )
{
......@@ -4334,6 +4334,8 @@ void Document::processKeystrokeAction( const Action * action, Okular::FormFieldT
d->executeScriptEvent( event, linkscript );
returnCode = event->returnCode();
if( changeFormText )
fft->setText( event->value().toString() );
}
void Document::processFocusAction( const Action * action, Okular::FormField *field )
......
......@@ -680,7 +680,7 @@ class OKULARCORE_EXPORT Document : public QObject
*
* @since 1.9
*/
void processKeystrokeAction( const Action *action, Okular::FormFieldText *field, bool &returnCode );
void processKeystrokeAction( const Action *action, Okular::FormFieldText *field, bool &returnCode, const bool changeFormText = false );
/**
* Processes the given focus action on the field.
......
......@@ -497,6 +497,7 @@ FormLineEdit::FormLineEdit( Okular::FormFieldText * text, QWidget * parent )
m_prevCursorPos = cursorPosition();
m_prevAnchorPos = cursorPosition();
m_editing = false;
m_formatted = true;
connect( this, &QLineEdit::textEdited, this, &FormLineEdit::slotChanged );
connect( this, &QLineEdit::cursorPositionChanged, this, &FormLineEdit::slotChanged );
......@@ -516,6 +517,7 @@ bool FormLineEdit::event( QEvent* e )
if ( e->type() == QEvent::KeyPress )
{
QKeyEvent *keyEvent = static_cast< QKeyEvent* >( e );
qDebug() << (keyEvent->text());
if ( keyEvent == QKeySequence::Undo )
{
emit m_controller->requestUndo();
......@@ -526,23 +528,37 @@ bool FormLineEdit::event( QEvent* e )
emit m_controller->requestRedo();
return true;
}
else if( keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return )
{
processFormTextCommitActions();
}
}
else if ( e->type() == QEvent::FocusIn )
{
const auto fft = static_cast< Okular::FormFieldText * > ( m_ff );
setText( fft->text() );
m_editing = true;
m_editing = m_formatted = true;
if( const Okular::Action *action = m_ff->additionalAction( Okular::Annotation::FocusIn ) )
emit m_controller->focusAction( action, fft );
setFocus();
}
else if ( e->type() == QEvent::FocusOut )
{
// Don't worry about focus events from other sources than the user FocusEvent to edit the field
QFocusEvent *focusEvent = static_cast< QFocusEvent* >( e );
if( focusEvent->reason() == Qt::OtherFocusReason )
return true;
if( !m_formatted )
processFormTextCommitActions();
}
return QLineEdit::event( e );
}
void FormLineEdit::processFormTextCommitActions()
{
m_editing = false;
if( const Okular::Action *action = m_ff->additionalAction( Okular::FormField::FieldModified ) )
{
bool ok = false;
emit m_controller->keystrokeAction( action, static_cast< Okular::FormFieldText * > ( m_ff ), ok, true );
}
if( const Okular::Action *action = m_ff->additionalAction( Okular::Annotation::FocusOut ) )
{
......@@ -551,13 +567,12 @@ bool FormLineEdit::event( QEvent* e )
}
emit m_controller->recalculateForms();
if ( const Okular::Action *action = m_ff->additionalAction( Okular::FormField::FormatField ) )
{
m_formatted = true;
emit m_controller->formatAction( action, static_cast< Okular::FormFieldText * > ( m_ff ) );
}
}
return QLineEdit::event( e );
}
void FormLineEdit::contextMenuEvent( QContextMenuEvent* event )
......
......@@ -123,7 +123,7 @@ class FormWidgetsController : public QObject
void formatAction( const Okular::Action *action, Okular::FormFieldText *ff );
void keystrokeAction( const Okular::Action *action, Okular::FormFieldText *ff, bool &ok );
void keystrokeAction( const Okular::Action *action, Okular::FormFieldText *ff, bool &ok, const bool changeFormText = false );
void validateAction( const Okular::Action *action, Okular::FormFieldText *ff, bool &ok );
......@@ -244,6 +244,7 @@ class FormLineEdit : public QLineEdit, public FormWidgetIface
void setFormWidgetsController( FormWidgetsController *controller ) override;
bool event ( QEvent * e ) override;
void contextMenuEvent( QContextMenuEvent* event ) override;
void processFormTextCommitActions();
public Q_SLOTS:
......@@ -262,6 +263,7 @@ class FormLineEdit : public QLineEdit, public FormWidgetIface
int m_prevCursorPos;
int m_prevAnchorPos;
bool m_editing;
bool m_formatted;
DECLARE_ADDITIONAL_ACTIONS
};
......
......@@ -269,8 +269,8 @@ FormWidgetsController* PageViewPrivate::formWidgetsController()
document->processFormatAction( action, fft );
} );
QObject::connect( formsWidgetController, &FormWidgetsController::keystrokeAction,
q, [this] (const Okular::Action *action, Okular::FormFieldText *fft, bool &ok ) {
document->processKeystrokeAction( action, fft, ok );
q, [this] (const Okular::Action *action, Okular::FormFieldText *fft, bool &ok, const bool changeFormText ) {
document->processKeystrokeAction( action, fft, ok, changeFormText );
} );
QObject::connect( formsWidgetController, &FormWidgetsController::focusAction,
q, [this] (const Okular::Action *action, Okular::FormFieldText *fft ) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment