Commit 81bb03b4 authored by Piotr Szymanski's avatar Piotr Szymanski

- added suport for changing rotation of the current document, looked at...

- added suport for changing rotation of the current document, looked at ghostview code, on how to do it
  still i implemented all of this myself, damn ghostview is making me lose all the joy i had in working
  on okular, working with such a badlyu document API like libgs has i just killing me...

svn path=/trunk/playground/graphics/oKular/kpdf/; revision=437094
parent 210a0d44
......@@ -311,6 +311,17 @@ void KPDFDocument::addObserver( DocumentObserver * pObserver )
}
}
void KPDFDocument::slotOrientation( int orientation )
{
if (generator->supportsRotation())
{
generator->setOrientation(pages_vector,orientation);
foreachObserver( notifySetup( pages_vector, true ) );
kdDebug() << "Oreint: " << orientation << endl;
}
}
void KPDFDocument::removeObserver( DocumentObserver * pObserver )
{
// remove observer from the map. it won't receive notifications anymore
......@@ -426,6 +437,11 @@ bool KPDFDocument::supportsSearching() const
return generator ? generator->supportsSearching() : false;
}
bool KPDFDocument::supportsRotation() const
{
return generator ? generator->supportsRotation() : false;
}
bool KPDFDocument::historyAtBegin() const
{
return d->viewportIterator == d->viewportHistory.begin();
......
......@@ -77,12 +77,18 @@ class KPDFDocument : public QObject
KURL currentDocument() const;
bool isAllowed( int /*Document::Permisison(s)*/ ) const;
bool supportsSearching() const;
bool supportsRotation() const;
// might be useful later
// bool hasFonts() const;
bool historyAtBegin() const;
bool historyAtEnd() const;
QString getMetaData( const QString & key, const QString & option = QString() ) const;
// gui altering stuff
bool altersGUI ();
QString& getXMLFile();
void setupActions(KActionCollection *ac);
// perform actions on document / pages
void setViewportPage( int page, int excludeId = -1, bool smoothMove = false );
void setViewport( const DocumentViewport & viewport, int excludeId = -1, bool smoothMove = false );
......@@ -105,6 +111,9 @@ class KPDFDocument : public QObject
// notifications sent by generator
void requestDone( PixmapRequest * request );
public slots:
void slotOrientation( int orientation );
signals:
void linkFind();
void linkGoToPage();
......
......@@ -67,7 +67,3 @@ bool KIMGIOGenerator::print( KPrinter& printer )
return true;
}
bool KIMGIOGenerator::supportsSearching() const
{
return false;
}
......@@ -26,11 +26,12 @@ class KIMGIOGenerator : public Generator
void generatePixmap( PixmapRequest * request );
void generateSyncTextPage( KPDFPage * page ) {;};
// [INHERITED] capability querying
bool supportsSearching() const;
bool hasFonts() const;
bool canGenerateTextPage() { return false; };
bool supportsSearching() { return false; };
bool supportsRotation() { return false; };
bool prefersInternalSearching() { return false; };
void setOrientation(QValueVector<KPDFPage*> & pagesVector, int orientation) {;};
RegularAreaRect* findText(const QString&, SearchDir, bool, const RegularAreaRect*, KPDFPage*)
{ return 0; };
QString * getText(const RegularAreaRect*, KPDFPage*) { return 0; };
......
......@@ -105,6 +105,11 @@ PDFGenerator::~PDFGenerator()
delete globalParams;
}
void PDFGenerator::setOrientation(QValueVector<KPDFPage*> & pagesVector, int orientation)
{
loadPages(pagesVector,orientation,true);
}
//BEGIN Generator inherited functions
bool PDFGenerator::loadDocument( const QString & filePath, QValueVector<KPDFPage*> & pagesVector )
{
......@@ -187,31 +192,40 @@ bool PDFGenerator::loadDocument( const QString & filePath, QValueVector<KPDFPage
// build Pages (currentPage was set -1 by deletePages)
uint pageCount = pdfdoc->getNumPages();
pagesVector.resize( pageCount );
loadPages(pagesVector,0);
// the file has been loaded correctly
return true;
}
void PDFGenerator::loadPages(QValueVector<KPDFPage*> & pagesVector, int rotation, bool clear)
{
KPDFTextDev td;
for ( uint i = 0; i < pageCount ; i++ )
int count=pagesVector.count();
for ( uint i = 0; i < count ; i++ )
{
// get xpdf page
Page * p = pdfdoc->getCatalog()->getPage( i + 1 );
// init a kpdfpage, add transition and annotations informations
KPDFPage * page = new KPDFPage( i, p->getWidth(), p->getHeight(), p->getRotate() );
KPDFPage * page = new KPDFPage( i, p->getWidth(), p->getHeight(), rotation );
addTransition( p, page );
if ( true ) //TODO real check
addAnnotations( p, page );
docLock.lock();
pdfdoc->displayPage( &td, page->number()+1, 72, 72, 0, true, false );
pdfdoc->displayPage( &td, page->number()+1, 72, 72, rotation, true, false );
TextPage * textPage = td.takeTextPage();
docLock.unlock();
page->setSearchPage(abstractTextPage(textPage,page->height(),page->width()));
if (clear && pagesVector[i])
delete pagesVector[i];
// set the kpdfpage at the right position in document's pages vector
pagesVector[i] = page;
}
// the file has been loaded correctly
return true;
}
TextPage * PDFGenerator::fastTextPage (KPDFPage * page)
......@@ -2234,7 +2248,8 @@ void PDFPixmapGeneratorThread::run()
d->generator->kpdfOutputDev->setParams( width, height, genTextPage,
genObjectRects, genObjectRects, TRUE /*thread safety*/ );
d->generator->pdfdoc->displayPage( d->generator->kpdfOutputDev, page->number() + 1,
fakeDpiX, fakeDpiY, 0, true, genObjectRects );
fakeDpiX, fakeDpiY,
d->currentRequest->rotation , true, genObjectRects );
// 2. grab data from the OutputDev and store it locally (note takeIMAGE)
#ifndef NDEBUG
......
......@@ -53,7 +53,7 @@ class PDFGenerator : public Generator
// [INHERITED] load a document and fill up the pagesVector
bool loadDocument( const QString & fileName, QValueVector<KPDFPage*> & pagesVector );
void loadPages(QValueVector<KPDFPage*> & pagesVector, int rotation, bool clear=false);
// [INHERITED] document informations
const DocumentInfo * generateDocumentInfo();
const DocumentSynopsis * generateDocumentSynopsis();
......@@ -68,12 +68,16 @@ class PDFGenerator : public Generator
bool canGenerateTextPage();
void generateSyncTextPage( KPDFPage * page );
bool supportsSearching() { return true; };
bool supportsRotation() { return true; };
bool prefersInternalSearching() { return false; };
RegularAreaRect * findText (const QString & text, SearchDir dir,
const bool strictCase, const RegularAreaRect * lastRect,
KPDFPage * page );
QString * getText( const RegularAreaRect * area, KPDFPage * page );
void setOrientation(QValueVector<KPDFPage*> & pagesVector, int orientation);
// [INHERITED] print page using an already configured kprinter
bool print( KPrinter& printer );
......
......@@ -287,6 +287,7 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
// set our XML-UI resource file
setXMLFile("part.rc");
//
updateViewActions();
}
......@@ -406,6 +407,11 @@ bool Part::openFile()
slotShowPresentation();
}
if (m_document->altersGUI())
{
setXMLFile(m_document->getXMLFile(),true);
m_document->setupActions(actionCollection());
}
return true;
}
......
......@@ -15,6 +15,7 @@
</Menu>
<Menu name="view"><text>&amp;View</text>
<Action name="presentation"/>
<Action name="orientation_menu"/>
<Separator/>
<Action name="zoom_in"/>
<Action name="zoom_out"/>
......
......@@ -102,6 +102,7 @@ public:
PageViewMessage * messageWindow; // in pageviewutils.h
// actions
KSelectAction * aOrientation;
KToggleAction * aMouseNormal;
KToggleAction * aMouseSelect;
KToggleAction * aToggleAnnotator;
......@@ -132,6 +133,7 @@ PageView::PageView( QWidget *parent, KPDFDocument *document )
// create and initialize private storage structure
d = new PageViewPrivate();
d->document = document;
d->aOrientation = 0;
d->zoomMode = (PageView::ZoomMode) Settings::zoomMode();
d->zoomFactor = Settings::zoomFactor();
d->mouseMode = MouseNormal;
......@@ -184,6 +186,20 @@ PageView::~PageView()
void PageView::setupActions( KActionCollection * ac )
{
d->aOrientation=new KSelectAction( i18n( "&Orientation" ), 0, this, 0, ac, "orientation_menu" );
QStringList orientations;
orientations.append( i18n( "Portrait" ) );
orientations.append( i18n( "Landscape" ) );
orientations.append( i18n( "Upside Down" ) );
orientations.append( i18n( "Seascape" ) );
d->aOrientation->setItems( orientations );
connect( d->aOrientation , SIGNAL( activated( int ) ),
d->document , SLOT( slotOrientation( int ) ) );
d->aOrientation->setEnabled(d->document->supportsRotation());
// Zoom actions ( higher scales takes lots of memory! )
d->aZoom = new KSelectAction( i18n( "Zoom" ), "viewmag", 0, this, SLOT( slotZoom() ), ac, "zoom_to" );
d->aZoom->setEditable( true );
......@@ -318,6 +334,8 @@ void PageView::notifySetup( const QValueVector< KPDFPage * > & pageSet, bool doc
" Loaded a %n-page document.",
pageSet.count() ),
PageViewMessage::Info, 4000 );
d->aOrientation->setEnabled(d->document->supportsRotation());
}
void PageView::notifyViewportChanged( bool smoothMove )
......@@ -1876,7 +1894,7 @@ void PageView::slotRequestVisiblePixmaps( int newLeft, int newTop )
if ( !i->page()->hasPixmap( PAGEVIEW_ID, i->width(), i->height() ) )
{
PixmapRequest * p = new PixmapRequest(
PAGEVIEW_ID, i->pageNumber(), i->width(), i->height(), PAGEVIEW_PRIO, true );
PAGEVIEW_ID, i->pageNumber(), i->width(), i->height(), i->rotation(), PAGEVIEW_PRIO, true );
requestedPixmaps.push_back( p );
}
......
......@@ -48,6 +48,11 @@ int PageViewItem::pageNumber() const
return m_page->number();
}
int PageViewItem::rotation() const
{
return m_page->rotation();
}
const QRect& PageViewItem::geometry() const
{
return m_geometry;
......
......@@ -34,6 +34,7 @@ class PageViewItem
int width() const;
int height() const;
double zoomFactor() const;
int rotation() const;
void setGeometry( int x, int y, int width, int height );
void setWHZ( int w, int h, double zoom );
......
......@@ -442,6 +442,7 @@ void PresentationWidget::changePage( int newPage )
PresentationFrame * frame = m_frames[ m_frameIndex ];
int pixW = frame->geometry.width();
int pixH = frame->geometry.height();
int rot = frame->page->rotation();
// if pixmap not inside the KPDFPage we request it and wait for
// notifyPixmapChanged call or else we can proceed to pixmap generation
......@@ -451,7 +452,7 @@ void PresentationWidget::changePage( int newPage )
QApplication::setOverrideCursor( KCursor::workingCursor() );
// request the pixmap
QValueList< PixmapRequest * > request;
request.push_back( new PixmapRequest( PRESENTATION_ID, m_frameIndex, pixW, pixH, PRESENTATION_PRIO ) );
request.push_back( new PixmapRequest( PRESENTATION_ID, m_frameIndex, pixW, pixH, rot, PRESENTATION_PRIO ) );
m_document->requestPixmaps( request );
// restore cursor
QApplication::restoreOverrideCursor();
......
......@@ -402,7 +402,8 @@ void ThumbnailList::slotRequestVisiblePixmaps( int /*newContentsX*/, int newCont
if ( !t->page()->hasPixmap( THUMBNAILS_ID, t->pixmapWidth(), t->pixmapHeight() ) )
{
PixmapRequest * p = new PixmapRequest(
THUMBNAILS_ID, t->pageNumber(), t->pixmapWidth(), t->pixmapHeight(), THUMBNAILS_PRIO, true );
THUMBNAILS_ID, t->pageNumber(), t->pixmapWidth(), t->pixmapHeight(),
t->page()->rotation(), THUMBNAILS_PRIO, true );
requestedPixmaps.push_back( p );
}
}
......
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