Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Graphics
Okular
Commits
552e4a39
Commit
552e4a39
authored
Jun 06, 2019
by
Joao Oliveira
Committed by
Albert Astals Cid
Jul 20, 2019
Browse files
Added support for buttonSetIcon and buttonGetIcon.
Added support for the setIcon/getIcon defined in Poppler > 0_78
parent
f3c8bb92
Changes
7
Hide whitespace changes
Inline
Side-by-side
core/form.cpp
View file @
552e4a39
...
...
@@ -147,6 +147,10 @@ void FormFieldButton::setState( bool )
{
}
void
FormFieldButton
::
setIcon
(
Okular
::
FormField
*
)
{
}
class
Okular
::
FormFieldTextPrivate
:
public
Okular
::
FormFieldPrivate
{
...
...
core/form.h
View file @
552e4a39
...
...
@@ -207,6 +207,13 @@ class OKULARCORE_EXPORT FormFieldButton : public FormField
*/
virtual
QList
<
int
>
siblings
()
const
=
0
;
/**
* Sets the icon of the Button to the Icon of the field parameter.
*
* @since 1.7
*/
virtual
void
setIcon
(
Okular
::
FormField
*
field
);
protected:
FormFieldButton
();
...
...
core/script/kjs_field.cpp
View file @
552e4a39
...
...
@@ -17,6 +17,7 @@
#include <qhash.h>
#include <QDebug>
#include <memory>
#include "../debug_p.h"
#include "../document_p.h"
...
...
@@ -30,6 +31,8 @@ static KJSPrototype *g_fieldProto;
typedef
QHash
<
FormField
*
,
Page
*
>
FormCache
;
Q_GLOBAL_STATIC
(
FormCache
,
g_fieldCache
)
typedef
QHash
<
QString
,
FormField
*
>
ButtonCache
;
Q_GLOBAL_STATIC
(
ButtonCache
,
g_buttonCache
)
// Helper for modified fields
...
...
@@ -241,6 +244,39 @@ static void fieldSetDisplay( KJSContext *context, void *object, KJSObject value
updateField
(
field
);
}
// Instead of getting the Icon, we pick the field.
static
KJSObject
fieldButtonGetIcon
(
KJSContext
*
ctx
,
void
*
object
,
const
KJSArguments
&
)
{
FormField
*
field
=
reinterpret_cast
<
FormField
*
>
(
object
);
KJSObject
fieldObject
;
fieldObject
.
setProperty
(
ctx
,
QStringLiteral
(
"name"
).
toLatin1
().
toBase64
(),
field
->
name
()
);
g_buttonCache
->
insert
(
field
->
name
(),
field
);
return
fieldObject
;
}
/*
* Now we send to the button what Icon should be drawn on it
*/
static
KJSObject
fieldButtonSetIcon
(
KJSContext
*
ctx
,
void
*
object
,
const
KJSArguments
&
arguments
)
{
FormField
*
field
=
reinterpret_cast
<
FormField
*
>
(
object
);
QString
fieldName
=
arguments
.
at
(
0
).
property
(
ctx
,
QStringLiteral
(
"name"
).
toLatin1
().
toBase64
()
).
toString
(
ctx
);
if
(
field
->
type
()
==
Okular
::
FormField
::
FormButton
)
{
FormFieldButton
*
button
=
static_cast
<
FormFieldButton
*
>
(
field
);
button
->
setIcon
(
g_buttonCache
->
value
(
fieldName
)
);
}
updateField
(
field
);
return
KJSUndefined
();
}
void
JSField
::
initType
(
KJSContext
*
ctx
)
{
...
...
@@ -260,6 +296,9 @@ void JSField::initType( KJSContext *ctx )
g_fieldProto
->
defineProperty
(
ctx
,
QStringLiteral
(
"value"
),
fieldGetValue
,
fieldSetValue
);
g_fieldProto
->
defineProperty
(
ctx
,
QStringLiteral
(
"hidden"
),
fieldGetHidden
,
fieldSetHidden
);
g_fieldProto
->
defineProperty
(
ctx
,
QStringLiteral
(
"display"
),
fieldGetDisplay
,
fieldSetDisplay
);
g_fieldProto
->
defineFunction
(
ctx
,
QStringLiteral
(
"buttonGetIcon"
),
fieldButtonGetIcon
);
g_fieldProto
->
defineFunction
(
ctx
,
QStringLiteral
(
"buttonSetIcon"
),
fieldButtonSetIcon
);
}
KJSObject
JSField
::
wrapField
(
KJSContext
*
ctx
,
FormField
*
field
,
Page
*
page
)
...
...
@@ -274,7 +313,8 @@ KJSObject JSField::wrapField( KJSContext *ctx, FormField *field, Page *page )
void
JSField
::
clearCachedFields
()
{
if
(
g_fieldCache
.
exists
()
)
{
g_fieldCache
->
clear
();
}
if
(
g_buttonCache
.
exists
()
)
g_buttonCache
->
clear
();
}
generators/poppler/CMakeLists.txt
View file @
552e4a39
...
...
@@ -144,6 +144,18 @@ int main()
}
"
HAVE_POPPLER_0_73
)
check_cxx_source_compiles
(
"
#include <poppler-form.h>
#include <poppler-qt5.h>
int main()
{
Poppler::FormFieldIcon icon(nullptr);
Poppler::FormFieldButton *button;
button->setIcon( icon );
return 0;
}
"
HAVE_POPPLER_0_78
)
configure_file
(
${
CMAKE_CURRENT_SOURCE_DIR
}
/config-okular-poppler.h.cmake
${
CMAKE_CURRENT_BINARY_DIR
}
/config-okular-poppler.h
...
...
generators/poppler/config-okular-poppler.h.cmake
View file @
552e4a39
...
...
@@ -45,3 +45,6 @@
/* Defined if we have the 0.73 version of the Poppler library */
#cmakedefine HAVE_POPPLER_0_73 1
/* Defined if we have the 0.78 version of the Poppler library */
#cmakedefine HAVE_POPPLER_0_78 1
generators/poppler/formfields.cpp
View file @
552e4a39
...
...
@@ -139,6 +139,26 @@ QList< int > PopplerFormFieldButton::siblings() const
return
m_field
->
siblings
();
}
#ifdef HAVE_POPPLER_0_78
Poppler
::
FormFieldIcon
PopplerFormFieldButton
::
icon
()
const
{
return
m_field
->
icon
();
}
#endif
void
PopplerFormFieldButton
::
setIcon
(
Okular
::
FormField
*
field
)
{
#ifdef HAVE_POPPLER_0_78
if
(
field
->
type
()
==
Okular
::
FormField
::
FormButton
)
{
PopplerFormFieldButton
*
button
=
static_cast
<
PopplerFormFieldButton
*
>
(
field
);
m_field
->
setIcon
(
button
->
icon
()
);
}
#else
Q_UNUSED
(
field
);
#endif
}
PopplerFormFieldText
::
PopplerFormFieldText
(
Poppler
::
FormFieldText
*
field
)
:
Okular
::
FormFieldText
(),
m_field
(
field
)
...
...
generators/poppler/formfields.h
View file @
552e4a39
...
...
@@ -11,6 +11,7 @@
#define _OKULAR_GENERATOR_PDF_FORMFIELDS_H_
#include <poppler-form.h>
#include <config-okular-poppler.h>
#include "core/form.h"
class
PopplerFormFieldButton
:
public
Okular
::
FormFieldButton
...
...
@@ -35,6 +36,15 @@ class PopplerFormFieldButton : public Okular::FormFieldButton
bool
state
()
const
override
;
void
setState
(
bool
state
)
override
;
QList
<
int
>
siblings
()
const
override
;
void
setIcon
(
Okular
::
FormField
*
field
)
override
;
#ifdef HAVE_POPPLER_0_78
/*
* Supported only in newer versions of Poppler library.
*
* @since 1.7
*/
Poppler
::
FormFieldIcon
icon
()
const
;
#endif
private:
Poppler
::
FormFieldButton
*
m_field
;
...
...
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