2004-09-08 12:41:14 +00:00
/***************************************************************************
* Copyright ( C ) 2004 by Enrico Ros < eros . kde @ email . it > *
2004-09-23 21:33:53 +00:00
* Copyright ( C ) 2004 by Albert Astals Cid < tsdgeos @ terra . es > *
2004-09-08 12:41:14 +00:00
* *
* 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 . *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-10-06 00:05:49 +00:00
// qt/kde/system includes
# include <qdir.h>
2004-09-08 12:41:14 +00:00
# include <qfile.h>
2004-10-06 00:05:49 +00:00
# include <qfileinfo.h>
2004-09-08 12:41:14 +00:00
# include <qmutex.h>
# include <qvaluevector.h>
2004-09-15 20:45:00 +00:00
# include <qmap.h>
2004-09-12 23:19:18 +00:00
# include <kdebug.h>
2004-09-16 21:04:49 +00:00
# include <klocale.h>
# include <kfinddialog.h>
# include <kmessagebox.h>
2004-09-23 22:11:44 +00:00
# include <kpassdlg.h>
2004-09-17 17:58:42 +00:00
# include <kstandarddirs.h>
2004-10-06 00:05:49 +00:00
# include <kapplication.h>
# include <krun.h>
# include <kurl.h>
# include <kuserprofile.h>
# include <string.h>
2004-09-08 12:41:14 +00:00
// local includes
2004-09-23 22:11:44 +00:00
# include "ErrorCodes.h"
2004-09-08 12:41:14 +00:00
# include "PDFDoc.h"
2004-09-10 17:44:05 +00:00
# include "QOutputDev.h"
2004-09-08 12:41:14 +00:00
# include "kpdf_error.h"
# include "document.h"
# include "page.h"
2004-09-09 13:25:40 +00:00
/* Notes:
2004-09-17 17:58:42 +00:00
- FIXME event queuing to avoid flow loops ( ! ! ? ? ) maybe avoided by the
2004-09-09 13:25:40 +00:00
warning to not call something ' active ' inside an observer method .
*/
2004-09-26 23:39:39 +00:00
// structure used internally by KPDFDocument for local variables storage
2004-09-09 13:25:40 +00:00
class KPDFDocumentPrivate
2004-09-08 12:41:14 +00:00
{
2004-09-09 13:25:40 +00:00
public :
2004-09-08 12:41:14 +00:00
// document related
QMutex docLock ;
PDFDoc * pdfdoc ;
2004-09-15 20:45:00 +00:00
KPDFOutputDev * kpdfOutputDev ;
2004-09-08 12:41:14 +00:00
int currentPage ;
2004-09-11 15:59:32 +00:00
float currentPosition ;
2004-09-08 12:41:14 +00:00
QValueVector < KPDFPage * > pages ;
2004-09-12 23:19:18 +00:00
2004-09-16 21:04:49 +00:00
// find related
2004-09-17 17:58:42 +00:00
QString searchText ;
bool searchCase ;
int searchPage ;
2004-09-16 21:04:49 +00:00
// filtering related
2004-09-17 17:58:42 +00:00
QString filterText ;
bool filterCase ;
2004-09-16 21:04:49 +00:00
2004-09-08 12:41:14 +00:00
// observers related (note: won't delete oservers)
2004-09-15 20:45:00 +00:00
QMap < int , KPDFDocumentObserver * > observers ;
2004-09-08 12:41:14 +00:00
} ;
# define foreachObserver( cmd ) {\
2004-09-15 20:45:00 +00:00
QMap < int , KPDFDocumentObserver * > : : iterator it = d - > observers . begin ( ) ; \
QMap < int , KPDFDocumentObserver * > : : iterator end = d - > observers . end ( ) ; \
2004-09-08 12:41:14 +00:00
for ( ; it ! = end ; + + it ) { ( * it ) - > cmd ; } }
/*
* KPDFDocument class
*/
KPDFDocument : : KPDFDocument ( )
{
d = new KPDFDocumentPrivate ;
d - > pdfdoc = 0 ;
2004-09-09 13:25:40 +00:00
d - > currentPage = - 1 ;
2004-09-11 15:59:32 +00:00
d - > currentPosition = 0 ;
2004-09-17 17:58:42 +00:00
d - > searchPage = - 1 ;
2004-09-11 15:59:32 +00:00
SplashColor paperColor ;
paperColor . rgb8 = splashMakeRGB8 ( 0xff , 0xff , 0xff ) ;
2004-09-15 20:45:00 +00:00
d - > kpdfOutputDev = new KPDFOutputDev ( paperColor ) ;
2004-09-08 12:41:14 +00:00
}
2004-09-12 23:19:18 +00:00
2004-09-08 12:41:14 +00:00
KPDFDocument : : ~ KPDFDocument ( )
{
2004-09-17 17:58:42 +00:00
closeDocument ( ) ;
2004-09-15 20:45:00 +00:00
delete d - > kpdfOutputDev ;
2004-09-08 12:41:14 +00:00
delete d ;
}
2004-09-17 17:58:42 +00:00
bool KPDFDocument : : openDocument ( const QString & docFile )
2004-09-08 12:41:14 +00:00
{
// docFile is always local so we can use QFile on it
QFile fileReadTest ( docFile ) ;
if ( ! fileReadTest . open ( IO_ReadOnly ) )
return false ;
2004-09-17 17:58:42 +00:00
long fileSize = fileReadTest . size ( ) ;
2004-09-08 12:41:14 +00:00
fileReadTest . close ( ) ;
2004-09-17 17:58:42 +00:00
// free internal data
closeDocument ( ) ;
2004-09-08 12:41:14 +00:00
GString * filename = new GString ( QFile : : encodeName ( docFile ) ) ;
delete d - > pdfdoc ;
2004-09-10 17:44:05 +00:00
d - > pdfdoc = new PDFDoc ( filename , 0 , 0 ) ;
2004-09-11 15:59:32 +00:00
if ( ! d - > pdfdoc - > isOk ( ) )
2004-09-08 12:41:14 +00:00
{
2004-09-23 22:11:44 +00:00
if ( d - > pdfdoc - > getErrorCode ( ) = = errEncrypted )
{
bool first , correct ;
QString prompt ;
QCString pwd ;
first = true ;
correct = false ;
while ( ! correct )
{
if ( first )
{
prompt = i18n ( " Please insert the password to read the document: " ) ;
first = false ;
}
else prompt = i18n ( " Incorrect password. Try again: " ) ;
if ( KPasswordDialog : : getPassword ( pwd , prompt ) = = KPasswordDialog : : Accepted )
{
GString * pwd2 ;
pwd2 = new GString ( pwd . data ( ) ) ;
d - > pdfdoc = new PDFDoc ( filename , pwd2 , pwd2 ) ;
delete pwd2 ;
correct = d - > pdfdoc - > isOk ( ) ;
if ( ! correct & & d - > pdfdoc - > getErrorCode ( ) ! = errEncrypted )
{
delete d - > pdfdoc ;
d - > pdfdoc = 0 ;
return false ;
}
}
else
{
delete d - > pdfdoc ;
d - > pdfdoc = 0 ;
return false ;
}
}
}
else
{
delete d - > pdfdoc ;
d - > pdfdoc = 0 ;
return false ;
}
2004-09-08 12:41:14 +00:00
}
// clear xpdf errors
errors : : clear ( ) ;
2004-09-11 15:59:32 +00:00
// initialize output device for rendering current pdf
2004-09-15 20:45:00 +00:00
d - > kpdfOutputDev - > startDoc ( d - > pdfdoc - > getXRef ( ) ) ;
2004-09-11 15:59:32 +00:00
// build Pages (currentPage was set -1 by deletePages)
2004-09-08 12:41:14 +00:00
uint pageCount = d - > pdfdoc - > getNumPages ( ) ;
d - > pages . resize ( pageCount ) ;
2004-09-11 15:59:32 +00:00
if ( pageCount > 0 )
{
for ( uint i = 0 ; i < pageCount ; i + + )
d - > pages [ i ] = new KPDFPage ( i , d - > pdfdoc - > getPageWidth ( i + 1 ) , d - > pdfdoc - > getPageHeight ( i + 1 ) , d - > pdfdoc - > getPageRotate ( i + 1 ) ) ;
// filter pages, setup observers and set the first page as current
2004-09-17 17:58:42 +00:00
processPageList ( true ) ;
2004-09-11 15:59:32 +00:00
slotSetCurrentPage ( 0 ) ;
}
2004-09-12 23:19:18 +00:00
2004-09-17 17:58:42 +00:00
// check local directory for an overlay xml
QString fileName = docFile . contains ( ' / ' ) ? docFile . section ( ' / ' , - 1 , - 1 ) : docFile ;
fileName = " kpdf/ " + QString : : number ( fileSize ) + " . " + fileName + " .xml " ;
QString localFN = locateLocal ( " data " , fileName ) ;
kdWarning ( ) < < localFN < < endl ;
2004-09-08 12:41:14 +00:00
return true ;
}
2004-09-17 17:58:42 +00:00
void KPDFDocument : : closeDocument ( )
2004-09-08 12:41:14 +00:00
{
2004-09-17 17:58:42 +00:00
// delete pages and clear container
for ( uint i = 0 ; i < d - > pages . count ( ) ; i + + )
delete d - > pages [ i ] ;
d - > pages . clear ( ) ;
// broadcast zero pages
processPageList ( true ) ;
// reset internal variables
d - > currentPage = - 1 ;
d - > searchPage = - 1 ;
// delete xpds's PDFDoc contents generator
2004-09-08 12:41:14 +00:00
delete d - > pdfdoc ;
d - > pdfdoc = 0 ;
}
2004-09-09 13:25:40 +00:00
uint KPDFDocument : : currentPage ( ) const
2004-09-08 12:41:14 +00:00
{
2004-09-09 13:25:40 +00:00
return d - > currentPage ;
2004-09-08 12:41:14 +00:00
}
uint KPDFDocument : : pages ( ) const
{
return d - > pdfdoc ? d - > pdfdoc - > getNumPages ( ) : 0 ;
}
2004-09-09 13:25:40 +00:00
bool KPDFDocument : : atBegin ( ) const
{
return d - > currentPage < 1 ;
}
bool KPDFDocument : : atEnd ( ) const
{
return d - > currentPage > = ( ( int ) d - > pages . count ( ) - 1 ) ;
}
const KPDFPage * KPDFDocument : : page ( uint n ) const
{
return ( n < d - > pages . count ( ) ) ? d - > pages [ n ] : 0 ;
}
2004-09-23 21:33:53 +00:00
Outline * KPDFDocument : : outline ( ) const
{
return d - > pdfdoc ? d - > pdfdoc - > getOutline ( ) : 0 ;
}
2004-09-09 13:25:40 +00:00
2004-09-15 20:45:00 +00:00
void KPDFDocument : : addObserver ( KPDFDocumentObserver * pObserver )
{
2004-09-17 17:58:42 +00:00
d - > observers [ pObserver - > observerId ( ) ] = pObserver ;
2004-09-15 20:45:00 +00:00
}
void KPDFDocument : : requestPixmap ( int id , uint page , int width , int height , bool syn )
{
KPDFPage * kp = d - > pages [ page ] ;
if ( ! d - > pdfdoc | | ! kp | | kp - > width ( ) < 1 | | kp - > height ( ) < 1 )
return ;
if ( syn )
{
// in-place Pixmap generation for syncronous requests
if ( ! kp - > hasPixmap ( id , width , height ) )
{
// compute dpi used to get an image with desired width and height
double fakeDpiX = width * 72.0 / kp - > width ( ) ,
fakeDpiY = height * 72.0 / kp - > height ( ) ;
2004-09-16 21:04:49 +00:00
// setup kpdf output device: text page is generated only if we are at 72dpi.
// since we can pre-generate the TextPage at the right res.. why not?
bool genTextPage = ! kp - > hasSearchPage ( ) & & ( width = = kp - > width ( ) ) & & ( height = = kp - > height ( ) ) ;
2004-10-02 14:30:30 +00:00
// generate links if rendering pages on pageview
bool genLinks = id = = PAGEVIEW_ID ;
d - > kpdfOutputDev - > setParams ( width , height , genTextPage , genLinks ) ;
2004-09-16 21:04:49 +00:00
2004-09-15 20:45:00 +00:00
d - > docLock . lock ( ) ;
2004-10-02 14:30:30 +00:00
d - > pdfdoc - > displayPage ( d - > kpdfOutputDev , page + 1 , fakeDpiX , fakeDpiY , 0 , true , genLinks ) ;
2004-09-15 20:45:00 +00:00
d - > docLock . unlock ( ) ;
kp - > setPixmap ( id , d - > kpdfOutputDev - > takePixmap ( ) ) ;
2004-09-16 21:04:49 +00:00
if ( genTextPage )
kp - > setSearchPage ( d - > kpdfOutputDev - > takeTextPage ( ) ) ;
2004-10-02 14:30:30 +00:00
if ( genLinks )
kp - > setLinks ( d - > kpdfOutputDev - > takeLinks ( ) ) ;
2004-09-15 20:45:00 +00:00
d - > observers [ id ] - > notifyPixmapChanged ( page ) ;
}
}
else
{
//TODO asyncronous events queuing
}
}
2004-09-23 21:33:53 +00:00
// BEGIN slots
2004-09-09 13:25:40 +00:00
void KPDFDocument : : slotSetCurrentPage ( int page )
{
slotSetCurrentPagePosition ( page , 0.0 ) ;
}
void KPDFDocument : : slotSetCurrentPagePosition ( int page , float position )
{
2004-09-11 15:59:32 +00:00
if ( page = = d - > currentPage & & position = = d - > currentPosition )
2004-09-08 12:41:14 +00:00
return ;
d - > currentPage = page ;
2004-09-11 15:59:32 +00:00
d - > currentPosition = position ;
2004-09-08 12:41:14 +00:00
foreachObserver ( pageSetCurrent ( page , position ) ) ;
pageChanged ( ) ;
}
2004-09-17 17:58:42 +00:00
void KPDFDocument : : slotSetFilter ( const QString & pattern , bool keepCase )
2004-09-08 12:41:14 +00:00
{
2004-09-17 17:58:42 +00:00
d - > filterText = pattern ;
d - > filterCase = keepCase ;
processPageList ( false ) ;
2004-09-16 21:04:49 +00:00
}
2004-09-08 12:41:14 +00:00
2004-10-06 00:05:49 +00:00
void KPDFDocument : : slotBookmarkPage ( int n , bool on )
2004-09-30 18:16:12 +00:00
{
2004-10-06 00:05:49 +00:00
KPDFPage * page = ( n < ( int ) d - > pages . count ( ) ) ? d - > pages [ n ] : 0 ;
if ( page )
2004-09-30 18:16:12 +00:00
{
2004-10-06 00:05:49 +00:00
page - > bookmark ( on ) ;
foreachObserver ( notifyPixmapChanged ( n ) ) ;
2004-09-30 18:16:12 +00:00
}
}
2004-09-17 17:58:42 +00:00
void KPDFDocument : : slotFind ( const QString & string , bool keepCase )
2004-09-16 21:04:49 +00:00
{
2004-09-17 17:58:42 +00:00
// turn selection drawing off on filtered pages
if ( ! d - > filterText . isEmpty ( ) )
unHilightPages ( ) ;
// save params for the 'find next' case
if ( ! string . isEmpty ( ) )
2004-09-08 12:41:14 +00:00
{
2004-09-17 17:58:42 +00:00
d - > searchText = string ;
d - > searchCase = keepCase ;
2004-09-08 12:41:14 +00:00
}
2004-09-16 21:04:49 +00:00
// continue checking last SearchPage first (if it is the current page)
int currentPage = d - > currentPage ;
int pageCount = d - > pages . count ( ) ;
2004-09-17 17:58:42 +00:00
KPDFPage * foundPage = 0 ,
* lastPage = ( d - > searchPage > - 1 ) ? d - > pages [ d - > searchPage ] : 0 ;
if ( lastPage & & d - > searchPage = = currentPage )
if ( lastPage - > hasText ( d - > searchText , d - > searchCase , false ) )
foundPage = lastPage ;
2004-09-16 21:04:49 +00:00
else
2004-09-08 12:41:14 +00:00
{
2004-09-17 17:58:42 +00:00
lastPage - > hilightLastSearch ( false ) ;
2004-09-16 21:04:49 +00:00
currentPage + + ;
pageCount - - ;
2004-09-08 12:41:14 +00:00
}
2004-09-16 21:04:49 +00:00
if ( ! foundPage )
// loop through the whole document
for ( int i = 0 ; i < pageCount ; i + + )
2004-09-13 08:51:36 +00:00
{
2004-09-16 21:04:49 +00:00
if ( currentPage > = pageCount )
{
if ( KMessageBox : : questionYesNo ( 0 , i18n ( " End of document reached. \n Continue from the beginning? " ) ) = = KMessageBox : : Yes )
currentPage = 0 ;
else
break ;
}
KPDFPage * page = d - > pages [ currentPage ] ;
if ( ! page - > hasSearchPage ( ) )
{
// build a TextPage using the lightweight KPDFTextDev generator..
KPDFTextDev td ;
d - > docLock . lock ( ) ;
d - > pdfdoc - > displayPage ( & td , page - > number ( ) + 1 , 72 , 72 , 0 , true , false ) ;
d - > docLock . unlock ( ) ;
// ..and attach it to the page
page - > setSearchPage ( td . takeTextPage ( ) ) ;
}
2004-09-17 17:58:42 +00:00
if ( page - > hasText ( d - > searchText , d - > searchCase , true ) )
2004-09-16 21:04:49 +00:00
{
foundPage = page ;
break ;
}
currentPage + + ;
2004-09-13 08:51:36 +00:00
}
2004-09-16 21:04:49 +00:00
if ( foundPage )
2004-09-08 12:41:14 +00:00
{
2004-09-17 17:58:42 +00:00
int pageNumber = foundPage - > number ( ) ;
d - > searchPage = pageNumber ;
2004-09-16 21:04:49 +00:00
foundPage - > hilightLastSearch ( true ) ;
2004-09-17 17:58:42 +00:00
slotSetCurrentPage ( pageNumber ) ;
foreachObserver ( notifyPixmapChanged ( pageNumber ) ) ;
2004-09-08 12:41:14 +00:00
}
2004-09-16 21:04:49 +00:00
else
2004-09-17 17:58:42 +00:00
KMessageBox : : information ( 0 , i18n ( " No matches found for '%1'. " ) . arg ( d - > searchText ) ) ;
2004-09-08 12:41:14 +00:00
}
2004-10-06 00:05:49 +00:00
void KPDFDocument : : slotProcessLink ( int n , int x , int y )
2004-09-08 12:41:14 +00:00
{
2004-10-06 00:05:49 +00:00
KPDFPage * page = ( n < ( int ) d - > pages . count ( ) ) ? d - > pages [ n ] : 0 ;
const KPDFLink * link = page ? page - > getLink ( x , y ) : 0 ;
if ( ! link )
return ;
switch ( link - > type ( ) )
{
case KPDFLink : : Goto : {
// make copies of the 'nameDest' (string) and the 'dest' (class)
char * namedDest = 0 ;
link - > copyString ( namedDest , link - > getNamedDest ( ) ) ;
LinkDest * dest = link - > getDest ( ) ? ( ( LinkDest * ) link - > getDest ( ) ) - > copy ( ) : 0 ;
// first open filename if link is pointing outside this document
QString fileName ( link - > getFileName ( ) ) ;
if ( ! fileName . isNull ( ) )
if ( ! openRelativeFile ( fileName ) )
{
kdWarning ( ) < < " Link: Error opening ' " < < fileName < < " '. " < < endl ;
delete dest ;
delete namedDest ;
return ;
}
// now previous KPDFLink and KPDFPage don't exist anymore!
if ( namedDest & & ! dest )
{
d - > docLock . lock ( ) ;
GString temp ( namedDest ) ;
dest = d - > pdfdoc - > findDest ( & temp ) ;
d - > docLock . unlock ( ) ;
}
if ( dest )
{
// TODO implement page traversal
//pri NOWARN ntf("HERE I AM\n");
//displayDest(dest, zoom, rotate, gTrue);
}
delete namedDest ;
delete dest ;
} break ;
case KPDFLink : : Execute : {
QString fileName ( link - > getFileName ( ) ) ;
if ( fileName . endsWith ( " .pdf " ) | | fileName . endsWith ( " .PDF " ) )
openRelativeFile ( fileName ) ;
else
{
KMessageBox : : information ( 0 , i18n ( " The pdf file is trying to execute an external application and for your safety kpdf does not allow that. " ) ) ;
/* core developers say this is too dangerous
fileName = fileName - > copy ( ) ;
if ( ( ( LinkLaunch * ) action ) - > getParams ( ) )
{
fileName - > append ( ' ' ) ;
fileName - > append ( ( ( LinkLaunch * ) action ) - > getParams ( ) ) ;
}
fileName - > append ( " & " ) ;
if ( KMessageBox : : questionYesNo ( widget ( ) , i18n ( " Do you want to execute the command: \n %1 " ) . arg ( fileName - > getCString ( ) ) , i18n ( " Launching external application " ) ) = = KMessageBox : : Yes )
{
system ( fileName - > getCString ( ) ) ;
} */
}
} break ;
case KPDFLink : : Named : {
const char * name = link - > getName ( ) ;
if ( ! strcmp ( name , " NextPage " ) & & ( d - > currentPage < ( int ) d - > pages . count ( ) - 1 ) )
slotSetCurrentPage ( d - > currentPage + 1 ) ;
else if ( ! strcmp ( name , " PrevPage " ) & & d - > currentPage > 0 )
slotSetCurrentPage ( d - > currentPage - 1 ) ;
else if ( ! strcmp ( name , " FirstPage " ) )
slotSetCurrentPage ( 0 ) ;
else if ( ! strcmp ( name , " LastPage " ) )
slotSetCurrentPage ( d - > pages . count ( ) - 1 ) ;
else if ( ! strcmp ( name , " GoBack " ) )
{ } //TODO
else if ( ! strcmp ( name , " GoForward " ) )
{ } //TODO
else if ( ! strcmp ( name , " Quit " ) )
kapp - > quit ( ) ;
else
{ } //FIXME error(-1, "Unknown named action: '%s'", name);
} break ;
case KPDFLink : : URI : {
KService : : Ptr ptr = KServiceTypeProfile : : preferredService ( " text/html " , " Application " ) ;
KURL : : List lst ;
lst . append ( link - > getURI ( ) ) ;
KRun : : run ( * ptr , lst ) ;
} break ;
case KPDFLink : : Movie :
case KPDFLink : : Unknown :
// unimplemented cases
break ;
}
2004-09-09 13:25:40 +00:00
}
2004-09-23 21:33:53 +00:00
//END slots
2004-09-08 12:41:14 +00:00
2004-10-06 00:05:49 +00:00
bool KPDFDocument : : openRelativeFile ( const QString & fileName )
{
const char * currentName = d - > pdfdoc - > getFileName ( ) - > getCString ( ) ;
if ( ! currentName | | currentName [ 0 ] = = 0 )
return false ;
// convert the pdf fileName to absolute using current pdf path
QFileInfo currentInfo ( currentName ) ;
QString absFileName ( currentInfo . dir ( ) . absFilePath ( fileName ) ) ;
kdDebug ( ) < < " openDocument: ' " < < absFileName < < " ' " < < endl ;
// open the absolute filename
return openDocument ( absFileName ) ;
}
2004-09-17 17:58:42 +00:00
void KPDFDocument : : processPageList ( bool documentChanged )
2004-09-09 13:25:40 +00:00
{
2004-09-17 17:58:42 +00:00
if ( d - > filterText . length ( ) < 3 )
unHilightPages ( ) ;
else
2004-09-16 21:27:34 +00:00
{
2004-09-17 17:58:42 +00:00
uint pageCount = d - > pages . count ( ) ;
2004-09-15 20:45:00 +00:00
for ( uint i = 0 ; i < pageCount ; i + + )
2004-09-16 21:27:34 +00:00
{
KPDFPage * page = d - > pages [ i ] ;
2004-09-17 17:58:42 +00:00
if ( d - > filterText . length ( ) < 3 )
2004-09-16 21:27:34 +00:00
page - > hilightLastSearch ( false ) ;
else
{
if ( ! page - > hasSearchPage ( ) )
{
// build a TextPage using the lightweight KPDFTextDev generator..
KPDFTextDev td ;
d - > docLock . lock ( ) ;
d - > pdfdoc - > displayPage ( & td , page - > number ( ) + 1 , 72 , 72 , 0 , true , false ) ;
d - > docLock . unlock ( ) ;
// ..and attach it to the page
page - > setSearchPage ( td . takeTextPage ( ) ) ;
}
2004-09-17 17:58:42 +00:00
bool found = page - > hasText ( d - > filterText , d - > filterCase , true ) ;
page - > hilightLastSearch ( found ) ;
2004-09-16 21:27:34 +00:00
}
}
}
2004-09-08 12:41:14 +00:00
// send the list to observers
2004-09-17 17:58:42 +00:00
foreachObserver ( pageSetup ( d - > pages , documentChanged ) ) ;
2004-09-08 12:41:14 +00:00
}
2004-09-17 17:58:42 +00:00
void KPDFDocument : : unHilightPages ( )
2004-09-08 12:41:14 +00:00
{
2004-09-17 17:58:42 +00:00
if ( d - > filterText = = " " )
2004-09-08 12:41:14 +00:00
return ;
2004-09-17 17:58:42 +00:00
d - > filterText = " " ;
QValueVector < KPDFPage * > : : iterator it = d - > pages . begin ( ) , end = d - > pages . end ( ) ;
for ( ; it ! = end ; + + it )
{
KPDFPage * page = * it ;
if ( page - > isHilighted ( ) )
{
page - > hilightLastSearch ( false ) ;
foreachObserver ( notifyPixmapChanged ( page - > number ( ) ) ) ;
}
}
2004-09-08 12:41:14 +00:00
}
2004-09-10 00:35:26 +00:00
/** TO BE IMPORTED:
void generateThumbnails ( PDFDoc * doc ) ;
void stopThumbnailGeneration ( ) ;
protected slots :
void customEvent ( QCustomEvent * e ) ;
private slots :
void changeSelected ( int i ) ;
void emitClicked ( int i ) ;
signals :
void clicked ( int ) ;
private :
void generateNextThumbnail ( ) ;
ThumbnailGenerator * m_tg ;
void resizeThumbnails ( ) ;
int m_nextThumbnail ;
bool m_ignoreNext ;
DELETE :
if ( m_tg )
{
m_tg - > wait ( ) ;
delete m_tg ;
}
void ThumbnailList : : generateThumbnails ( PDFDoc * doc )
{
m_nextThumbnail = 1 ;
m_doc = doc ;
generateNextThumbnail ( ) ;
}
void ThumbnailList : : generateNextThumbnail ( )
{
if ( m_tg )
{
m_tg - > wait ( ) ;
delete m_tg ;
}
m_tg = new ThumbnailGenerator ( m_doc , m_docMutex , m_nextThumbnail , QPaintDevice : : x11AppDpiX ( ) , this ) ;
m_tg - > start ( ) ;
}
void ThumbnailList : : stopThumbnailGeneration ( )
{
if ( m_tg )
{
m_ignoreNext = true ;
m_tg - > wait ( ) ;
delete m_tg ;
m_tg = 0 ;
}
}
void ThumbnailList : : customEvent ( QCustomEvent * e )
{
if ( e - > type ( ) = = 65432 & & ! m_ignoreNext )
{
QImage * i = ( QImage * ) ( e - > data ( ) ) ;
2004-09-23 21:33:53 +00:00
2004-09-10 00:35:26 +00:00
setThumbnail ( m_nextThumbnail , i ) ;
m_nextThumbnail + + ;
if ( m_nextThumbnail < = m_doc - > getNumPages ( ) ) generateNextThumbnail ( ) ;
else
{
m_tg - > wait ( ) ;
delete m_tg ;
m_tg = 0 ;
}
}
m_ignoreNext = false ;
}
*/
2004-09-08 12:41:14 +00:00
# include "document.moc"