Changeset View
Changeset View
Standalone View
Standalone View
core/script/kjs_document.cpp
Show All 18 Lines | |||||
19 | #include <QDebug> | 19 | #include <QDebug> | ||
20 | #include <assert.h> | 20 | #include <assert.h> | ||
21 | 21 | | |||
22 | #include "../document_p.h" | 22 | #include "../document_p.h" | ||
23 | #include "../page.h" | 23 | #include "../page.h" | ||
24 | #include "../form.h" | 24 | #include "../form.h" | ||
25 | #include "kjs_data_p.h" | 25 | #include "kjs_data_p.h" | ||
26 | #include "kjs_field_p.h" | 26 | #include "kjs_field_p.h" | ||
27 | #include "kjs_ocg_p.h" | ||||
27 | 28 | | |||
28 | using namespace Okular; | 29 | using namespace Okular; | ||
29 | 30 | | |||
30 | static KJSPrototype *g_docProto; | 31 | static KJSPrototype *g_docProto; | ||
31 | 32 | | |||
32 | // Document.numPages | 33 | // Document.numPages | ||
33 | static KJSObject docGetNumPages( KJSContext *, void *object ) | 34 | static KJSObject docGetNumPages( KJSContext *, void *object ) | ||
34 | { | 35 | { | ||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | 123 | { | |||
124 | QWidget *widget = doc->m_widget; | 125 | QWidget *widget = doc->m_widget; | ||
125 | 126 | | |||
126 | const bool isShell = ( widget | 127 | const bool isShell = ( widget | ||
127 | && widget->parentWidget() | 128 | && widget->parentWidget() | ||
128 | && widget->parentWidget()->objectName().startsWith( QLatin1String( "okular::Shell" ) ) ); | 129 | && widget->parentWidget()->objectName().startsWith( QLatin1String( "okular::Shell" ) ) ); | ||
129 | return KJSBoolean( !isShell ); | 130 | return KJSBoolean( !isShell ); | ||
130 | } | 131 | } | ||
131 | 132 | | |||
133 | // Document.numFields | ||||
134 | static KJSObject docGetNumFields( KJSContext *, void *object ) | ||||
135 | { | ||||
136 | const DocumentPrivate *doc = reinterpret_cast< DocumentPrivate* >( object ); | ||||
137 | | ||||
138 | unsigned int numFields = 0; | ||||
139 | | ||||
140 | for ( const Page * pIt : qAsConst(doc->m_pagesVector) ) | ||||
141 | { | ||||
142 | numFields += pIt->formFields().size(); | ||||
143 | } | ||||
144 | | ||||
145 | return KJSNumber( numFields ); | ||||
146 | } | ||||
147 | | ||||
132 | 148 | | |||
133 | static KJSObject docGetInfo( KJSContext *ctx, void *object ) | 149 | static KJSObject docGetInfo( KJSContext *ctx, void *object ) | ||
134 | { | 150 | { | ||
135 | DocumentPrivate *doc = reinterpret_cast< DocumentPrivate* >( object ); | 151 | DocumentPrivate *doc = reinterpret_cast< DocumentPrivate* >( object ); | ||
136 | 152 | | |||
137 | KJSObject obj; | 153 | KJSObject obj; | ||
138 | QSet<DocumentInfo::Key> keys; | 154 | QSet<DocumentInfo::Key> keys; | ||
139 | keys << DocumentInfo::Title | 155 | keys << DocumentInfo::Title | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 202 | { | |||
190 | 206 | | |||
191 | QVector< Page * >::const_iterator pIt = doc->m_pagesVector.constBegin(), pEnd = doc->m_pagesVector.constEnd(); | 207 | QVector< Page * >::const_iterator pIt = doc->m_pagesVector.constBegin(), pEnd = doc->m_pagesVector.constEnd(); | ||
192 | for ( ; pIt != pEnd; ++pIt ) | 208 | for ( ; pIt != pEnd; ++pIt ) | ||
193 | { | 209 | { | ||
194 | const QLinkedList< Okular::FormField * > pageFields = (*pIt)->formFields(); | 210 | const QLinkedList< Okular::FormField * > pageFields = (*pIt)->formFields(); | ||
195 | QLinkedList< Okular::FormField * >::const_iterator ffIt = pageFields.constBegin(), ffEnd = pageFields.constEnd(); | 211 | QLinkedList< Okular::FormField * >::const_iterator ffIt = pageFields.constBegin(), ffEnd = pageFields.constEnd(); | ||
196 | for ( ; ffIt != ffEnd; ++ffIt ) | 212 | for ( ; ffIt != ffEnd; ++ffIt ) | ||
197 | { | 213 | { | ||
198 | if ( (*ffIt)->name() == cName ) | 214 | if ( (*ffIt)->fullyQualifiedName() == cName ) | ||
199 | { | 215 | { | ||
200 | return JSField::wrapField( context, *ffIt, *pIt ); | 216 | return JSField::wrapField( context, *ffIt, *pIt ); | ||
201 | } | 217 | } | ||
202 | } | 218 | } | ||
203 | } | 219 | } | ||
204 | return KJSUndefined(); | 220 | return KJSUndefined(); | ||
205 | } | 221 | } | ||
206 | 222 | | |||
Show All 36 Lines | |||||
243 | 259 | | |||
244 | // Document.syncAnnotScan() | 260 | // Document.syncAnnotScan() | ||
245 | static KJSObject docSyncAnnotScan( KJSContext *, void *, | 261 | static KJSObject docSyncAnnotScan( KJSContext *, void *, | ||
246 | const KJSArguments & ) | 262 | const KJSArguments & ) | ||
247 | { | 263 | { | ||
248 | return KJSUndefined(); | 264 | return KJSUndefined(); | ||
249 | } | 265 | } | ||
250 | 266 | | |||
267 | // Document.getNthFieldName | ||||
268 | static KJSObject docGetNthFieldName( KJSContext *ctx, void *object, | ||||
269 | const KJSArguments &arguments ) | ||||
270 | { | ||||
271 | const DocumentPrivate *doc = reinterpret_cast< DocumentPrivate* >( object ); | ||||
272 | | ||||
273 | int numField = arguments.at( 0 ).toInt32( ctx ); | ||||
274 | | ||||
275 | for ( const Page * pIt : qAsConst(doc->m_pagesVector) ) | ||||
276 | { | ||||
277 | const QLinkedList< Okular::FormField * > pageFields = pIt->formFields(); | ||||
278 | | ||||
279 | if(numField < pageFields.size()) | ||||
280 | { | ||||
281 | const auto ffIt = pageFields.begin() + numField; | ||||
282 | | ||||
283 | return KJSString( (*ffIt)->fullyQualifiedName() ); | ||||
284 | } | ||||
285 | | ||||
286 | numField -= pageFields.size(); | ||||
287 | } | ||||
288 | | ||||
289 | return KJSUndefined(); | ||||
290 | } | ||||
291 | | ||||
292 | static KJSObject docGetOCGs( KJSContext *ctx, void *object, | ||||
293 | const KJSArguments & ) | ||||
294 | { | ||||
295 | const DocumentPrivate *doc = reinterpret_cast< DocumentPrivate* >( object ); | ||||
296 | | ||||
297 | QAbstractItemModel * model = doc->m_parent->layersModel(); | ||||
298 | | ||||
299 | KJSArray array( ctx, model->rowCount() ); | ||||
300 | | ||||
301 | for(int i = 0;i < model->rowCount();++i){ | ||||
302 | for(int j = 0;j < model->columnCount();++j){ | ||||
303 | const QModelIndex index = model->index( i, j ); | ||||
304 | | ||||
305 | KJSObject item = JSOCG::wrapOCGObject( ctx, model, i, j ); | ||||
306 | item.setProperty( ctx, QStringLiteral("name"), model->data( index , Qt::DisplayRole ).toString() ); | ||||
307 | item.setProperty( ctx, QStringLiteral("initState"), model->data( index , Qt::CheckStateRole ).toBool() ); | ||||
308 | | ||||
309 | array.setProperty( ctx, QString::number( i ), item ); | ||||
310 | } | ||||
311 | } | ||||
312 | | ||||
313 | return array; | ||||
314 | } | ||||
315 | | ||||
251 | void JSDocument::initType( KJSContext *ctx ) | 316 | void JSDocument::initType( KJSContext *ctx ) | ||
252 | { | 317 | { | ||
253 | assert( g_docProto ); | 318 | assert( g_docProto ); | ||
254 | 319 | | |||
255 | static bool initialized = false; | 320 | static bool initialized = false; | ||
256 | if ( initialized ) | 321 | if ( initialized ) | ||
257 | return; | 322 | return; | ||
258 | initialized = true; | 323 | initialized = true; | ||
259 | 324 | | |||
260 | g_docProto->defineProperty( ctx, QStringLiteral("numPages"), docGetNumPages ); | 325 | g_docProto->defineProperty( ctx, QStringLiteral("numPages"), docGetNumPages ); | ||
261 | g_docProto->defineProperty( ctx, QStringLiteral("pageNum"), docGetPageNum, docSetPageNum ); | 326 | g_docProto->defineProperty( ctx, QStringLiteral("pageNum"), docGetPageNum, docSetPageNum ); | ||
262 | g_docProto->defineProperty( ctx, QStringLiteral("documentFileName"), docGetDocumentFileName ); | 327 | g_docProto->defineProperty( ctx, QStringLiteral("documentFileName"), docGetDocumentFileName ); | ||
263 | g_docProto->defineProperty( ctx, QStringLiteral("filesize"), docGetFilesize ); | 328 | g_docProto->defineProperty( ctx, QStringLiteral("filesize"), docGetFilesize ); | ||
264 | g_docProto->defineProperty( ctx, QStringLiteral("path"), docGetPath ); | 329 | g_docProto->defineProperty( ctx, QStringLiteral("path"), docGetPath ); | ||
265 | g_docProto->defineProperty( ctx, QStringLiteral("URL"), docGetURL ); | 330 | g_docProto->defineProperty( ctx, QStringLiteral("URL"), docGetURL ); | ||
266 | g_docProto->defineProperty( ctx, QStringLiteral("permStatusReady"), docGetPermStatusReady ); | 331 | g_docProto->defineProperty( ctx, QStringLiteral("permStatusReady"), docGetPermStatusReady ); | ||
267 | g_docProto->defineProperty( ctx, QStringLiteral("dataObjects"), docGetDataObjects ); | 332 | g_docProto->defineProperty( ctx, QStringLiteral("dataObjects"), docGetDataObjects ); | ||
268 | g_docProto->defineProperty( ctx, QStringLiteral("external"), docGetExternal ); | 333 | g_docProto->defineProperty( ctx, QStringLiteral("external"), docGetExternal ); | ||
334 | g_docProto->defineProperty( ctx, QStringLiteral("numFields"), docGetNumFields ); | ||||
269 | 335 | | |||
270 | // info properties | 336 | // info properties | ||
271 | g_docProto->defineProperty( ctx, QStringLiteral("info"), docGetInfo ); | 337 | g_docProto->defineProperty( ctx, QStringLiteral("info"), docGetInfo ); | ||
272 | g_docProto->defineProperty( ctx, QStringLiteral("author"), docGetAuthor ); | 338 | g_docProto->defineProperty( ctx, QStringLiteral("author"), docGetAuthor ); | ||
273 | g_docProto->defineProperty( ctx, QStringLiteral("creator"), docGetCreator ); | 339 | g_docProto->defineProperty( ctx, QStringLiteral("creator"), docGetCreator ); | ||
274 | g_docProto->defineProperty( ctx, QStringLiteral("keywords"), docGetKeywords ); | 340 | g_docProto->defineProperty( ctx, QStringLiteral("keywords"), docGetKeywords ); | ||
275 | g_docProto->defineProperty( ctx, QStringLiteral("producer"), docGetProducer ); | 341 | g_docProto->defineProperty( ctx, QStringLiteral("producer"), docGetProducer ); | ||
276 | g_docProto->defineProperty( ctx, QStringLiteral("title"), docGetTitle ); | 342 | g_docProto->defineProperty( ctx, QStringLiteral("title"), docGetTitle ); | ||
277 | g_docProto->defineProperty( ctx, QStringLiteral("subject"), docGetSubject ); | 343 | g_docProto->defineProperty( ctx, QStringLiteral("subject"), docGetSubject ); | ||
278 | 344 | | |||
279 | g_docProto->defineFunction( ctx, QStringLiteral("getField"), docGetField ); | 345 | g_docProto->defineFunction( ctx, QStringLiteral("getField"), docGetField ); | ||
280 | g_docProto->defineFunction( ctx, QStringLiteral("getPageLabel"), docGetPageLabel ); | 346 | g_docProto->defineFunction( ctx, QStringLiteral("getPageLabel"), docGetPageLabel ); | ||
281 | g_docProto->defineFunction( ctx, QStringLiteral("getPageRotation"), docGetPageRotation ); | 347 | g_docProto->defineFunction( ctx, QStringLiteral("getPageRotation"), docGetPageRotation ); | ||
282 | g_docProto->defineFunction( ctx, QStringLiteral("gotoNamedDest"), docGotoNamedDest ); | 348 | g_docProto->defineFunction( ctx, QStringLiteral("gotoNamedDest"), docGotoNamedDest ); | ||
283 | g_docProto->defineFunction( ctx, QStringLiteral("syncAnnotScan"), docSyncAnnotScan ); | 349 | g_docProto->defineFunction( ctx, QStringLiteral("syncAnnotScan"), docSyncAnnotScan ); | ||
350 | g_docProto->defineFunction( ctx, QStringLiteral("getNthFieldName"), docGetNthFieldName ); | ||||
351 | g_docProto->defineFunction( ctx, QStringLiteral("getOCGs"), docGetOCGs ); | ||||
284 | } | 352 | } | ||
285 | 353 | | |||
286 | KJSGlobalObject JSDocument::wrapDocument( DocumentPrivate *doc ) | 354 | KJSGlobalObject JSDocument::wrapDocument( DocumentPrivate *doc ) | ||
287 | { | 355 | { | ||
288 | if ( !g_docProto ) | 356 | if ( !g_docProto ) | ||
289 | g_docProto = new KJSPrototype(); | 357 | g_docProto = new KJSPrototype(); | ||
290 | return g_docProto->constructGlobalObject( doc ); | 358 | return g_docProto->constructGlobalObject( doc ); | ||
291 | } | 359 | } |