Changeset View
Changeset View
Standalone View
Standalone View
core/document.cpp
Show First 20 Lines • Show All 691 Lines • ▼ Show 20 Line(s) | 680 | { | |||
---|---|---|---|---|---|
692 | const int newmode = !modeString.isEmpty() ? modeString.toInt( &newmode_ok ) : 2; | 692 | const int newmode = !modeString.isEmpty() ? modeString.toInt( &newmode_ok ) : 2; | ||
693 | if ( newmode_ok | 693 | if ( newmode_ok | ||
694 | && view->supportsCapability( View::ZoomModality ) | 694 | && view->supportsCapability( View::ZoomModality ) | ||
695 | && ( view->capabilityFlags( View::ZoomModality ) & ( View::CapabilityRead | View::CapabilitySerializable ) ) ) | 695 | && ( view->capabilityFlags( View::ZoomModality ) & ( View::CapabilityRead | View::CapabilitySerializable ) ) ) | ||
696 | { | 696 | { | ||
697 | view->setCapability( View::ZoomModality, newmode ); | 697 | view->setCapability( View::ZoomModality, newmode ); | ||
698 | } | 698 | } | ||
699 | } | 699 | } | ||
700 | else if ( viewElement.tagName() == "viewMode" ) | ||||
701 | { | ||||
702 | const QString modeString = viewElement.attribute( "mode" ); | ||||
703 | bool newmode_ok = true; | ||||
704 | const int newmode = !modeString.isEmpty() ? modeString.toInt( &newmode_ok ) : 2; | ||||
705 | if ( newmode_ok | ||||
706 | && view->supportsCapability( View::ViewModeModality ) | ||||
707 | && ( view->capabilityFlags( View::ViewModeModality ) | ||||
708 | & ( View::CapabilityRead | View::CapabilitySerializable ) ) ) | ||||
709 | { | ||||
710 | view->setCapability( View::ViewModeModality, newmode ); | ||||
711 | } | ||||
712 | } | ||||
713 | else if ( viewElement.tagName() == "continuous" ) | ||||
714 | { | ||||
715 | const QString modeString = viewElement.attribute( "mode" ); | ||||
716 | bool newmode_ok = true; | ||||
717 | const int newmode = !modeString.isEmpty() ? modeString.toInt( &newmode_ok ) : 2; | ||||
718 | if ( newmode_ok | ||||
719 | && view->supportsCapability( View::Continuous ) | ||||
720 | && ( view->capabilityFlags( View::Continuous ) | ||||
721 | & ( View::CapabilityRead | View::CapabilitySerializable ) ) ) | ||||
722 | { | ||||
723 | view->setCapability( View::Continuous, newmode ); | ||||
724 | } | ||||
725 | } | ||||
726 | else if ( viewElement.tagName() == "trimMargins" ) | ||||
727 | { | ||||
728 | const QString valueString = viewElement.attribute( "value" ); | ||||
729 | bool newmode_ok = true; | ||||
730 | const int newmode = !valueString.isEmpty() ? valueString.toInt( &newmode_ok ) : 2; | ||||
731 | if ( newmode_ok | ||||
732 | && view->supportsCapability( View::TrimMargins ) | ||||
733 | && ( view->capabilityFlags( View::TrimMargins ) | ||||
734 | & ( View::CapabilityRead | View::CapabilitySerializable ) ) ) | ||||
735 | { | ||||
736 | view->setCapability( View::TrimMargins, newmode ); | ||||
737 | } | ||||
738 | } | ||||
700 | 739 | | |||
701 | viewNode = viewNode.nextSibling(); | 740 | viewNode = viewNode.nextSibling(); | ||
702 | } | 741 | } | ||
703 | } | 742 | } | ||
704 | 743 | | |||
705 | void DocumentPrivate::saveViewsInfo( View *view, QDomElement &e ) const | 744 | void DocumentPrivate::saveViewsInfo( View *view, QDomElement &e ) const | ||
706 | { | 745 | { | ||
707 | if ( view->supportsCapability( View::Zoom ) | 746 | if ( view->supportsCapability( View::Zoom ) | ||
Show All 10 Lines | 756 | { | |||
718 | zoomEl.setAttribute( QStringLiteral("value"), QString::number(zoom) ); | 757 | zoomEl.setAttribute( QStringLiteral("value"), QString::number(zoom) ); | ||
719 | } | 758 | } | ||
720 | const int mode = view->capability( View::ZoomModality ).toInt( &ok ); | 759 | const int mode = view->capability( View::ZoomModality ).toInt( &ok ); | ||
721 | if ( ok ) | 760 | if ( ok ) | ||
722 | { | 761 | { | ||
723 | zoomEl.setAttribute( QStringLiteral("mode"), mode ); | 762 | zoomEl.setAttribute( QStringLiteral("mode"), mode ); | ||
724 | } | 763 | } | ||
725 | } | 764 | } | ||
765 | if ( view->supportsCapability( View::Continuous ) | ||||
766 | && ( view->capabilityFlags( View::Continuous ) | ||||
767 | & ( View::CapabilityRead | View::CapabilitySerializable ) ) ) | ||||
768 | { | ||||
769 | QDomElement contEl = e.ownerDocument().createElement( "continuous" ); | ||||
770 | e.appendChild( contEl ); | ||||
771 | const bool mode = view->capability( View::Continuous ).toBool(); | ||||
772 | contEl.setAttribute( "mode", mode ); | ||||
773 | } | ||||
774 | if ( view->supportsCapability( View::ViewModeModality ) | ||||
775 | && ( view->capabilityFlags( View::ViewModeModality ) | ||||
776 | & ( View::CapabilityRead | View::CapabilitySerializable ) ) ) | ||||
777 | { | ||||
778 | QDomElement viewEl = e.ownerDocument().createElement( "viewMode" ); | ||||
779 | e.appendChild( viewEl ); | ||||
780 | bool ok = true; | ||||
781 | const int mode = view->capability( View::ViewModeModality ).toInt( &ok ); | ||||
782 | if ( ok ) | ||||
783 | { | ||||
784 | viewEl.setAttribute( "mode", mode ); | ||||
785 | } | ||||
786 | } | ||||
787 | if ( view->supportsCapability( View::TrimMargins ) | ||||
788 | && ( view->capabilityFlags( View::TrimMargins ) | ||||
789 | & ( View::CapabilityRead | View::CapabilitySerializable ) ) ) | ||||
790 | { | ||||
791 | QDomElement contEl = e.ownerDocument().createElement( "trimMargins" ); | ||||
792 | e.appendChild( contEl ); | ||||
793 | const bool value = view->capability( View::TrimMargins ).toBool(); | ||||
794 | contEl.setAttribute( "value", value ); | ||||
795 | } | ||||
726 | } | 796 | } | ||
727 | 797 | | |||
728 | QUrl DocumentPrivate::giveAbsoluteUrl( const QString & fileName ) const | 798 | QUrl DocumentPrivate::giveAbsoluteUrl( const QString & fileName ) const | ||
729 | { | 799 | { | ||
730 | if ( !QDir::isRelativePath( fileName ) ) | 800 | if ( !QDir::isRelativePath( fileName ) ) | ||
731 | return QUrl::fromLocalFile(fileName); | 801 | return QUrl::fromLocalFile(fileName); | ||
732 | 802 | | |||
733 | if ( !m_url.isValid() ) | 803 | if ( !m_url.isValid() ) | ||
▲ Show 20 Lines • Show All 412 Lines • ▼ Show 20 Line(s) | 1200 | { | |||
1146 | if ( event && fft ) | 1216 | if ( event && fft ) | ||
1147 | { | 1217 | { | ||
1148 | // Update text field from calculate | 1218 | // Update text field from calculate | ||
1149 | m_scripter->setEvent( nullptr ); | 1219 | m_scripter->setEvent( nullptr ); | ||
1150 | const QString newVal = event->value().toString(); | 1220 | const QString newVal = event->value().toString(); | ||
1151 | if ( newVal != oldVal ) | 1221 | if ( newVal != oldVal ) | ||
1152 | { | 1222 | { | ||
1153 | fft->setText( newVal ); | 1223 | fft->setText( newVal ); | ||
1224 | if ( const Okular::Action *action = fft->additionalAction( Okular::FormField::FormatField ) ) | ||||
1225 | { | ||||
1226 | // The format action handles the refresh. | ||||
1227 | m_parent->processFormatAction( action, fft ); | ||||
1228 | } | ||||
1229 | else | ||||
1230 | { | ||||
1154 | emit m_parent->refreshFormWidget( fft ); | 1231 | emit m_parent->refreshFormWidget( fft ); | ||
1155 | pageNeedsRefresh = true; | 1232 | pageNeedsRefresh = true; | ||
1156 | } | 1233 | } | ||
1157 | } | 1234 | } | ||
1158 | } | 1235 | } | ||
1236 | } | ||||
1159 | else | 1237 | else | ||
1160 | { | 1238 | { | ||
1161 | qWarning() << "Form that is part of calculate order doesn't have a calculate action"; | 1239 | qWarning() << "Form that is part of calculate order doesn't have a calculate action"; | ||
1162 | } | 1240 | } | ||
1163 | } | 1241 | } | ||
1164 | } | 1242 | } | ||
1165 | if ( pageNeedsRefresh ) | 1243 | if ( pageNeedsRefresh ) | ||
1166 | { | 1244 | { | ||
▲ Show 20 Lines • Show All 1032 Lines • ▼ Show 20 Line(s) | 2276 | { | |||
2199 | m_closingLoop = &loop; | 2277 | m_closingLoop = &loop; | ||
2200 | loop.exec(); | 2278 | loop.exec(); | ||
2201 | m_closingLoop = nullptr; | 2279 | m_closingLoop = nullptr; | ||
2202 | } | 2280 | } | ||
2203 | } | 2281 | } | ||
2204 | while ( startEventLoop ); | 2282 | while ( startEventLoop ); | ||
2205 | } | 2283 | } | ||
2206 | 2284 | | |||
2285 | int DocumentPrivate::findFieldPageNumber( Okular::FormField *field ) | ||||
2286 | { | ||||
2287 | // Lookup the page of the FormField | ||||
2288 | int foundPage = -1; | ||||
2289 | for ( uint pageIdx = 0, nPages = m_parent->pages(); pageIdx < nPages; pageIdx++ ) | ||||
2290 | { | ||||
2291 | const Page *p = m_parent->page( pageIdx ); | ||||
2292 | if ( p && p->formFields().contains( field ) ) | ||||
2293 | { | ||||
2294 | foundPage = static_cast< int >( pageIdx ); | ||||
2295 | break; | ||||
2296 | } | ||||
2297 | } | ||||
2298 | return foundPage; | ||||
2299 | } | ||||
2300 | | ||||
2301 | void DocumentPrivate::executeScriptEvent( const std::shared_ptr< Event > &event, const Okular::ScriptAction * linkscript ) | ||||
2302 | { | ||||
2303 | if ( !m_scripter ) | ||||
2304 | { | ||||
2305 | m_scripter = new Scripter( this ); | ||||
2306 | } | ||||
2307 | m_scripter->setEvent( event.get() ); | ||||
2308 | m_scripter->execute( linkscript->scriptType(), linkscript->script() ); | ||||
2309 | | ||||
2310 | // Clear out the event after execution | ||||
2311 | m_scripter->setEvent( nullptr ); | ||||
2312 | } | ||||
2313 | | ||||
2314 | | ||||
2207 | Document::Document( QWidget *widget ) | 2315 | Document::Document( QWidget *widget ) | ||
2208 | : QObject( nullptr ), d( new DocumentPrivate( this ) ) | 2316 | : QObject( nullptr ), d( new DocumentPrivate( this ) ) | ||
2209 | { | 2317 | { | ||
2210 | d->m_widget = widget; | 2318 | d->m_widget = widget; | ||
2211 | d->m_bookmarkManager = new BookmarkManager( d ); | 2319 | d->m_bookmarkManager = new BookmarkManager( d ); | ||
2212 | d->m_viewportIterator = d->m_viewportHistory.insert( d->m_viewportHistory.end(), DocumentViewport() ); | 2320 | d->m_viewportIterator = d->m_viewportHistory.insert( d->m_viewportHistory.end(), DocumentViewport() ); | ||
2213 | d->m_undoStack = new QUndoStack(this); | 2321 | d->m_undoStack = new QUndoStack(this); | ||
2214 | 2322 | | |||
▲ Show 20 Lines • Show All 2072 Lines • ▼ Show 20 Line(s) | 4186 | { | |||
4287 | { | 4395 | { | ||
4288 | for ( const Action *a : action->nextActions() ) | 4396 | for ( const Action *a : action->nextActions() ) | ||
4289 | { | 4397 | { | ||
4290 | processAction( a ); | 4398 | processAction( a ); | ||
4291 | } | 4399 | } | ||
4292 | } | 4400 | } | ||
4293 | } | 4401 | } | ||
4294 | 4402 | | |||
4403 | void Document::processFormatAction( const Action * action, Okular::FormFieldText *fft ) | ||||
4404 | { | ||||
4405 | if ( action->actionType() != Action::Script ) | ||||
4406 | { | ||||
4407 | qCDebug( OkularCoreDebug ) << "Unsupported action type" << action->actionType() << "for formatting."; | ||||
4408 | return; | ||||
4409 | } | ||||
4410 | | ||||
4411 | // Lookup the page of the FormFieldText | ||||
4412 | int foundPage = d->findFieldPageNumber( fft ); | ||||
4413 | | ||||
4414 | if ( foundPage == -1 ) | ||||
4415 | { | ||||
4416 | qCDebug( OkularCoreDebug ) << "Could not find page for formfield!"; | ||||
4417 | return; | ||||
4418 | } | ||||
4419 | | ||||
4420 | const QString unformattedText = fft->text(); | ||||
4421 | | ||||
4422 | std::shared_ptr< Event > event = Event::createFormatEvent( fft, d->m_pagesVector[foundPage] ); | ||||
4423 | | ||||
4424 | const ScriptAction * linkscript = static_cast< const ScriptAction * >( action ); | ||||
4425 | | ||||
4426 | d->executeScriptEvent( event, linkscript ); | ||||
4427 | | ||||
4428 | const QString formattedText = event->value().toString(); | ||||
4429 | if ( formattedText != unformattedText ) | ||||
4430 | { | ||||
4431 | // We set the formattedText, because when we call refreshFormWidget | ||||
4432 | // It will set the QLineEdit to this formattedText | ||||
4433 | fft->setText( formattedText ); | ||||
4434 | fft->setAppearanceText( formattedText ); | ||||
4435 | emit refreshFormWidget( fft ); | ||||
4436 | d->refreshPixmaps( foundPage ); | ||||
4437 | // Then we make the form have the unformatted text, to use | ||||
4438 | // in calculations and other things. | ||||
4439 | fft->setText( unformattedText ); | ||||
4440 | } | ||||
4441 | else if ( fft->additionalAction( FormField::CalculateField ) ) | ||||
4442 | { | ||||
4443 | // When the field was calculated we need to refresh even | ||||
4444 | // if the format script changed nothing. e.g. on error. | ||||
4445 | // This is because the recalculateForms function delegated | ||||
4446 | // the responsiblity for the refresh to us. | ||||
4447 | emit refreshFormWidget( fft ); | ||||
4448 | d->refreshPixmaps( foundPage ); | ||||
4449 | } | ||||
4450 | } | ||||
4451 | | ||||
4452 | void Document::processKeystrokeAction( const Action * action, Okular::FormFieldText *fft, bool &returnCode ) | ||||
4453 | { | ||||
4454 | if ( action->actionType() != Action::Script ) | ||||
4455 | { | ||||
4456 | qCDebug( OkularCoreDebug ) << "Unsupported action type" << action->actionType() << "for keystroke."; | ||||
4457 | return; | ||||
4458 | } | ||||
4459 | // Lookup the page of the FormFieldText | ||||
4460 | int foundPage = d->findFieldPageNumber( fft ); | ||||
4461 | | ||||
4462 | if ( foundPage == -1 ) | ||||
4463 | { | ||||
4464 | qCDebug( OkularCoreDebug ) << "Could not find page for formfield!"; | ||||
4465 | return; | ||||
4466 | } | ||||
4467 | | ||||
4468 | std::shared_ptr< Event > event = Event::createKeystrokeEvent( fft, d->m_pagesVector[foundPage] ); | ||||
4469 | | ||||
4470 | const ScriptAction * linkscript = static_cast< const ScriptAction * >( action ); | ||||
4471 | | ||||
4472 | d->executeScriptEvent( event, linkscript ); | ||||
4473 | | ||||
4474 | returnCode = event->returnCode(); | ||||
4475 | } | ||||
4476 | | ||||
4477 | void Document::processFocusAction( const Action * action, Okular::FormField *field ) | ||||
4478 | { | ||||
4479 | if ( !action || action->actionType() != Action::Script ) | ||||
4480 | return; | ||||
4481 | | ||||
4482 | // Lookup the page of the FormFieldText | ||||
4483 | int foundPage = d->findFieldPageNumber( field ); | ||||
4484 | | ||||
4485 | if ( foundPage == -1 ) | ||||
4486 | { | ||||
4487 | qCDebug( OkularCoreDebug ) << "Could not find page for formfield!"; | ||||
4488 | return; | ||||
4489 | } | ||||
4490 | | ||||
4491 | std::shared_ptr< Event > event = Event::createFormFocusEvent( field, d->m_pagesVector[foundPage] ); | ||||
4492 | | ||||
4493 | const ScriptAction * linkscript = static_cast< const ScriptAction * >( action ); | ||||
4494 | | ||||
4495 | d->executeScriptEvent( event, linkscript ); | ||||
4496 | } | ||||
4497 | | ||||
4498 | void Document::processValidateAction( const Action * action, Okular::FormFieldText *fft, bool &returnCode ) | ||||
4499 | { | ||||
4500 | if ( !action || action->actionType() != Action::Script ) | ||||
4501 | return; | ||||
4502 | | ||||
4503 | // Lookup the page of the FormFieldText | ||||
4504 | int foundPage = d->findFieldPageNumber( fft ); | ||||
4505 | | ||||
4506 | if ( foundPage == -1 ) | ||||
4507 | { | ||||
4508 | qCDebug( OkularCoreDebug ) << "Could not find page for formfield!"; | ||||
4509 | return; | ||||
4510 | } | ||||
4511 | | ||||
4512 | std::shared_ptr< Event > event = Event::createFormValidateEvent( fft, d->m_pagesVector[foundPage] ); | ||||
4513 | | ||||
4514 | const ScriptAction * linkscript = static_cast< const ScriptAction * >( action ); | ||||
4515 | | ||||
4516 | d->executeScriptEvent( event, linkscript ); | ||||
4517 | returnCode = event->returnCode(); | ||||
4518 | } | ||||
4519 | | ||||
4295 | void Document::processSourceReference( const SourceReference * ref ) | 4520 | void Document::processSourceReference( const SourceReference * ref ) | ||
4296 | { | 4521 | { | ||
4297 | if ( !ref ) | 4522 | if ( !ref ) | ||
4298 | return; | 4523 | return; | ||
4299 | 4524 | | |||
4300 | const QUrl url = d->giveAbsoluteUrl( ref->fileName() ); | 4525 | const QUrl url = d->giveAbsoluteUrl( ref->fileName() ); | ||
4301 | if ( !url.isLocalFile() ) | 4526 | if ( !url.isLocalFile() ) | ||
4302 | { | 4527 | { | ||
▲ Show 20 Lines • Show All 807 Lines • ▼ Show 20 Line(s) | 5325 | { | |||
5110 | QByteArray data; | 5335 | QByteArray data; | ||
5111 | QDataStream stream( &data, QIODevice::WriteOnly ); | 5336 | QDataStream stream( &data, QIODevice::WriteOnly ); | ||
5112 | stream << f.read( byteRange.last() - byteRange.first() ); | 5337 | stream << f.read( byteRange.last() - byteRange.first() ); | ||
5113 | f.close(); | 5338 | f.close(); | ||
5114 | 5339 | | |||
5115 | return data; | 5340 | return data; | ||
5116 | } | 5341 | } | ||
5117 | 5342 | | |||
5343 | void DocumentPrivate::executeScript( const QString &function ) | ||||
5344 | { | ||||
5345 | if( !m_scripter ) | ||||
5346 | m_scripter = new Scripter( this ); | ||||
5347 | m_scripter->execute( JavaScript, function ); | ||||
5348 | } | ||||
5349 | | ||||
5118 | void DocumentPrivate::requestDone( PixmapRequest * req ) | 5350 | void DocumentPrivate::requestDone( PixmapRequest * req ) | ||
5119 | { | 5351 | { | ||
5120 | if ( !req ) | 5352 | if ( !req ) | ||
5121 | return; | 5353 | return; | ||
5122 | 5354 | | |||
5123 | if ( !m_generator || m_closingLoop ) | 5355 | if ( !m_generator || m_closingLoop ) | ||
5124 | { | 5356 | { | ||
5125 | m_pixmapRequestsMutex.lock(); | 5357 | m_pixmapRequestsMutex.lock(); | ||
▲ Show 20 Lines • Show All 549 Lines • Show Last 20 Lines |