Commit bd81ccae authored by Enrico Ros's avatar Enrico Ros

merged patch_064,065,066,068,075,091,092 (tinyurl.com/8t5ec)

svn path=/branches/kpdf/annotations/kdegraphics/kpdf/; revision=428594
parent e7fadb9a
SUBDIRS = generator_pdf
SUBDIRS = generator_pdf generator_kimgio
INCLUDES = -I$(srcdir)/generator_pdf -I$(srcdir)/.. -I$(srcdir)/../xpdf -I$(srcdir)/../xpdf/goo -I$(top_builddir)/kpdf $(all_includes)
METASOURCES = AUTO
libkpdfcore_la_LIBADD = ./generator_pdf/libgeneratorpdf.la
libkpdfcore_la_LIBADD = ./generator_pdf/libgeneratorpdf.la ./generator_kimgio/libgeneratorkimgio.la
libkpdfcore_la_SOURCES = page.cpp document.cpp link.cpp annotations.cpp \
pagetransition.cpp
......
......@@ -12,11 +12,13 @@
#include <qdir.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qimage.h>
#include <qtextstream.h>
#include <qvaluevector.h>
#include <qtimer.h>
#include <qmap.h>
#include <kdebug.h>
#include <kimageio.h>
#include <klocale.h>
#include <kfinddialog.h>
#include <kmessagebox.h>
......@@ -31,7 +33,8 @@
#include "observer.h"
#include "page.h"
#include "link.h"
#include "generator_pdf/generator_pdf.h" // PDF generator
#include "generator_pdf/generator_pdf.h" // PDF generator
#include "generator_kimgio/generator_kimgio.h" // Images generator
#include "conf/settings.h"
// structures used internally by KPDFDocument for local variables storage
......@@ -51,6 +54,9 @@ class KPDFDocumentPrivate
QString docFileName;
QString xmlFileName;
// list of the mimetypes 'generator_kimgio' can understand
QStringList kimgioMimes;
// viewport stuff
QValueList< DocumentViewport > viewportHistory;
QValueList< DocumentViewport >::iterator viewportIterator;
......@@ -139,15 +145,40 @@ bool KPDFDocument::openDocument( const QString & docFile, const KURL & url )
// create the generator based on the file's mimetype
KMimeType::Ptr mime = KMimeType::findByPath( docFile );
QString mimeName = mime->name();
if ( mimeName == "application/pdf" ||
mimeName == "application/x-pdf" )
// a.1. check for mimetypes supported by generator_pdf
if ( (*mime).is( "application/pdf" ) || (*mime).is( "application/x-pdf" ) )
generator = new PDFGenerator( this );
/* else if ( mimeName == "application/postscript" )
kdError() << "PS generator not available" << endl;*/
else
// a.2. check for mimetypes supported by generator_kimgio
if ( !generator )
{
kdWarning() << "Unknown mimetype '" << mimeName << "'." << endl;
// build the mimetypes list the first time
if ( d->kimgioMimes.isEmpty() )
{
KImageIO::registerFormats();
QStringList list = QImage::inputFormatList();
QStringList::Iterator it = list.begin(), end = list.end();
for ( ; it != end; ++it )
d->kimgioMimes << KMimeType::findByPath( QString("foo.%1").arg(*it), 0, true )->name();
}
// scan over the list
QStringList::Iterator it = d->kimgioMimes.begin(), end = d->kimgioMimes.end();
for ( ; it != end; ++it )
{
kdDebug() << *it << endl;
if ( (*mime).is( *it ) )
{
generator = new KIMGIOGenerator( this );
break;
}
}
}
// a.3. no supported mimetype
if ( !generator )
{
if ( (*mime).is( "application/postscript" ) )
kdWarning() << "PS generator not available" << endl;
else
kdWarning() << "Unknown mimetype '" << mime->name() << "'." << endl;
return false;
}
......@@ -384,6 +415,11 @@ bool KPDFDocument::isAllowed( int flags ) const
return generator ? generator->isAllowed( flags ) : false;
}
bool KPDFDocument::supportsSearching() const
{
return generator ? generator->canGenerateTextPage() : false;
}
bool KPDFDocument::historyAtBegin() const
{
return d->viewportIterator == d->viewportHistory.begin();
......
......@@ -76,6 +76,7 @@ class KPDFDocument : public QObject
uint pages() const;
KURL currentDocument() const;
bool isAllowed( int /*Document::Permisison(s)*/ ) const;
bool supportsSearching() const;
bool historyAtBegin() const;
bool historyAtEnd() const;
QString getMetaData( const QString & key, const QString & option = QString() ) const;
......
......@@ -57,6 +57,7 @@ class Generator : public QObject
// page contents generation
virtual bool canGeneratePixmap() = 0;
virtual void generatePixmap( PixmapRequest * request ) = 0;
virtual bool canGenerateTextPage() = 0;
virtual void generateSyncTextPage( KPDFPage * page ) = 0;
// print document using already configured kprinter
......
INCLUDES = -I$(srcdir)/../../ $(all_includes)
libgeneratorkimgio_la_LDFLAGS = $(all_libraries)
libgeneratorkimgio_la_SOURCES = generator_kimgio.cpp
noinst_LTLIBRARIES = libgeneratorkimgio.la
/***************************************************************************
* Copyright (C) 2005 by Albert Astals Cid <tsdgeos@terra.es> *
* *
* 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. *
***************************************************************************/
#include <qpainter.h>
#include <qpixmap.h>
#include <kprinter.h>
#include "core/page.h"
#include "generator_kimgio.h"
KIMGIOGenerator::KIMGIOGenerator( KPDFDocument * document ) : Generator( document )
{
}
KIMGIOGenerator::~KIMGIOGenerator()
{
delete m_pix;
}
bool KIMGIOGenerator::loadDocument( const QString & fileName, QValueVector<KPDFPage*> & pagesVector )
{
m_pix = new QPixmap(fileName);
pagesVector.resize( 1 );
KPDFPage * page = new KPDFPage( 0, m_pix->width(), m_pix->height(), 0 );
pagesVector[0] = page;
return true;
}
bool KIMGIOGenerator::canGeneratePixmap()
{
return true;
}
void KIMGIOGenerator::generatePixmap( PixmapRequest * request )
{
QPixmap *p = new QPixmap(*m_pix);
request->page->setPixmap(request->id, p);
signalRequestDone(request);
}
bool KIMGIOGenerator::canGenerateTextPage()
{
return false;
}
void KIMGIOGenerator::generateSyncTextPage( KPDFPage * /*page*/ )
{
}
bool KIMGIOGenerator::print( KPrinter& printer )
{
QPainter p(&printer);
p.drawPixmap(0, 0, *m_pix);
return true;
}
/***************************************************************************
* Copyright (C) 2005 by Albert Astals Cid <tsdgeos@terra.es> *
* *
* 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. *
***************************************************************************/
#ifndef _KPDF_GENERATOR_PNG_H_
#define _KPDF_GENERATOR_PNG_H_
#include "core/generator.h"
class KIMGIOGenerator : public Generator
{
public:
KIMGIOGenerator( KPDFDocument * document );
virtual ~KIMGIOGenerator();
// [INHERITED] load a document and fill up the pagesVector
bool loadDocument( const QString & fileName, QValueVector<KPDFPage*> & pagesVector );
// [INHERITED] perform actions on document / pages
bool canGeneratePixmap();
void generatePixmap( PixmapRequest * request );
bool canGenerateTextPage();
void generateSyncTextPage( KPDFPage * page );
// [INHERITED] print document using already configured kprinter
bool print( KPrinter& printer );
private:
QPixmap *m_pix;
};
#endif
......@@ -387,6 +387,11 @@ void PDFGenerator::generatePixmap( PixmapRequest * request )
signalRequestDone( request );
}
bool PDFGenerator::canGenerateTextPage()
{
return true;
}
void PDFGenerator::generateSyncTextPage( KPDFPage * page )
{
// build a TextPage using the lightweight KPDFTextDev generator..
......
......@@ -64,6 +64,7 @@ class PDFGenerator : public Generator
// [INHERITED] perform actions on document / pages
bool canGeneratePixmap();
void generatePixmap( PixmapRequest * request );
bool canGenerateTextPage();
void generateSyncTextPage( KPDFPage * page );
// [INHERITED] print page using an already configured kprinter
......
......@@ -344,10 +344,11 @@ KAboutData* Part::createAboutData()
bool Part::openFile()
{
bool ok = m_document->openDocument( m_file, url() );
bool canSearch = m_document->supportsSearching();
// update one-time actions
m_find->setEnabled( ok );
m_findNext->setEnabled( ok );
m_find->setEnabled( ok && canSearch );
m_findNext->setEnabled( ok && canSearch );
m_saveAs->setEnabled( ok );
m_printPreview->setEnabled( ok );
m_showProperties->setEnabled( ok );
......
......@@ -656,7 +656,7 @@ void PageView::keyPressEvent( QKeyEvent * e )
}
return;
}
else if( e->key() == '/' && d->document->isOpened() )
else if( e->key() == '/' && d->document->isOpened() && d->document->supportsSearching() )
{
// stop scrolling the page (if doing it)
if ( d->autoScrollTimer )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment