summaryrefslogtreecommitdiff
path: root/qt4
diff options
context:
space:
mode:
authorFabio D'Urso <fabiodurso@hotmail.it>2012-03-09 19:31:16 +0100
committerAlbert Astals Cid <aacid@kde.org>2012-04-12 20:10:10 +0200
commit20b4feec612448be8a800173ddadbf257657477e (patch)
tree217d7b5497f137f1c46bee9c082bf7227ab28e06 /qt4
parent0e8c35b59f0fba926b30c9a87823c92ae03bf116 (diff)
qt4: Basic setters to edit annotations
Diffstat (limited to 'qt4')
-rw-r--r--qt4/src/poppler-annotation-helper.h15
-rw-r--r--qt4/src/poppler-annotation-private.h1
-rw-r--r--qt4/src/poppler-annotation.cc128
3 files changed, 135 insertions, 9 deletions
diff --git a/qt4/src/poppler-annotation-helper.h b/qt4/src/poppler-annotation-helper.h
index 5fc00a85..5f335c04 100644
--- a/qt4/src/poppler-annotation-helper.h
+++ b/qt4/src/poppler-annotation-helper.h
@@ -45,6 +45,7 @@ class XPDFReader
static inline void lookupDate( Dict *, char *, QDateTime & dest );
// transform from user coords to normalized ones using the matrix M
static inline void transform( double * M, double x, double y, QPointF &res );
+ static inline void invTransform( double * M, const QPointF &p, double &x, double &y );
};
void XPDFReader::lookupName( Dict * dict, char * type, QString & dest )
@@ -178,6 +179,20 @@ void XPDFReader::transform( double * M, double x, double y, QPointF &res )
res.setY( M[1] * x + M[3] * y + M[5] );
}
+void XPDFReader::invTransform( double * M, const QPointF &p, double &x, double &y )
+{
+ const double det = M[0]*M[3] - M[1]*M[2];
+ Q_ASSERT(det != 0);
+
+ const double invM[4] = { M[3]/det, -M[1]/det, -M[2]/det, M[0]/det };
+ const double xt = p.x() - M[4];
+ const double yt = p.y() - M[5];
+
+ x = invM[0] * xt + invM[2] * yt;
+ y = invM[1] * xt + invM[3] * yt;
+}
+
QColor convertAnnotColor( AnnotColor *color );
+AnnotColor* convertQColor( const QColor &color );
}
diff --git a/qt4/src/poppler-annotation-private.h b/qt4/src/poppler-annotation-private.h
index 24850346..24f5343a 100644
--- a/qt4/src/poppler-annotation-private.h
+++ b/qt4/src/poppler-annotation-private.h
@@ -77,6 +77,7 @@ class AnnotationPrivate : public QSharedData
/* The following helpers only work if pdfPage is set */
void fillMTX(double MTX[6]) const;
QRectF fromPdfRectangle(const PDFRectangle &r) const;
+ PDFRectangle toPdfRectangle(const QRectF &r) const;
/* Scan page for annotations, parentId=0 searches for root annotations */
static QList<Annotation*> findAnnotations(::Page *pdfPage, DocumentData *doc, int parentId = 0);
diff --git a/qt4/src/poppler-annotation.cc b/qt4/src/poppler-annotation.cc
index c57475b1..3e7b3612 100644
--- a/qt4/src/poppler-annotation.cc
+++ b/qt4/src/poppler-annotation.cc
@@ -197,6 +197,32 @@ QRectF AnnotationPrivate::fromPdfRectangle(const PDFRectangle &r) const
return QRectF( QPointF(tl_x,tl_y) , QPointF(br_x,br_y) );
}
+PDFRectangle AnnotationPrivate::toPdfRectangle(const QRectF &r) const
+{
+ double MTX[6];
+ fillMTX(MTX);
+
+ double tl_x, tl_y, br_x, br_y, swp;
+ XPDFReader::invTransform( MTX, r.topLeft(), tl_x, tl_y );
+ XPDFReader::invTransform( MTX, r.bottomRight(), br_x, br_y );
+
+ if (tl_x > br_x)
+ {
+ swp = tl_x;
+ tl_x = br_x;
+ br_x = swp;
+ }
+
+ if (tl_y > br_y)
+ {
+ swp = tl_y;
+ tl_y = br_y;
+ br_y = swp;
+ }
+
+ return PDFRectangle(tl_x, tl_y, br_x, br_y);
+}
+
QList<Annotation*> AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentData *doc, int parentID)
{
Annots* annots = pdfPage->getAnnots();
@@ -906,7 +932,13 @@ void Annotation::setAuthor( const QString &author )
return;
}
- // TODO: Set pdfAnnot
+ AnnotMarkup *markupann = dynamic_cast<AnnotMarkup*>(d->pdfAnnot);
+ if (markupann)
+ {
+ GooString *s = QStringToUnicodeGooString(author);
+ markupann->setLabel(s);
+ delete s;
+ }
}
QString Annotation::contents() const
@@ -929,7 +961,9 @@ void Annotation::setContents( const QString &contents )
return;
}
- // TODO: Set pdfAnnot
+ GooString *s = QStringToUnicodeGooString(contents);
+ d->pdfAnnot->setContents(s);
+ delete s;
}
QString Annotation::uniqueName() const
@@ -952,7 +986,9 @@ void Annotation::setUniqueName( const QString &uniqueName )
return;
}
- // TODO: Set pdfAnnot
+ QByteArray ascii = uniqueName.toAscii();
+ GooString s(ascii.constData());
+ d->pdfAnnot->setName(&s);
}
QDateTime Annotation::modificationDate() const
@@ -978,7 +1014,15 @@ void Annotation::setModificationDate( const QDateTime &date )
return;
}
- // TODO: Set pdfAnnot
+#if 0 // TODO: Conversion routine is broken
+ if (d->pdfAnnot)
+ {
+ time_t t = date.toTime_t();
+ GooString *s = timeToDateString(&t);
+ d->pdfAnnot->setModified(s);
+ delete s;
+ }
+#endif
}
QDateTime Annotation::creationDate() const
@@ -1006,7 +1050,16 @@ void Annotation::setCreationDate( const QDateTime &date )
return;
}
- // TODO: Set pdfAnnot
+#if 0 // TODO: Conversion routine is broken
+ AnnotMarkup *markupann = dynamic_cast<AnnotMarkup*>(d->pdfAnnot);
+ if (markupann)
+ {
+ time_t t = date.toTime_t();
+ GooString *s = timeToDateString(&t);
+ markupann->setDate(s);
+ delete s;
+ }
+#endif
}
static int fromPdfFlags(int flags)
@@ -1031,6 +1084,28 @@ static int fromPdfFlags(int flags)
return qtflags;
}
+static int toPdfFlags(int qtflags)
+{
+ int flags = 0;
+
+ if ( qtflags & Annotation::Hidden )
+ flags |= Annot::flagHidden;
+ if ( qtflags & Annotation::FixedSize )
+ flags |= Annot::flagNoZoom;
+ if ( qtflags & Annotation::FixedRotation )
+ flags |= Annot::flagNoRotate;
+ if ( !( qtflags & Annotation::DenyPrint ) )
+ flags |= Annot::flagPrint;
+ if ( qtflags & Annotation::DenyWrite )
+ flags |= Annot::flagReadOnly;
+ if ( qtflags & Annotation::DenyDelete )
+ flags |= Annot::flagLocked;
+ if ( qtflags & Annotation::ToggleHidingOnMouse )
+ flags |= Annot::flagToggleNoView;
+
+ return flags;
+}
+
int Annotation::flags() const
{
Q_D( const Annotation );
@@ -1051,7 +1126,7 @@ void Annotation::setFlags( int flags )
return;
}
- // TODO: Set pdfAnnot
+ d->pdfAnnot->setFlags(toPdfFlags( flags ));
}
QRectF Annotation::boundary() const
@@ -1075,7 +1150,8 @@ void Annotation::setBoundary( const QRectF &boundary )
return;
}
- // TODO: Set pdfAnnot
+ PDFRectangle rect = d->toPdfRectangle(boundary);
+ d->pdfAnnot->setRect(&rect);
}
Annotation::Style Annotation::style() const
@@ -1145,7 +1221,17 @@ void Annotation::setStyle( const Annotation::Style& style )
return;
}
- // TODO: Set pdfAnnot
+ d->pdfAnnot->setColor(convertQColor( style.color() ));
+
+ AnnotMarkup *markupann = dynamic_cast<AnnotMarkup*>(d->pdfAnnot);
+ if (markupann)
+ markupann->setOpacity( style.opacity() );
+
+ AnnotBorderArray * border = new AnnotBorderArray();
+ border->setWidth( style.width() );
+ border->setHorizontalCorner( style.xCorners() );
+ border->setVerticalCorner( style.yCorners() );
+ d->pdfAnnot->setBorder(border);
}
Annotation::Popup Annotation::popup() const
@@ -1210,7 +1296,23 @@ void Annotation::setPopup( const Annotation::Popup& popup )
return;
}
- // TODO: Set pdfAnnot
+#if 0 /* TODO: Remove old popup and add AnnotPopup to page */
+ AnnotMarkup *markupann = dynamic_cast<AnnotMarkup*>(d->pdfAnnot);
+ if (!markupann)
+ return;
+
+ // Create a new AnnotPopup and assign it to pdfAnnot
+ PDFRectangle rect = d->toPdfRectangle( popup.geometry() );
+ AnnotPopup * p = new AnnotPopup( d->pdfPage->getDoc(), &rect );
+ p->setOpen( !(popup.flags() & Annotation::Hidden) );
+ if (!popup.summary().isEmpty())
+ {
+ GooString *s = QStringToUnicodeGooString(popup.summary());
+ markupann->setLabel(s);
+ delete s;
+ }
+ markupann->setPopup(p);
+#endif
}
Annotation::RevScope Annotation::revisionScope() const
@@ -3613,6 +3715,14 @@ QColor convertAnnotColor( AnnotColor *color )
}
return newcolor;
}
+
+AnnotColor* convertQColor( const QColor &c )
+{
+ if (!c.isValid() || c.alpha() == 0)
+ return new AnnotColor(); // Transparent
+ else
+ return new AnnotColor(c.redF(), c.greenF(), c.blueF());
+}
//END utility annotation functions
}