Commit 5ce3593e authored by Albert Astals Cid's avatar Albert Astals Cid

createAnnotationFromPopplerAnnotation: Renames to make the code easier to read

It's not clear ann was a popplerAnnotation but annotation was an
okularAnnotation
parent 4e89757a
...@@ -258,17 +258,17 @@ void PopplerAnnotationProxy::notifyRemoval(Okular::Annotation *okl_ann, int page ...@@ -258,17 +258,17 @@ void PopplerAnnotationProxy::notifyRemoval(Okular::Annotation *okl_ann, int page
} }
// END PopplerAnnotationProxy implementation // END PopplerAnnotationProxy implementation
Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *ann, bool *doDelete) Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *popplerAnnotation, bool *doDelete)
{ {
Okular::Annotation *annotation = nullptr; Okular::Annotation *okularAnnotation = nullptr;
*doDelete = true; *doDelete = true;
bool tieToOkularAnn = false; bool tieToOkularAnn = false;
bool externallyDrawn = false; bool externallyDrawn = false;
switch (ann->subType()) { switch (popplerAnnotation->subType()) {
case Poppler::Annotation::AFileAttachment: { case Poppler::Annotation::AFileAttachment: {
Poppler::FileAttachmentAnnotation *attachann = static_cast<Poppler::FileAttachmentAnnotation *>(ann); Poppler::FileAttachmentAnnotation *attachann = static_cast<Poppler::FileAttachmentAnnotation *>(popplerAnnotation);
Okular::FileAttachmentAnnotation *f = new Okular::FileAttachmentAnnotation(); Okular::FileAttachmentAnnotation *f = new Okular::FileAttachmentAnnotation();
annotation = f; okularAnnotation = f;
tieToOkularAnn = true; tieToOkularAnn = true;
*doDelete = false; *doDelete = false;
...@@ -278,9 +278,9 @@ Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *a ...@@ -278,9 +278,9 @@ Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *a
break; break;
} }
case Poppler::Annotation::ASound: { case Poppler::Annotation::ASound: {
Poppler::SoundAnnotation *soundann = static_cast<Poppler::SoundAnnotation *>(ann); Poppler::SoundAnnotation *soundann = static_cast<Poppler::SoundAnnotation *>(popplerAnnotation);
Okular::SoundAnnotation *s = new Okular::SoundAnnotation(); Okular::SoundAnnotation *s = new Okular::SoundAnnotation();
annotation = s; okularAnnotation = s;
s->setSoundIconName(soundann->soundIconName()); s->setSoundIconName(soundann->soundIconName());
s->setSound(createSoundFromPopplerSound(soundann->sound())); s->setSound(createSoundFromPopplerSound(soundann->sound()));
...@@ -288,9 +288,9 @@ Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *a ...@@ -288,9 +288,9 @@ Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *a
break; break;
} }
case Poppler::Annotation::AMovie: { case Poppler::Annotation::AMovie: {
Poppler::MovieAnnotation *movieann = static_cast<Poppler::MovieAnnotation *>(ann); Poppler::MovieAnnotation *movieann = static_cast<Poppler::MovieAnnotation *>(popplerAnnotation);
Okular::MovieAnnotation *m = new Okular::MovieAnnotation(); Okular::MovieAnnotation *m = new Okular::MovieAnnotation();
annotation = m; okularAnnotation = m;
tieToOkularAnn = true; tieToOkularAnn = true;
*doDelete = false; *doDelete = false;
...@@ -299,25 +299,25 @@ Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *a ...@@ -299,25 +299,25 @@ Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *a
break; break;
} }
case Poppler::Annotation::AWidget: { case Poppler::Annotation::AWidget: {
annotation = new Okular::WidgetAnnotation(); okularAnnotation = new Okular::WidgetAnnotation();
break; break;
} }
case Poppler::Annotation::AScreen: { case Poppler::Annotation::AScreen: {
Okular::ScreenAnnotation *m = new Okular::ScreenAnnotation(); Okular::ScreenAnnotation *m = new Okular::ScreenAnnotation();
annotation = m; okularAnnotation = m;
tieToOkularAnn = true; tieToOkularAnn = true;
*doDelete = false; *doDelete = false;
break; break;
} }
case Poppler::Annotation::ARichMedia: { case Poppler::Annotation::ARichMedia: {
Poppler::RichMediaAnnotation *richmediaann = static_cast<Poppler::RichMediaAnnotation *>(ann); Poppler::RichMediaAnnotation *richmediaann = static_cast<Poppler::RichMediaAnnotation *>(popplerAnnotation);
const QPair<Okular::Movie *, Okular::EmbeddedFile *> result = createMovieFromPopplerRichMedia(richmediaann); const QPair<Okular::Movie *, Okular::EmbeddedFile *> result = createMovieFromPopplerRichMedia(richmediaann);
if (result.first) { if (result.first) {
Okular::RichMediaAnnotation *r = new Okular::RichMediaAnnotation(); Okular::RichMediaAnnotation *r = new Okular::RichMediaAnnotation();
tieToOkularAnn = true; tieToOkularAnn = true;
*doDelete = false; *doDelete = false;
annotation = r; okularAnnotation = r;
r->setMovie(result.first); r->setMovie(result.first);
r->setEmbeddedFile(result.second); r->setEmbeddedFile(result.second);
...@@ -342,30 +342,30 @@ Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *a ...@@ -342,30 +342,30 @@ Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *a
QDomDocument doc; QDomDocument doc;
QDomElement root = doc.createElement(QStringLiteral("root")); QDomElement root = doc.createElement(QStringLiteral("root"));
doc.appendChild(root); doc.appendChild(root);
Poppler::AnnotationUtils::storeAnnotation(ann, root, doc); Poppler::AnnotationUtils::storeAnnotation(popplerAnnotation, root, doc);
annotation = Okular::AnnotationUtils::createAnnotation(root); okularAnnotation = Okular::AnnotationUtils::createAnnotation(root);
break; break;
} }
} }
if (annotation) { if (okularAnnotation) {
// the Contents field might have lines separated by \r // the Contents field might have lines separated by \r
QString contents = ann->contents(); QString contents = popplerAnnotation->contents();
contents.replace(QLatin1Char('\r'), QLatin1Char('\n')); contents.replace(QLatin1Char('\r'), QLatin1Char('\n'));
annotation->setAuthor(ann->author()); okularAnnotation->setAuthor(popplerAnnotation->author());
annotation->setContents(contents); okularAnnotation->setContents(contents);
annotation->setUniqueName(ann->uniqueName()); okularAnnotation->setUniqueName(popplerAnnotation->uniqueName());
annotation->setModificationDate(ann->modificationDate()); okularAnnotation->setModificationDate(popplerAnnotation->modificationDate());
annotation->setCreationDate(ann->creationDate()); okularAnnotation->setCreationDate(popplerAnnotation->creationDate());
annotation->setFlags(ann->flags() | Okular::Annotation::External); okularAnnotation->setFlags(popplerAnnotation->flags() | Okular::Annotation::External);
annotation->setBoundingRectangle(Okular::NormalizedRect::fromQRectF(ann->boundary())); okularAnnotation->setBoundingRectangle(Okular::NormalizedRect::fromQRectF(popplerAnnotation->boundary()));
if (externallyDrawn) if (externallyDrawn)
annotation->setFlags(annotation->flags() | Okular::Annotation::ExternallyDrawn); okularAnnotation->setFlags(okularAnnotation->flags() | Okular::Annotation::ExternallyDrawn);
// Poppler stores highlight points in swapped order // Poppler stores highlight points in swapped order
if (annotation->subType() == Okular::Annotation::AHighlight) { if (okularAnnotation->subType() == Okular::Annotation::AHighlight) {
Okular::HighlightAnnotation *hlann = static_cast<Okular::HighlightAnnotation *>(annotation); Okular::HighlightAnnotation *hlann = static_cast<Okular::HighlightAnnotation *>(okularAnnotation);
for (Okular::HighlightAnnotation::Quad &quad : hlann->highlightQuads()) { for (Okular::HighlightAnnotation::Quad &quad : hlann->highlightQuads()) {
const Okular::NormalizedPoint p3 = quad.point(3); const Okular::NormalizedPoint p3 = quad.point(3);
quad.setPoint(quad.point(0), 3); quad.setPoint(quad.point(0), 3);
...@@ -376,11 +376,11 @@ Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *a ...@@ -376,11 +376,11 @@ Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *a
} }
} }
if (annotation->subType() == Okular::Annotation::AText) { if (okularAnnotation->subType() == Okular::Annotation::AText) {
Okular::TextAnnotation *txtann = static_cast<Okular::TextAnnotation *>(annotation); Okular::TextAnnotation *txtann = static_cast<Okular::TextAnnotation *>(okularAnnotation);
if (txtann->textType() == Okular::TextAnnotation::Linked) { if (txtann->textType() == Okular::TextAnnotation::Linked) {
Poppler::TextAnnotation *ppl_txtann = static_cast<Poppler::TextAnnotation *>(ann); Poppler::TextAnnotation *ppl_txtann = static_cast<Poppler::TextAnnotation *>(popplerAnnotation);
// Poppler and Okular assume a different default icon name in XML // Poppler and Okular assume a different default icon name in XML
// We re-read it via getter, which always tells the right one // We re-read it via getter, which always tells the right one
...@@ -392,9 +392,9 @@ Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *a ...@@ -392,9 +392,9 @@ Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *a
// TODO clone window // TODO clone window
// TODO clone revisions // TODO clone revisions
if (tieToOkularAnn) { if (tieToOkularAnn) {
annotation->setNativeId(QVariant::fromValue(ann)); okularAnnotation->setNativeId(QVariant::fromValue(popplerAnnotation));
annotation->setDisposeDataFunction(disposeAnnotation); okularAnnotation->setDisposeDataFunction(disposeAnnotation);
} }
} }
return annotation; return okularAnnotation;
} }
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "config-okular-poppler.h" #include "config-okular-poppler.h"
#include "core/annotations.h" #include "core/annotations.h"
extern Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *ann, bool *doDelete); extern Okular::Annotation *createAnnotationFromPopplerAnnotation(Poppler::Annotation *popplerAnnotation, bool *doDelete);
class PopplerAnnotationProxy : public Okular::AnnotationProxy class PopplerAnnotationProxy : public Okular::AnnotationProxy
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment