2006-07-20 20:47:05 +00:00
/***************************************************************************
* Copyright ( C ) 2005 by Piotr Szymanski < niedakh @ gmail . com > *
2008-08-01 20:26:22 +00:00
* Copyright ( C ) 2008 by Albert Astals Cid < aacid @ kde . org > *
2006-07-20 20:47:05 +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 . *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-04-19 18:30:20 +00:00
# include "generator.h"
# include "generator_p.h"
2012-07-02 06:22:51 +00:00
# include "observer.h"
2007-04-19 18:30:20 +00:00
2007-10-08 21:49:27 +00:00
# include <qeventloop.h>
2014-08-07 23:35:27 +00:00
# include <QtPrintSupport/QPrinter>
2007-10-08 21:49:27 +00:00
2014-09-11 19:12:27 +00:00
# include <QtCore/QDebug>
2014-10-06 06:31:17 +00:00
# include <QIcon>
2014-10-08 11:48:01 +00:00
# include <QMimeDatabase>
2014-10-14 05:37:01 +00:00
# include <KLocalizedString>
2014-05-10 13:31:59 +00:00
# include <kwallet.h>
2006-03-21 20:00:24 +00:00
2006-12-28 16:45:50 +00:00
# include "document.h"
2007-09-14 15:29:16 +00:00
# include "document_p.h"
2007-01-31 18:31:19 +00:00
# include "page.h"
2014-02-19 22:40:43 +00:00
# include "page_p.h"
2007-10-08 21:49:27 +00:00
# include "textpage.h"
2008-05-18 23:06:21 +00:00
# include "utils.h"
2005-11-20 15:30:15 +00:00
2006-09-21 08:45:36 +00:00
using namespace Okular ;
2007-09-14 13:31:55 +00:00
GeneratorPrivate : : GeneratorPrivate ( )
2007-12-02 22:55:12 +00:00
: m_document ( 0 ) ,
2007-04-20 17:17:44 +00:00
mPixmapGenerationThread ( 0 ) , mTextPageGenerationThread ( 0 ) ,
2007-10-08 21:49:27 +00:00
m_mutex ( 0 ) , m_threadsMutex ( 0 ) , mPixmapReady ( true ) , mTextPageReady ( true ) ,
2014-01-13 00:15:55 +00:00
m_closing ( false ) , m_closingLoop ( 0 ) ,
m_dpi ( 72.0 , 72.0 )
2007-04-20 17:17:44 +00:00
{
}
GeneratorPrivate : : ~ GeneratorPrivate ( )
2006-10-25 15:35:53 +00:00
{
2007-04-20 17:17:44 +00:00
if ( mPixmapGenerationThread )
mPixmapGenerationThread - > wait ( ) ;
delete mPixmapGenerationThread ;
if ( mTextPageGenerationThread )
mTextPageGenerationThread - > wait ( ) ;
delete mTextPageGenerationThread ;
2007-09-15 11:35:53 +00:00
delete m_mutex ;
2007-10-08 21:49:27 +00:00
delete m_threadsMutex ;
2007-04-20 17:17:44 +00:00
}
2007-04-20 17:59:12 +00:00
PixmapGenerationThread * GeneratorPrivate : : pixmapGenerationThread ( )
2007-01-31 18:50:31 +00:00
{
if ( mPixmapGenerationThread )
2007-04-20 17:59:12 +00:00
return mPixmapGenerationThread ;
2007-01-31 18:50:31 +00:00
2007-09-14 13:31:55 +00:00
Q_Q ( Generator ) ;
mPixmapGenerationThread = new PixmapGenerationThread ( q ) ;
2014-10-01 12:02:01 +00:00
QObject : : connect ( mPixmapGenerationThread , SIGNAL ( finished ( ) ) , q , SLOT ( pixmapGenerationFinished ( ) ) ,
2007-01-31 18:50:31 +00:00
Qt : : QueuedConnection ) ;
2007-04-20 17:59:12 +00:00
return mPixmapGenerationThread ;
2007-01-31 18:50:31 +00:00
}
2007-04-20 17:59:12 +00:00
TextPageGenerationThread * GeneratorPrivate : : textPageGenerationThread ( )
2007-01-31 18:50:31 +00:00
{
if ( mTextPageGenerationThread )
2007-04-20 17:59:12 +00:00
return mTextPageGenerationThread ;
2007-01-31 18:50:31 +00:00
2007-09-14 13:31:55 +00:00
Q_Q ( Generator ) ;
mTextPageGenerationThread = new TextPageGenerationThread ( q ) ;
2014-10-01 12:02:01 +00:00
QObject : : connect ( mTextPageGenerationThread , SIGNAL ( finished ( ) ) , q , SLOT ( textpageGenerationFinished ( ) ) ,
2007-01-31 18:50:31 +00:00
Qt : : QueuedConnection ) ;
2007-04-20 17:59:12 +00:00
return mTextPageGenerationThread ;
2007-01-31 18:50:31 +00:00
}
2007-04-20 17:17:44 +00:00
void GeneratorPrivate : : pixmapGenerationFinished ( )
2007-01-31 18:31:19 +00:00
{
2007-09-14 13:31:55 +00:00
Q_Q ( Generator ) ;
2007-01-31 18:31:19 +00:00
PixmapRequest * request = mPixmapGenerationThread - > request ( ) ;
mPixmapGenerationThread - > endGeneration ( ) ;
2007-10-08 21:49:27 +00:00
QMutexLocker locker ( threadsLock ( ) ) ;
2007-01-31 18:31:19 +00:00
mPixmapReady = true ;
2007-10-08 21:49:27 +00:00
if ( m_closing )
{
delete request ;
if ( mTextPageReady )
{
locker . unlock ( ) ;
m_closingLoop - > quit ( ) ;
}
return ;
}
2008-05-18 23:06:21 +00:00
const QImage & img = mPixmapGenerationThread - > image ( ) ;
2013-02-24 21:58:53 +00:00
request - > page ( ) - > setPixmap ( request - > observer ( ) , new QPixmap ( QPixmap : : fromImage ( img ) ) , request - > normalizedRect ( ) ) ;
2008-05-31 11:23:02 +00:00
const int pageNumber = request - > page ( ) - > number ( ) ;
2007-10-08 21:49:27 +00:00
2008-05-31 11:23:02 +00:00
if ( mPixmapGenerationThread - > calcBoundingBox ( ) )
q - > updatePageBoundingBox ( pageNumber , mPixmapGenerationThread - > boundingBox ( ) ) ;
2012-07-17 18:35:54 +00:00
q - > signalPixmapRequestDone ( request ) ;
2007-01-31 18:31:19 +00:00
}
2007-04-20 17:17:44 +00:00
void GeneratorPrivate : : textpageGenerationFinished ( )
2007-01-31 18:31:19 +00:00
{
2008-05-04 15:10:32 +00:00
Q_Q ( Generator ) ;
2007-01-31 18:31:19 +00:00
Page * page = mTextPageGenerationThread - > page ( ) ;
mTextPageGenerationThread - > endGeneration ( ) ;
2007-10-08 21:49:27 +00:00
QMutexLocker locker ( threadsLock ( ) ) ;
2007-01-31 18:31:19 +00:00
mTextPageReady = true ;
2007-10-08 21:49:27 +00:00
if ( m_closing )
{
delete mTextPageGenerationThread - > textPage ( ) ;
if ( mPixmapReady )
{
locker . unlock ( ) ;
m_closingLoop - > quit ( ) ;
}
return ;
}
2007-01-31 18:31:19 +00:00
if ( mTextPageGenerationThread - > textPage ( ) )
2008-05-04 15:10:32 +00:00
{
TextPage * tp = mTextPageGenerationThread - > textPage ( ) ;
page - > setTextPage ( tp ) ;
q - > signalTextGenerationDone ( page , tp ) ;
}
2007-01-31 18:31:19 +00:00
}
2007-10-08 21:49:27 +00:00
QMutex * GeneratorPrivate : : threadsLock ( )
{
if ( ! m_threadsMutex )
m_threadsMutex = new QMutex ( ) ;
return m_threadsMutex ;
}
2008-03-15 02:15:16 +00:00
QVariant GeneratorPrivate : : metaData ( const QString & , const QVariant & ) const
{
return QVariant ( ) ;
}
2008-05-06 20:20:10 +00:00
QImage GeneratorPrivate : : image ( PixmapRequest * )
{
return QImage ( ) ;
}
2007-01-31 18:31:19 +00:00
2014-08-13 09:16:28 +00:00
Generator : : Generator ( QObject * parent , const QVariantList & )
: QObject ( parent )
, d_ptr ( new GeneratorPrivate ( ) )
2006-10-20 16:51:46 +00:00
{
2007-09-14 13:31:55 +00:00
d_ptr - > q_ptr = this ;
}
2014-09-17 21:52:14 +00:00
Generator : : Generator ( GeneratorPrivate & dd , QObject * parent , const QVariantList & args )
: QObject ( parent ) , d_ptr ( & dd )
2007-09-14 13:31:55 +00:00
{
d_ptr - > q_ptr = this ;
2014-09-17 21:52:14 +00:00
Q_UNUSED ( args )
2006-10-20 16:51:46 +00:00
}
Generator : : ~ Generator ( )
{
2007-09-14 13:31:55 +00:00
delete d_ptr ;
2006-10-20 16:51:46 +00:00
}
2014-05-09 17:56:16 +00:00
bool Generator : : loadDocument ( const QString & fileName , QVector < Page * > & pagesVector )
{
2016-07-11 20:57:11 +00:00
Q_UNUSED ( fileName ) ;
Q_UNUSED ( pagesVector ) ;
2014-05-09 17:56:16 +00:00
return false ;
}
2007-01-12 22:49:14 +00:00
bool Generator : : loadDocumentFromData ( const QByteArray & , QVector < Page * > & )
{
return false ;
}
2014-05-09 17:56:16 +00:00
Document : : OpenResult Generator : : loadDocumentWithPassword ( const QString & fileName , QVector < Page * > & pagesVector , const QString & )
{
return loadDocument ( fileName , pagesVector ) ? Document : : OpenSuccess : Document : : OpenError ;
}
Document : : OpenResult Generator : : loadDocumentFromDataWithPassword ( const QByteArray & fileData , QVector < Page * > & pagesVector , const QString & )
{
return loadDocumentFromData ( fileData , pagesVector ) ? Document : : OpenSuccess : Document : : OpenError ;
}
2007-10-08 16:46:51 +00:00
bool Generator : : closeDocument ( )
{
2007-10-08 21:49:27 +00:00
Q_D ( Generator ) ;
d - > m_closing = true ;
d - > threadsLock ( ) - > lock ( ) ;
if ( ! ( d - > mPixmapReady & & d - > mTextPageReady ) )
{
QEventLoop loop ;
d - > m_closingLoop = & loop ;
d - > threadsLock ( ) - > unlock ( ) ;
loop . exec ( ) ;
d - > m_closingLoop = 0 ;
}
else
{
d - > threadsLock ( ) - > unlock ( ) ;
}
bool ret = doCloseDocument ( ) ;
d - > m_closing = false ;
return ret ;
2007-10-08 16:46:51 +00:00
}
2007-01-31 18:31:19 +00:00
bool Generator : : canGeneratePixmap ( ) const
2007-01-24 15:06:45 +00:00
{
2007-09-14 13:31:55 +00:00
Q_D ( const Generator ) ;
2007-01-31 18:31:19 +00:00
return d - > mPixmapReady ;
2007-01-24 15:06:45 +00:00
}
2007-01-31 18:31:19 +00:00
void Generator : : generatePixmap ( PixmapRequest * request )
2007-01-24 15:06:45 +00:00
{
2007-09-14 13:31:55 +00:00
Q_D ( Generator ) ;
2007-01-31 18:31:19 +00:00
d - > mPixmapReady = false ;
2012-12-01 16:12:40 +00:00
const bool calcBoundingBox = ! request - > isTile ( ) & & ! request - > page ( ) - > isBoundingBoxKnown ( ) ;
2009-01-20 12:52:01 +00:00
if ( request - > asynchronous ( ) & & hasFeature ( Threaded ) )
2007-01-31 18:31:19 +00:00
{
2012-12-01 16:12:40 +00:00
d - > pixmapGenerationThread ( ) - > startGeneration ( request , calcBoundingBox ) ;
2007-01-31 21:10:00 +00:00
/**
* We create the text page for every page that is visible to the
* user , so he can use the text extraction tools without a delay .
*/
2014-03-01 16:01:14 +00:00
if ( hasFeature ( TextExtraction ) & & ! request - > page ( ) - > hasTextPage ( ) & & canGenerateTextPage ( ) & & ! d - > m_closing ) {
2007-01-31 21:10:00 +00:00
d - > mTextPageReady = false ;
2007-04-20 17:59:12 +00:00
d - > textPageGenerationThread ( ) - > startGeneration ( request - > page ( ) ) ;
2007-01-31 21:10:00 +00:00
}
2007-01-31 18:31:19 +00:00
return ;
}
2008-05-18 23:06:21 +00:00
const QImage & img = image ( request ) ;
2013-02-24 21:58:53 +00:00
request - > page ( ) - > setPixmap ( request - > observer ( ) , new QPixmap ( QPixmap : : fromImage ( img ) ) , request - > normalizedRect ( ) ) ;
2008-05-31 11:23:02 +00:00
const int pageNumber = request - > page ( ) - > number ( ) ;
2007-01-31 18:31:19 +00:00
d - > mPixmapReady = true ;
2007-09-14 13:31:55 +00:00
signalPixmapRequestDone ( request ) ;
2012-12-01 16:12:40 +00:00
if ( calcBoundingBox )
2008-05-31 11:23:02 +00:00
updatePageBoundingBox ( pageNumber , Utils : : imageBoundingBox ( & img ) ) ;
2007-01-24 15:06:45 +00:00
}
2007-01-31 18:31:19 +00:00
bool Generator : : canGenerateTextPage ( ) const
2007-01-24 18:27:54 +00:00
{
2007-09-14 13:31:55 +00:00
Q_D ( const Generator ) ;
2007-01-31 18:31:19 +00:00
return d - > mTextPageReady ;
2007-01-24 18:27:54 +00:00
}
2007-08-13 22:25:27 +00:00
void Generator : : generateTextPage ( Page * page )
2007-01-24 15:06:45 +00:00
{
2008-05-04 15:10:32 +00:00
TextPage * tp = textPage ( page ) ;
page - > setTextPage ( tp ) ;
signalTextGenerationDone ( page , tp ) ;
2007-01-24 15:06:45 +00:00
}
2008-05-06 20:20:10 +00:00
QImage Generator : : image ( PixmapRequest * request )
2007-01-24 18:27:54 +00:00
{
2008-05-06 20:20:10 +00:00
Q_D ( Generator ) ;
return d - > image ( request ) ;
2007-01-24 18:27:54 +00:00
}
2007-01-31 18:31:19 +00:00
TextPage * Generator : : textPage ( Page * )
2006-10-20 16:51:46 +00:00
{
2007-01-31 18:31:19 +00:00
return 0 ;
2006-10-20 16:51:46 +00:00
}
2014-05-11 09:17:49 +00:00
DocumentInfo Generator : : generateDocumentInfo ( const QSet < DocumentInfo : : Key > & keys ) const
2006-10-20 16:51:46 +00:00
{
2016-07-11 20:57:11 +00:00
Q_UNUSED ( keys ) ;
2014-05-11 09:17:49 +00:00
return DocumentInfo ( ) ;
2006-10-20 16:51:46 +00:00
}
const DocumentSynopsis * Generator : : generateDocumentSynopsis ( )
{
2006-10-25 17:43:15 +00:00
return 0 ;
2006-10-20 16:51:46 +00:00
}
2007-07-07 20:35:01 +00:00
FontInfo : : List Generator : : fontsForPage ( int )
2006-10-20 16:51:46 +00:00
{
2007-07-07 20:35:01 +00:00
return FontInfo : : List ( ) ;
2006-10-20 16:51:46 +00:00
}
const QList < EmbeddedFile * > * Generator : : embeddedFiles ( ) const
{
2006-10-25 17:43:15 +00:00
return 0 ;
2006-10-20 16:51:46 +00:00
}
Generator : : PageSizeMetric Generator : : pagesSizeMetric ( ) const
{
2006-10-25 17:43:15 +00:00
return None ;
2006-10-20 16:51:46 +00:00
}
2007-03-10 23:59:11 +00:00
bool Generator : : isAllowed ( Permission ) const
2006-10-20 16:51:46 +00:00
{
2006-10-25 17:43:15 +00:00
return true ;
2006-10-20 16:51:46 +00:00
}
2007-01-05 17:09:47 +00:00
void Generator : : rotationChanged ( Rotation , Rotation )
2006-10-20 16:51:46 +00:00
{
}
2007-01-05 23:12:06 +00:00
PageSize : : List Generator : : pageSizes ( ) const
2006-10-20 16:51:46 +00:00
{
2007-01-05 23:12:06 +00:00
return PageSize : : List ( ) ;
2006-10-20 16:51:46 +00:00
}
2007-01-05 23:12:06 +00:00
void Generator : : pageSizeChanged ( const PageSize & , const PageSize & )
2006-10-20 16:51:46 +00:00
{
}
2007-10-15 23:01:27 +00:00
bool Generator : : print ( QPrinter & )
2006-10-20 16:51:46 +00:00
{
2006-10-25 17:43:15 +00:00
return false ;
2006-10-20 16:51:46 +00:00
}
2010-04-14 23:07:27 +00:00
Generator : : PrintError Generator : : printError ( ) const
{
return UnknownPrintError ;
}
2016-11-26 15:00:02 +00:00
void Generator : : opaqueAction ( const BackendOpaqueAction * /*action*/ )
{
}
2008-03-15 02:15:16 +00:00
QVariant Generator : : metaData ( const QString & key , const QVariant & option ) const
2006-10-20 16:51:46 +00:00
{
2008-03-15 02:15:16 +00:00
Q_D ( const Generator ) ;
return d - > metaData ( key , option ) ;
2006-10-20 16:51:46 +00:00
}
2006-10-25 15:35:53 +00:00
ExportFormat : : List Generator : : exportFormats ( ) const
2006-10-20 16:51:46 +00:00
{
2006-10-25 17:43:15 +00:00
return ExportFormat : : List ( ) ;
2006-10-20 16:51:46 +00:00
}
2006-10-25 15:35:53 +00:00
bool Generator : : exportTo ( const QString & , const ExportFormat & )
2006-10-20 16:51:46 +00:00
{
2006-10-25 17:43:15 +00:00
return false ;
2006-10-20 16:51:46 +00:00
}
2014-05-10 13:31:59 +00:00
void Generator : : walletDataForFile ( const QString & fileName , QString * walletName , QString * walletFolder , QString * walletKey ) const
{
2016-07-11 20:07:57 +00:00
* walletKey = fileName . section ( QLatin1Char ( ' / ' ) , - 1 , - 1 ) ;
2014-05-10 13:31:59 +00:00
* walletName = KWallet : : Wallet : : NetworkWallet ( ) ;
2015-10-29 12:37:11 +00:00
* walletFolder = QStringLiteral ( " KPdf " ) ;
2014-05-10 13:31:59 +00:00
}
2007-01-26 16:35:30 +00:00
bool Generator : : hasFeature ( GeneratorFeature feature ) const
2007-01-12 22:49:14 +00:00
{
2007-09-14 13:31:55 +00:00
Q_D ( const Generator ) ;
2007-01-26 16:35:30 +00:00
return d - > m_features . contains ( feature ) ;
2007-01-12 22:49:14 +00:00
}
2007-01-29 08:17:45 +00:00
void Generator : : signalPixmapRequestDone ( PixmapRequest * request )
2006-10-20 16:51:46 +00:00
{
2007-09-14 13:31:55 +00:00
Q_D ( Generator ) ;
2006-10-25 17:43:15 +00:00
if ( d - > m_document )
d - > m_document - > requestDone ( request ) ;
else
2008-02-01 00:30:48 +00:00
{
delete request ;
}
2006-10-20 16:51:46 +00:00
}
2008-05-04 15:10:32 +00:00
void Generator : : signalTextGenerationDone ( Page * page , TextPage * textPage )
{
Q_D ( Generator ) ;
if ( d - > m_document )
d - > m_document - > textGenerationDone ( page ) ;
else
delete textPage ;
}
2007-03-17 12:11:41 +00:00
const Document * Generator : : document ( ) const
2006-10-20 16:51:46 +00:00
{
2007-09-14 13:31:55 +00:00
Q_D ( const Generator ) ;
2008-03-19 17:01:00 +00:00
if ( d - > m_document )
{
return d - > m_document - > m_parent ;
}
return 0 ;
2006-10-20 16:51:46 +00:00
}
2007-01-26 16:35:30 +00:00
void Generator : : setFeature ( GeneratorFeature feature , bool on )
{
2007-09-14 13:31:55 +00:00
Q_D ( Generator ) ;
2007-01-26 16:35:30 +00:00
if ( on )
d - > m_features . insert ( feature ) ;
else
d - > m_features . remove ( feature ) ;
}
2007-09-14 22:16:00 +00:00
QVariant Generator : : documentMetaData ( const QString & key , const QVariant & option ) const
2017-03-02 20:04:59 +00:00
{
Q_D ( const Generator ) ;
if ( ! d - > m_document )
return QVariant ( ) ;
if ( key = = QLatin1String ( " PaperColor " ) )
return documentMetaData ( PaperColorMetaData , option ) ;
if ( key = = QLatin1String ( " GraphicsAntialias " ) )
return documentMetaData ( GraphicsAntialiasMetaData , option ) ;
if ( key = = QLatin1String ( " TextAntialias " ) )
return documentMetaData ( TextAntialiasMetaData , option ) ;
if ( key = = QLatin1String ( " TextHinting " ) )
return documentMetaData ( TextHintingMetaData , option ) ;
return QVariant ( ) ;
}
2017-03-02 21:45:45 +00:00
QVariant Generator : : documentMetaData ( const DocumentMetaDataKey key , const QVariant & option ) const
2007-09-14 22:16:00 +00:00
{
Q_D ( const Generator ) ;
if ( ! d - > m_document )
return QVariant ( ) ;
return d - > m_document - > documentMetaData ( key , option ) ;
}
2007-09-15 11:35:53 +00:00
QMutex * Generator : : userMutex ( ) const
{
Q_D ( const Generator ) ;
if ( ! d - > m_mutex )
{
d - > m_mutex = new QMutex ( ) ;
}
return d - > m_mutex ;
}
2008-05-18 23:06:21 +00:00
void Generator : : updatePageBoundingBox ( int page , const NormalizedRect & boundingBox )
{
Q_D ( Generator ) ;
if ( d - > m_document ) // still connected to document?
d - > m_document - > setPageBoundingBox ( page , boundingBox ) ;
}
2008-08-01 20:26:22 +00:00
void Generator : : requestFontData ( const Okular : : FontInfo & /*font*/ , QByteArray * /*data*/ )
{
}
2007-01-26 16:35:30 +00:00
2014-01-13 00:15:55 +00:00
void Generator : : setDPI ( const QSizeF & dpi )
{
Q_D ( Generator ) ;
d - > m_dpi = dpi ;
}
QSizeF Generator : : dpi ( ) const
{
Q_D ( const Generator ) ;
return d - > m_dpi ;
}
2015-05-29 04:24:06 +00:00
QAbstractItemModel * Generator : : layersModel ( ) const
{
return 0 ;
}
2013-02-24 21:58:53 +00:00
PixmapRequest : : PixmapRequest ( DocumentObserver * observer , int pageNumber , int width , int height , int priority , PixmapRequestFeatures features )
2007-09-30 21:44:31 +00:00
: d ( new PixmapRequestPrivate )
2006-10-20 16:51:46 +00:00
{
2013-02-24 21:58:53 +00:00
d - > mObserver = observer ;
2006-10-25 17:43:15 +00:00
d - > mPageNumber = pageNumber ;
d - > mWidth = width ;
d - > mHeight = height ;
d - > mPriority = priority ;
2013-02-24 21:58:53 +00:00
d - > mFeatures = features ;
2008-03-07 15:50:48 +00:00
d - > mForce = false ;
2012-08-24 16:32:39 +00:00
d - > mTile = false ;
2012-07-08 16:52:00 +00:00
d - > mNormalizedRect = NormalizedRect ( ) ;
2006-10-20 16:51:46 +00:00
}
2006-10-25 15:35:53 +00:00
PixmapRequest : : ~ PixmapRequest ( )
{
2006-10-25 17:43:15 +00:00
delete d ;
2006-10-25 15:35:53 +00:00
}
2013-02-24 21:58:53 +00:00
DocumentObserver * PixmapRequest : : observer ( ) const
2006-10-25 15:35:53 +00:00
{
2013-02-24 21:58:53 +00:00
return d - > mObserver ;
2006-10-25 15:35:53 +00:00
}
int PixmapRequest : : pageNumber ( ) const
{
2006-10-25 17:43:15 +00:00
return d - > mPageNumber ;
2006-10-25 15:35:53 +00:00
}
int PixmapRequest : : width ( ) const
{
2006-10-25 17:43:15 +00:00
return d - > mWidth ;
2006-10-25 15:35:53 +00:00
}
int PixmapRequest : : height ( ) const
2006-10-22 11:25:08 +00:00
{
2006-10-25 17:43:15 +00:00
return d - > mHeight ;
2006-10-22 11:25:08 +00:00
}
2006-10-25 15:35:53 +00:00
int PixmapRequest : : priority ( ) const
{
2006-10-25 17:43:15 +00:00
return d - > mPriority ;
2006-10-25 15:35:53 +00:00
}
bool PixmapRequest : : asynchronous ( ) const
{
2013-02-24 21:58:53 +00:00
return d - > mFeatures & Asynchronous ;
}
bool PixmapRequest : : preload ( ) const
{
return d - > mFeatures & Preload ;
2006-10-25 15:35:53 +00:00
}
Page * PixmapRequest : : page ( ) const
{
2006-10-25 17:43:15 +00:00
return d - > mPage ;
2006-10-25 15:35:53 +00:00
}
2012-08-24 16:32:39 +00:00
void PixmapRequest : : setTile ( bool tile )
{
d - > mTile = tile ;
}
bool PixmapRequest : : isTile ( ) const
{
return d - > mTile ;
}
2012-07-08 16:52:00 +00:00
void PixmapRequest : : setNormalizedRect ( const NormalizedRect & rect )
2012-05-28 02:52:26 +00:00
{
2012-07-08 16:52:00 +00:00
if ( d - > mNormalizedRect = = rect )
2012-05-28 02:52:26 +00:00
return ;
2012-07-08 16:52:00 +00:00
d - > mNormalizedRect = rect ;
2012-05-28 02:52:26 +00:00
}
2012-11-10 17:30:01 +00:00
const NormalizedRect & PixmapRequest : : normalizedRect ( ) const
2012-05-28 02:52:26 +00:00
{
2012-07-08 16:52:00 +00:00
return d - > mNormalizedRect ;
2012-05-28 02:52:26 +00:00
}
2014-02-19 22:40:43 +00:00
Okular : : TilesManager * PixmapRequestPrivate : : tilesManager ( ) const
{
return mPage - > d - > tilesManager ( mObserver ) ;
}
2007-12-04 21:36:32 +00:00
void PixmapRequestPrivate : : swap ( )
2006-11-20 07:53:32 +00:00
{
2007-12-04 21:36:32 +00:00
qSwap ( mWidth , mHeight ) ;
2006-11-20 07:53:32 +00:00
}
2012-07-02 06:22:51 +00:00
2007-04-12 20:43:37 +00:00
class Okular : : ExportFormatPrivate : public QSharedData
2006-10-25 15:35:53 +00:00
{
2006-10-25 17:43:15 +00:00
public :
2014-09-11 13:18:05 +00:00
ExportFormatPrivate ( const QString & description , const QMimeType & mimeType , const QIcon & icon = QIcon ( ) )
2007-04-12 20:43:37 +00:00
: QSharedData ( ) , mDescription ( description ) , mMimeType ( mimeType ) , mIcon ( icon )
{
}
~ ExportFormatPrivate ( )
2006-10-25 17:43:15 +00:00
{
}
2006-10-25 15:35:53 +00:00
2006-10-25 17:43:15 +00:00
QString mDescription ;
2014-09-11 13:18:05 +00:00
QMimeType mMimeType ;
2014-08-13 09:54:49 +00:00
QIcon mIcon ;
2006-10-25 15:35:53 +00:00
} ;
ExportFormat : : ExportFormat ( )
2014-09-11 13:18:05 +00:00
: d ( new ExportFormatPrivate ( QString ( ) , QMimeType ( ) ) )
2006-10-25 15:35:53 +00:00
{
}
2014-09-11 13:18:05 +00:00
ExportFormat : : ExportFormat ( const QString & description , const QMimeType & mimeType )
2007-04-12 20:43:37 +00:00
: d ( new ExportFormatPrivate ( description , mimeType ) )
2006-10-25 15:35:53 +00:00
{
}
2014-09-11 13:18:05 +00:00
ExportFormat : : ExportFormat ( const QIcon & icon , const QString & description , const QMimeType & mimeType )
2007-04-12 20:43:37 +00:00
: d ( new ExportFormatPrivate ( description , mimeType , icon ) )
2006-10-25 15:35:53 +00:00
{
}
ExportFormat : : ~ ExportFormat ( )
{
}
ExportFormat : : ExportFormat ( const ExportFormat & other )
2007-04-12 20:43:37 +00:00
: d ( other . d )
2006-10-25 15:35:53 +00:00
{
}
ExportFormat & ExportFormat : : operator = ( const ExportFormat & other )
{
2006-10-25 17:43:15 +00:00
if ( this = = & other )
return * this ;
2006-10-25 15:35:53 +00:00
2007-04-12 20:43:37 +00:00
d = other . d ;
2006-10-25 15:35:53 +00:00
2006-10-25 17:43:15 +00:00
return * this ;
2006-10-25 15:35:53 +00:00
}
QString ExportFormat : : description ( ) const
{
2006-10-25 17:43:15 +00:00
return d - > mDescription ;
2006-10-25 15:35:53 +00:00
}
2014-09-11 13:18:05 +00:00
QMimeType ExportFormat : : mimeType ( ) const
2006-10-25 15:35:53 +00:00
{
2006-10-25 17:43:15 +00:00
return d - > mMimeType ;
2006-10-25 15:35:53 +00:00
}
2014-08-13 09:54:49 +00:00
QIcon ExportFormat : : icon ( ) const
2006-10-25 15:35:53 +00:00
{
2006-10-25 17:43:15 +00:00
return d - > mIcon ;
2006-10-25 15:35:53 +00:00
}
2006-10-22 11:25:08 +00:00
2007-03-10 20:51:50 +00:00
bool ExportFormat : : isNull ( ) const
{
2014-09-11 13:18:05 +00:00
return ! d - > mMimeType . isValid ( ) | | d - > mDescription . isNull ( ) ;
2007-03-10 20:51:50 +00:00
}
2007-04-21 11:09:41 +00:00
ExportFormat ExportFormat : : standardFormat ( StandardExportFormat type )
2007-03-10 21:32:09 +00:00
{
2014-09-11 13:18:05 +00:00
QMimeDatabase db ;
2007-04-21 11:09:41 +00:00
switch ( type )
{
case PlainText :
2015-10-29 12:37:11 +00:00
return ExportFormat ( QIcon : : fromTheme ( QStringLiteral ( " text-x-generic " ) ) , i18n ( " Plain &Text... " ) , db . mimeTypeForName ( QStringLiteral ( " text/plain " ) ) ) ;
2007-04-21 11:09:41 +00:00
break ;
case PDF :
2015-10-29 12:37:11 +00:00
return ExportFormat ( QIcon : : fromTheme ( QStringLiteral ( " application-pdf " ) ) , i18n ( " PDF " ) , db . mimeTypeForName ( QStringLiteral ( " application/pdf " ) ) ) ;
2007-04-21 11:09:41 +00:00
break ;
2008-08-07 13:45:43 +00:00
case OpenDocumentText :
return ExportFormat (
2015-10-29 12:37:11 +00:00
QIcon : : fromTheme ( QStringLiteral ( " application-vnd.oasis.opendocument.text " ) ) ,
2008-08-07 13:45:43 +00:00
i18nc ( " This is the document format " , " OpenDocument Text " ) ,
2015-10-29 12:37:11 +00:00
db . mimeTypeForName ( QStringLiteral ( " application/vnd.oasis.opendocument.text " ) ) ) ;
2008-09-01 12:00:50 +00:00
break ;
case HTML :
2015-10-29 12:37:11 +00:00
return ExportFormat ( QIcon : : fromTheme ( QStringLiteral ( " text-html " ) ) , i18nc ( " This is the document format " , " HTML " ) , db . mimeTypeForName ( QStringLiteral ( " text/html " ) ) ) ;
2008-08-07 13:45:43 +00:00
break ;
2007-04-21 11:09:41 +00:00
}
return ExportFormat ( ) ;
2007-03-10 21:32:09 +00:00
}
2007-04-12 20:43:37 +00:00
bool ExportFormat : : operator = = ( const ExportFormat & other ) const
{
return d = = other . d ;
}
bool ExportFormat : : operator ! = ( const ExportFormat & other ) const
{
return d ! = other . d ;
}
2007-07-30 23:58:04 +00:00
QDebug operator < < ( QDebug str , const Okular : : PixmapRequest & req )
2005-11-20 15:30:15 +00:00
{
2015-10-29 12:37:11 +00:00
QString s = QStringLiteral ( " PixmapRequest(#%2, %1, %3x%4, page %6, prio %5) " )
2016-07-11 20:07:57 +00:00
. arg ( QString ( req . asynchronous ( ) ? QStringLiteral ( " async " ) : QStringLiteral ( " sync " ) ) )
2013-02-24 21:58:53 +00:00
. arg ( ( qulonglong ) req . observer ( ) )
2006-10-25 15:35:53 +00:00
. arg ( req . width ( ) )
. arg ( req . height ( ) )
. arg ( req . priority ( ) )
. arg ( req . pageNumber ( ) ) ;
2007-11-04 23:33:05 +00:00
str < < qPrintable ( s ) ;
2006-10-22 13:34:47 +00:00
return str ;
2005-11-20 15:30:15 +00:00
}
2006-06-10 12:59:09 +00:00
2014-08-08 22:00:07 +00:00
# include "moc_generator.cpp"
2010-04-14 23:07:27 +00:00
/* kate: replace-tabs on; indent-width 4; */