diff --git a/core/document.cpp b/core/document.cpp index 72fbf61be..cda494643 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -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(); diff --git a/core/document.h b/core/document.h index 5810efde4..81571a5fc 100644 --- a/core/document.h +++ b/core/document.h @@ -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(); diff --git a/core/generator_kimgio/generator_kimgio.cpp b/core/generator_kimgio/generator_kimgio.cpp index 2724c1021..ba4fe6862 100644 --- a/core/generator_kimgio/generator_kimgio.cpp +++ b/core/generator_kimgio/generator_kimgio.cpp @@ -67,7 +67,3 @@ bool KIMGIOGenerator::print( KPrinter& printer ) return true; } -bool KIMGIOGenerator::supportsSearching() const -{ - return false; -} diff --git a/core/generator_kimgio/generator_kimgio.h b/core/generator_kimgio/generator_kimgio.h index ff0dfec6a..2b1fddf50 100644 --- a/core/generator_kimgio/generator_kimgio.h +++ b/core/generator_kimgio/generator_kimgio.h @@ -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 & pagesVector, int orientation) {;}; RegularAreaRect* findText(const QString&, SearchDir, bool, const RegularAreaRect*, KPDFPage*) { return 0; }; QString * getText(const RegularAreaRect*, KPDFPage*) { return 0; }; diff --git a/core/generator_pdf/generator_pdf.cpp b/core/generator_pdf/generator_pdf.cpp index 9479a0eb4..72886138b 100644 --- a/core/generator_pdf/generator_pdf.cpp +++ b/core/generator_pdf/generator_pdf.cpp @@ -105,6 +105,11 @@ PDFGenerator::~PDFGenerator() delete globalParams; } +void PDFGenerator::setOrientation(QValueVector & pagesVector, int orientation) +{ + loadPages(pagesVector,orientation,true); +} + //BEGIN Generator inherited functions bool PDFGenerator::loadDocument( const QString & filePath, QValueVector & pagesVector ) { @@ -187,31 +192,40 @@ bool PDFGenerator::loadDocument( const QString & filePath, QValueVectorgetNumPages(); pagesVector.resize( pageCount ); + + loadPages(pagesVector,0); + + // the file has been loaded correctly + return true; +} + +void PDFGenerator::loadPages(QValueVector & 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 diff --git a/core/generator_pdf/generator_pdf.h b/core/generator_pdf/generator_pdf.h index 839c185f6..96cbd9d9f 100644 --- a/core/generator_pdf/generator_pdf.h +++ b/core/generator_pdf/generator_pdf.h @@ -53,7 +53,7 @@ class PDFGenerator : public Generator // [INHERITED] load a document and fill up the pagesVector bool loadDocument( const QString & fileName, QValueVector & pagesVector ); - + void loadPages(QValueVector & 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 & pagesVector, int orientation); + // [INHERITED] print page using an already configured kprinter bool print( KPrinter& printer ); diff --git a/part.cpp b/part.cpp index 7c38b2a60..301ddb1e9 100644 --- a/part.cpp +++ b/part.cpp @@ -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; } diff --git a/part.rc b/part.rc index 842cef87c..c3b642b7b 100644 --- a/part.rc +++ b/part.rc @@ -15,6 +15,7 @@ &View + diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 4c8a44dbc..10da3fbe3 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -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 ); } diff --git a/ui/pageviewutils.cpp b/ui/pageviewutils.cpp index 3e6834bc0..f41a31916 100644 --- a/ui/pageviewutils.cpp +++ b/ui/pageviewutils.cpp @@ -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; diff --git a/ui/pageviewutils.h b/ui/pageviewutils.h index 97e06798b..d32d2a5b9 100644 --- a/ui/pageviewutils.h +++ b/ui/pageviewutils.h @@ -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 ); diff --git a/ui/presentationwidget.cpp b/ui/presentationwidget.cpp index 6c4c06d48..147eb44d8 100644 --- a/ui/presentationwidget.cpp +++ b/ui/presentationwidget.cpp @@ -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(); diff --git a/ui/thumbnaillist.cpp b/ui/thumbnaillist.cpp index 9633b9035..836ea19dd 100644 --- a/ui/thumbnaillist.cpp +++ b/ui/thumbnaillist.cpp @@ -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 ); } }