Commit b41dcfed authored by Pino Toscano's avatar Pino Toscano

- store a pointer of the owning page in each annotation

- preliminary API for translating an annotation

svn path=/trunk/KDE/kdegraphics/okular/; revision=689133
parent 425252e0
......@@ -14,6 +14,9 @@
#include <QtGui/QApplication>
#include <QtGui/QColor>
// local includes
#include "page_p.h"
using namespace Okular;
//BEGIN AnnotationUtils implementation
......@@ -422,7 +425,7 @@ Annotation::RevisionType Annotation::Revision::type() const
AnnotationPrivate::AnnotationPrivate()
: m_flags( 0 )
: m_page( 0 ), m_flags( 0 )
{
}
......@@ -627,6 +630,12 @@ void Annotation::setBoundingRectangle( const NormalizedRect &rectangle )
{
Q_D( Annotation );
d->m_boundary = rectangle;
if ( d->m_page )
{
d->transform( d->m_page->rotationMatrix() );
}
else
d->m_transformedBoundary = d->m_boundary;
}
NormalizedRect Annotation::boundingRectangle() const
......@@ -641,6 +650,18 @@ NormalizedRect Annotation::transformedBoundingRectangle() const
return d->m_transformedBoundary;
}
void Annotation::translate( const NormalizedPoint &coord )
{
Q_D( Annotation );
d->translate( coord );
if ( d->m_page )
{
d->transform( d->m_page->rotationMatrix() );
}
else
d->m_transformedBoundary = d->m_boundary;
}
Annotation::SubType Annotation::subType() const
{
return A_BASE;
......@@ -789,6 +810,14 @@ void AnnotationPrivate::transform( const QMatrix &matrix )
m_transformedBoundary.transform( matrix );
}
void AnnotationPrivate::translate( const NormalizedPoint &coord )
{
m_boundary.left = m_boundary.left + coord.x;
m_boundary.right = m_boundary.right + coord.x;
m_boundary.top = m_boundary.top + coord.y;
m_boundary.bottom = m_boundary.bottom + coord.y;
}
//END Annotation implementation
......@@ -1056,6 +1085,7 @@ class Okular::LineAnnotationPrivate : public Okular::AnnotationPrivate
}
virtual void transform( const QMatrix &matrix );
virtual void translate( const NormalizedPoint &coord );
QLinkedList<NormalizedPoint> m_linePoints;
QLinkedList<NormalizedPoint> m_transformedLinePoints;
......@@ -1307,6 +1337,19 @@ void LineAnnotationPrivate::transform( const QMatrix &matrix )
it.next().transform( matrix );
}
void LineAnnotationPrivate::translate( const NormalizedPoint &coord )
{
AnnotationPrivate::translate( coord );
QMutableLinkedListIterator<NormalizedPoint> it( m_linePoints );
while ( it.hasNext() )
{
NormalizedPoint& p = it.next();
p.x = p.x + coord.x;
p.y = p.y + coord.y;
}
}
/** GeomAnnotation [Annotation] */
class Okular::GeomAnnotationPrivate : public Okular::AnnotationPrivate
......
......@@ -26,6 +26,8 @@ namespace Okular {
class Annotation;
class AnnotationObjectRect;
class AnnotationPrivate;
class Document;
class Page;
class TextAnnotationPrivate;
class LineAnnotationPrivate;
class GeomAnnotationPrivate;
......@@ -80,6 +82,8 @@ class OKULAR_EXPORT AnnotationUtils
class OKULAR_EXPORT Annotation
{
friend class AnnotationObjectRect;
friend class Document;
friend class Page;
public:
/**
......@@ -245,6 +249,11 @@ class OKULAR_EXPORT Annotation
*/
NormalizedRect transformedBoundingRectangle() const;
/**
* Move the annotation by the specified coordinates.
*/
void translate( const NormalizedPoint &coord );
/**
* The Style class contains all information about style of the
* annotation.
......
......@@ -22,6 +22,8 @@ class QMatrix;
namespace Okular {
class PagePrivate;
class AnnotationPrivate
{
public:
......@@ -34,6 +36,9 @@ class AnnotationPrivate
* defined by @p matrix.
*/
virtual void transform( const QMatrix &matrix );
virtual void translate( const NormalizedPoint &coord );
PagePrivate * m_page;
QString m_author;
QString m_contents;
......
......@@ -40,6 +40,8 @@
// local includes
#include "action.h"
#include "annotations.h"
#include "annotations_p.h"
#include "audioplayer.h"
#include "audioplayer_p.h"
#include "bookmarkmanager.h"
......@@ -1599,6 +1601,10 @@ void Document::addPageAnnotation( int page, Annotation * annotation )
if ( !d->m_generator || !kp )
return;
// the annotation belongs already to a page
if ( annotation->d_ptr->m_page )
return;
// add annotation to the page
kp->addAnnotation( annotation );
......
......@@ -23,6 +23,7 @@
// local includes
#include "action.h"
#include "annotations.h"
#include "annotations_p.h"
#include "area.h"
#include "form.h"
#include "form_p.h"
......@@ -478,6 +479,7 @@ void Page::addAnnotation( Annotation * annotation )
annotation->setUniqueName( uniqueName );
}
annotation->d_ptr->m_page = d;
m_annotations.append( annotation );
AnnotationObjectRect *rect = new AnnotationObjectRect( annotation );
......
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