[elvystrac] r1716 - non functional implementation of pdf-presentations

  • From: elvys@xxxxxxxxxxxxxxxxxxxxxx
  • To: elvystrac@xxxxxxxxxxxxx
  • Date: Fri, 12 Feb 2010 18:15:13 +0100

Author: JirkaH
Date: 2010-02-12 18:15:13 +0100 (Fri, 12 Feb 2010)
New Revision: 1716

Added:
   
branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationdocument.cpp
   
branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationdocument.h
   
branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.cpp
   
branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.h
Modified:
   branches/client/pdf-presentation-branch/elvys-client/src/Makefile
   branches/client/pdf-presentation-branch/elvys-client/src/constants.h
   
branches/client/pdf-presentation-branch/elvys-client/src/documentmaintainer.cpp
   branches/client/pdf-presentation-branch/elvys-client/src/documentmaintainer.h
   branches/client/pdf-presentation-branch/elvys-client/src/pdfzoomed.h
   branches/client/pdf-presentation-branch/elvys-client/src/src.pro
   
branches/client/pdf-presentation-branch/elvys-client/src/xmldocumentparser.cpp
   branches/client/pdf-presentation-branch/elvys-client/src/xmldocumentparser.h
Log:
non functional implementation of pdf-presentations


Modified: branches/client/pdf-presentation-branch/elvys-client/src/Makefile
===================================================================
--- branches/client/pdf-presentation-branch/elvys-client/src/Makefile   
2010-02-12 13:46:03 UTC (rev 1715)
+++ branches/client/pdf-presentation-branch/elvys-client/src/Makefile   
2010-02-12 17:15:13 UTC (rev 1716)
@@ -1,6 +1,6 @@
 #############################################################################
 # Makefile for building: ../bin/elvys-client
-# Generated by qmake (2.01a) (Qt 4.5.3) on: Thu Feb 11 11:03:45 2010
+# Generated by qmake (2.01a) (Qt 4.5.3) on: Fri Feb 12 17:15:34 2010
 # Project:  src.pro
 # Template: app
 # Command: /usr/bin/qmake -spec /usr/share/qt4/mkspecs/linux-g++ -unix 
CONFIG+=debug_and_release -o Makefile src.pro

Modified: branches/client/pdf-presentation-branch/elvys-client/src/constants.h
===================================================================
--- branches/client/pdf-presentation-branch/elvys-client/src/constants.h        
2010-02-12 13:46:03 UTC (rev 1715)
+++ branches/client/pdf-presentation-branch/elvys-client/src/constants.h        
2010-02-12 17:15:13 UTC (rev 1716)
@@ -19,7 +19,7 @@
  * recommended size is as much as you can stand :-)
 */
 
-#define PIXMAP_CACHE_LIMIT (1024*800)
+#define PIXMAP_CACHE_LIMIT (1024*200)
 
 /** scale factor for zooming-in and zooming-out*/
 #define SCALE_FACTOR 1.2L
@@ -30,6 +30,8 @@
 /** What is the minimum font size for category and panel descriptions */
 #define TAB_FONT_SIZE 14
 
+#define KEY_SEPERATOR "."
+
 #define ELVYS_VERSION "1.0-b1"
 
 #endif

Modified: 
branches/client/pdf-presentation-branch/elvys-client/src/documentmaintainer.cpp
===================================================================
--- 
branches/client/pdf-presentation-branch/elvys-client/src/documentmaintainer.cpp 
    2010-02-12 13:46:03 UTC (rev 1715)
+++ 
branches/client/pdf-presentation-branch/elvys-client/src/documentmaintainer.cpp 
    2010-02-12 17:15:13 UTC (rev 1716)
@@ -9,6 +9,7 @@
 #include "statistics.h"
 #include "document.h"
 #include "pdfdocument.h"
+#include "pdfpresentationdocument.h"
 #include "dummydocument.h"
 #include "statictext.h"
 #include "dynamictext.h"
@@ -53,11 +54,17 @@
 
 void DocumentMaintainer::setPages(QString & _toId, QList<int> & _pages, int 
mainPage) {
        //TODO udelat setPages virtualni!!!!
-       PDFDocument * doc = panel->findChild<PDFDocument *>(_toId);
+       /** @todo this is really ugly and should be rewritten using one common 
base to PDFDocuments!
+         */
+
+       PDFDocument * doc = panel->findChild<PDFDocument *>(_toId);     
+       PDFPresentationDocument * doc2 = 
panel->findChild<PDFPresentationDocument *>(_toId);
        if ( doc != NULL) {
                doc->setPages(_pages, mainPage);
+       } else if ( doc2 != NULL) {
+               doc2->setPages(_pages, mainPage);
        } else {
-               qWarning() << "PDF document on position" << _toId << "doesn't 
exist!";
+               qWarning() << "PDF document/presentation on position" << _toId 
<< "doesn't exist!";
        }
 }
 
@@ -81,7 +88,17 @@
        }
 }
 
+void DocumentMaintainer::setPeriod(QString &toId, int period) {
+       PDFPresentationDocument * pdfPres = 
panel->findChild<PDFPresentationDocument *>(toId);
 
+       if ( pdfPres == NULL ) {
+               qWarning() << Q_FUNC_INFO << "PDF Presentation document on 
position" << toId << "doesn't exist!";\
+       } else {
+               pdfPres->setPeriod(period);
+       }
+}
+
+
 void DocumentMaintainer::closeOldDocuments() {
        int id; 
        QString sId;
@@ -157,6 +174,10 @@
        }
 }
 
+void DocumentMaintainer::newPDFPresentation(QString & to_id, QString & docId, 
QString & name) {
+       newDownloadableDocument<PDFPresentationDocument>(to_id, docId, name);
+}
+
 void DocumentMaintainer::newPDFDocument(QString & to_id, QString & docId, 
QString & name) {
        newDownloadableDocument<PDFDocument>(to_id, docId, name);
 }
@@ -167,6 +188,7 @@
 
 void DocumentMaintainer::newDownloadableDocument(QString & to_id, QString & 
docId, QString & name) {
        Document * doc = findChild<Document *>(to_id);
+       PDFPresentationDocument * pdfPresentation;
        PDFDocument * pdfDoc;
        VideoDocument * videoDoc;
 
@@ -174,6 +196,8 @@
                newDownloadableDocument<PDFDocument>(to_id, docId, name);
        } else if ( (videoDoc = qobject_cast<VideoDocument *>(doc)) != 0) {
                newDownloadableDocument<VideoDocument>(to_id, docId, name);
+       } else if ( (pdfPresentation = qobject_cast<PDFPresentationDocument 
*>(doc)) != 0) {
+               newDownloadableDocument<PDFPresentationDocument>(to_id, docId, 
name);
        }
 
 }
@@ -219,13 +243,13 @@
 
 void DocumentMaintainer::connectSignals() {
 
-/* POZOR NA TOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO */
-
        connect((XMLDocumentParser *)parser, SIGNAL(setPages(QString &, 
QList<int> &, int)), this, SLOT(setPages(QString &, QList<int> &, int)));
+       connect((XMLDocumentParser *)parser, SIGNAL(setPeriod(QString &, int)), 
this, SLOT(setPeriod(QString&, int)));
        connect((XMLDocumentParser *)parser, SIGNAL(setStartAt(QString &, 
qint64)), this, SLOT(setStartAt(QString&, qint64)));
        connect((XMLDocumentParser *)parser, SIGNAL(setAutoStart(QString &, 
bool)), this, SLOT(setAutoStart(QString&, bool)));
        connect((XMLDocumentParser *)parser, SIGNAL(noneDocument(QString &)), 
this, SLOT (closeDocument(QString & )));
        connect((XMLDocumentParser *)parser, SIGNAL(newPDFDocument(QString &, 
QString &, QString&)), this, SLOT(newPDFDocument(QString &, QString &, 
QString&)));
+       connect((XMLDocumentParser *)parser, SIGNAL(newPDFPresentation(QString 
&, QString &, QString&)), this, SLOT(newPDFPresentation(QString &, QString &, 
QString&)));
        connect((XMLDocumentParser *)parser, SIGNAL(newVideoDocument(QString &, 
QString &, QString&)), this, SLOT(newVideoDocument(QString &, QString &, 
QString&)));
 
        connect((XMLDocumentParser *)parser, SIGNAL(newStaticText(QString&, 
QString&, QString&, int, QString&, QString &)),
@@ -236,11 +260,13 @@
 
 void DocumentMaintainer::disconnectSignals() {
        disconnect((XMLDocumentParser *)parser, SIGNAL(noneDocument(QString&)), 
this, SLOT (closeDocument(QString& )));
+       disconnect((XMLDocumentParser *)parser, SIGNAL(setPeriod(QString &, 
int)), this, SLOT(setPeriod(QString&, int)));
        disconnect((XMLDocumentParser *)parser, SIGNAL(setStartAt(QString &, 
qint64)), this, SLOT(setStartAt(QString&, qint64)));
        disconnect((XMLDocumentParser *)parser, SIGNAL(setAutoStart(QString &, 
bool)), this, SLOT(setAutoStart(QString&, bool)));
        disconnect((XMLDocumentParser *)parser, SIGNAL(setPages(QString&, 
QList<int> &, int)), this, SLOT(setPages(QString&, QList<int> &, int)));
 
        disconnect((XMLDocumentParser *)parser, SIGNAL(newPDFDocument(QString&, 
QString &, QString&)), this, SLOT(newPDFDocument(QString&, QString &, 
QString&)));
+       disconnect((XMLDocumentParser *)parser, 
SIGNAL(newPDFPresentation(QString &, QString &, QString&)), this, 
SLOT(newPDFPresentation(QString &, QString &, QString&)));
        disconnect((XMLDocumentParser *)parser, SIGNAL(newVideoDocument(QString 
&, QString &, QString&)), this, SLOT(newVideoDocument(QString &, QString &, 
QString&)));
        disconnect((XMLDocumentParser *)parser, SIGNAL(newStaticText(QString&, 
QString&, QString&, int, QString&, QString &)),
                this, SLOT(newStaticText(QString&, QString&, QString&, int, 
QString&, QString &)));

Modified: 
branches/client/pdf-presentation-branch/elvys-client/src/documentmaintainer.h
===================================================================
--- 
branches/client/pdf-presentation-branch/elvys-client/src/documentmaintainer.h   
    2010-02-12 13:46:03 UTC (rev 1715)
+++ 
branches/client/pdf-presentation-branch/elvys-client/src/documentmaintainer.h   
    2010-02-12 17:15:13 UTC (rev 1716)
@@ -27,7 +27,9 @@
                void setPages(QString & toId, QList<int> & _pages, int 
mainPage);
                void setAutoStart(QString & toId, bool autoStart);
                void setStartAt(QString & toId, qint64 startAt);
+               void setPeriod(QString & toId, int period);
                void newPDFDocument(QString &, QString &, QString & );
+               void newPDFPresentation(QString & to_id, QString & docId, 
QString & name);
                void newVideoDocument(QString &, QString &, QString & );
                void newDownloadableDocument(QString &, QString &, QString &);
                void newStaticText(QString &, QString&, QString&, int, 
QString&, QString & );

Added: 
branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationdocument.cpp
===================================================================
--- 
branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationdocument.cpp
                                (rev 0)
+++ 
branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationdocument.cpp
        2010-02-12 17:15:13 UTC (rev 1716)
@@ -0,0 +1,195 @@
+#include "pdfpresentationdocument.h"
+
+#include "appconfig.h"
+#include "pageselector.h"
+#include <XpdfRasterizer.h>
+
+PDFPresentationDocument::PDFPresentationDocument(Document * doc, int _docId) : 
Document(doc) {
+
+       docId = _docId; 
+       qRegisterMetaType<PageSelector>( "PageSelector" );
+
+       pdfFiller = new PDFFiller(doc->width(), doc->height());
+       pdfPresViewer = new PDFPresentationViewer(parentWidget(), 
doc->geometry());
+
+       connect(pdfFiller, SIGNAL(requestPages()), this, SLOT(setPages()));
+       connect(pdfFiller, SIGNAL(zoomedSize(int, int)), pdfPresViewer, 
SLOT(setZoomedSize(int, int)));
+       connect(pdfFiller, SIGNAL(pageLoaded(PageSelector  , PDFPage *)), 
pdfPresViewer, SLOT(pageReady(PageSelector , PDFPage *)));
+
+       connect(pdfPresViewer, SIGNAL(getPage(int, QSize, QString)), pdfFiller, 
SLOT(loadPage(int, QSize, QString)));
+
+       // event oriented connects
+       connect(pdfPresViewer, SIGNAL(zoomEvent()), this, 
SLOT(zoomEventHandler()));
+       connect(pdfPresViewer, SIGNAL(unZoomEvent()), this, 
SLOT(unZoomEventHandler()));
+
+       connect(pdfFiller, SIGNAL(badPDF(QString )), this, 
SLOT(handleBadPDF(QString )));
+
+       //mtx oriented connects
+       connect(pdfFiller, SIGNAL(imageGenerationStarted()), this, 
SLOT(mutexLock()));
+       connect(pdfFiller, SIGNAL(imageGenerationFinished()), this, 
SLOT(mutexUnlock()));
+       connect(pdfFiller, SIGNAL(pagesAboutToDelete()), this, 
SLOT(mutexLock()));
+       connect(pdfFiller, SIGNAL(pagesDeleted()), this, SLOT(mutexUnlock()));
+       connect(pdfPresViewer, SIGNAL(imageGenerationStarted()), this, 
SLOT(mutexLock()));
+       connect(pdfPresViewer, SIGNAL(imageGenerationFinished()), this, 
SLOT(mutexUnlock()));
+}
+
+PDFPresentationDocument::~PDFPresentationDocument() {
+       close();
+
+       delete pdfPresViewer;
+       pdfPresViewer = NULL;
+       delete pdfFiller;
+       pdfFiller = NULL;
+}
+
+int PDFPresentationDocument::period() {
+       return pdfPresViewer->period();
+}
+
+void PDFPresentationDocument::setPeriod(int period) {
+       pdfPresViewer->setPeriod(period);
+}
+
+void PDFPresentationDocument::setPages() {
+       bool retval;
+
+       retval = pdfFiller->setPages(pages, pages.first());
+
+       if ( retval)  { //there was a change in pages list
+               
pdfFiller->updatePageSizes(AppConfig::getInstance()->getZoomWidth(parentWidget()),
 AppConfig::getInstance()->getZoomHeight(parentWidget()));
+       }
+       update();
+}
+
+void PDFPresentationDocument::setPages(QList <int> & _pageNumbers, int 
_mainPage) {
+       Q_UNUSED(_mainPage);
+       bool same = true;
+
+       mtx.lock();
+       if (pages.size() < _pageNumbers.size()) {
+               same = false;
+       } else {
+               for (int i = 0; i < _pageNumbers.size(); ++i) {
+                       if ( pages.at(i)!= _pageNumbers[i]) {
+                               same = false;
+                               qDebug() << "PDFFiller Nestejne cisla stranek";
+                               break;
+                       }
+               }
+       }
+
+       if (same) {
+               mtx.unlock();
+               return;
+       }
+// there were some changes
+       pages.clear();
+       for (int i = 0; i < _pageNumbers.size(); ++i) {
+               pages.insert(i, _pageNumbers[i]);
+       }
+
+
+       mtx.unlock();
+
+       setPages();
+}
+
+void PDFPresentationDocument::reLoad() {
+
+       if (pdfPresViewer->isZoomed()) { // je to zoomnute - musim pockat, az 
se to vrati
+               
QTimer::singleShot(AppConfig::getInstance()->getDocumentPeriod()*100, this, 
SLOT(reLoad()));
+       } else {                
+               pdfFiller->load(_name);
+       }
+}
+
+void PDFPresentationDocument::mutexLock() {
+       if (imgMtx.tryLock() == false) {
+               qWarning() << Q_FUNC_INFO << 
"...........................................POTENTIONAL DEAD LOCK 
PREVENTED!!!!.......................................";
+               imgMtx.lock();
+       }
+}
+
+void PDFPresentationDocument::mutexUnlock() {
+       imgMtx.unlock();
+}
+
+void PDFPresentationDocument::load(QString _name, int _docId) {
+       docId = _docId;
+       load(_name);
+}
+
+void PDFPresentationDocument::load(QString name) {
+
+       if ( _name == name ) { //trying to load same pdf document
+               return;
+       }
+
+       _name = name;
+       if (pdfPresViewer->isZoomed()) { // je to zoomnute - musim pockat, az 
se to vrati
+               
QTimer::singleShot(AppConfig::getInstance()->getDocumentPeriod()*100, this, 
SLOT(reLoad()));
+       } else {                
+               pdfFiller->load(_name);
+               pdfPresViewer->load(_name);
+               if (! pdfFiller->isRunning()) {
+                       pdfFiller->start();
+               }
+       }
+}
+
+bool PDFPresentationDocument::isZoomed() {
+       if ( pdfPresViewer ) {
+               return pdfPresViewer->isZoomed();
+       } else {
+               return false;
+       }
+}
+
+void PDFPresentationDocument::setZoomable(bool _zoomable) {
+       if ( pdfPresViewer ) {
+               pdfPresViewer->setZoomable(_zoomable);
+       }
+}
+
+int PDFPresentationDocument::close() {
+       if ( _name != "" ) {
+               pdfPresViewer->close();
+               pdfFiller->close();
+               _name = "";
+               emit exhibitCompleteEvent(docId, objectName().toInt());
+       }
+
+       return 0;
+}
+
+void PDFPresentationDocument::resizeEvent(QResizeEvent *event) {
+       Q_UNUSED(event);                
+
+       pdfFiller->clear();
+       
pdfFiller->updatePageSizes(AppConfig::getInstance()->getZoomWidth(parentWidget()),AppConfig::getInstance()->getZoomHeight(parentWidget()));
+       pdfPresViewer->setGeometry(geometry());
+}
+
+void PDFPresentationDocument::hideEvent(QHideEvent * event) {
+       Q_UNUSED(event);
+
+       pdfFiller->clearCache();
+}
+
+void PDFPresentationDocument::zoomEventHandler() {
+       emit zoomEvent(docId, objectName().toInt());
+}
+
+void PDFPresentationDocument::unZoomEventHandler() {
+       emit unZoomEvent(docId, objectName().toInt());
+}
+
+void PDFPresentationDocument::handleBadPDF(QString filename) {
+       Q_UNUSED(filename);
+       close();
+}
+
+
+QString PDFPresentationDocument::getFileName() {
+       return getName();
+}

Added: 
branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationdocument.h
===================================================================
--- 
branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationdocument.h
                          (rev 0)
+++ 
branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationdocument.h
  2010-02-12 17:15:13 UTC (rev 1716)
@@ -0,0 +1,57 @@
+#ifndef PDFPRESENTATIONDOCUMENT_H
+#define PDFPRESENTATIONDOCUMENT_H
+
+#include "document.h"
+#include "pdfpresentationviewer.h"
+#include "pdffiller.h"
+#include "pdfpage.h"
+
+class PDFPresentationDocument : public Document {
+       Q_OBJECT
+
+       signals:
+               void exhibitCompleteEvent(int documentId, int layoutPosition);
+
+       public slots:
+               virtual void load(QString name);
+               void load(QString _name, int _docId);
+               void reLoad();
+               void zoomEventHandler();
+               void unZoomEventHandler();
+               void handleBadPDF(QString );
+               void mutexLock();
+               void mutexUnlock();
+               virtual int close();
+               void setPages();
+               void setPages(QList <int>  & _pageNumbers, int mainPage);
+
+       signals:
+               void zoomEvent(int documentId, int layoutPos);
+               void unZoomEvent(int documentId, int layoutPos);
+
+       public:
+               /// @todo delete this constructor
+               PDFPresentationDocument(QWidget * parent, int _x, int _y, int 
_w, int _h);
+               PDFPresentationDocument(Document * doc, int docId);
+               virtual ~PDFPresentationDocument();
+               virtual bool isZoomed();
+               virtual void setZoomable(bool _zoomable);
+               virtual QString getFileName();
+               void setPeriod(int period);
+               int period();
+
+       protected:
+               virtual void resizeEvent(QResizeEvent * event);
+               virtual void hideEvent(QHideEvent *event);
+
+       private:
+               PDFPresentationViewer * pdfPresViewer;
+               PDFFiller * pdfFiller;          
+
+               QList<int> pages;               
+               int docId;
+               QMutex imgMtx;
+               QMutex mtx;
+};
+
+#endif // PDFPRESENTATIONDOCUMENT_H

Added: 
branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.cpp
===================================================================
--- 
branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.cpp
                          (rev 0)
+++ 
branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.cpp
  2010-02-12 17:15:13 UTC (rev 1716)
@@ -0,0 +1,535 @@
+#include <QImage>
+#include <QtGlobal>
+#include <QTest>
+#include <QLabel>
+#include <QPixmap>
+#include <QPainter>
+#include <QPen>
+#include <QFrame>
+#include <QLayout>
+#include <QFont>
+#include <QScrollArea>
+#include <QStylePainter>
+#include <QKeyEvent>
+#include <QScrollBar>
+#include <QPaintEngine>
+
+#include <math.h>
+
+#include "pdfpresentationviewer.h"
+#include "appconfig.h"
+#include "constants.h"
+
+
+PDFPresentationViewer::PDFPresentationViewer(QWidget * parent, const QRect & 
rect) : QLabel (parent) {
+       origSize = rect;
+       currentPage = 0;
+       _period = 20;
+       inPageTransition = false;
+
+       zoomed = false;
+       zoomable = true;
+       toBeZoomed = false;
+
+       alfa = 1;
+       timeOpened = 0; 
+       setGeometry(origSize);
+       setParent(parent);
+       pageKeyBase = "PDF_PRESENTATION_VIEWER";
+       pageKeyCur = "CUR";
+       pageKeyPrev = "PREV";
+       pageKeyNext = "NEXT";
+
+       setSizePolicy(QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored));
+       setFocusPolicy(Qt::StrongFocus);
+
+       connect(&closeWatcher, SIGNAL(timeout()), this, 
SLOT(closeEnlargement()));
+       connect(&fadeEffect, SIGNAL(timeout()), this, SLOT(doFadeEffect()));
+
+       setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
+       setAlignment(Qt::AlignCenter);
+
+       if ( hasFocus() ) {
+               setPalette(AppConfig::getInstance()->getPaletteFocused());
+       }
+       setVisible(true);
+}
+
+void PDFPresentationViewer::setKeyBase(QString keyBase) {
+       pageKeyBase = keyBase;
+}
+
+QString PDFPresentationViewer::getPageKey(const QSize & size, const QString & 
identifier) {
+       return pageKeyBase + identifier + QString::number(size.width()) + 
KEY_SEPERATOR + QString::number(size.height());
+}
+
+
+/** Request of rendering current page of the document. This page will be 
displayed once rendered.
+  */
+
+void PDFPresentationViewer::getCurrentPage() {
+       emit getPage(currentPage, size(), getPageKey(size(), pageKeyCur));
+}
+
+/** Request the next page of the PDF. This page will NOT be displayed once 
rendered, it will just be cached and ready.
+  If the current page is the last one allowed, it does nothing.
+  */
+
+void PDFPresentationViewer::getNextPage() {
+       if (currentPage != pages.size() -1) { //we are still not at the end
+               emit getPage(currentPage +1, size(), getPageKey(size(), 
pageKeyNext));
+       }
+}
+
+/** Request the next page of the PDF. This page will NOT be displayed once 
rendered, it will just be cached and ready.
+  If the current page is the first one allowed, it does nothing.
+  */
+
+void PDFPresentationViewer::getPreviousPage() {
+       if ( currentPage != 0 ) { // we are not on the first page
+               emit getPage(currentPage -1, size(), getPageKey(size(), 
pageKeyPrev));
+       }
+}
+
+/** Loads and displays previous page. If the current page is the last page of 
the document, it does nothing.
+  */
+
+void PDFPresentationViewer::previousPage() {   
+
+       if (pages.size() == 0) {
+               return;
+       }
+       if (currentPage == 0) { //we are already on the first page
+               return;
+       } else {
+               currentPage -= 1;
+               nextPixmap = currentPixmap;
+               currentPixmap = previousPixmap;         
+               getPreviousPage();
+               showPDF();
+       }
+}
+
+/** Loads and displays next page. If the current page is the last page of the 
document, it does nothing.
+  */
+
+void PDFPresentationViewer::nextPage() {
+       if (pages.size() == 0) {
+               return;
+       }
+       if (currentPage == pages.size() -1) {
+               return;
+       } else {
+               currentPage += 1;
+               previousPixmap = currentPixmap;
+               currentPixmap = nextPixmap;
+               getNextPage();
+               showPDF();
+       }
+}
+
+void PDFPresentationViewer::pageReady(PageSelector selector, PDFPage * page) {
+       QPixmap myPixmap;
+
+       if ( ! selector.desc.contains(pageKeyBase)) { //this page was not 
requested by us
+               return;
+       }
+
+       qDebug() << Q_FUNC_INFO << selector.desc << selector.desSize << 
selector.pageNum;
+
+       emit imageGenerationStarted();
+       myPixmap = QPixmap::fromImage(*page->getImage()); ///< @todo better 
observe this place, as it may fail here
+       emit imageGenerationFinished();
+
+       if (selector.desc.contains(pageKeyCur)) {
+               QPixmapCache::insert(getPageKey(myPixmap.size(), pageKeyCur), 
myPixmap);
+               currentPixmap = myPixmap;
+               update();
+       } else if (selector.desc.contains(pageKeyNext)) {
+               QPixmapCache::insert(getPageKey(myPixmap.size(), pageKeyNext), 
myPixmap);
+               nextPixmap = myPixmap;
+
+       } else if (selector.desc.contains(pageKeyPrev)) {
+               QPixmapCache::insert(getPageKey(myPixmap.size(), pageKeyPrev), 
myPixmap);
+               previousPixmap = myPixmap;
+
+       }
+}
+
+void PDFPresentationViewer::setZoomedSize(int width, int height) {
+       zoomW = width;
+       zoomH = height;
+}
+
+/**
+  If not zoomed, it sets currentPage to zero and redisplay it. If zoomed, this 
a timer is started to ensure this action will take place
+  as soon as possible.
+  */
+
+void PDFPresentationViewer::reloadPages() {
+       if (zoomed) {
+               QTimer::singleShot(1000, this, SLOT(reloadPages()));            
+       } else {
+               currentPage = 0;
+               getCurrentPage();
+               getNextPage();
+       }
+}
+
+
+/** Sets list of pages to display.
+  * @param _pageNumbers list of pages
+   */
+
+void PDFPresentationViewer::setPages(QList<int> & _pageNumbers) {
+       bool same = true;
+       Page page;
+
+       // do we have the same list, so no change is needed?
+       if (pages.size() < _pageNumbers.size()) {
+               same = false;
+       } else {
+               for (int i = 0; i < _pageNumbers.size(); ++i) {
+                       if ( pages.at(i).num != _pageNumbers[i]) {
+                               same = false;                           
+                               break;
+                       }
+               }
+       }
+
+       if (same) {
+               return;
+       }
+
+       pages.clear();
+
+       page.h = 0;
+       page.w = 0;
+
+       for (int i = 0; i < _pageNumbers.size(); ++i) {
+               page.num = _pageNumbers[i];
+               pages.insert(i,page);
+       }
+
+       //we might be displaying something different now
+       reloadPages();  
+}
+
+
+QRect PDFPresentationViewer::getZoomedGeometry() {
+       int newX;
+       int newY;
+       int overlap = 0;
+       QWidget * parW = parentWidget();
+       QScrollArea area;
+
+       // get offsets when scroll bars are not visible
+       area.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+       area.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+       int scrollAreaOffsetInvisibleWidth = area.geometry().width() - 
area.maximumViewportSize().width();
+       int scrollAreaOffsetInvisibleHeight = area.geometry().height() - 
area.maximumViewportSize().height();
+
+       area.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+       area.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+       int scrollAreaOffsetVisibleWidth = area.geometry().width() - 
area.maximumViewportSize().width();
+       int scrollAreaOffsetVisibleHeight = area.geometry().height() - 
area.maximumViewportSize().height();
+
+       int scrollAreaOffsetHeight = scrollAreaOffsetInvisibleHeight;
+       int scrollAreaOffsetWidth = scrollAreaOffsetInvisibleWidth;
+
+       if (zoomW + scrollAreaOffsetInvisibleWidth >  
AppConfig::getInstance()->getZoomWidth(parW)) { //there will be horizontal 
scrollbar for sure
+               scrollAreaOffsetHeight = scrollAreaOffsetVisibleHeight;
+               if (zoomH + scrollAreaOffsetVisibleHeight > 
AppConfig::getInstance()->getZoomHeight(parW)) { //there will be vertical 
scrollbar for sure
+                       scrollAreaOffsetWidth = scrollAreaOffsetVisibleWidth;
+               }
+       } else { //maybe there will not be horizontal scrollbar - but it 
depends on presentance of vertical scrollbar too
+               if (zoomH + scrollAreaOffsetInvisibleHeight > 
AppConfig::getInstance()->getZoomHeight(parW)) { //there will be vertical 
scrollbar
+                       scrollAreaOffsetWidth = scrollAreaOffsetVisibleWidth;
+                       if (zoomW + scrollAreaOffsetVisibleWidth >  
AppConfig::getInstance()->getZoomWidth(parW)) { //there will be horizontal 
scrollbar for sure
+                               scrollAreaOffsetHeight = 
scrollAreaOffsetVisibleHeight;
+                       }
+               }
+       }
+
+       int centerX = origSize.x() + origSize.width() / 2; ///< center of my 
widget
+       int zoomWHalf = zoomW / 2; ///< half width of zoomed image
+
+       if ( (overlap = (centerX + zoomWHalf + scrollAreaOffsetWidth) - 
parW->width()) > 0 ) { // it wouldnt fit the screen! Move left
+               //we know that center needs to be in centerX - overlap
+               //so new docX can be counted from it
+               newX = (centerX - overlap) - zoomWHalf;
+       } else if ( (overlap = (centerX - zoomWHalf)) < 0 ) { //we are of the 
screen
+               newX = 0;
+       } else { //center it
+               newX = centerX - zoomWHalf;
+       }
+
+       if ( (origSize.y() + AppConfig::getInstance()->getZoomHeight(parW)) + 
scrollAreaOffsetHeight > parW->height() ) {
+               newY = 0;
+       } else {
+               newY = origSize.y();
+       }
+
+       if (zoomH + scrollAreaOffsetHeight < 
AppConfig::getInstance()->getZoomHeight(parW) ) {
+               return QRect(newX, newY, zoomW + scrollAreaOffsetWidth, zoomH + 
scrollAreaOffsetHeight);
+       } else {
+               return QRect(newX, newY, zoomW + scrollAreaOffsetWidth, 
AppConfig::getInstance()->getZoomHeight(parW));
+       }
+}
+
+void getPreviousPage() {
+}
+
+void getNextPage() {
+}
+
+
+/** Shows zoomed or normal-sized pdf document. This function sets right 
geometry of windows and also sets image to QLabel. Zoomed image is
+  * positioned at the center of widget area, if possible (fits the window), 
otherwise it is moved to the left as needed. Actual
+  * drawing is done in paintEvent.
+  */
+
+void PDFPresentationViewer::showPDF() {
+       QRect rect;
+
+       setPixmap(currentPixmap);
+       alfa = 1;
+
+       // TOTO JE 
SPATNEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
+       // TOTO JE 
SPATNEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
+       // TOTO JE 
SPATNEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
+       // TOTO JE 
SPATNEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
+       move(origSize.center() - currentPixmap.rect().center());
+       setGeometry(x(), y(),currentPixmap.width(), currentPixmap.height());
+
+       update();
+}
+
+void PDFPresentationViewer::keyPressEvent ( QKeyEvent * event ) {
+
+       if ( ! zoomed ) {
+               if ( event->key() == Qt::Key_Return) {                  
+                       zoom();
+               } else {
+                       event->ignore(); // required step, so we can navigate 
in whole kiosk
+               }
+               return;
+       }
+       // zoomed
+       timeOpened = 0; 
+
+       switch (event->key()) {
+               case Qt::Key_Down:              
+                       previousPage();
+                       break;
+               case Qt::Key_Up:
+                       nextPage();
+                       break;
+               case Qt::Key_Left:
+                       previousPage();
+                       break;
+               case Qt::Key_PageUp:
+                       nextPage();
+                       break;
+               case Qt::Key_Right:
+                       nextPage();
+                       break;
+               case Qt::Key_PageDown:
+                       previousPage();
+                       break;
+               case Qt::Key_Return:
+                       zoom();
+                       break;
+               case Qt::Key_Backspace:
+                       unzoom();
+                       break;
+               default:
+                       if (!zoomed) { // do not propagate key events if we are 
zoomed
+                               event->ignore();
+                       }
+       }
+}
+
+void PDFPresentationViewer::unzoom() {
+       if ( zoomed ) {
+               emit unZoomEvent();
+               closeWatcher.stop();
+               timeOpened = 0;
+               zoomed = false;
+               setGeometry(origSize);
+               getCurrentPage();
+               showPDF();
+               setBorderFocused();
+       }
+}
+
+void PDFPresentationViewer::zoom() {
+       if ( ! zoomed ) {
+               if ( ! zoomable ) {
+                       qDebug() << "Nemuzu zvetsovat, nejsem ve stavu 
zoomable" ;
+                       return;
+               }
+               emit zoomEvent();
+               closeWatcher.start(1000);
+               toBeZoomed = true;
+               setGeometry(getZoomedGeometry());
+               getCurrentPage();
+               showPDF();
+       }
+}
+
+
+void PDFPresentationViewer::mousePressEvent ( QMouseEvent * event ) {
+       if (event->button() == Qt::LeftButton) {
+               zoom();
+       } else if ( event->button() == Qt::RightButton) {
+               unzoom();
+       }
+}
+
+void PDFPresentationViewer::setBorder(bool focused) {
+       if (focused) {
+               setFrameStyle(QFrame::Box | QFrame::Raised);
+               setLineWidth(3);
+               setMidLineWidth(3);
+               setPalette( AppConfig::getInstance()->getPaletteFocused() );
+       } else {
+               setLineWidth(1);
+               setMidLineWidth(1);
+               setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
+               setPalette( AppConfig::getInstance()->getPaletteNotFocused());
+       }
+}
+
+void PDFPresentationViewer::setBorderFocused() {
+       setBorder(hasFocus());
+}
+
+void PDFPresentationViewer::resizeEvent(QResizeEvent * event) {
+       Q_UNUSED(event);
+
+       if (! zoomed ) { // I might get called in zoomed state
+               origSize = geometry();
+       }
+
+       update();
+}
+
+
+void PDFPresentationViewer::focusInEvent( QFocusEvent * event ) {
+       Q_UNUSED(event);
+
+       if ( zoomed ) { //nechceme nastavovat ramecek
+               return;
+       }
+       setBorderFocused();
+}
+
+void PDFPresentationViewer::focusOutEvent( QFocusEvent * event ) {
+       Q_UNUSED(event);
+
+       setBorderFocused();
+       if ( zoomed ) {
+               setFocus();
+       }
+}
+
+PDFPresentationViewer::~PDFPresentationViewer() {              
+       closeWatcher.stop();
+}
+
+
+
+void PDFPresentationViewer::doFadeEffect() {
+       alfa += 15;
+       update();
+}
+
+void PDFPresentationViewer::closeEnlargement() {
+       if ( timeOpened >= AppConfig::getInstance()->getDocumentTimeOut() ) {
+               unzoom();
+       } else {
+               timeOpened++;
+       }
+}
+
+/** Enables or disables zooming
+  @arg _zoomable true if zooming should be enabled, false otherwise
+  */
+
+void PDFPresentationViewer::setZoomable(bool _zoomable) {
+       zoomable = _zoomable;
+}
+
+/** Returns true if widget is zoomed, false otherwise;
+  @return returns true if widget is zoomed, false otherwise;
+  */
+
+bool PDFPresentationViewer::isZoomed() {
+       return zoomed;
+}
+
+void PDFPresentationViewer::stopFadeEffect() {
+       if (fadeEffect.isActive()) {
+               fadeEffect.stop();
+               setGeometry(myGeometry); //restore geometry of small first page
+       }
+       if (scroll) {
+               scroll->raise();
+       }
+}
+
+void PDFPresentationViewer::paintEvent(QPaintEvent * event) {
+       Q_UNUSED(event);
+
+       if (inPageTransition) {
+               QPainter p(&pixmapOpac);
+               QPainter painter(this);
+
+               p.drawPixmap((zoomW - pageW)/2, 0, currentPixmap);
+
+               p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
+
+               p.fillRect(pixmapOpac.rect(), QColor(0, 0, 0, alfa));
+               p.end();
+               painter.drawPixmap(0,0,pixmapOpac);
+               painter.end();
+       } else {
+               if ( QPixmapCache::find(getPageKey(size(), pageKeyBase)) == 
false) {
+                       getCurrentPage();
+                       return;
+               }
+       }
+}
+
+void PDFPresentationViewer::setPeriod(int period) {
+       _period = period;
+}
+
+int PDFPresentationViewer::period() {
+       return _period;
+}
+
+void PDFPresentationViewer::close() {
+       zoomable = false;
+       update();
+       setPixmap(NULL);
+       setFocusPolicy(Qt::NoFocus);
+       clearFocus();
+}
+
+void PDFPresentationViewer::load(QString & filename) {
+       Q_UNUSED(filename);
+
+       zoomable = true;
+
+       setFocusPolicy(Qt::StrongFocus);
+       if ( QApplication::focusWidget() == NULL ) {
+               setFocus();
+       } else {
+               if ( qobject_cast<Document *>(QApplication::focusWidget()) == 
NULL ) { //no document has focus
+                       setFocus();
+               }
+       }
+       update();
+}

Added: 
branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.h
===================================================================
--- 
branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.h
                            (rev 0)
+++ 
branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.h
    2010-02-12 17:15:13 UTC (rev 1716)
@@ -0,0 +1,114 @@
+#ifndef PDFPRESENTATIONVIEWER_H
+#define PDFPRESENTATIONVIEWER_H
+
+#include <QImage>
+#include <QLabel>
+#include <QScrollArea>
+#include <QWidget>
+#include <QPixmapCache>
+#include <QTimer>
+#include <QList>
+#include <QRect>
+
+#include "document.h"
+#include "pageselector.h"
+#include "pdfpage.h"
+#include "page.h"
+
+
+#include <XpdfRasterizer.h>
+
+/** Trida zodpovedna za spravne zobrazeni pdfdokumentu.....
+ */      
+class PDFPresentationViewer : public QLabel {
+       Q_OBJECT
+
+       signals:
+               void getPage(int pageNum, QSize size, QString desc);            
        
+               void imageGenerationStarted();
+               void imageGenerationFinished();
+               void unZoomEvent();
+               void zoomEvent();
+
+       public slots:
+               void pageReady(PageSelector selector, PDFPage * page);
+               void setZoomedSize(int, int);
+               void setKeyBase(QString keyBase);
+               void nextPage();
+               void previousPage();
+
+       private slots:
+               void doFadeEffect();
+               void closeEnlargement();
+               void reloadPages();
+
+       public:
+               PDFPresentationViewer(QWidget * parent, const QRect & rect);
+               virtual ~PDFPresentationViewer();
+               bool isZoomed();
+               void setZoomable(bool _zoomable);
+               void close();
+               void load(QString & filename);
+               void setPeriod(int period);
+               int period();
+               void setPages(QList <int> & _pageNumbers);
+
+
+       protected:
+               void mousePressEvent( QMouseEvent * event );
+               void keyPressEvent( QKeyEvent * event );
+               void paintEvent(QPaintEvent * event);
+               void resizeEvent(QResizeEvent * event);
+               virtual void focusInEvent ( QFocusEvent * event );
+               virtual void focusOutEvent ( QFocusEvent * event );
+
+       private:
+               void getNextPage();
+               void getPreviousPage();
+               void getCurrentPage();
+               void stopFadeEffect();
+               QRect getZoomedGeometry();
+               QString getPageKey(const QSize & size, const QString & 
identifier = "");
+               void zoom();
+               void unzoom();
+               void showPDF();
+               void setBorderFocused();
+               void setBorder(bool focused);           
+
+               QRect origSize;
+               QRect myGeometry;
+               QString pageKeyBase;
+               QString pageKeyCur;
+               QString pageKeyNext;
+               QString pageKeyPrev;
+
+               int currentPage;
+               int _period;
+               bool inPageTransition;
+
+               int zoomW; //maximalni sirka
+               int zoomH; //celkova delka
+
+               int pageW; //velikost prvni zvetsene stranky
+               int pageH;
+
+               int timeOpened;
+
+               bool toBeZoomed;
+               bool zoomable; // pokud uz je nactena aspon first page big 
stranka a nejakej ten buffer
+               bool zoomed;
+
+               QVector<Page> pages;
+               int alfa;
+
+               QPixmap pixmapOpac;
+               QScrollArea * scroll;
+
+               QPixmap currentPixmap;
+               QPixmap previousPixmap;
+               QPixmap nextPixmap;
+               QTimer fadeEffect;
+               QTimer closeWatcher;
+};
+
+#endif // PDFPRESENTATIONVIEWER_H

Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdfzoomed.h
===================================================================
--- branches/client/pdf-presentation-branch/elvys-client/src/pdfzoomed.h        
2010-02-12 13:46:03 UTC (rev 1715)
+++ branches/client/pdf-presentation-branch/elvys-client/src/pdfzoomed.h        
2010-02-12 17:15:13 UTC (rev 1716)
@@ -17,8 +17,6 @@
 #include "page.h"
 #include "pageselector.h"
 
-#define KEY_SEPERATOR "."
-
 class PDFZoomed : public QWidget {
        Q_OBJECT
 

Modified: branches/client/pdf-presentation-branch/elvys-client/src/src.pro
===================================================================
--- branches/client/pdf-presentation-branch/elvys-client/src/src.pro    
2010-02-12 13:46:03 UTC (rev 1715)
+++ branches/client/pdf-presentation-branch/elvys-client/src/src.pro    
2010-02-12 17:15:13 UTC (rev 1716)
@@ -46,7 +46,9 @@
     autodeleter.cpp \
     xmlfilecacheparser.cpp \
     filecachemaintainer.cpp \
-    logotabbar.cpp
+    logotabbar.cpp \
+    pdfpresentationdocument.cpp \
+    pdfpresentationviewer.cpp
 HEADERS += elvys.h \
     pdfdocument.h \
     pdffiller.h \
@@ -95,7 +97,9 @@
     autodeleter.h \
     xmlfilecacheparser.h \
     filecachemaintainer.h \
-    logotabbar.h
+    logotabbar.h \
+    pdfpresentationdocument.h \
+    pdfpresentationviewer.h
 TEMPLATE = app
 CONFIG += warn_on \
     thread \

Modified: 
branches/client/pdf-presentation-branch/elvys-client/src/xmldocumentparser.cpp
===================================================================
--- 
branches/client/pdf-presentation-branch/elvys-client/src/xmldocumentparser.cpp  
    2010-02-12 13:46:03 UTC (rev 1715)
+++ 
branches/client/pdf-presentation-branch/elvys-client/src/xmldocumentparser.cpp  
    2010-02-12 17:15:13 UTC (rev 1716)
@@ -68,6 +68,8 @@
                if (isStartElement()) {
                        if (name() == "pdf_doc") {
                                readPDFDocument();
+                       } else if (name() == "pdf_presentation") {
+                               readPDFPresentation();
                        } else if (name() == "html_doc") {
                                readHTMLDocument();
                        } else if (name() == "static_text") {
@@ -188,6 +190,64 @@
        return true;
 }
 
+
+bool XMLDocumentParser::readPDFPresentation() {
+       QString filename;
+       QString docId;
+       int period = 0;
+       Q_ASSERT(isStartElement() && name() == "pdf_presentation");
+
+       toId = attributes().value("to_id").toString();
+       qDebug() << "ID PDF presentation is " << toId ;
+
+       while (!atEnd()) {
+               readNext();
+
+               if (isEndElement()) {
+                       break;
+               }
+
+               if (isStartElement()) {
+                       if (name() == "id") {
+                               docId = readElementText();
+                               if ( docId != "" && filename != "") {
+                                       emit newPDFPresentation(toId, docId, 
filename);
+                               }
+                               readNext();
+                       } else if (name() == "name") {
+                               filename = readElementText();
+                               if ( docId != "" && filename != "") {
+                                       emit newPDFPresentation(toId, docId, 
filename);
+                               }
+                               readNext(); //end element
+                       } else if (name() == "pages") {
+                               readPages();
+                       } else if (name() == "period") {
+                               period = readPeriod();
+                               if ( docId != "" && filename != "") {
+                                       emit newPDFPresentation(toId, docId, 
filename);
+                               }
+                               emit setPeriod(toId, period);
+                       } else if (name() == "orig-name") {
+                         //ignore it now
+                               readElementText();
+                               readNext(); // end element
+                       } else {
+                               qDebug() << Q_FUNC_INFO << "NOT IMPLEMENTED???" 
<< name().toString();
+                               return false;
+                       }
+               }
+       }
+       return true;
+}
+
+int XMLDocumentParser::readPeriod() {
+       Q_ASSERT(isStartElement() && name() == "period");
+
+       return readElementText().toInt();
+       readNext(); //end element
+}
+
 bool XMLDocumentParser::readHTMLDocument() {
        skipElement();
        //skipCurrentElement();

Modified: 
branches/client/pdf-presentation-branch/elvys-client/src/xmldocumentparser.h
===================================================================
--- 
branches/client/pdf-presentation-branch/elvys-client/src/xmldocumentparser.h    
    2010-02-12 13:46:03 UTC (rev 1715)
+++ 
branches/client/pdf-presentation-branch/elvys-client/src/xmldocumentparser.h    
    2010-02-12 17:15:13 UTC (rev 1716)
@@ -15,6 +15,8 @@
        signals:
                void setPages(QString & toId, QList<int> & _pages, int 
mainPage);
                void newPDFDocument(QString & toId, QString & docId, QString & 
_name);
+               void newPDFPresentation(QString & toId, QString & docId, 
QString & _name);
+               void setPeriod(QString & toId, int period);
                void setAutoStart(QString & toId, bool autoStart);
                void setStartAt(QString & toId, qint64 startAt);
                void newVideoDocument(QString & toId, QString & docId, QString 
& _name);
@@ -33,11 +35,13 @@
                bool readDocument();
                QString readName();
                bool readPDFDocument();
+               bool readPDFPresentation();
                bool readHTMLDocument();
                bool readStaticText();
                bool readVideo();
                bool readDynamicText();
                bool readPages();
+               int readPeriod();
 
                QList<int> readPage();
 


Other related posts:

  • » [elvystrac] r1716 - non functional implementation of pdf-presentations - elvys