Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Joao Oliveira
Okular
Commits
69398447
Commit
69398447
authored
Aug 16, 2019
by
Joao Oliveira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented validate actions and made formwidgets leave these actions to QLineEdit::Event
parent
601da352
Pipeline
#6924
passed with stage
in 13 minutes and 32 seconds
Changes
10
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
148 additions
and
4 deletions
+148
-4
autotests/data/formattest.pdf
autotests/data/formattest.pdf
+0
-0
autotests/formattest.cpp
autotests/formattest.cpp
+24
-0
core/document.cpp
core/document.cpp
+40
-0
core/document.h
core/document.h
+8
-1
core/script/event.cpp
core/script/event.cpp
+22
-0
core/script/event_p.h
core/script/event_p.h
+8
-1
core/script/kjs_event.cpp
core/script/kjs_event.cpp
+1
-0
ui/formwidgets.cpp
ui/formwidgets.cpp
+37
-2
ui/formwidgets.h
ui/formwidgets.h
+4
-0
ui/pageview.cpp
ui/pageview.cpp
+4
-0
No files found.
autotests/data/formattest.pdf
View file @
69398447
No preview for this file type
autotests/formattest.cpp
View file @
69398447
...
...
@@ -33,6 +33,8 @@ private slots:
void
testSpecialFormat_data
();
void
testFocusAction
();
void
testFocusAction_data
();
void
testValidateAction
();
void
testValidateAction_data
();
private:
Okular
::
Document
*
m_document
;
...
...
@@ -154,6 +156,28 @@ void FormatTest::testFocusAction_data()
QTest
::
newRow
(
"when focuses"
)
<<
QStringLiteral
(
"No"
);
}
void
FormatTest
::
testValidateAction
()
{
QFETCH
(
QString
,
text
);
QFETCH
(
QString
,
result
);
Okular
::
FormFieldText
*
fft
=
reinterpret_cast
<
Okular
::
FormFieldText
*
>
(
m_fields
[
"Validate/Focus"
]
);
fft
->
setText
(
text
);
bool
ok
=
false
;
m_document
->
processValidateAction
(
fft
->
additionalAction
(
Okular
::
Annotation
::
FocusOut
),
fft
,
ok
);
QCOMPARE
(
fft
->
text
(),
result
);
QVERIFY
(
ok
);
}
void
FormatTest
::
testValidateAction_data
()
{
QTest
::
addColumn
<
QString
>
(
"text"
);
QTest
::
addColumn
<
QString
>
(
"result"
);
QTest
::
newRow
(
"valid text was set"
)
<<
QStringLiteral
(
"123"
)
<<
QStringLiteral
(
"valid"
);
QTest
::
newRow
(
"invalid text was set"
)
<<
QStringLiteral
(
"abc"
)
<<
QStringLiteral
(
"invalid"
);
}
void
FormatTest
::
cleanupTestCase
()
{
m_document
->
closeDocument
();
...
...
core/document.cpp
View file @
69398447
...
...
@@ -4442,6 +4442,46 @@ void Document::processFocusAction( const Action * action, Okular::FormField *fie
d
->
m_scripter
->
setEvent
(
nullptr
);
}
void
Document
::
processValidateAction
(
const
Action
*
action
,
Okular
::
FormFieldText
*
fft
,
bool
&
returnCode
)
{
if
(
action
->
actionType
()
!=
Action
::
Script
)
{
qCDebug
(
OkularCoreDebug
)
<<
"Unsupported action type"
<<
action
->
actionType
()
<<
"for keystroke."
;
return
;
}
// Lookup the page of the FormFieldText
int
foundPage
=
-
1
;
for
(
uint
pageIdx
=
0
,
nPages
=
pages
();
pageIdx
<
nPages
;
pageIdx
++
)
{
const
Page
*
p
=
page
(
pageIdx
);
if
(
p
&&
p
->
formFields
().
contains
(
fft
)
)
{
foundPage
=
static_cast
<
int
>
(
pageIdx
);
break
;
}
}
if
(
foundPage
==
-
1
)
{
qCDebug
(
OkularCoreDebug
)
<<
"Could not find page for formfield!"
;
return
;
}
std
::
shared_ptr
<
Event
>
event
=
Event
::
createFormValidateEvent
(
fft
,
d
->
m_pagesVector
[
foundPage
]
);
const
ScriptAction
*
linkscript
=
static_cast
<
const
ScriptAction
*
>
(
action
);
if
(
!
d
->
m_scripter
)
{
d
->
m_scripter
=
new
Scripter
(
d
);
}
d
->
m_scripter
->
setEvent
(
event
.
get
()
);
d
->
m_scripter
->
execute
(
linkscript
->
scriptType
(),
linkscript
->
script
()
);
// Clear out the event after execution
d
->
m_scripter
->
setEvent
(
nullptr
);
returnCode
=
event
->
returnCode
();
}
void
Document
::
processSourceReference
(
const
SourceReference
*
ref
)
{
if
(
!
ref
)
...
...
core/document.h
View file @
69398447
...
...
@@ -688,7 +688,14 @@ class OKULARCORE_EXPORT Document : public QObject
* @since 1.9
*/
void
processFocusAction
(
const
Action
*
action
,
Okular
::
FormField
*
field
);
/**
* Processes the given keystroke @p action on @p field.
*
* @since 1.9
*/
void
processValidateAction
(
const
Action
*
action
,
Okular
::
FormFieldText
*
field
,
bool
&
returnCode
);
/**
* Returns a list of the bookmarked.pages
*/
...
...
core/script/event.cpp
View file @
69398447
...
...
@@ -64,6 +64,8 @@ QString Event::name() const
return
QStringLiteral
(
"Keystroke"
);
case
(
FieldFocus
):
return
QStringLiteral
(
"Focus"
);
case
(
FieldValidate
):
return
QStringLiteral
(
"Validate"
);
case
(
UnknownEvent
):
default:
return
QStringLiteral
(
"Unknown"
);
...
...
@@ -78,6 +80,7 @@ QString Event::type() const
case
(
FieldFormat
):
case
(
FieldKeystroke
):
case
(
FieldFocus
):
case
(
FieldValidate
):
return
QStringLiteral
(
"Field"
);
case
(
UnknownEvent
):
default:
...
...
@@ -242,4 +245,23 @@ std::shared_ptr<Event> Event::createFormFocusEvent( FormField *target,
ret
->
setValue
(
QVariant
(
fft
->
text
()
)
);
}
return
ret
;
}
std
::
shared_ptr
<
Event
>
Event
::
createFormValidateEvent
(
FormField
*
target
,
Page
*
targetPage
,
const
QString
&
targetName
)
{
std
::
shared_ptr
<
Event
>
ret
(
new
Event
(
Event
::
FieldValidate
)
);
ret
->
setTarget
(
target
);
ret
->
setTargetPage
(
targetPage
);
ret
->
setTargetName
(
targetName
);
ret
->
setShiftModifier
(
QApplication
::
keyboardModifiers
()
&
Qt
::
ShiftModifier
);
FormFieldText
*
fft
=
dynamic_cast
<
FormFieldText
*
>
(
target
);
if
(
fft
)
{
ret
->
setValue
(
QVariant
(
fft
->
text
()
)
);
ret
->
setReturnCode
(
true
);
}
return
ret
;
}
\ No newline at end of file
core/script/event_p.h
View file @
69398447
...
...
@@ -63,7 +63,11 @@ class Event
FieldMouseEnter
,
/// < Not implemented.
FieldMouseExit
,
/// < Not implemented.
FieldMouseUp
,
/// < Not implemented.
FieldValidate
,
/// < Not implemented.
/* Validates the field after every change is commited
* (clicked outside or tabbed to another field).
* The enter event is not handled
*/
FieldValidate
,
LinkMouseUp
,
/// < Not implemented.
MenuExec
,
/// < Not implemented.
PageOpen
,
/// < Not implemented.
...
...
@@ -115,6 +119,9 @@ class Event
static
std
::
shared_ptr
<
Event
>
createFormFocusEvent
(
FormField
*
target
,
Page
*
targetPage
,
const
QString
&
targetName
=
QString
()
);
static
std
::
shared_ptr
<
Event
>
createFormValidateEvent
(
FormField
*
target
,
Page
*
targetPage
,
const
QString
&
targetName
=
QString
()
);
private:
class
Private
;
std
::
shared_ptr
<
Private
>
d
;
...
...
core/script/kjs_event.cpp
View file @
69398447
...
...
@@ -79,6 +79,7 @@ static KJSObject eventGetTarget( KJSContext *ctx, void *object )
case
Event
::
FieldFormat
:
case
Event
::
FieldKeystroke
:
case
Event
::
FieldFocus
:
case
Event
::
FieldValidate
:
{
FormField
*
target
=
static_cast
<
FormField
*
>
(
event
->
target
()
);
if
(
target
)
...
...
ui/formwidgets.cpp
View file @
69398447
...
...
@@ -90,6 +90,30 @@ void FormWidgetsController::signalAction( Okular::Action *a )
emit
action
(
a
);
}
void
FormWidgetsController
::
processScriptAction
(
Okular
::
Action
*
a
,
Okular
::
FormField
*
field
,
Okular
::
Annotation
::
AdditionalActionType
type
)
{
// If it's not a Action Script or if the field is not a FormText, handle it normally
if
(
a
->
actionType
()
!=
Okular
::
Action
::
Script
||
field
->
type
()
!=
Okular
::
FormField
::
FormText
)
{
emit
action
(
a
);
return
;
}
switch
(
type
)
{
// These cases are to be handled by the FormField text, so we let it happen.
case
Okular
::
Annotation
::
FocusIn
:
case
Okular
::
Annotation
::
FocusOut
:
return
;
case
Okular
::
Annotation
::
PageOpening
:
case
Okular
::
Annotation
::
PageClosing
:
case
Okular
::
Annotation
::
CursorEntering
:
case
Okular
::
Annotation
::
CursorLeaving
:
case
Okular
::
Annotation
::
MousePressed
:
case
Okular
::
Annotation
::
MouseReleased
:
emit
action
(
a
);
}
}
void
FormWidgetsController
::
registerRadioButton
(
FormWidgetIface
*
fwButton
,
Okular
::
FormFieldButton
*
formButton
)
{
if
(
!
fwButton
)
...
...
@@ -510,10 +534,21 @@ bool FormLineEdit::event( QEvent* e )
m_editing
=
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
;
m_editing
=
false
;
if
(
const
Okular
::
Action
*
action
=
m_ff
->
additionalAction
(
Okular
::
Annotation
::
FocusOut
)
)
{
bool
ok
=
false
;
emit
m_controller
->
validateAction
(
action
,
static_cast
<
Okular
::
FormFieldText
*
>
(
m_ff
),
ok
);
}
if
(
const
Okular
::
Action
*
action
=
m_ff
->
additionalAction
(
Okular
::
FormField
::
FormatField
)
)
{
emit
m_controller
->
formatAction
(
action
,
static_cast
<
Okular
::
FormFieldText
*
>
(
m_ff
)
);
...
...
@@ -1299,7 +1334,7 @@ void SignatureEdit::slotViewProperties()
Okular::Action *act = m_ff->additionalAction( Okular::Annotation::FocusIn ); \
if ( act ) \
{ \
m_controller->
signalAction( act
); \
m_controller->
processScriptAction( act, m_ff, Okular::Annotation::FocusIn
); \
} \
BaseClass::focusInEvent( event ); \
} \
...
...
@@ -1308,7 +1343,7 @@ void SignatureEdit::slotViewProperties()
Okular::Action *act = m_ff->additionalAction( Okular::Annotation::FocusOut ); \
if ( act ) \
{ \
m_controller->
signalAction( ac
t ); \
m_controller->
processScriptAction( act, m_ff, Okular::Annotation::FocusOu
t ); \
} \
BaseClass::focusOutEvent( event ); \
} \
...
...
ui/formwidgets.h
View file @
69398447
...
...
@@ -61,6 +61,8 @@ class FormWidgetsController : public QObject
void
signalAction
(
Okular
::
Action
*
action
);
void
processScriptAction
(
Okular
::
Action
*
a
,
Okular
::
FormField
*
field
,
Okular
::
Annotation
::
AdditionalActionType
type
);
void
registerRadioButton
(
FormWidgetIface
*
fwButton
,
Okular
::
FormFieldButton
*
formButton
);
void
dropRadioButtons
();
bool
canUndo
();
...
...
@@ -123,6 +125,8 @@ class FormWidgetsController : public QObject
void
keystrokeAction
(
const
Okular
::
Action
*
action
,
Okular
::
FormFieldText
*
ff
,
bool
&
ok
);
void
validateAction
(
const
Okular
::
Action
*
action
,
Okular
::
FormFieldText
*
ff
,
bool
&
ok
);
void
refreshFormWidget
(
Okular
::
FormField
*
form
);
private
Q_SLOTS
:
...
...
ui/pageview.cpp
View file @
69398447
...
...
@@ -276,6 +276,10 @@ FormWidgetsController* PageViewPrivate::formWidgetsController()
q
,
[
this
]
(
const
Okular
::
Action
*
action
,
Okular
::
FormFieldText
*
fft
)
{
document
->
processFocusAction
(
action
,
fft
);
}
);
QObject
::
connect
(
formsWidgetController
,
&
FormWidgetsController
::
validateAction
,
q
,
[
this
]
(
const
Okular
::
Action
*
action
,
Okular
::
FormFieldText
*
fft
,
bool
&
ok
)
{
document
->
processValidateAction
(
action
,
fft
,
ok
);
}
);
}
return
formsWidgetController
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment