Commit b1ad685b authored by Enrico Ros's avatar Enrico Ros

Small API fixes. Preparing for mem-manager / async-gen. Removed KPDFDocument

dependancy from QObject. Kpdf_Part is now a Document Observer (only monitors
page changes to update actions).
Modified Accessibility(Recolor) settings and config dialog, fixed a bug,
page color change on-the-fly (pixmap refresh mechanism to add..).

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=361759
parent 49438a20
This diff is collapsed.
......@@ -11,17 +11,19 @@
<entry key="HighlightLinks" type="Bool" >
<default>false</default>
</entry>
<entry key="ChangeColors" type="Bool" >
<default>false</default>
</entry>
<entry key="RenderMode" type="Enum" >
<default>Normal</default>
<default>Inverted</default>
<choices>
<choice name="Normal" />
<choice name="pad_paper_color" />
<choice name="Inverted" />
<choice name="Paper" />
<choice name="pad_paper_color" />
<choice name="Recolor" />
<choice name="pad_fg_color" />
<choice name="pad_bg_color" />
<choice name="BlackWhite" />
<choice name="pad_contrast" />
</choices>
</entry>
<entry key="RecolorForeground" type="Color" >
......
......@@ -57,6 +57,7 @@ public:
int currentPage;
QRect currentViewport;
QValueVector< KPDFPage* > pages;
QColor paperColor;
// find related
QString searchText;
......@@ -84,12 +85,9 @@ KPDFDocument::KPDFDocument()
d->pdfdoc = 0;
d->currentPage = -1;
d->searchPage = -1;
// load paper color from Settings
QColor col = Settings::paperColor();
SplashColor paperColor;
paperColor.rgb8 = splashMakeRGB8( col.red(), col.green(), col.blue() );
// create the output device
d->kpdfOutputDev = new KPDFOutputDev( paperColor );
d->kpdfOutputDev = 0;
// create the outputdev
reparseConfig();
}
KPDFDocument::~KPDFDocument()
......@@ -179,7 +177,7 @@ bool KPDFDocument::openDocument( const QString & docFile )
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
processPageList( true );
slotSetCurrentPage( 0 );
setCurrentPage( 0 );
}
// check local directory for an overlay xml
......@@ -212,29 +210,47 @@ void KPDFDocument::closeDocument()
}
uint KPDFDocument::currentPage() const
void KPDFDocument::addObserver( KPDFDocumentObserver * pObserver )
{
return d->currentPage;
d->observers[ pObserver->observerId() ] = pObserver;
}
uint KPDFDocument::pages() const
void KPDFDocument::reparseConfig()
{
return d->pdfdoc ? d->pdfdoc->getNumPages() : 0;
// load paper color from Settings or use the white default color
QColor color = ( (Settings::renderMode() == Settings::EnumRenderMode::Paper ) &&
Settings::changeColors() ) ? Settings::paperColor() : Qt::white;
if ( color != d->paperColor || !d->kpdfOutputDev )
{
d->paperColor = color;
SplashColor paperColor;
paperColor.rgb8 = splashMakeRGB8( d->paperColor.red(), d->paperColor.green(), d->paperColor.blue() );
// rebuild the output device using the new paper color
d->docLock.lock();
delete d->kpdfOutputDev;
d->kpdfOutputDev = new KPDFOutputDev( paperColor );
if ( d->pdfdoc )
d->kpdfOutputDev->startDoc( d->pdfdoc->getXRef() );
d->docLock.unlock();
// invalidate pixmaps
//FIXME missing
}
}
bool KPDFDocument::atBegin() const
uint KPDFDocument::currentPage() const
{
return d->currentPage < 1;
return d->currentPage;
}
bool KPDFDocument::atEnd() const
uint KPDFDocument::pages() const
{
return d->currentPage >= ((int)d->pages.count() - 1);
return d->pdfdoc ? d->pdfdoc->getNumPages() : 0;
}
const KPDFPage * KPDFDocument::page( uint n ) const
bool KPDFDocument::okToPrint() const
{
return ( n < d->pages.count() ) ? d->pages[n] : 0;
return d->pdfdoc->okToPrint();
}
Outline * KPDFDocument::outline() const
......@@ -242,12 +258,12 @@ Outline * KPDFDocument::outline() const
return d->pdfdoc ? d->pdfdoc->getOutline() : 0;
}
void KPDFDocument::addObserver( KPDFDocumentObserver * pObserver )
const KPDFPage * KPDFDocument::page( uint n ) const
{
d->observers[ pObserver->observerId() ] = pObserver;
return ( n < d->pages.count() ) ? d->pages[n] : 0;
}
void KPDFDocument::requestPixmap( int id, uint page, int width, int height, bool syn )
{
KPDFPage * kp = d->pages[page];
......@@ -305,51 +321,7 @@ void KPDFDocument::requestTextPage( uint n )
page->setSearchPage( td.takeTextPage() );
}
bool KPDFDocument::okToPrint() const
{
return d->pdfdoc->okToPrint();
}
bool KPDFDocument::print(KPrinter &printer)
{
KTempFile tf( QString::null, ".ps" );
PSOutputDev *psOut = new PSOutputDev(tf.name().latin1(), d->pdfdoc->getXRef(), d->pdfdoc->getCatalog(), 1, d->pdfdoc->getNumPages(), psModePS);
if (psOut->isOk())
{
std::list<int> pages;
if (!printer.previewOnly())
{
QValueList<int> pageList = printer.pageList();
QValueList<int>::const_iterator it;
for(it = pageList.begin(); it != pageList.end(); ++it) pages.push_back(*it);
}
else
{
for(int i = 1; i <= d->pdfdoc->getNumPages(); i++) pages.push_back(i);
}
d->docLock.lock();
d->pdfdoc->displayPages(psOut, pages, 72, 72, 0, globalParams->getPSCrop(), gFalse);
d->docLock.unlock();
// needs to be here so that the file is flushed, do not merge with the one
// in the else
delete psOut;
printer.printFiles(tf.name(), true);
return true;
}
else
{
delete psOut;
return false;
}
}
// BEGIN slots
void KPDFDocument::slotSetCurrentPage( int page, const QRect & viewport )
void KPDFDocument::setCurrentPage( int page, const QRect & viewport )
{
if ( page < 0 )
page = 0;
......@@ -360,27 +332,9 @@ void KPDFDocument::slotSetCurrentPage( int page, const QRect & viewport )
d->currentPage = page;
d->currentViewport = viewport;
foreachObserver( pageSetCurrent( page, viewport ) );
pageChanged();
}
void KPDFDocument::slotSetFilter( const QString & pattern, bool keepCase )
{
d->filterText = pattern;
d->filterCase = keepCase;
processPageList( false );
}
void KPDFDocument::slotToggleBookmark( int n )
{
KPDFPage * page = ( n < (int)d->pages.count() ) ? d->pages[ n ] : 0;
if ( page )
{
page->toggleAttribute( KPDFPage::Bookmark );
foreachObserver( notifyPixmapChanged( n ) );
}
}
void KPDFDocument::slotFind( const QString & string, bool keepCase )
void KPDFDocument::findText( const QString & string, bool keepCase )
{
// turn selection drawing off on filtered pages
if ( !d->filterText.isEmpty() )
......@@ -435,14 +389,31 @@ void KPDFDocument::slotFind( const QString & string, bool keepCase )
int pageNumber = foundPage->number();
d->searchPage = pageNumber;
foundPage->setAttribute( KPDFPage::Highlight );
slotSetCurrentPage( pageNumber );
setCurrentPage( pageNumber );
foreachObserver( notifyPixmapChanged( pageNumber ) );
}
else
KMessageBox::information( 0, i18n("No matches found for '%1'.").arg(d->searchText) );
}
void KPDFDocument::slotProcessLink( const KPDFLink * link )
void KPDFDocument::findTextAll( const QString & pattern, bool keepCase )
{
d->filterText = pattern;
d->filterCase = keepCase;
processPageList( false );
}
void KPDFDocument::toggleBookmark( int n )
{
KPDFPage * page = ( n < (int)d->pages.count() ) ? d->pages[ n ] : 0;
if ( page )
{
page->toggleAttribute( KPDFPage::Bookmark );
foreachObserver( notifyPixmapChanged( n ) );
}
}
void KPDFDocument::processLink( const KPDFLink * link )
{
if ( !link )
return;
......@@ -512,7 +483,7 @@ void KPDFDocument::slotProcessLink( const KPDFLink * link )
destFitR
read and fit left,bottom,right,top
}*/
slotSetCurrentPage( pageNum, r );
setCurrentPage( pageNum, r );
}
delete namedDest;
delete dest;
......@@ -571,13 +542,13 @@ void KPDFDocument::slotProcessLink( const KPDFLink * link )
case KPDFLink::Named: {
const char * name = link->getName();
if ( !strcmp( name, "NextPage" ) && (d->currentPage < (int)d->pages.count() - 1) )
slotSetCurrentPage( d->currentPage + 1 );
setCurrentPage( d->currentPage + 1 );
else if ( !strcmp( name, "PrevPage" ) && d->currentPage > 0 )
slotSetCurrentPage( d->currentPage - 1 );
setCurrentPage( d->currentPage - 1 );
else if ( !strcmp( name, "FirstPage" ) )
slotSetCurrentPage( 0 );
setCurrentPage( 0 );
else if ( !strcmp( name, "LastPage" ) )
slotSetCurrentPage( d->pages.count() - 1 );
setCurrentPage( d->pages.count() - 1 );
else if ( !strcmp( name, "GoBack" ) )
{} //TODO
else if ( !strcmp( name, "GoForward" ) )
......@@ -601,6 +572,44 @@ void KPDFDocument::slotProcessLink( const KPDFLink * link )
break;
}
}
bool KPDFDocument::print(KPrinter &printer)
{
KTempFile tf( QString::null, ".ps" );
PSOutputDev *psOut = new PSOutputDev(tf.name().latin1(), d->pdfdoc->getXRef(), d->pdfdoc->getCatalog(), 1, d->pdfdoc->getNumPages(), psModePS);
if (psOut->isOk())
{
std::list<int> pages;
if (!printer.previewOnly())
{
QValueList<int> pageList = printer.pageList();
QValueList<int>::const_iterator it;
for(it = pageList.begin(); it != pageList.end(); ++it) pages.push_back(*it);
}
else
{
for(int i = 1; i <= d->pdfdoc->getNumPages(); i++) pages.push_back(i);
}
d->docLock.lock();
d->pdfdoc->displayPages(psOut, pages, 72, 72, 0, globalParams->getPSCrop(), gFalse);
d->docLock.unlock();
// needs to be here so that the file is flushed, do not merge with the one
// in the else
delete psOut;
printer.printFiles(tf.name(), true);
return true;
}
else
{
delete psOut;
return false;
}
}
//END slots
QString KPDFDocument::giveAbsolutePath( const QString & fileName )
......
......@@ -15,9 +15,7 @@
#include <qvaluevector.h>
class KPrinter;
class Outline;
class KPDFPage;
class KPDFLink;
......@@ -29,21 +27,22 @@ class KPDFLink;
*/
class KPDFDocumentObserver
{
public:
// you must give each observer a unique ID (used for notifications)
virtual uint observerId() const = 0;
public:
// you must give each observer a unique ID (used for notifications)
virtual uint observerId() const = 0;
// monitor changes in pixmaps (generation thread complete)
virtual void notifyPixmapChanged( int /*pageNumber*/ ) {};
// monitor changes in pixmaps (generation thread complete)
virtual void notifyPixmapChanged( int /*pageNumber*/ ) {};
// commands from the Document to all observers
virtual void pageSetup( const QValueVector<KPDFPage*> & /*pages*/, bool /*documentChanged*/ ) {};
virtual void pageSetCurrent( int /*pageNumber*/, const QRect & /*viewport*/ = QRect() ) {};
// commands from the Document to all observers
virtual void pageSetup( const QValueVector<KPDFPage*> & /*pages*/, bool /*documentChanged*/ ) {};
virtual void pageSetCurrent( int /*pageNumber*/, const QRect & /*viewport*/ = QRect() ) {};
};
#define PAGEVIEW_ID 1
#define THUMBNAILS_ID 2
#define TOC_ID 3
#define PART_ID 1
#define PAGEVIEW_ID 2
#define THUMBNAILS_ID 3
#define TOC_ID 4
/**
* @short The information container. Actions (like open,find) take place here.
......@@ -51,54 +50,44 @@ public:
* xxxxxx
* yyy.
*/
class KPDFDocument : public QObject
class KPDFDocument
{
Q_OBJECT
public:
KPDFDocument();
~KPDFDocument();
// document handling
bool openDocument( const QString & docFile );
void closeDocument();
// query methods
uint currentPage() const;
uint pages() const;
bool atBegin() const;
bool atEnd() const;
const KPDFPage * page( uint page ) const;
Outline * outline() const;
// observers related methods
void addObserver( KPDFDocumentObserver * pObserver );
void requestPixmap( int id, uint page, int width, int height, bool syncronous = false );
void requestTextPage( uint page );
bool okToPrint() const;
bool print(KPrinter &printer);
//public slots: TODO remove me
// document commands via slots
void slotSetCurrentPage( int page, const QRect & viewport = QRect() );
void slotSetFilter( const QString & pattern, bool caseSensitive );
void slotToggleBookmark( int page );
void slotFind( const QString & text = "", bool caseSensitive = false );
void slotProcessLink( const KPDFLink * link );
signals:
// notify changes via signals
void pageChanged();
private:
QString giveAbsolutePath( const QString & fileName );
bool openRelativeFile( const QString & fileName );
void processPageList( bool documentChanged );
void unHilightPages();
class KPDFDocumentPrivate * d;
public:
KPDFDocument();
~KPDFDocument();
// document handling
bool openDocument( const QString & docFile );
void closeDocument();
// misc methods
void addObserver( KPDFDocumentObserver * pObserver );
void reparseConfig();
// query methods (const ones)
uint currentPage() const;
uint pages() const;
bool okToPrint() const;
Outline * outline() const;
const KPDFPage * page( uint page ) const;
// perform actions on document / pages
void requestPixmap( int id, uint page, int width, int height, bool syncronous = false );
void requestTextPage( uint page );
void setCurrentPage( int page, const QRect & viewport = QRect() );
void findText( const QString & text = "", bool caseSensitive = false );
void findTextAll( const QString & pattern, bool caseSensitive );
void toggleBookmark( int page );
void processLink( const KPDFLink * link );
bool print( KPrinter &printer );
private:
QString giveAbsolutePath( const QString & fileName );
bool openRelativeFile( const QString & fileName );
void processPageList( bool documentChanged );
void unHilightPages();
class KPDFDocumentPrivate * d;
};
#endif
This diff is collapsed.
......@@ -20,6 +20,7 @@
#include <kparts/part.h>
#include "kpdf_dcop.h"
#include "document.h"
class QWidget;
class QSplitter;
......@@ -39,7 +40,6 @@ class LinkDest;
class ThumbnailList;
class PageView;
class SearchWidget;
class KPDFDocument;
namespace KPDF {
......@@ -53,7 +53,7 @@ class BrowserExtension;
* @author Wilco Greven <greven@kde.org>
* @version 0.2
*/
class Part : public KParts::ReadOnlyPart, virtual public kpdf_dcop
class Part : public KParts::ReadOnlyPart, public KPDFDocumentObserver, virtual public kpdf_dcop
{
Q_OBJECT
......@@ -65,8 +65,12 @@ public:
// Destructor
~Part();
// inherited from KPDFDocumentObserver
uint observerId() const { return PART_ID; }
void pageSetCurrent( int pageNumber, const QRect & viewport );
static KAboutData* createAboutData();
ASYNC goToPage(uint page);
ASYNC openDocument(KURL doc);
uint pages();
......@@ -97,14 +101,14 @@ protected slots:
public slots:
// connected to Shell action (and browserExtension), not local one
void slotPrint();
void restoreDocument(const KURL &url, int page);
void saveDocumentRestoreInfo(KConfig* config);
void restoreDocument(const KURL &url, int page);
void saveDocumentRestoreInfo(KConfig* config);
private:
void doPrint( KPrinter& printer );
// the document
KPDFDocument * document;
KPDFDocument * m_document;
// main widgets
QSplitter *m_splitter;
......
......@@ -185,12 +185,17 @@ void PagePainter::paintPageOnPainter( const KPDFPage * page, int id, int flags,
if ( !pixmap )
{
destPainter->fillRect( limits, Settings::paperColor() );
if ( Settings::changeColors() &&
Settings::renderMode() == Settings::EnumRenderMode::Paper )
destPainter->fillRect( limits, Settings::paperColor() );
else
destPainter->fillRect( limits, Qt::white );
return;
}
// we have a pixmap to paint, now let's paint it using a direct or buffered painter
bool backBuffer = Settings::renderMode() != Settings::EnumRenderMode::Normal;
bool backBuffer = Settings::changeColors() &&
Settings::renderMode() != Settings::EnumRenderMode::Paper;
// if PagePainter::Accessibility is not in 'flags', disable backBuffer
backBuffer = backBuffer && (flags & Accessibility);
QPixmap * backPixmap = 0;
......
......@@ -430,7 +430,7 @@ void PageView::keyPressEvent( QKeyEvent * e )
verticalScrollBar()->subtractPage();
}
else if ( d->vectorIndex > 0 )
d->document->slotSetCurrentPage( d->items[ d->vectorIndex - 1 ]->pageNumber() );
d->document->setCurrentPage( d->items[ d->vectorIndex - 1 ]->pageNumber() );
break;
case Key_Down:
case Key_PageDown:
......@@ -443,7 +443,7 @@ void PageView::keyPressEvent( QKeyEvent * e )
verticalScrollBar()->addPage();
}
else if ( d->vectorIndex < (int)d->items.count() - 1 )
d->document->slotSetCurrentPage( d->items[ d->vectorIndex + 1 ]->pageNumber() );
d->document->setCurrentPage( d->items[ d->vectorIndex + 1 ]->pageNumber() );
break;
case Key_Left:
horizontalScrollBar()->subtractLine();
......@@ -595,13 +595,13 @@ void PageView::contentsMouseReleaseEvent( QMouseEvent * e )
// activate link
int linkX = e->x() - pageItem->geometry().left(),
linkY = e->y() - pageItem->geometry().top();
d->document->slotProcessLink( pageItem->page()->getLink( linkX, linkY ) );
d->document->processLink( pageItem->page()->getLink( linkX, linkY ) );
}
else
{
// mouse not moved since press, so we have a click. select the page.
if ( e->globalPos() == d->mouseStartPos )
d->document->slotSetCurrentPage( pageItem->pageNumber() );
d->document->setCurrentPage( pageItem->pageNumber() );
}
}
else if ( rightButton && pageItem )
......@@ -625,7 +625,7 @@ void PageView::contentsMouseReleaseEvent( QMouseEvent * e )
switch ( m_popup->exec(e->globalPos()) )
{
case 1:
d->document->slotToggleBookmark( kpdfPage->number() );
d->document->toggleBookmark( kpdfPage->number() );
break;
case 2:
// zoom: Fit Width, columns: 1. setActions + relayout + setPage + update
......@@ -639,7 +639,7 @@ void PageView::contentsMouseReleaseEvent( QMouseEvent * e )
slotRelayoutPages();
viewport()->setUpdatesEnabled( true );
updateContents();
d->document->slotSetCurrentPage( kpdfPage->number() );
d->document->setCurrentPage( kpdfPage->number() );
break;
case 3: // ToDO switch to edit mode
slotSetMouseDraw();
......@@ -794,13 +794,13 @@ void PageView::wheelEvent( QWheelEvent *e )
{
// go to next page
if ( d->vectorIndex < (int)d->items.count() - 1 )
d->document->slotSetCurrentPage( d->items[ d->vectorIndex + 1 ]->pageNumber() );
d->document->setCurrentPage( d->items[ d->vectorIndex + 1 ]->pageNumber() );
}
else if ( delta >= 120 && !Settings::viewContinous() && vScroll == verticalScrollBar()->minValue() )
{
// go to prev page
if ( d->vectorIndex > 0 )
d->document->slotSetCurrentPage( d->items[ d->vectorIndex - 1 ]->pageNumber() );
d->document->setCurrentPage( d->items[ d->vectorIndex - 1 ]->pageNumber() );
}
else
QScrollView::wheelEvent( e );
......
......@@ -56,7 +56,7 @@ SearchWidget::SearchWidget( QWidget * parent, KPDFDocument * document )
void SearchWidget::hideEvent( QHideEvent * )
{
m_document->slotSetFilter( QString::null, m_caseSensitive );
m_document->findTextAll( QString::null, m_caseSensitive );
}
void SearchWidget::slotTextChanged( const QString & text )
......@@ -64,12 +64,12 @@ void SearchWidget::slotTextChanged( const QString & text )
if ( text.length() > 2 || text.isEmpty() )
{
m_lineEdit->setPaletteForegroundColor( palette().active().text() );
m_document->slotSetFilter( text, m_caseSensitive );
m_document->findTextAll( text, m_caseSensitive );
}
else
{
m_lineEdit->setPaletteForegroundColor( Qt::red );
m_document->slotSetFilter( QString::null, m_caseSensitive );
m_document->findTextAll( QString::null, m_caseSensitive );
}
}
......
......@@ -225,7 +225,7 @@ void ThumbnailList::keyPressEvent( QKeyEvent * keyEvent )
if ( m_selected )
m_selected->setSelected( false );
m_selected = 0;
m_document->slotSetCurrentPage( nextPage );
m_document->setCurrentPage( nextPage );
}
void ThumbnailList::contentsMousePressEvent( QMouseEvent * e )
......@@ -241,7 +241,7 @@ void ThumbnailList::contentsMousePressEvent( QMouseEvent * e )
int childTop = childY(t);
if ( clickY > childTop && clickY < (childTop + t->height()) )
{
m_document->slotSetCurrentPage( t->pageNumber() );
m_document->setCurrentPage( t->pageNumber() );
break;
}
}
......
......@@ -140,7 +140,7 @@ void TOC::slotExecuted(QListViewItem *i)
{
TOCItem *ti = dynamic_cast<TOCItem*>(i);
KPDFLink l( ti->getAction() );
m_document->slotProcessLink( &l );
m_document->processLink( &