mirror of
https://invent.kde.org/graphics/okular
synced 2024-07-16 10:17:04 +00:00
Refresh the pixmap of the page that contains the field when setting its text
This commit is contained in:
parent
2ca1779feb
commit
56bcdad680
|
@ -108,4 +108,5 @@ void ExecutorKJS::execute( const QString &script )
|
|||
{
|
||||
qCDebug(OkularCoreDebug) << "result:" << result.value().toString( ctx );
|
||||
}
|
||||
JSField::clearCachedFields();
|
||||
}
|
||||
|
|
|
@ -22,11 +22,15 @@
|
|||
#include "../document_p.h"
|
||||
#include "../form.h"
|
||||
#include "../page.h"
|
||||
#include "../page_p.h"
|
||||
|
||||
using namespace Okular;
|
||||
|
||||
static KJSPrototype *g_fieldProto;
|
||||
|
||||
typedef QHash< FormField *, Page * > FormCache;
|
||||
Q_GLOBAL_STATIC( FormCache, g_fieldCache )
|
||||
|
||||
// Field.doc
|
||||
static KJSObject fieldGetDoc( KJSContext *context, void * )
|
||||
{
|
||||
|
@ -109,7 +113,7 @@ static KJSObject fieldGetType( KJSContext *, void *object )
|
|||
}
|
||||
|
||||
// Field.value (getter)
|
||||
static KJSObject fieldGetValue( KJSContext *context, void *object )
|
||||
static KJSObject fieldGetValue( KJSContext */*context*/, void *object )
|
||||
{
|
||||
FormField *field = reinterpret_cast< FormField * >( object );
|
||||
|
||||
|
@ -156,8 +160,23 @@ static void fieldSetValue( KJSContext *context, void *object, KJSObject value )
|
|||
}
|
||||
case FormField::FormText:
|
||||
{
|
||||
FormFieldText *text = static_cast< FormFieldText * >( field );
|
||||
text->setText( value.toString( context ) );
|
||||
FormFieldText *textField = static_cast< FormFieldText * >( field );
|
||||
const QString text = value.toString( context );
|
||||
if ( text != textField->text() )
|
||||
{
|
||||
textField->setText( text );
|
||||
|
||||
Page *page = g_fieldCache->value( field );
|
||||
if (page)
|
||||
{
|
||||
Document *doc = PagePrivate::get( page )->m_doc->m_parent;
|
||||
QMetaObject::invokeMethod( doc, "refreshPixmaps", Qt::QueuedConnection, Q_ARG( int, page->number() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Could not get page of field" << field;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FormField::FormChoice:
|
||||
|
@ -196,5 +215,14 @@ KJSObject JSField::wrapField( KJSContext *ctx, FormField *field, Page *page )
|
|||
// ### cache unique wrapper
|
||||
KJSObject f = g_fieldProto->constructObject( ctx, field );
|
||||
f.setProperty( ctx, QStringLiteral("page"), page->number() );
|
||||
g_fieldCache->insert( field, page );
|
||||
return f;
|
||||
}
|
||||
|
||||
void JSField::clearCachedFields()
|
||||
{
|
||||
if ( g_fieldCache.exists() )
|
||||
{
|
||||
g_fieldCache->clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ class JSField
|
|||
public:
|
||||
static void initType( KJSContext *ctx );
|
||||
static KJSObject wrapField( KJSContext *ctx, FormField *field, Page *page );
|
||||
static void clearCachedFields();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue