00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "page.h"
00010 #include "page_p.h"
00011
00012
00013 #include <QtCore/QHash>
00014 #include <QtCore/QSet>
00015 #include <QtCore/QString>
00016 #include <QtCore/QVariant>
00017 #include <QtGui/QPixmap>
00018 #include <QtXml/QDomDocument>
00019 #include <QtXml/QDomElement>
00020
00021 #include <kdebug.h>
00022
00023
00024 #include "action.h"
00025 #include "annotations.h"
00026 #include "annotations_p.h"
00027 #include "area.h"
00028 #include "debug_p.h"
00029 #include "form.h"
00030 #include "form_p.h"
00031 #include "pagecontroller_p.h"
00032 #include "pagesize.h"
00033 #include "pagetransition.h"
00034 #include "rotationjob_p.h"
00035 #include "textpage.h"
00036 #include "textpage_p.h"
00037
00038 #ifdef PAGE_PROFILE
00039 #include <QtCore/QTime>
00040 #endif
00041
00042 using namespace Okular;
00043
00044 static void deleteObjectRects( QLinkedList< ObjectRect * >& rects, const QSet<ObjectRect::ObjectType>& which )
00045 {
00046 QLinkedList< ObjectRect * >::iterator it = rects.begin(), end = rects.end();
00047 for ( ; it != end; )
00048 if ( which.contains( (*it)->objectType() ) )
00049 {
00050 delete *it;
00051 it = rects.erase( it );
00052 }
00053 else
00054 ++it;
00055 }
00056
00057 PagePrivate::PagePrivate( Page *page, uint n, double w, double h, Rotation o )
00058 : m_page( page ), m_number( n ), m_orientation( o ),
00059 m_width( w ), m_height( h ),
00060 m_rotation( Rotation0 ), m_maxuniqueNum( 0 ),
00061 m_text( 0 ), m_transition( 0 ), m_textSelections( 0 ),
00062 m_openingAction( 0 ), m_closingAction( 0 ), m_duration( -1 )
00063 {
00064
00065 if ( m_width <= 0 )
00066 m_width = 1;
00067
00068 if ( m_height <= 0 )
00069 m_height = 1;
00070 }
00071
00072 PagePrivate::~PagePrivate()
00073 {
00074 qDeleteAll( formfields );
00075 delete m_openingAction;
00076 delete m_closingAction;
00077 delete m_text;
00078 delete m_transition;
00079 }
00080
00081
00082 void PagePrivate::imageRotationDone( RotationJob * job )
00083 {
00084 QMap< int, PixmapObject >::iterator it = m_pixmaps.find( job->id() );
00085 if ( it != m_pixmaps.end() )
00086 {
00087 PixmapObject &object = it.value();
00088 (*object.m_pixmap) = QPixmap::fromImage( job->image() );
00089 object.m_rotation = job->rotation();
00090 } else {
00091 PixmapObject object;
00092 object.m_pixmap = new QPixmap( QPixmap::fromImage( job->image() ) );
00093 object.m_rotation = job->rotation();
00094
00095 m_pixmaps.insert( job->id(), object );
00096 }
00097 }
00098
00099 QMatrix PagePrivate::rotationMatrix() const
00100 {
00101 QMatrix matrix;
00102 matrix.rotate( (int)m_rotation * 90 );
00103
00104 switch ( m_rotation )
00105 {
00106 case Rotation90:
00107 matrix.translate( 0, -1 );
00108 break;
00109 case Rotation180:
00110 matrix.translate( -1, -1 );
00111 break;
00112 case Rotation270:
00113 matrix.translate( -1, 0 );
00114 break;
00115 default: ;
00116 }
00117
00118 return matrix;
00119 }
00120
00123 Page::Page( uint page, double w, double h, Rotation o )
00124 : d( new PagePrivate( this, page, w, h, o ) )
00125 {
00126 }
00127
00128 Page::~Page()
00129 {
00130 deletePixmaps();
00131 deleteRects();
00132 d->deleteHighlights();
00133 deleteAnnotations();
00134 d->deleteTextSelections();
00135 deleteSourceReferences();
00136
00137 delete d;
00138 }
00139
00140 int Page::number() const
00141 {
00142 return d->m_number;
00143 }
00144
00145 Rotation Page::orientation() const
00146 {
00147 return d->m_orientation;
00148 }
00149
00150 Rotation Page::rotation() const
00151 {
00152 return d->m_rotation;
00153 }
00154
00155 Rotation Page::totalOrientation() const
00156 {
00157 return (Rotation)( ( (int)d->m_orientation + (int)d->m_rotation ) % 4 );
00158 }
00159
00160 double Page::width() const
00161 {
00162 return d->m_width;
00163 }
00164
00165 double Page::height() const
00166 {
00167 return d->m_height;
00168 }
00169
00170 double Page::ratio() const
00171 {
00172 return d->m_height / d->m_width;
00173 }
00174
00175 bool Page::hasPixmap( int id, int width, int height ) const
00176 {
00177 QMap< int, PagePrivate::PixmapObject >::const_iterator it = d->m_pixmaps.constFind( id );
00178 if ( it == d->m_pixmaps.constEnd() )
00179 return false;
00180
00181 if ( width == -1 || height == -1 )
00182 return true;
00183
00184 const QPixmap *pixmap = it.value().m_pixmap;
00185
00186 return (pixmap->width() == width && pixmap->height() == height);
00187 }
00188
00189 bool Page::hasTextPage() const
00190 {
00191 return d->m_text != 0;
00192 }
00193
00194 RegularAreaRect * Page::textArea ( TextSelection * selection ) const
00195 {
00196 if ( d->m_text )
00197 return d->m_text->textArea( selection );
00198
00199 return 0;
00200 }
00201
00202 bool Page::hasObjectRect( double x, double y, double xScale, double yScale ) const
00203 {
00204 if ( m_rects.isEmpty() )
00205 return false;
00206
00207 QLinkedList< ObjectRect * >::const_iterator it = m_rects.begin(), end = m_rects.end();
00208 for ( ; it != end; ++it )
00209 if ( (*it)->contains( x, y, xScale, yScale ) )
00210 return true;
00211
00212 return false;
00213 }
00214
00215 bool Page::hasHighlights( int s_id ) const
00216 {
00217
00218 if ( m_highlights.isEmpty() )
00219 return false;
00220
00221 if ( s_id == -1 )
00222 return true;
00223
00224 QLinkedList< HighlightAreaRect * >::const_iterator it = m_highlights.begin(), end = m_highlights.end();
00225 for ( ; it != end; ++it )
00226 if ( (*it)->s_id == s_id )
00227 return true;
00228 return false;
00229 }
00230
00231 bool Page::hasTransition() const
00232 {
00233 return d->m_transition != 0;
00234 }
00235
00236 bool Page::hasAnnotations() const
00237 {
00238 return !m_annotations.isEmpty();
00239 }
00240
00241 RegularAreaRect * Page::findText( int id, const QString & text, SearchDirection direction,
00242 Qt::CaseSensitivity caseSensitivity, const RegularAreaRect *lastRect ) const
00243 {
00244 RegularAreaRect* rect = 0;
00245 if ( text.isEmpty() || !d->m_text )
00246 return rect;
00247
00248 rect = d->m_text->findText( id, text, direction, caseSensitivity, lastRect );
00249 return rect;
00250 }
00251
00252 QString Page::text( const RegularAreaRect * area ) const
00253 {
00254 QString ret;
00255
00256 if ( !d->m_text )
00257 return ret;
00258
00259 if ( area )
00260 {
00261 RegularAreaRect rotatedArea = *area;
00262 rotatedArea.transform( d->rotationMatrix().inverted() );
00263
00264 ret = d->m_text->text( &rotatedArea );
00265 }
00266 else
00267 ret = d->m_text->text();
00268
00269 return ret;
00270 }
00271
00272 void PagePrivate::rotateAt( Rotation orientation )
00273 {
00274 if ( orientation == m_rotation )
00275 return;
00276
00277 deleteHighlights();
00278 deleteTextSelections();
00279
00280 if ( ( (int)m_orientation + (int)m_rotation ) % 2 != ( (int)m_orientation + (int)orientation ) % 2 )
00281 qSwap( m_width, m_height );
00282
00283 Rotation oldRotation = m_rotation;
00284 m_rotation = orientation;
00285
00289 QMapIterator< int, PagePrivate::PixmapObject > it( m_pixmaps );
00290 while ( it.hasNext() ) {
00291 it.next();
00292
00293 const PagePrivate::PixmapObject &object = it.value();
00294
00295 RotationJob *job = new RotationJob( object.m_pixmap->toImage(), object.m_rotation, m_rotation, it.key() );
00296 job->setPage( this );
00297 PageController::self()->addRotationJob(job);
00298 }
00299
00303 const QMatrix matrix = rotationMatrix();
00304 QLinkedList< ObjectRect * >::const_iterator objectIt = m_page->m_rects.begin(), end = m_page->m_rects.end();
00305 for ( ; objectIt != end; ++objectIt )
00306 (*objectIt)->transform( matrix );
00307
00308 QLinkedList< HighlightAreaRect* >::const_iterator hlIt = m_page->m_highlights.begin(), hlItEnd = m_page->m_highlights.end();
00309 for ( ; hlIt != hlItEnd; ++hlIt )
00310 {
00311 (*hlIt)->transform( RotationJob::rotationMatrix( oldRotation, m_rotation ) );
00312 }
00313 }
00314
00315 void PagePrivate::changeSize( const PageSize &size )
00316 {
00317 if ( size.isNull() || ( size.width() == m_width && size.height() == m_height ) )
00318 return;
00319
00320 m_page->deletePixmaps();
00321
00322
00323
00324 m_width = size.width();
00325 m_height = size.height();
00326 if ( m_rotation % 2 )
00327 qSwap( m_width, m_height );
00328 }
00329
00330 const ObjectRect * Page::objectRect( ObjectRect::ObjectType type, double x, double y, double xScale, double yScale ) const
00331 {
00332 QLinkedList< ObjectRect * >::const_iterator it = m_rects.begin(), end = m_rects.end();
00333 for ( ; it != end; ++it )
00334 if ( ( (*it)->objectType() == type ) && (*it)->contains( x, y, xScale, yScale ) )
00335 return *it;
00336 return 0;
00337 }
00338
00339 const PageTransition * Page::transition() const
00340 {
00341 return d->m_transition;
00342 }
00343
00344 QLinkedList< Annotation* > Page::annotations() const
00345 {
00346 return m_annotations;
00347 }
00348
00349 const Action * Page::pageAction( PageAction action ) const
00350 {
00351 switch ( action )
00352 {
00353 case Page::Opening:
00354 return d->m_openingAction;
00355 break;
00356 case Page::Closing:
00357 return d->m_closingAction;
00358 break;
00359 }
00360
00361 return 0;
00362 }
00363
00364 QLinkedList< FormField * > Page::formFields() const
00365 {
00366 return d->formfields;
00367 }
00368
00369 void Page::setPixmap( int id, QPixmap *pixmap )
00370 {
00371 if ( d->m_rotation == Rotation0 ) {
00372 QMap< int, PagePrivate::PixmapObject >::iterator it = d->m_pixmaps.find( id );
00373 if ( it != d->m_pixmaps.end() )
00374 {
00375 delete it.value().m_pixmap;
00376 }
00377 else
00378 {
00379 it = d->m_pixmaps.insert( id, PagePrivate::PixmapObject() );
00380 }
00381 it.value().m_pixmap = pixmap;
00382 it.value().m_rotation = d->m_rotation;
00383 } else {
00384 RotationJob *job = new RotationJob( pixmap->toImage(), Rotation0, d->m_rotation, id );
00385 job->setPage( d );
00386 PageController::self()->addRotationJob(job);
00387
00388 delete pixmap;
00389 }
00390 }
00391
00392 void Page::setTextPage( TextPage * textPage )
00393 {
00394 delete d->m_text;
00395
00396 d->m_text = textPage;
00397 if ( d->m_text )
00398 {
00399 d->m_text->d->m_page = d;
00400 }
00401 }
00402
00403 void Page::setObjectRects( const QLinkedList< ObjectRect * > & rects )
00404 {
00405 QSet<ObjectRect::ObjectType> which;
00406 which << ObjectRect::Action << ObjectRect::Image;
00407 deleteObjectRects( m_rects, which );
00408
00412 const QMatrix matrix = d->rotationMatrix();
00413
00414 QLinkedList< ObjectRect * >::const_iterator objectIt = rects.begin(), end = rects.end();
00415 for ( ; objectIt != end; ++objectIt )
00416 (*objectIt)->transform( matrix );
00417
00418 m_rects << rects;
00419 }
00420
00421 void PagePrivate::setHighlight( int s_id, RegularAreaRect *rect, const QColor & color )
00422 {
00423 HighlightAreaRect * hr = new HighlightAreaRect(rect);
00424 hr->s_id = s_id;
00425 hr->color = color;
00426
00427 m_page->m_highlights.append( hr );
00428 }
00429
00430 void PagePrivate::setTextSelections( RegularAreaRect *r, const QColor & color )
00431 {
00432 deleteTextSelections();
00433 if ( r )
00434 {
00435 HighlightAreaRect * hr = new HighlightAreaRect( r );
00436 hr->s_id = -1;
00437 hr->color = color;
00438 m_textSelections = hr;
00439 delete r;
00440 }
00441 }
00442
00443 void Page::setSourceReferences( const QLinkedList< SourceRefObjectRect * > & refRects )
00444 {
00445 deleteSourceReferences();
00446 foreach( SourceRefObjectRect * rect, refRects )
00447 m_rects << rect;
00448 }
00449
00450 void Page::setDuration( double seconds )
00451 {
00452 d->m_duration = seconds;
00453 }
00454
00455 double Page::duration() const
00456 {
00457 return d->m_duration;
00458 }
00459
00460 void Page::setLabel( const QString& label )
00461 {
00462 d->m_label = label;
00463 }
00464
00465 QString Page::label() const
00466 {
00467 return d->m_label;
00468 }
00469
00470 const RegularAreaRect * Page::textSelection() const
00471 {
00472 return d->m_textSelections;
00473 }
00474
00475 QColor Page::textSelectionColor() const
00476 {
00477 return d->m_textSelections ? d->m_textSelections->color : QColor();
00478 }
00479
00480 void Page::addAnnotation( Annotation * annotation )
00481 {
00482
00483 if(annotation->uniqueName().isEmpty())
00484 {
00485 QString uniqueName = "okular-";
00486 uniqueName += ( QString::number(d->m_number) + '-' + QString::number(++(d->m_maxuniqueNum)) );
00487
00488 kDebug(OkularDebug).nospace() << "inc m_maxuniqueNum=" << d->m_maxuniqueNum;
00489
00490 annotation->setUniqueName( uniqueName );
00491 }
00492 annotation->d_ptr->m_page = d;
00493 m_annotations.append( annotation );
00494
00495 AnnotationObjectRect *rect = new AnnotationObjectRect( annotation );
00496
00497
00498 const QMatrix matrix = d->rotationMatrix();
00499 annotation->d_ptr->baseTransform( matrix.inverted() );
00500 annotation->d_ptr->annotationTransform( matrix );
00501
00502 m_rects.append( rect );
00503 }
00504
00505 void PagePrivate::modifyAnnotation(Annotation * newannotation )
00506 {
00507 if(!newannotation)
00508 return;
00509
00510 QLinkedList< Annotation * >::iterator aIt = m_page->m_annotations.begin(), aEnd = m_page->m_annotations.end();
00511 for ( ; aIt != aEnd; ++aIt )
00512 {
00513 if((*aIt)==newannotation)
00514 return;
00515 if((*aIt) && (*aIt)->uniqueName()==newannotation->uniqueName())
00516 {
00517 int rectfound = false;
00518 QLinkedList< ObjectRect * >::iterator it = m_page->m_rects.begin(), end = m_page->m_rects.end();
00519 for ( ; it != end && !rectfound; ++it )
00520 if ( ( (*it)->objectType() == ObjectRect::OAnnotation ) && ( (*it)->object() == (*aIt) ) )
00521 {
00522 delete *it;
00523 *it = new AnnotationObjectRect( newannotation );
00524 rectfound = true;
00525 }
00526 delete *aIt;
00527 *aIt = newannotation;
00528 break;
00529 }
00530 }
00531 }
00532
00533 bool Page::removeAnnotation( Annotation * annotation )
00534 {
00535 if ( !annotation || ( annotation->flags() & Annotation::DenyDelete ) )
00536 return false;
00537
00538 QLinkedList< Annotation * >::iterator aIt = m_annotations.begin(), aEnd = m_annotations.end();
00539 for ( ; aIt != aEnd; ++aIt )
00540 {
00541 if((*aIt) && (*aIt)->uniqueName()==annotation->uniqueName())
00542 {
00543 int rectfound = false;
00544 QLinkedList< ObjectRect * >::iterator it = m_rects.begin(), end = m_rects.end();
00545 for ( ; it != end && !rectfound; ++it )
00546 if ( ( (*it)->objectType() == ObjectRect::OAnnotation ) && ( (*it)->object() == (*aIt) ) )
00547 {
00548 delete *it;
00549 it = m_rects.erase( it );
00550 rectfound = true;
00551 }
00552 kDebug(OkularDebug) << "removed annotation:" << annotation->uniqueName();
00553 delete *aIt;
00554 m_annotations.erase( aIt );
00555 break;
00556 }
00557 }
00558
00559 return true;
00560 }
00561
00562 void Page::setTransition( PageTransition * transition )
00563 {
00564 delete d->m_transition;
00565 d->m_transition = transition;
00566 }
00567
00568 void Page::setPageAction( PageAction action, Action * link )
00569 {
00570 switch ( action )
00571 {
00572 case Page::Opening:
00573 delete d->m_openingAction;
00574 d->m_openingAction = link;
00575 break;
00576 case Page::Closing:
00577 delete d->m_closingAction;
00578 d->m_closingAction = link;
00579 break;
00580 }
00581 }
00582
00583 void Page::setFormFields( const QLinkedList< FormField * >& fields )
00584 {
00585 qDeleteAll( d->formfields );
00586 d->formfields = fields;
00587 QLinkedList< FormField * >::const_iterator it = d->formfields.begin(), itEnd = d->formfields.end();
00588 for ( ; it != itEnd; ++it )
00589 {
00590 (*it)->d_ptr->setDefault();
00591 }
00592 }
00593
00594 void Page::deletePixmap( int id )
00595 {
00596 PagePrivate::PixmapObject object = d->m_pixmaps.take( id );
00597 delete object.m_pixmap;
00598 }
00599
00600 void Page::deletePixmaps()
00601 {
00602 QMapIterator< int, PagePrivate::PixmapObject > it( d->m_pixmaps );
00603 while ( it.hasNext() ) {
00604 it.next();
00605 delete it.value().m_pixmap;
00606 }
00607
00608 d->m_pixmaps.clear();
00609 }
00610
00611 void Page::deleteRects()
00612 {
00613
00614 QSet<ObjectRect::ObjectType> which;
00615 which << ObjectRect::Action << ObjectRect::Image;
00616 deleteObjectRects( m_rects, which );
00617 }
00618
00619 void PagePrivate::deleteHighlights( int s_id )
00620 {
00621
00622 QLinkedList< HighlightAreaRect* >::iterator it = m_page->m_highlights.begin(), end = m_page->m_highlights.end();
00623 while ( it != end )
00624 {
00625 HighlightAreaRect* highlight = *it;
00626 if ( s_id == -1 || highlight->s_id == s_id )
00627 {
00628 it = m_page->m_highlights.erase( it );
00629 delete highlight;
00630 }
00631 else
00632 ++it;
00633 }
00634 }
00635
00636 void PagePrivate::deleteTextSelections()
00637 {
00638 delete m_textSelections;
00639 m_textSelections = 0;
00640 }
00641
00642 void Page::deleteSourceReferences()
00643 {
00644 deleteObjectRects( m_rects, QSet<ObjectRect::ObjectType>() << ObjectRect::SourceRef );
00645 }
00646
00647 void Page::deleteAnnotations()
00648 {
00649
00650 deleteObjectRects( m_rects, QSet<ObjectRect::ObjectType>() << ObjectRect::OAnnotation );
00651
00652 QLinkedList< Annotation * >::const_iterator aIt = m_annotations.begin(), aEnd = m_annotations.end();
00653 for ( ; aIt != aEnd; ++aIt )
00654 delete *aIt;
00655 m_annotations.clear();
00656 }
00657
00658 void PagePrivate::restoreLocalContents( const QDomNode & pageNode )
00659 {
00660
00661 QDomNode childNode = pageNode.firstChild();
00662 while ( childNode.isElement() )
00663 {
00664 QDomElement childElement = childNode.toElement();
00665 childNode = childNode.nextSibling();
00666
00667
00668 if ( childElement.tagName() == "annotationList" )
00669 {
00670 #ifdef PAGE_PROFILE
00671 QTime time;
00672 time.start();
00673 #endif
00674
00675
00676 QDomNode annotationNode = childElement.firstChild();
00677 while( annotationNode.isElement() )
00678 {
00679
00680 QDomElement annotElement = annotationNode.toElement();
00681 annotationNode = annotationNode.nextSibling();
00682
00683
00684 Annotation * annotation = AnnotationUtils::createAnnotation( annotElement );
00685
00686
00687 if ( annotation )
00688 {
00689 annotation->d_ptr->m_page = this;
00690 m_page->m_annotations.append( annotation );
00691 m_page->m_rects.append( new AnnotationObjectRect( annotation ) );
00692 int pos = annotation->uniqueName().lastIndexOf("-");
00693 if(pos != -1)
00694 {
00695 int uniqID=annotation->uniqueName().right(annotation->uniqueName().length()-pos-1).toInt();
00696 if ( m_maxuniqueNum < uniqID )
00697 m_maxuniqueNum = uniqID;
00698 }
00699
00700 kDebug(OkularDebug) << "restored annot:" << annotation->uniqueName();
00701 }
00702 else
00703 kWarning(OkularDebug).nospace() << "page (" << m_number << "): can't restore an annotation from XML.";
00704 }
00705 #ifdef PAGE_PROFILE
00706 kDebug(OkularDebug).nospace() << "annots: XML Load time: " << time.elapsed() << "ms";
00707 #endif
00708 }
00709
00710 else if ( childElement.tagName() == "forms" )
00711 {
00712 if ( formfields.isEmpty() )
00713 continue;
00714
00715 QHash<int, FormField*> hashedforms;
00716 QLinkedList< FormField * >::const_iterator fIt = formfields.begin(), fItEnd = formfields.end();
00717 for ( ; fIt != fItEnd; ++fIt )
00718 {
00719 hashedforms[(*fIt)->id()] = (*fIt);
00720 }
00721
00722
00723 QDomNode formsNode = childElement.firstChild();
00724 while( formsNode.isElement() )
00725 {
00726
00727 QDomElement formElement = formsNode.toElement();
00728 formsNode = formsNode.nextSibling();
00729
00730 if ( formElement.tagName() != "form" )
00731 continue;
00732
00733 bool ok = true;
00734 int index = formElement.attribute( "id" ).toInt( &ok );
00735 if ( !ok )
00736 continue;
00737
00738 QHash<int, FormField*>::const_iterator wantedIt = hashedforms.find( index );
00739 if ( wantedIt == hashedforms.end() )
00740 continue;
00741
00742 QString value = formElement.attribute( "value" );
00743 (*wantedIt)->d_ptr->setValue( value );
00744 }
00745 }
00746 }
00747 }
00748
00749 void PagePrivate::saveLocalContents( QDomNode & parentNode, QDomDocument & document ) const
00750 {
00751
00752 if ( m_page->m_annotations.isEmpty() && formfields.isEmpty() )
00753 return;
00754
00755
00756 QDomElement pageElement = document.createElement( "page" );
00757 pageElement.setAttribute( "number", m_number );
00758
00759 #if 0
00760
00761 if ( d->m_bookmarked )
00762 {
00763
00764 QDomElement bookmarkElement = document.createElement( "bookmark" );
00765 pageElement.appendChild( bookmarkElement );
00766
00767
00768
00769 }
00770 #endif
00771
00772
00773 if ( !m_page->m_annotations.isEmpty() )
00774 {
00775
00776 QDomElement annotListElement = document.createElement( "annotationList" );
00777
00778
00779 QLinkedList< Annotation * >::const_iterator aIt = m_page->m_annotations.begin(), aEnd = m_page->m_annotations.end();
00780 for ( ; aIt != aEnd; ++aIt )
00781 {
00782
00783 const Annotation * a = *aIt;
00784
00785 if ( !(a->flags() & Annotation::External) )
00786 {
00787
00788 QDomElement annElement = document.createElement( "annotation" );
00789 AnnotationUtils::storeAnnotation( a, annElement, document );
00790 annotListElement.appendChild( annElement );
00791 kDebug(OkularDebug) << "save annotation:" << a->uniqueName();
00792 }
00793 }
00794
00795
00796 if ( annotListElement.hasChildNodes() )
00797 pageElement.appendChild( annotListElement );
00798 }
00799
00800
00801 if ( !formfields.isEmpty() )
00802 {
00803
00804 QDomElement formListElement = document.createElement( "forms" );
00805
00806
00807 QLinkedList< FormField * >::const_iterator fIt = formfields.begin(), fItEnd = formfields.end();
00808 for ( ; fIt != fItEnd; ++fIt )
00809 {
00810
00811 const FormField * f = *fIt;
00812
00813 QString newvalue = f->d_ptr->value();
00814 if ( f->d_ptr->m_default == newvalue )
00815 continue;
00816
00817
00818 QDomElement formElement = document.createElement( "form" );
00819 formElement.setAttribute( "id", f->id() );
00820 formElement.setAttribute( "value", newvalue );
00821 formListElement.appendChild( formElement );
00822 }
00823
00824
00825 if ( formListElement.hasChildNodes() )
00826 pageElement.appendChild( formListElement );
00827 }
00828
00829
00830 if ( pageElement.hasChildNodes() )
00831 parentNode.appendChild( pageElement );
00832 }
00833
00834 const QPixmap * Page::_o_nearestPixmap( int pixID, int w, int h ) const
00835 {
00836 Q_UNUSED( h )
00837
00838 const QPixmap * pixmap = 0;
00839
00840
00841 QMap< int, PagePrivate::PixmapObject >::const_iterator itPixmap = d->m_pixmaps.find( pixID );
00842 if ( itPixmap != d->m_pixmaps.end() )
00843 pixmap = itPixmap.value().m_pixmap;
00844
00845 else if ( !d->m_pixmaps.isEmpty() )
00846 {
00847 int minDistance = -1;
00848 QMap< int, PagePrivate::PixmapObject >::const_iterator it = d->m_pixmaps.begin(), end = d->m_pixmaps.end();
00849 for ( ; it != end; ++it )
00850 {
00851 int pixWidth = (*it).m_pixmap->width(),
00852 distance = pixWidth > w ? pixWidth - w : w - pixWidth;
00853 if ( minDistance == -1 || distance < minDistance )
00854 {
00855 pixmap = (*it).m_pixmap;
00856 minDistance = distance;
00857 }
00858 }
00859 }
00860
00861 return pixmap;
00862 }