2004-09-08 12:41:14 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2007-04-19 18:30:20 +00:00
|
|
|
#include "page.h"
|
|
|
|
#include "page_p.h"
|
|
|
|
|
2004-11-06 01:19:35 +00:00
|
|
|
// qt/kde includes
|
2007-07-04 11:41:45 +00:00
|
|
|
#include <QtCore/QHash>
|
2006-09-21 08:45:36 +00:00
|
|
|
#include <QtCore/QSet>
|
|
|
|
#include <QtCore/QString>
|
2007-07-04 11:41:45 +00:00
|
|
|
#include <QtCore/QVariant>
|
2007-01-03 14:30:48 +00:00
|
|
|
#include <QtGui/QPixmap>
|
2006-09-21 08:45:36 +00:00
|
|
|
#include <QtXml/QDomDocument>
|
|
|
|
#include <QtXml/QDomElement>
|
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
#include <kdebug.h>
|
2004-09-08 12:41:14 +00:00
|
|
|
|
|
|
|
// local includes
|
2007-04-20 11:26:05 +00:00
|
|
|
#include "action.h"
|
2006-09-21 08:45:36 +00:00
|
|
|
#include "annotations.h"
|
2007-07-17 18:10:25 +00:00
|
|
|
#include "annotations_p.h"
|
2006-09-21 08:45:36 +00:00
|
|
|
#include "area.h"
|
2008-01-20 16:39:21 +00:00
|
|
|
#include "debug_p.h"
|
2007-02-25 00:07:59 +00:00
|
|
|
#include "form.h"
|
2007-07-04 11:41:45 +00:00
|
|
|
#include "form_p.h"
|
2007-03-24 10:47:22 +00:00
|
|
|
#include "pagecontroller_p.h"
|
2007-01-05 23:12:06 +00:00
|
|
|
#include "pagesize.h"
|
2005-01-02 22:33:28 +00:00
|
|
|
#include "pagetransition.h"
|
2007-07-04 14:39:52 +00:00
|
|
|
#include "rotationjob_p.h"
|
2007-01-02 22:37:55 +00:00
|
|
|
#include "textpage.h"
|
2007-09-03 19:58:30 +00:00
|
|
|
#include "textpage_p.h"
|
2004-09-08 12:41:14 +00:00
|
|
|
|
2007-03-30 14:27:22 +00:00
|
|
|
#ifdef PAGE_PROFILE
|
|
|
|
#include <QtCore/QTime>
|
|
|
|
#endif
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
using namespace Okular;
|
|
|
|
|
2006-09-19 17:17:29 +00:00
|
|
|
static void deleteObjectRects( QLinkedList< ObjectRect * >& rects, const QSet<ObjectRect::ObjectType>& which )
|
|
|
|
{
|
|
|
|
QLinkedList< ObjectRect * >::iterator it = rects.begin(), end = rects.end();
|
|
|
|
for ( ; it != end; )
|
|
|
|
if ( which.contains( (*it)->objectType() ) )
|
|
|
|
{
|
|
|
|
delete *it;
|
|
|
|
it = rects.erase( it );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
2007-03-24 00:18:54 +00:00
|
|
|
PagePrivate::PagePrivate( Page *page, uint n, double w, double h, Rotation o )
|
|
|
|
: m_page( page ), m_number( n ), m_orientation( o ),
|
|
|
|
m_width( w ), m_height( h ),
|
|
|
|
m_rotation( Rotation0 ), m_maxuniqueNum( 0 ),
|
2007-03-30 14:08:20 +00:00
|
|
|
m_text( 0 ), m_transition( 0 ), m_textSelections( 0 ),
|
2007-03-24 00:18:54 +00:00
|
|
|
m_openingAction( 0 ), m_closingAction( 0 ), m_duration( -1 )
|
2006-11-23 19:25:52 +00:00
|
|
|
{
|
2007-03-24 00:18:54 +00:00
|
|
|
// avoid Division-By-Zero problems in the program
|
|
|
|
if ( m_width <= 0 )
|
|
|
|
m_width = 1;
|
2006-11-23 19:25:52 +00:00
|
|
|
|
2007-03-24 00:18:54 +00:00
|
|
|
if ( m_height <= 0 )
|
|
|
|
m_height = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PagePrivate::~PagePrivate()
|
|
|
|
{
|
|
|
|
qDeleteAll( formfields );
|
|
|
|
delete m_openingAction;
|
|
|
|
delete m_closingAction;
|
|
|
|
delete m_text;
|
|
|
|
delete m_transition;
|
|
|
|
}
|
2006-11-23 19:25:52 +00:00
|
|
|
|
|
|
|
|
2007-03-24 10:47:22 +00:00
|
|
|
void PagePrivate::imageRotationDone( RotationJob * job )
|
2006-11-23 19:25:52 +00:00
|
|
|
{
|
2007-03-25 22:36:41 +00:00
|
|
|
QMap< int, PixmapObject >::iterator it = m_pixmaps.find( job->id() );
|
|
|
|
if ( it != m_pixmaps.end() )
|
2007-01-28 17:28:28 +00:00
|
|
|
{
|
2007-03-25 22:36:41 +00:00
|
|
|
PixmapObject &object = it.value();
|
2006-11-23 19:25:52 +00:00
|
|
|
(*object.m_pixmap) = QPixmap::fromImage( job->image() );
|
|
|
|
object.m_rotation = job->rotation();
|
|
|
|
} else {
|
2007-03-25 22:36:41 +00:00
|
|
|
PixmapObject object;
|
2006-11-23 19:25:52 +00:00
|
|
|
object.m_pixmap = new QPixmap( QPixmap::fromImage( job->image() ) );
|
|
|
|
object.m_rotation = job->rotation();
|
|
|
|
|
2007-03-25 22:36:41 +00:00
|
|
|
m_pixmaps.insert( job->id(), object );
|
2006-11-23 19:25:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-24 00:18:54 +00:00
|
|
|
QMatrix PagePrivate::rotationMatrix() const
|
2006-11-23 19:25:52 +00:00
|
|
|
{
|
|
|
|
QMatrix matrix;
|
2007-01-05 17:09:47 +00:00
|
|
|
matrix.rotate( (int)m_rotation * 90 );
|
|
|
|
|
|
|
|
switch ( m_rotation )
|
|
|
|
{
|
|
|
|
case Rotation90:
|
|
|
|
matrix.translate( 0, -1 );
|
|
|
|
break;
|
|
|
|
case Rotation180:
|
|
|
|
matrix.translate( -1, -1 );
|
|
|
|
break;
|
|
|
|
case Rotation270:
|
|
|
|
matrix.translate( -1, 0 );
|
|
|
|
break;
|
|
|
|
default: ;
|
2006-11-23 19:25:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return matrix;
|
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
/** class Page **/
|
2004-12-10 16:04:45 +00:00
|
|
|
|
2007-01-05 17:09:47 +00:00
|
|
|
Page::Page( uint page, double w, double h, Rotation o )
|
2007-03-30 14:08:20 +00:00
|
|
|
: d( new PagePrivate( this, page, w, h, o ) )
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
Page::~Page()
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2006-11-20 07:53:32 +00:00
|
|
|
deletePixmaps();
|
2006-11-03 17:57:32 +00:00
|
|
|
deleteRects();
|
2007-05-05 18:07:34 +00:00
|
|
|
d->deleteHighlights();
|
2005-02-18 18:24:45 +00:00
|
|
|
deleteAnnotations();
|
2007-09-03 23:47:12 +00:00
|
|
|
d->deleteTextSelections();
|
2006-11-17 22:15:15 +00:00
|
|
|
deleteSourceReferences();
|
2006-11-23 19:25:52 +00:00
|
|
|
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Page::number() const
|
|
|
|
{
|
|
|
|
return d->m_number;
|
|
|
|
}
|
|
|
|
|
2007-01-05 17:09:47 +00:00
|
|
|
Rotation Page::orientation() const
|
2006-11-23 19:25:52 +00:00
|
|
|
{
|
|
|
|
return d->m_orientation;
|
|
|
|
}
|
|
|
|
|
2007-01-05 17:09:47 +00:00
|
|
|
Rotation Page::rotation() const
|
2006-11-23 19:25:52 +00:00
|
|
|
{
|
|
|
|
return d->m_rotation;
|
|
|
|
}
|
|
|
|
|
2007-01-05 17:09:47 +00:00
|
|
|
Rotation Page::totalOrientation() const
|
2006-11-23 19:25:52 +00:00
|
|
|
{
|
2007-01-05 17:09:47 +00:00
|
|
|
return (Rotation)( ( (int)d->m_orientation + (int)d->m_rotation ) % 4 );
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
|
|
|
|
2006-11-23 19:25:52 +00:00
|
|
|
double Page::width() const
|
|
|
|
{
|
|
|
|
return d->m_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Page::height() const
|
|
|
|
{
|
|
|
|
return d->m_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Page::ratio() const
|
|
|
|
{
|
|
|
|
return d->m_height / d->m_width;
|
|
|
|
}
|
2004-09-15 20:45:00 +00:00
|
|
|
|
2006-11-20 07:53:32 +00:00
|
|
|
bool Page::hasPixmap( int id, int width, int height ) const
|
2004-09-16 21:04:49 +00:00
|
|
|
{
|
2007-08-13 22:25:27 +00:00
|
|
|
QMap< int, PagePrivate::PixmapObject >::const_iterator it = d->m_pixmaps.constFind( id );
|
|
|
|
if ( it == d->m_pixmaps.constEnd() )
|
2004-09-16 21:04:49 +00:00
|
|
|
return false;
|
2006-11-03 17:57:32 +00:00
|
|
|
|
2004-12-21 12:38:52 +00:00
|
|
|
if ( width == -1 || height == -1 )
|
|
|
|
return true;
|
2006-11-03 17:57:32 +00:00
|
|
|
|
2006-11-24 21:42:56 +00:00
|
|
|
const QPixmap *pixmap = it.value().m_pixmap;
|
2006-11-03 17:57:32 +00:00
|
|
|
|
2006-11-20 07:53:32 +00:00
|
|
|
return (pixmap->width() == width && pixmap->height() == height);
|
2004-09-16 21:04:49 +00:00
|
|
|
}
|
|
|
|
|
2006-11-23 16:09:26 +00:00
|
|
|
bool Page::hasTextPage() const
|
2004-12-10 16:04:45 +00:00
|
|
|
{
|
2006-11-23 19:25:52 +00:00
|
|
|
return d->m_text != 0;
|
2004-12-10 16:04:45 +00:00
|
|
|
}
|
|
|
|
|
2006-11-23 17:11:04 +00:00
|
|
|
RegularAreaRect * Page::textArea ( TextSelection * selection ) const
|
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
|
|
|
{
|
2006-11-23 19:25:52 +00:00
|
|
|
if ( d->m_text )
|
|
|
|
return d->m_text->textArea( selection );
|
2006-11-23 17:11:04 +00:00
|
|
|
|
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
bool Page::hasObjectRect( double x, double y, double xScale, double yScale ) const
|
2004-09-16 21:04:49 +00:00
|
|
|
{
|
2006-09-19 17:17:29 +00:00
|
|
|
if ( m_rects.isEmpty() )
|
2004-10-02 14:30:30 +00:00
|
|
|
return false;
|
2006-11-23 19:25:52 +00:00
|
|
|
|
2006-03-20 22:40:11 +00:00
|
|
|
QLinkedList< ObjectRect * >::const_iterator it = m_rects.begin(), end = m_rects.end();
|
2004-10-02 14:30:30 +00:00
|
|
|
for ( ; it != end; ++it )
|
2006-09-19 17:17:29 +00:00
|
|
|
if ( (*it)->contains( x, y, xScale, yScale ) )
|
2004-10-02 14:30:30 +00:00
|
|
|
return true;
|
2006-11-23 19:25:52 +00:00
|
|
|
|
2004-10-02 14:30:30 +00:00
|
|
|
return false;
|
2004-09-16 21:04:49 +00:00
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
bool Page::hasHighlights( int s_id ) const
|
2004-10-20 16:27:20 +00:00
|
|
|
{
|
2005-02-08 15:24:23 +00:00
|
|
|
// simple case: have no highlights
|
|
|
|
if ( m_highlights.isEmpty() )
|
|
|
|
return false;
|
|
|
|
// simple case: we have highlights and no id to match
|
|
|
|
if ( s_id == -1 )
|
|
|
|
return true;
|
|
|
|
// iterate on the highlights list to find an entry by id
|
2006-03-20 22:40:11 +00:00
|
|
|
QLinkedList< HighlightAreaRect * >::const_iterator it = m_highlights.begin(), end = m_highlights.end();
|
2004-10-20 16:27:20 +00:00
|
|
|
for ( ; it != end; ++it )
|
2005-02-08 15:24:23 +00:00
|
|
|
if ( (*it)->s_id == s_id )
|
|
|
|
return true;
|
|
|
|
return false;
|
2004-10-20 16:27:20 +00:00
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
bool Page::hasTransition() const
|
2005-01-02 20:32:58 +00:00
|
|
|
{
|
2006-11-23 19:25:52 +00:00
|
|
|
return d->m_transition != 0;
|
2004-11-06 00:56:55 +00:00
|
|
|
}
|
|
|
|
|
2006-11-23 19:25:52 +00:00
|
|
|
bool Page::hasAnnotations() const
|
|
|
|
{
|
|
|
|
return !m_annotations.isEmpty();
|
|
|
|
}
|
2004-09-08 12:41:14 +00:00
|
|
|
|
2006-11-23 16:54:28 +00:00
|
|
|
RegularAreaRect * Page::findText( int id, const QString & text, SearchDirection direction,
|
|
|
|
Qt::CaseSensitivity caseSensitivity, const RegularAreaRect *lastRect ) const
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2006-11-23 16:54:28 +00:00
|
|
|
RegularAreaRect* rect = 0;
|
2007-09-03 19:38:46 +00:00
|
|
|
if ( text.isEmpty() || !d->m_text )
|
2006-11-23 16:54:28 +00:00
|
|
|
return rect;
|
|
|
|
|
2006-11-23 19:25:52 +00:00
|
|
|
rect = d->m_text->findText( id, text, direction, caseSensitivity, lastRect );
|
2006-11-23 16:54:28 +00:00
|
|
|
return rect;
|
2005-02-08 15:24:23 +00:00
|
|
|
}
|
|
|
|
|
2006-11-23 17:11:04 +00:00
|
|
|
QString Page::text( const RegularAreaRect * area ) const
|
2005-02-08 15:24:23 +00:00
|
|
|
{
|
2006-11-23 16:54:28 +00:00
|
|
|
QString ret;
|
2005-07-15 18:20:57 +00:00
|
|
|
|
2006-11-23 19:25:52 +00:00
|
|
|
if ( !d->m_text )
|
2006-11-23 16:54:28 +00:00
|
|
|
return ret;
|
2005-07-15 18:20:57 +00:00
|
|
|
|
2007-01-31 14:29:28 +00:00
|
|
|
if ( area )
|
|
|
|
{
|
|
|
|
RegularAreaRect rotatedArea = *area;
|
|
|
|
rotatedArea.transform( d->rotationMatrix().inverted() );
|
2006-12-29 18:18:07 +00:00
|
|
|
|
2007-01-31 14:29:28 +00:00
|
|
|
ret = d->m_text->text( &rotatedArea );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = d->m_text->text();
|
2005-07-15 18:20:57 +00:00
|
|
|
|
2006-11-23 16:54:28 +00:00
|
|
|
return ret;
|
2005-02-08 15:24:23 +00:00
|
|
|
}
|
|
|
|
|
2007-05-01 23:36:57 +00:00
|
|
|
void PagePrivate::rotateAt( Rotation orientation )
|
2006-10-08 15:07:23 +00:00
|
|
|
{
|
2007-05-01 23:36:57 +00:00
|
|
|
if ( orientation == m_rotation )
|
2006-10-08 15:07:23 +00:00
|
|
|
return;
|
|
|
|
|
2007-05-05 18:07:34 +00:00
|
|
|
deleteHighlights();
|
2007-09-03 23:47:12 +00:00
|
|
|
deleteTextSelections();
|
2006-11-23 22:14:04 +00:00
|
|
|
|
2007-05-01 23:36:57 +00:00
|
|
|
if ( ( (int)m_orientation + (int)m_rotation ) % 2 != ( (int)m_orientation + (int)orientation ) % 2 )
|
|
|
|
qSwap( m_width, m_height );
|
2006-10-08 15:07:23 +00:00
|
|
|
|
2007-09-03 18:32:07 +00:00
|
|
|
Rotation oldRotation = m_rotation;
|
2007-05-01 23:36:57 +00:00
|
|
|
m_rotation = orientation;
|
2006-11-20 07:53:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Rotate the images of the page.
|
|
|
|
*/
|
2007-05-01 23:36:57 +00:00
|
|
|
QMapIterator< int, PagePrivate::PixmapObject > it( m_pixmaps );
|
2006-10-25 15:35:53 +00:00
|
|
|
while ( it.hasNext() ) {
|
|
|
|
it.next();
|
|
|
|
|
2007-03-25 22:36:41 +00:00
|
|
|
const PagePrivate::PixmapObject &object = it.value();
|
2006-11-20 07:53:32 +00:00
|
|
|
|
2007-05-01 23:36:57 +00:00
|
|
|
RotationJob *job = new RotationJob( object.m_pixmap->toImage(), object.m_rotation, m_rotation, it.key() );
|
|
|
|
job->setPage( this );
|
2007-07-04 16:55:33 +00:00
|
|
|
PageController::self()->addRotationJob(job);
|
2006-10-25 15:35:53 +00:00
|
|
|
}
|
2006-11-20 07:53:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Rotate the object rects on the page.
|
|
|
|
*/
|
2007-05-01 23:36:57 +00:00
|
|
|
const QMatrix matrix = rotationMatrix();
|
|
|
|
QLinkedList< ObjectRect * >::const_iterator objectIt = m_page->m_rects.begin(), end = m_page->m_rects.end();
|
2006-11-20 07:53:32 +00:00
|
|
|
for ( ; objectIt != end; ++objectIt )
|
|
|
|
(*objectIt)->transform( matrix );
|
2007-09-03 18:32:07 +00:00
|
|
|
|
|
|
|
QLinkedList< HighlightAreaRect* >::const_iterator hlIt = m_page->m_highlights.begin(), hlItEnd = m_page->m_highlights.end();
|
|
|
|
for ( ; hlIt != hlItEnd; ++hlIt )
|
|
|
|
{
|
|
|
|
(*hlIt)->transform( RotationJob::rotationMatrix( oldRotation, m_rotation ) );
|
|
|
|
}
|
2006-10-08 15:07:23 +00:00
|
|
|
}
|
|
|
|
|
2007-05-01 23:36:57 +00:00
|
|
|
void PagePrivate::changeSize( const PageSize &size )
|
2007-01-05 23:12:06 +00:00
|
|
|
{
|
2007-05-01 23:36:57 +00:00
|
|
|
if ( size.isNull() || ( size.width() == m_width && size.height() == m_height ) )
|
2007-01-05 23:12:06 +00:00
|
|
|
return;
|
|
|
|
|
2007-05-01 23:36:57 +00:00
|
|
|
m_page->deletePixmaps();
|
2007-01-05 23:12:06 +00:00
|
|
|
// deleteHighlights();
|
|
|
|
// deleteTextSelections();
|
|
|
|
|
2007-05-01 23:36:57 +00:00
|
|
|
m_width = size.width();
|
|
|
|
m_height = size.height();
|
|
|
|
if ( m_rotation % 2 )
|
|
|
|
qSwap( m_width, m_height );
|
2007-01-05 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
2006-11-23 17:11:04 +00:00
|
|
|
const ObjectRect * Page::objectRect( ObjectRect::ObjectType type, double x, double y, double xScale, double yScale ) const
|
2005-02-08 15:24:23 +00:00
|
|
|
{
|
2006-03-20 22:40:11 +00:00
|
|
|
QLinkedList< ObjectRect * >::const_iterator it = m_rects.begin(), end = m_rects.end();
|
2005-02-08 15:24:23 +00:00
|
|
|
for ( ; it != end; ++it )
|
2006-09-19 17:17:29 +00:00
|
|
|
if ( ( (*it)->objectType() == type ) && (*it)->contains( x, y, xScale, yScale ) )
|
2005-02-08 15:24:23 +00:00
|
|
|
return *it;
|
2005-02-01 18:26:56 +00:00
|
|
|
return 0;
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
|
|
|
|
2006-11-23 17:11:04 +00:00
|
|
|
const PageTransition * Page::transition() const
|
2005-02-08 15:24:23 +00:00
|
|
|
{
|
2006-11-23 19:25:52 +00:00
|
|
|
return d->m_transition;
|
2005-02-08 15:24:23 +00:00
|
|
|
}
|
|
|
|
|
2007-09-03 23:01:57 +00:00
|
|
|
QLinkedList< Annotation* > Page::annotations() const
|
2006-10-09 18:02:59 +00:00
|
|
|
{
|
2006-11-23 19:25:52 +00:00
|
|
|
return m_annotations;
|
|
|
|
}
|
|
|
|
|
2007-04-20 12:37:12 +00:00
|
|
|
const Action * Page::pageAction( PageAction action ) const
|
2006-11-23 19:25:52 +00:00
|
|
|
{
|
|
|
|
switch ( action )
|
2006-10-09 18:02:59 +00:00
|
|
|
{
|
|
|
|
case Page::Opening:
|
2006-11-23 19:25:52 +00:00
|
|
|
return d->m_openingAction;
|
2006-10-09 18:02:59 +00:00
|
|
|
break;
|
|
|
|
case Page::Closing:
|
2006-11-23 19:25:52 +00:00
|
|
|
return d->m_closingAction;
|
2006-10-09 18:02:59 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-11-23 19:25:52 +00:00
|
|
|
|
2006-10-09 18:02:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-03 23:01:57 +00:00
|
|
|
QLinkedList< FormField * > Page::formFields() const
|
2007-02-25 00:07:59 +00:00
|
|
|
{
|
|
|
|
return d->formfields;
|
|
|
|
}
|
|
|
|
|
2006-11-20 07:53:32 +00:00
|
|
|
void Page::setPixmap( int id, QPixmap *pixmap )
|
2006-10-25 15:35:53 +00:00
|
|
|
{
|
2007-01-05 17:09:47 +00:00
|
|
|
if ( d->m_rotation == Rotation0 ) {
|
2007-03-25 22:36:41 +00:00
|
|
|
QMap< int, PagePrivate::PixmapObject >::iterator it = d->m_pixmaps.find( id );
|
|
|
|
if ( it != d->m_pixmaps.end() )
|
2007-01-09 23:37:26 +00:00
|
|
|
{
|
|
|
|
delete it.value().m_pixmap;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-25 22:36:41 +00:00
|
|
|
it = d->m_pixmaps.insert( id, PagePrivate::PixmapObject() );
|
2007-01-09 23:37:26 +00:00
|
|
|
}
|
|
|
|
it.value().m_pixmap = pixmap;
|
|
|
|
it.value().m_rotation = d->m_rotation;
|
2006-11-03 17:57:32 +00:00
|
|
|
} else {
|
2007-01-05 17:09:47 +00:00
|
|
|
RotationJob *job = new RotationJob( pixmap->toImage(), Rotation0, d->m_rotation, id );
|
2007-03-24 10:47:22 +00:00
|
|
|
job->setPage( d );
|
2007-07-04 16:55:33 +00:00
|
|
|
PageController::self()->addRotationJob(job);
|
2006-11-20 07:53:32 +00:00
|
|
|
|
|
|
|
delete pixmap;
|
2006-11-03 17:57:32 +00:00
|
|
|
}
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
|
|
|
|
2006-11-23 19:25:52 +00:00
|
|
|
void Page::setTextPage( TextPage * textPage )
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2006-11-23 19:25:52 +00:00
|
|
|
delete d->m_text;
|
2006-11-23 22:14:04 +00:00
|
|
|
|
2006-11-23 19:25:52 +00:00
|
|
|
d->m_text = textPage;
|
2007-09-03 18:32:07 +00:00
|
|
|
if ( d->m_text )
|
|
|
|
{
|
2007-09-04 22:37:39 +00:00
|
|
|
d->m_text->d->m_page = d;
|
2007-09-03 18:32:07 +00:00
|
|
|
}
|
2004-09-10 17:44:05 +00:00
|
|
|
}
|
2004-09-11 15:59:32 +00:00
|
|
|
|
2007-01-20 22:04:10 +00:00
|
|
|
void Page::setObjectRects( const QLinkedList< ObjectRect * > & rects )
|
2004-10-20 16:27:20 +00:00
|
|
|
{
|
2006-09-19 17:17:29 +00:00
|
|
|
QSet<ObjectRect::ObjectType> which;
|
2007-04-20 12:37:12 +00:00
|
|
|
which << ObjectRect::Action << ObjectRect::Image;
|
2006-09-19 17:17:29 +00:00
|
|
|
deleteObjectRects( m_rects, which );
|
2006-11-20 07:53:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Rotate the object rects of the page.
|
|
|
|
*/
|
2006-11-23 19:25:52 +00:00
|
|
|
const QMatrix matrix = d->rotationMatrix();
|
2006-11-20 07:53:32 +00:00
|
|
|
|
|
|
|
QLinkedList< ObjectRect * >::const_iterator objectIt = rects.begin(), end = rects.end();
|
|
|
|
for ( ; objectIt != end; ++objectIt )
|
|
|
|
(*objectIt)->transform( matrix );
|
|
|
|
|
2006-09-19 17:17:29 +00:00
|
|
|
m_rects << rects;
|
2004-10-20 16:27:20 +00:00
|
|
|
}
|
|
|
|
|
2007-05-05 18:07:34 +00:00
|
|
|
void PagePrivate::setHighlight( int s_id, RegularAreaRect *rect, const QColor & color )
|
2005-02-01 18:26:56 +00:00
|
|
|
{
|
2005-07-15 18:20:57 +00:00
|
|
|
HighlightAreaRect * hr = new HighlightAreaRect(rect);
|
2005-02-08 15:24:23 +00:00
|
|
|
hr->s_id = s_id;
|
|
|
|
hr->color = color;
|
2007-01-05 15:16:36 +00:00
|
|
|
|
2007-05-05 18:07:34 +00:00
|
|
|
m_page->m_highlights.append( hr );
|
2006-11-23 19:25:52 +00:00
|
|
|
}
|
2005-07-15 18:20:57 +00:00
|
|
|
|
2007-05-05 18:07:34 +00:00
|
|
|
void PagePrivate::setTextSelections( RegularAreaRect *r, const QColor & color )
|
2006-09-26 22:22:01 +00:00
|
|
|
{
|
2007-09-03 23:47:12 +00:00
|
|
|
deleteTextSelections();
|
2007-01-03 17:57:03 +00:00
|
|
|
if ( r )
|
|
|
|
{
|
|
|
|
HighlightAreaRect * hr = new HighlightAreaRect( r );
|
|
|
|
hr->s_id = -1;
|
|
|
|
hr->color = color;
|
2007-05-05 18:07:34 +00:00
|
|
|
m_textSelections = hr;
|
2007-06-08 23:06:04 +00:00
|
|
|
delete r;
|
2007-01-03 17:57:03 +00:00
|
|
|
}
|
2006-09-26 22:22:01 +00:00
|
|
|
}
|
2005-02-01 18:26:56 +00:00
|
|
|
|
2007-01-20 22:04:10 +00:00
|
|
|
void Page::setSourceReferences( const QLinkedList< SourceRefObjectRect * > & refRects )
|
2006-11-17 22:15:15 +00:00
|
|
|
{
|
|
|
|
deleteSourceReferences();
|
|
|
|
foreach( SourceRefObjectRect * rect, refRects )
|
|
|
|
m_rects << rect;
|
|
|
|
}
|
|
|
|
|
2006-12-31 14:41:34 +00:00
|
|
|
void Page::setDuration( double seconds )
|
2006-12-31 10:48:49 +00:00
|
|
|
{
|
2007-01-02 17:05:49 +00:00
|
|
|
d->m_duration = seconds;
|
2006-12-31 10:48:49 +00:00
|
|
|
}
|
|
|
|
|
2006-12-31 14:41:34 +00:00
|
|
|
double Page::duration() const
|
2006-12-31 10:48:49 +00:00
|
|
|
{
|
2007-01-02 17:05:49 +00:00
|
|
|
return d->m_duration;
|
2006-12-31 10:48:49 +00:00
|
|
|
}
|
|
|
|
|
2007-01-19 23:30:32 +00:00
|
|
|
void Page::setLabel( const QString& label )
|
|
|
|
{
|
|
|
|
d->m_label = label;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Page::label() const
|
|
|
|
{
|
|
|
|
return d->m_label;
|
|
|
|
}
|
|
|
|
|
2006-11-24 21:02:38 +00:00
|
|
|
const RegularAreaRect * Page::textSelection() const
|
|
|
|
{
|
2007-03-30 14:08:20 +00:00
|
|
|
return d->m_textSelections;
|
|
|
|
}
|
|
|
|
|
|
|
|
QColor Page::textSelectionColor() const
|
|
|
|
{
|
|
|
|
return d->m_textSelections ? d->m_textSelections->color : QColor();
|
2006-11-24 21:02:38 +00:00
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
void Page::addAnnotation( Annotation * annotation )
|
2005-02-18 18:24:45 +00:00
|
|
|
{
|
2006-08-10 06:32:03 +00:00
|
|
|
//uniqueName: okular-PAGENUM-ID
|
2006-12-05 11:05:50 +00:00
|
|
|
if(annotation->uniqueName().isEmpty())
|
2006-08-10 06:32:03 +00:00
|
|
|
{
|
2006-12-05 11:05:50 +00:00
|
|
|
QString uniqueName = "okular-";
|
|
|
|
uniqueName += ( QString::number(d->m_number) + '-' + QString::number(++(d->m_maxuniqueNum)) );
|
|
|
|
|
2008-01-20 16:39:21 +00:00
|
|
|
kDebug(OkularDebug).nospace() << "inc m_maxuniqueNum=" << d->m_maxuniqueNum;
|
2006-12-05 11:05:50 +00:00
|
|
|
|
|
|
|
annotation->setUniqueName( uniqueName );
|
2006-08-10 06:32:03 +00:00
|
|
|
}
|
2007-07-17 18:10:25 +00:00
|
|
|
annotation->d_ptr->m_page = d;
|
2005-02-18 18:24:45 +00:00
|
|
|
m_annotations.append( annotation );
|
2006-11-20 07:53:32 +00:00
|
|
|
|
|
|
|
AnnotationObjectRect *rect = new AnnotationObjectRect( annotation );
|
|
|
|
|
2007-10-07 11:00:57 +00:00
|
|
|
// Rotate the annotation on the page.
|
2007-10-07 15:10:58 +00:00
|
|
|
const QMatrix matrix = d->rotationMatrix();
|
|
|
|
annotation->d_ptr->baseTransform( matrix.inverted() );
|
|
|
|
annotation->d_ptr->annotationTransform( matrix );
|
2006-11-20 07:53:32 +00:00
|
|
|
|
|
|
|
m_rects.append( rect );
|
2005-02-18 18:24:45 +00:00
|
|
|
}
|
|
|
|
|
2007-04-17 19:55:18 +00:00
|
|
|
void PagePrivate::modifyAnnotation(Annotation * newannotation )
|
2006-08-10 06:32:03 +00:00
|
|
|
{
|
|
|
|
if(!newannotation)
|
|
|
|
return;
|
2006-09-19 17:17:29 +00:00
|
|
|
|
2007-04-17 19:55:18 +00:00
|
|
|
QLinkedList< Annotation * >::iterator aIt = m_page->m_annotations.begin(), aEnd = m_page->m_annotations.end();
|
2006-08-10 06:32:03 +00:00
|
|
|
for ( ; aIt != aEnd; ++aIt )
|
|
|
|
{
|
|
|
|
if((*aIt)==newannotation)
|
|
|
|
return; //modified already
|
2006-12-05 11:05:50 +00:00
|
|
|
if((*aIt) && (*aIt)->uniqueName()==newannotation->uniqueName())
|
2006-08-10 06:32:03 +00:00
|
|
|
{
|
2006-09-19 17:17:29 +00:00
|
|
|
int rectfound = false;
|
2007-04-17 19:55:18 +00:00
|
|
|
QLinkedList< ObjectRect * >::iterator it = m_page->m_rects.begin(), end = m_page->m_rects.end();
|
2006-09-19 17:17:29 +00:00
|
|
|
for ( ; it != end && !rectfound; ++it )
|
2007-01-02 17:05:49 +00:00
|
|
|
if ( ( (*it)->objectType() == ObjectRect::OAnnotation ) && ( (*it)->object() == (*aIt) ) )
|
2006-09-19 17:17:29 +00:00
|
|
|
{
|
|
|
|
delete *it;
|
|
|
|
*it = new AnnotationObjectRect( newannotation );
|
|
|
|
rectfound = true;
|
|
|
|
}
|
|
|
|
delete *aIt;
|
|
|
|
*aIt = newannotation;
|
2006-08-10 06:32:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
bool Page::removeAnnotation( Annotation * annotation )
|
2006-08-10 06:32:03 +00:00
|
|
|
{
|
2006-12-05 11:05:50 +00:00
|
|
|
if ( !annotation || ( annotation->flags() & Annotation::DenyDelete ) )
|
2006-09-14 18:42:28 +00:00
|
|
|
return false;
|
|
|
|
|
2006-08-10 06:32:03 +00:00
|
|
|
QLinkedList< Annotation * >::iterator aIt = m_annotations.begin(), aEnd = m_annotations.end();
|
|
|
|
for ( ; aIt != aEnd; ++aIt )
|
|
|
|
{
|
2006-12-05 11:05:50 +00:00
|
|
|
if((*aIt) && (*aIt)->uniqueName()==annotation->uniqueName())
|
2006-08-10 06:32:03 +00:00
|
|
|
{
|
2006-09-19 17:17:29 +00:00
|
|
|
int rectfound = false;
|
|
|
|
QLinkedList< ObjectRect * >::iterator it = m_rects.begin(), end = m_rects.end();
|
|
|
|
for ( ; it != end && !rectfound; ++it )
|
2007-01-02 17:05:49 +00:00
|
|
|
if ( ( (*it)->objectType() == ObjectRect::OAnnotation ) && ( (*it)->object() == (*aIt) ) )
|
2006-09-19 17:17:29 +00:00
|
|
|
{
|
|
|
|
delete *it;
|
2006-12-23 14:57:22 +00:00
|
|
|
it = m_rects.erase( it );
|
2006-09-19 17:17:29 +00:00
|
|
|
rectfound = true;
|
|
|
|
}
|
2008-01-20 16:39:21 +00:00
|
|
|
kDebug(OkularDebug) << "removed annotation:" << annotation->uniqueName();
|
2006-09-19 17:17:29 +00:00
|
|
|
delete *aIt;
|
|
|
|
m_annotations.erase( aIt );
|
2006-08-10 06:32:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-09-19 17:17:29 +00:00
|
|
|
|
2006-09-14 18:42:28 +00:00
|
|
|
return true;
|
2006-08-10 06:32:03 +00:00
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
void Page::setTransition( PageTransition * transition )
|
2005-01-02 20:32:58 +00:00
|
|
|
{
|
2006-11-23 19:25:52 +00:00
|
|
|
delete d->m_transition;
|
|
|
|
d->m_transition = transition;
|
2005-01-02 20:32:58 +00:00
|
|
|
}
|
|
|
|
|
2007-04-20 12:37:12 +00:00
|
|
|
void Page::setPageAction( PageAction action, Action * link )
|
2006-10-09 18:02:59 +00:00
|
|
|
{
|
2006-11-23 19:25:52 +00:00
|
|
|
switch ( action )
|
2006-10-09 18:02:59 +00:00
|
|
|
{
|
|
|
|
case Page::Opening:
|
2007-05-05 18:22:26 +00:00
|
|
|
delete d->m_openingAction;
|
2006-11-23 19:25:52 +00:00
|
|
|
d->m_openingAction = link;
|
2006-10-09 18:02:59 +00:00
|
|
|
break;
|
|
|
|
case Page::Closing:
|
2007-05-05 18:22:26 +00:00
|
|
|
delete d->m_closingAction;
|
2006-11-23 19:25:52 +00:00
|
|
|
d->m_closingAction = link;
|
2006-10-09 18:02:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
void Page::setFormFields( const QLinkedList< FormField * >& fields )
|
|
|
|
{
|
|
|
|
qDeleteAll( d->formfields );
|
|
|
|
d->formfields = fields;
|
2007-07-04 11:41:45 +00:00
|
|
|
QLinkedList< FormField * >::const_iterator it = d->formfields.begin(), itEnd = d->formfields.end();
|
|
|
|
for ( ; it != itEnd; ++it )
|
|
|
|
{
|
|
|
|
(*it)->d_ptr->setDefault();
|
|
|
|
}
|
2007-02-25 00:07:59 +00:00
|
|
|
}
|
|
|
|
|
2006-11-20 07:53:32 +00:00
|
|
|
void Page::deletePixmap( int id )
|
2006-11-03 17:57:32 +00:00
|
|
|
{
|
2007-03-25 22:36:41 +00:00
|
|
|
PagePrivate::PixmapObject object = d->m_pixmaps.take( id );
|
2006-11-20 07:53:32 +00:00
|
|
|
delete object.m_pixmap;
|
2006-11-03 17:57:32 +00:00
|
|
|
}
|
2006-10-09 18:02:59 +00:00
|
|
|
|
2006-11-20 07:53:32 +00:00
|
|
|
void Page::deletePixmaps()
|
2004-12-21 12:38:52 +00:00
|
|
|
{
|
2007-03-25 22:36:41 +00:00
|
|
|
QMapIterator< int, PagePrivate::PixmapObject > it( d->m_pixmaps );
|
2006-11-20 07:53:32 +00:00
|
|
|
while ( it.hasNext() ) {
|
|
|
|
it.next();
|
|
|
|
delete it.value().m_pixmap;
|
|
|
|
}
|
|
|
|
|
2007-03-25 22:36:41 +00:00
|
|
|
d->m_pixmaps.clear();
|
2004-12-21 12:38:52 +00:00
|
|
|
}
|
|
|
|
|
2006-11-03 17:57:32 +00:00
|
|
|
void Page::deleteRects()
|
2004-11-12 10:58:33 +00:00
|
|
|
{
|
2006-09-19 17:17:29 +00:00
|
|
|
// delete ObjectRects of type Link and Image
|
|
|
|
QSet<ObjectRect::ObjectType> which;
|
2007-04-20 12:37:12 +00:00
|
|
|
which << ObjectRect::Action << ObjectRect::Image;
|
2006-09-19 17:17:29 +00:00
|
|
|
deleteObjectRects( m_rects, which );
|
2004-11-12 10:58:33 +00:00
|
|
|
}
|
|
|
|
|
2007-05-05 18:07:34 +00:00
|
|
|
void PagePrivate::deleteHighlights( int s_id )
|
2005-02-01 18:26:56 +00:00
|
|
|
{
|
|
|
|
// delete highlights by ID
|
2007-05-05 18:07:34 +00:00
|
|
|
QLinkedList< HighlightAreaRect* >::iterator it = m_page->m_highlights.begin(), end = m_page->m_highlights.end();
|
2005-02-01 18:26:56 +00:00
|
|
|
while ( it != end )
|
|
|
|
{
|
2005-07-15 18:20:57 +00:00
|
|
|
HighlightAreaRect* highlight = *it;
|
2005-02-08 15:24:23 +00:00
|
|
|
if ( s_id == -1 || highlight->s_id == s_id )
|
2005-02-01 18:26:56 +00:00
|
|
|
{
|
2007-05-05 18:07:34 +00:00
|
|
|
it = m_page->m_highlights.erase( it );
|
2005-02-01 18:26:56 +00:00
|
|
|
delete highlight;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-03 23:47:12 +00:00
|
|
|
void PagePrivate::deleteTextSelections()
|
2006-09-26 22:22:01 +00:00
|
|
|
{
|
2007-09-03 23:47:12 +00:00
|
|
|
delete m_textSelections;
|
|
|
|
m_textSelections = 0;
|
2006-09-26 22:22:01 +00:00
|
|
|
}
|
|
|
|
|
2006-11-17 22:15:15 +00:00
|
|
|
void Page::deleteSourceReferences()
|
|
|
|
{
|
|
|
|
deleteObjectRects( m_rects, QSet<ObjectRect::ObjectType>() << ObjectRect::SourceRef );
|
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
void Page::deleteAnnotations()
|
2005-02-18 18:24:45 +00:00
|
|
|
{
|
2006-09-19 17:17:29 +00:00
|
|
|
// delete ObjectRects of type Annotation
|
|
|
|
deleteObjectRects( m_rects, QSet<ObjectRect::ObjectType>() << ObjectRect::OAnnotation );
|
2005-02-18 18:24:45 +00:00
|
|
|
// delete all stored annotations
|
2006-11-20 20:10:42 +00:00
|
|
|
QLinkedList< Annotation * >::const_iterator aIt = m_annotations.begin(), aEnd = m_annotations.end();
|
2005-02-18 18:24:45 +00:00
|
|
|
for ( ; aIt != aEnd; ++aIt )
|
|
|
|
delete *aIt;
|
|
|
|
m_annotations.clear();
|
|
|
|
}
|
|
|
|
|
2007-04-14 19:58:17 +00:00
|
|
|
void PagePrivate::restoreLocalContents( const QDomNode & pageNode )
|
2005-03-13 13:14:44 +00:00
|
|
|
{
|
2006-12-27 16:04:49 +00:00
|
|
|
// iterate over all chilren (annotationList, ...)
|
2005-03-13 13:14:44 +00:00
|
|
|
QDomNode childNode = pageNode.firstChild();
|
|
|
|
while ( childNode.isElement() )
|
|
|
|
{
|
|
|
|
QDomElement childElement = childNode.toElement();
|
|
|
|
childNode = childNode.nextSibling();
|
|
|
|
|
|
|
|
// parse annotationList child element
|
|
|
|
if ( childElement.tagName() == "annotationList" )
|
|
|
|
{
|
2007-03-30 14:27:22 +00:00
|
|
|
#ifdef PAGE_PROFILE
|
2006-11-15 15:48:49 +00:00
|
|
|
QTime time;
|
|
|
|
time.start();
|
2007-03-30 14:27:22 +00:00
|
|
|
#endif
|
2006-11-15 15:48:49 +00:00
|
|
|
|
2005-03-13 13:14:44 +00:00
|
|
|
// iterate over all annotations
|
|
|
|
QDomNode annotationNode = childElement.firstChild();
|
|
|
|
while( annotationNode.isElement() )
|
|
|
|
{
|
|
|
|
// get annotation element and advance to next annot
|
|
|
|
QDomElement annotElement = annotationNode.toElement();
|
|
|
|
annotationNode = annotationNode.nextSibling();
|
|
|
|
|
2005-04-04 23:55:40 +00:00
|
|
|
// get annotation from the dom element
|
2005-04-07 19:27:54 +00:00
|
|
|
Annotation * annotation = AnnotationUtils::createAnnotation( annotElement );
|
2005-03-13 13:14:44 +00:00
|
|
|
|
|
|
|
// append annotation to the list or show warning
|
|
|
|
if ( annotation )
|
2006-08-10 06:32:03 +00:00
|
|
|
{
|
2007-07-17 20:04:30 +00:00
|
|
|
annotation->d_ptr->m_page = this;
|
2007-04-14 19:58:17 +00:00
|
|
|
m_page->m_annotations.append( annotation );
|
|
|
|
m_page->m_rects.append( new AnnotationObjectRect( annotation ) );
|
2006-12-05 11:05:50 +00:00
|
|
|
int pos = annotation->uniqueName().lastIndexOf("-");
|
2006-08-10 06:32:03 +00:00
|
|
|
if(pos != -1)
|
|
|
|
{
|
2006-12-05 11:05:50 +00:00
|
|
|
int uniqID=annotation->uniqueName().right(annotation->uniqueName().length()-pos-1).toInt();
|
2007-04-14 19:58:17 +00:00
|
|
|
if ( m_maxuniqueNum < uniqID )
|
|
|
|
m_maxuniqueNum = uniqID;
|
2006-08-10 06:32:03 +00:00
|
|
|
}
|
2006-11-15 15:44:21 +00:00
|
|
|
|
2008-01-20 16:39:21 +00:00
|
|
|
kDebug(OkularDebug) << "restored annot:" << annotation->uniqueName();
|
2006-08-10 06:32:03 +00:00
|
|
|
}
|
2005-03-13 13:14:44 +00:00
|
|
|
else
|
2008-01-20 16:39:21 +00:00
|
|
|
kWarning(OkularDebug).nospace() << "page (" << m_number << "): can't restore an annotation from XML.";
|
2005-03-13 13:14:44 +00:00
|
|
|
}
|
2007-03-30 14:27:22 +00:00
|
|
|
#ifdef PAGE_PROFILE
|
2008-01-20 16:39:21 +00:00
|
|
|
kDebug(OkularDebug).nospace() << "annots: XML Load time: " << time.elapsed() << "ms";
|
2007-03-30 14:27:22 +00:00
|
|
|
#endif
|
2005-03-13 13:14:44 +00:00
|
|
|
}
|
2007-07-04 11:41:45 +00:00
|
|
|
// parse formList child element
|
|
|
|
else if ( childElement.tagName() == "forms" )
|
|
|
|
{
|
2007-08-26 23:31:01 +00:00
|
|
|
if ( formfields.isEmpty() )
|
|
|
|
continue;
|
|
|
|
|
2007-07-04 11:41:45 +00:00
|
|
|
QHash<int, FormField*> hashedforms;
|
|
|
|
QLinkedList< FormField * >::const_iterator fIt = formfields.begin(), fItEnd = formfields.end();
|
2007-08-26 20:55:56 +00:00
|
|
|
for ( ; fIt != fItEnd; ++fIt )
|
2007-07-04 11:41:45 +00:00
|
|
|
{
|
|
|
|
hashedforms[(*fIt)->id()] = (*fIt);
|
|
|
|
}
|
|
|
|
|
|
|
|
// iterate over all forms
|
|
|
|
QDomNode formsNode = childElement.firstChild();
|
|
|
|
while( formsNode.isElement() )
|
|
|
|
{
|
|
|
|
// get annotation element and advance to next annot
|
|
|
|
QDomElement formElement = formsNode.toElement();
|
|
|
|
formsNode = formsNode.nextSibling();
|
|
|
|
|
|
|
|
if ( formElement.tagName() != "form" )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
int index = formElement.attribute( "id" ).toInt( &ok );
|
|
|
|
if ( !ok )
|
|
|
|
continue;
|
|
|
|
|
2007-08-26 20:55:56 +00:00
|
|
|
QHash<int, FormField*>::const_iterator wantedIt = hashedforms.find( index );
|
|
|
|
if ( wantedIt == hashedforms.end() )
|
|
|
|
continue;
|
|
|
|
|
2007-07-04 11:41:45 +00:00
|
|
|
QString value = formElement.attribute( "value" );
|
2007-08-26 20:55:56 +00:00
|
|
|
(*wantedIt)->d_ptr->setValue( value );
|
2007-07-04 11:41:45 +00:00
|
|
|
}
|
|
|
|
}
|
2005-03-13 13:14:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-14 19:58:17 +00:00
|
|
|
void PagePrivate::saveLocalContents( QDomNode & parentNode, QDomDocument & document ) const
|
2005-03-13 13:14:44 +00:00
|
|
|
{
|
|
|
|
// only add a node if there is some stuff to write into
|
2007-07-04 11:41:45 +00:00
|
|
|
if ( m_page->m_annotations.isEmpty() && formfields.isEmpty() )
|
2005-04-07 19:27:54 +00:00
|
|
|
return;
|
2005-03-13 13:14:44 +00:00
|
|
|
|
2005-04-07 19:27:54 +00:00
|
|
|
// create the page node and set the 'number' attribute
|
|
|
|
QDomElement pageElement = document.createElement( "page" );
|
2007-04-14 19:58:17 +00:00
|
|
|
pageElement.setAttribute( "number", m_number );
|
2005-03-13 13:14:44 +00:00
|
|
|
|
2006-12-27 16:04:49 +00:00
|
|
|
#if 0
|
2005-04-07 19:27:54 +00:00
|
|
|
// add bookmark info if is bookmarked
|
2006-11-23 19:25:52 +00:00
|
|
|
if ( d->m_bookmarked )
|
2005-04-07 19:27:54 +00:00
|
|
|
{
|
|
|
|
// create the pageElement's 'bookmark' child
|
|
|
|
QDomElement bookmarkElement = document.createElement( "bookmark" );
|
|
|
|
pageElement.appendChild( bookmarkElement );
|
2005-03-13 13:14:44 +00:00
|
|
|
|
2005-04-07 19:27:54 +00:00
|
|
|
// add attributes to the element
|
|
|
|
//bookmarkElement.setAttribute( "name", bookmark name );
|
|
|
|
}
|
2006-12-27 16:04:49 +00:00
|
|
|
#endif
|
2005-04-07 19:27:54 +00:00
|
|
|
|
|
|
|
// add annotations info if has got any
|
2007-04-14 19:58:17 +00:00
|
|
|
if ( !m_page->m_annotations.isEmpty() )
|
2005-04-07 19:27:54 +00:00
|
|
|
{
|
|
|
|
// create the annotationList
|
|
|
|
QDomElement annotListElement = document.createElement( "annotationList" );
|
|
|
|
|
|
|
|
// add every annotation to the annotationList
|
2007-04-14 19:58:17 +00:00
|
|
|
QLinkedList< Annotation * >::const_iterator aIt = m_page->m_annotations.begin(), aEnd = m_page->m_annotations.end();
|
2005-04-07 19:27:54 +00:00
|
|
|
for ( ; aIt != aEnd; ++aIt )
|
2005-03-13 13:14:44 +00:00
|
|
|
{
|
2005-04-07 19:27:54 +00:00
|
|
|
// get annotation
|
|
|
|
const Annotation * a = *aIt;
|
2006-06-15 21:24:00 +00:00
|
|
|
// only save okular annotations (not the embedded in file ones)
|
2006-12-05 11:05:50 +00:00
|
|
|
if ( !(a->flags() & Annotation::External) )
|
2005-03-13 13:14:44 +00:00
|
|
|
{
|
2005-04-07 19:27:54 +00:00
|
|
|
// append an filled-up element called 'annotation' to the list
|
|
|
|
QDomElement annElement = document.createElement( "annotation" );
|
|
|
|
AnnotationUtils::storeAnnotation( a, annElement, document );
|
|
|
|
annotListElement.appendChild( annElement );
|
2008-01-20 16:39:21 +00:00
|
|
|
kDebug(OkularDebug) << "save annotation:" << a->uniqueName();
|
2005-03-13 13:14:44 +00:00
|
|
|
}
|
|
|
|
}
|
2005-04-08 10:33:20 +00:00
|
|
|
|
|
|
|
// append the annotationList element if annotations have been set
|
|
|
|
if ( annotListElement.hasChildNodes() )
|
|
|
|
pageElement.appendChild( annotListElement );
|
2005-03-13 13:14:44 +00:00
|
|
|
}
|
2005-04-08 10:33:20 +00:00
|
|
|
|
2007-07-04 11:41:45 +00:00
|
|
|
// add forms info if has got any
|
|
|
|
if ( !formfields.isEmpty() )
|
|
|
|
{
|
|
|
|
// create the formList
|
|
|
|
QDomElement formListElement = document.createElement( "forms" );
|
|
|
|
|
|
|
|
// add every form data to the formList
|
|
|
|
QLinkedList< FormField * >::const_iterator fIt = formfields.begin(), fItEnd = formfields.end();
|
|
|
|
for ( ; fIt != fItEnd; ++fIt )
|
|
|
|
{
|
|
|
|
// get the form field
|
|
|
|
const FormField * f = *fIt;
|
|
|
|
|
|
|
|
QString newvalue = f->d_ptr->value();
|
|
|
|
if ( f->d_ptr->m_default == newvalue )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// append an filled-up element called 'annotation' to the list
|
|
|
|
QDomElement formElement = document.createElement( "form" );
|
|
|
|
formElement.setAttribute( "id", f->id() );
|
|
|
|
formElement.setAttribute( "value", newvalue );
|
|
|
|
formListElement.appendChild( formElement );
|
|
|
|
}
|
|
|
|
|
|
|
|
// append the annotationList element if annotations have been set
|
|
|
|
if ( formListElement.hasChildNodes() )
|
|
|
|
pageElement.appendChild( formListElement );
|
|
|
|
}
|
|
|
|
|
2005-04-08 10:33:20 +00:00
|
|
|
// append the page element only if has children
|
|
|
|
if ( pageElement.hasChildNodes() )
|
|
|
|
parentNode.appendChild( pageElement );
|
2005-03-13 13:14:44 +00:00
|
|
|
}
|
2007-03-25 22:36:41 +00:00
|
|
|
|
|
|
|
const QPixmap * Page::_o_nearestPixmap( int pixID, int w, int h ) const
|
|
|
|
{
|
|
|
|
Q_UNUSED( h )
|
|
|
|
|
|
|
|
const QPixmap * pixmap = 0;
|
|
|
|
|
|
|
|
// if a pixmap is present for given id, use it
|
|
|
|
QMap< int, PagePrivate::PixmapObject >::const_iterator itPixmap = d->m_pixmaps.find( pixID );
|
|
|
|
if ( itPixmap != d->m_pixmaps.end() )
|
|
|
|
pixmap = itPixmap.value().m_pixmap;
|
|
|
|
// else find the closest match using pixmaps of other IDs (great optim!)
|
|
|
|
else if ( !d->m_pixmaps.isEmpty() )
|
|
|
|
{
|
|
|
|
int minDistance = -1;
|
|
|
|
QMap< int, PagePrivate::PixmapObject >::const_iterator it = d->m_pixmaps.begin(), end = d->m_pixmaps.end();
|
|
|
|
for ( ; it != end; ++it )
|
|
|
|
{
|
|
|
|
int pixWidth = (*it).m_pixmap->width(),
|
|
|
|
distance = pixWidth > w ? pixWidth - w : w - pixWidth;
|
|
|
|
if ( minDistance == -1 || distance < minDistance )
|
|
|
|
{
|
|
|
|
pixmap = (*it).m_pixmap;
|
|
|
|
minDistance = distance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pixmap;
|
|
|
|
}
|