Author: JirkaH Date: 2010-02-13 23:19:20 +0100 (Sat, 13 Feb 2010) New Revision: 1718 Modified: branches/client/pdf-presentation-branch/elvys-client/src/Makefile branches/client/pdf-presentation-branch/elvys-client/src/main.cpp branches/client/pdf-presentation-branch/elvys-client/src/pdfdocument.cpp branches/client/pdf-presentation-branch/elvys-client/src/pdffiller.cpp branches/client/pdf-presentation-branch/elvys-client/src/pdffiller.h branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationdocument.cpp branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.cpp branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.h branches/client/pdf-presentation-branch/elvys-client/src/pdfviewer.cpp Log: pdf-presentations - almost there Modified: branches/client/pdf-presentation-branch/elvys-client/src/Makefile =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/Makefile 2010-02-13 08:47:08 UTC (rev 1717) +++ branches/client/pdf-presentation-branch/elvys-client/src/Makefile 2010-02-13 22:19:20 UTC (rev 1718) @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: ../bin/elvys-client -# Generated by qmake (2.01a) (Qt 4.5.3) on: Fri Feb 12 17:15:34 2010 +# Generated by qmake (2.01a) (Qt 4.5.3) on: Sat Feb 13 22:02:48 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/main.cpp =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/main.cpp 2010-02-13 08:47:08 UTC (rev 1717) +++ branches/client/pdf-presentation-branch/elvys-client/src/main.cpp 2010-02-13 22:19:20 UTC (rev 1718) @@ -77,7 +77,7 @@ // saver->setWidget(&elvys); elvys.showFullScreen(); - //elvys.show(); +// elvys.show(); return app.exec(); // QObject::connect(&timer, SIGNAL(timeout()), saver, SLOT(render())); Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdfdocument.cpp =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/pdfdocument.cpp 2010-02-13 08:47:08 UTC (rev 1717) +++ branches/client/pdf-presentation-branch/elvys-client/src/pdfdocument.cpp 2010-02-13 22:19:20 UTC (rev 1718) @@ -86,7 +86,7 @@ if ( retval) { - pdfFiller->updatePageSizes(AppConfig::getInstance()->getZoomWidth(parentWidget()), AppConfig::getInstance()->getZoomHeight(parentWidget())); + pdfFiller->updatePageSizes(width(), height(), AppConfig::getInstance()->getZoomWidth(parentWidget()), AppConfig::getInstance()->getZoomHeight(parentWidget())); } update(); } @@ -200,7 +200,7 @@ int offset = 2 * area.frameWidth(); pdfFiller->clear(); - pdfFiller->updatePageSizes(AppConfig::getInstance()->getZoomWidth(parentWidget()),AppConfig::getInstance()->getZoomHeight(parentWidget()) -offset); + pdfFiller->updatePageSizes(width(), height(), AppConfig::getInstance()->getZoomWidth(parentWidget()),AppConfig::getInstance()->getZoomHeight(parentWidget()) -offset); pdfViewer->setGeometry(geometry()); } Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdffiller.cpp =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/pdffiller.cpp 2010-02-13 08:47:08 UTC (rev 1717) +++ branches/client/pdf-presentation-branch/elvys-client/src/pdffiller.cpp 2010-02-13 22:19:20 UTC (rev 1718) @@ -484,11 +484,14 @@ /** Computes normalized (keep aspect ratio, but stretch as much as possible) page dimension for all * pages in document */ -void PDFFiller::updatePageSizes(int zoomW, int zoomH) { - int sumHeight = 0; +void PDFFiller::updatePageSizes(int w, int h, int zoomedW, int zoomedH) { + int sumZoomedHeight = 0; int maxWidth = 0; - int docW; - int docH; + int maxHeight = 0; + int maxZoomedWidth = 0; + int maxZoomedHeight = 0; + int docZoomedW, docW; + int docZoomedH, docH; double docW72, docH72; double dpi; @@ -503,17 +506,29 @@ for (int i = 0; i < pages.size(); ++i) { docW72 = pdfGetPageWidth(pdf, pages[i]); docH72 = pdfGetPageHeight(pdf, pages[i]); - normalizeDimensions(docW72, docH72, zoomW, zoomH, docW, docH, dpi); - sumHeight += docH; + normalizeDimensions(docW72, docH72, zoomedW, zoomedH, docZoomedW, docZoomedH, dpi); + normalizeDimensions(docW72, docH72, w, h, docW, docH, dpi); + sumZoomedHeight += docZoomedH; + if (docZoomedW > maxZoomedWidth) { + maxZoomedWidth = docZoomedW; + } if (docW > maxWidth) { maxWidth = docW; } + if (docZoomedH > maxZoomedHeight) { + maxZoomedHeight = docZoomedH; + } + if (docH > maxHeight) { + maxHeight = docH; + } //qDebug() << "Page dimension " << i << docW << docH; - emit pageDimension(i, docW, docH); + emit pageDimension(i, docZoomedW, docZoomedH); } mutexPDF.unlock(); - emit zoomedSize(maxWidth, sumHeight + SEP_HEIGHT*(pages.size()-1)); + emit zoomedSize(maxZoomedWidth, sumZoomedHeight + SEP_HEIGHT*(pages.size()-1)); + emit zoomedSizeRect(maxZoomedWidth, maxZoomedHeight); + emit sizeRect(maxWidth, maxHeight); } Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdffiller.h =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/pdffiller.h 2010-02-13 08:47:08 UTC (rev 1717) +++ branches/client/pdf-presentation-branch/elvys-client/src/pdffiller.h 2010-02-13 22:19:20 UTC (rev 1718) @@ -44,6 +44,8 @@ void pageLoaded(PageSelector selector, PDFPage * page); void zoomedSize(int width, int height); void zoomedSizeFirstPage(int width, int height); + void zoomedSizeRect(int width, int height); + void sizeRect(int maxWidth, int maxHeight); void pageDimension(int page, int docW, int docH); void init(); void imageGenerationStarted(); @@ -63,7 +65,7 @@ ~PDFFiller(); void load(QString name); bool setPages(QList <int> & _pages, int _mainPage); - void updatePageSizes(int zoomW, int zoomH); + void updatePageSizes(int w, int h, int zoomedW, int zoomedH); bool makeInit(); void clear(); void close(); Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationdocument.cpp =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationdocument.cpp 2010-02-13 08:47:08 UTC (rev 1717) +++ branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationdocument.cpp 2010-02-13 22:19:20 UTC (rev 1718) @@ -13,7 +13,8 @@ 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(zoomedSizeRect(int, int)), pdfPresViewer, SLOT(setZoomedSize(int, int))); + connect(pdfFiller, SIGNAL(sizeRect(int,int)), pdfPresViewer, SLOT(setSizeRect(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))); @@ -54,9 +55,9 @@ bool retval; retval = pdfFiller->setPages(pages, pages.first()); - + pdfPresViewer->setPages(pages); if ( retval) { //there was a change in pages list - pdfFiller->updatePageSizes(AppConfig::getInstance()->getZoomWidth(parentWidget()), AppConfig::getInstance()->getZoomHeight(parentWidget())); + pdfFiller->updatePageSizes(width(), height(), AppConfig::getInstance()->getZoomWidth(parentWidget()), AppConfig::getInstance()->getZoomHeight(parentWidget())); } update(); } @@ -166,7 +167,7 @@ Q_UNUSED(event); pdfFiller->clear(); - pdfFiller->updatePageSizes(AppConfig::getInstance()->getZoomWidth(parentWidget()),AppConfig::getInstance()->getZoomHeight(parentWidget())); + pdfFiller->updatePageSizes(width(), height(), AppConfig::getInstance()->getZoomWidth(parentWidget()),AppConfig::getInstance()->getZoomHeight(parentWidget())); pdfPresViewer->setGeometry(geometry()); } Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.cpp =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.cpp 2010-02-13 08:47:08 UTC (rev 1717) +++ branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.cpp 2010-02-13 22:19:20 UTC (rev 1718) @@ -24,14 +24,15 @@ PDFPresentationViewer::PDFPresentationViewer(QWidget * parent, const QRect & rect) : QLabel (parent) { origSize = rect; currentPage = 0; - _period = 20; + _period = 10; inPageTransition = false; + alfa = 0; zoomed = false; zoomable = true; toBeZoomed = false; - alfa = 1; + alfa = 0; timeOpened = 0; setGeometry(origSize); setParent(parent); @@ -53,12 +54,49 @@ setPalette(AppConfig::getInstance()->getPaletteFocused()); } setVisible(true); + + connect(&nextTimer, SIGNAL(timeout()), this, SLOT(nextPageTimer())); + nextTimer.start(_period*1000); } +PDFPresentationViewer::~PDFPresentationViewer() { + if (nextTimer.isActive()) { + nextTimer.stop(); + } + if (fadeEffect.isActive()) { + fadeEffect.stop(); + } + if (closeWatcher.isActive()) { + closeWatcher.stop(); + } +} + void PDFPresentationViewer::setKeyBase(QString keyBase) { pageKeyBase = keyBase; } +/** Returns the change in page numbers that it is queued. For example, it returns possitive number, if there are + more Next movements than Previous movements. It returns 0 if number of changes to Next page and Previous page are equal. It returns exact number; + + @return change in page numbers that is queued + */ + +int PDFPresentationViewer::queuedChange() { + ElvysNs::Position movement; + int change = 0; + + foreach ( movement, pageChanges) { + if (movement == ElvysNs::Next) { + change++; + } else if ( movement == ElvysNs::Previous ) { + change --; + } + } + + return change; +} + + QString PDFPresentationViewer::getPageKey(const QSize & size, const QString & identifier) { return pageKeyBase + identifier + QString::number(size.width()) + KEY_SEPERATOR + QString::number(size.height()); } @@ -78,6 +116,8 @@ void PDFPresentationViewer::getNextPage() { if (currentPage != pages.size() -1) { //we are still not at the end emit getPage(currentPage +1, size(), getPageKey(size(), pageKeyNext)); + } else { + nextPixmap = QPixmap(); } } @@ -88,46 +128,94 @@ void PDFPresentationViewer::getPreviousPage() { if ( currentPage != 0 ) { // we are not on the first page emit getPage(currentPage -1, size(), getPageKey(size(), pageKeyPrev)); + } else { + previousPixmap = QPixmap(); } } -/** Loads and displays previous page. If the current page is the last page of the document, it does nothing. - */ - -void PDFPresentationViewer::previousPage() { - +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(); } + if ( currentPage + queuedChange() <= 0 ) { + return; + } + pageChanges.append(ElvysNs::Previous); + manageMovements(); } -/** Loads and displays next page. If the current page is the last page of the document, it does nothing. +/** Loads and displays previous page. If the current page is the last page of the document, it does nothing. */ +void PDFPresentationViewer::previousPageReal() { + currentPage -= 1; + pageMovement = ElvysNs::Previous; + nextPixmap = currentPixmap; + currentPixmap = previousPixmap; + startFadeEffect(); + getPreviousPage(); + showPDF(); +} + +/** Add request to move to queue +*/ + void PDFPresentationViewer::nextPage() { if (pages.size() == 0) { return; } if (currentPage == pages.size() -1) { return; + } + if ( currentPage + queuedChange() >= pages.size() - 1 ) { + return; + } + pageChanges.append(ElvysNs::Next); + manageMovements(); +} + +/** Loads and displays next page. It does not check anything, it is up to caller! This function should + always be used only throght nextPage(). + */ + +void PDFPresentationViewer::nextPageReal() { + currentPage += 1; + pageMovement = ElvysNs::Next; + previousPixmap = currentPixmap; + currentPixmap = nextPixmap; + startFadeEffect(); + getNextPage(); + showPDF(); +} + +/** This displayes nextPage and also makes sure if timer's period should be adjust or not + */ + +void PDFPresentationViewer::nextPageTimer() { + if ( nextTimer.interval() != _period * 1000) { + nextTimer.setInterval(_period * 1000); + } + + if ( currentPage == pages.size() -1 && pageChanges.size() == 0 ) { // we reached end of the document already and no movements are queued + currentPage = 0; + getCurrentPage(); + getNextPage(); + getPreviousPage(); } else { - currentPage += 1; - previousPixmap = currentPixmap; - currentPixmap = nextPixmap; - getNextPage(); - showPDF(); + nextPage(); } } +void PDFPresentationViewer::startFadeEffect() { + inPageTransition = true; + if ( ! fadeEffect.isActive()) { + fadeEffect.start(20); + } +} + void PDFPresentationViewer::pageReady(PageSelector selector, PDFPage * page) { QPixmap myPixmap; @@ -138,24 +226,38 @@ 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 + myPixmap = QPixmap::fromImage(*page->getImage()); ///< @todo better observe this place, as it may fail here (image inside page could have already been deleted) emit imageGenerationFinished(); if (selector.desc.contains(pageKeyCur)) { - QPixmapCache::insert(getPageKey(myPixmap.size(), pageKeyCur), myPixmap); + QPixmapCache::insert(getPageKey(size(), pageKeyCur), myPixmap); currentPixmap = myPixmap; + showPDF(); update(); } else if (selector.desc.contains(pageKeyNext)) { - QPixmapCache::insert(getPageKey(myPixmap.size(), pageKeyNext), myPixmap); + QPixmapCache::insert(getPageKey(size(), pageKeyNext), myPixmap); nextPixmap = myPixmap; } else if (selector.desc.contains(pageKeyPrev)) { - QPixmapCache::insert(getPageKey(myPixmap.size(), pageKeyPrev), myPixmap); + QPixmapCache::insert(getPageKey(size(), pageKeyPrev), myPixmap); previousPixmap = myPixmap; } + + manageMovements(); } +/** This is to provide maximum width and height of the pages in the document (not necessarily the same page) in normal mode. +It sets geometry of the widget. + @param width maximum width of page in the document + @param height maximum height of page in the document + */ + +void PDFPresentationViewer::setSizeRect(int width, int height) { + w = width; + h = height; +} + void PDFPresentationViewer::setZoomedSize(int width, int height) { zoomW = width; zoomH = height; @@ -220,41 +322,12 @@ int newX; int newY; int overlap = 0; - QWidget * parW = parentWidget(); - QScrollArea area; + QWidget * parW = parentWidget(); - // 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 + if ( (overlap = (centerX + zoomWHalf) - 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; @@ -264,43 +337,43 @@ newX = centerX - zoomWHalf; } - if ( (origSize.y() + AppConfig::getInstance()->getZoomHeight(parW)) + scrollAreaOffsetHeight > parW->height() ) { + if ( (origSize.y() + AppConfig::getInstance()->getZoomHeight(parW)) > parW->height() ) { newY = 0; } else { newY = origSize.y(); } - if (zoomH + scrollAreaOffsetHeight < AppConfig::getInstance()->getZoomHeight(parW) ) { - return QRect(newX, newY, zoomW + scrollAreaOffsetWidth, zoomH + scrollAreaOffsetHeight); + if (zoomH < AppConfig::getInstance()->getZoomHeight(parW) ) { + qDebug() << QRect(newX, newY, zoomW, zoomH); + return QRect(newX, newY, zoomW, zoomH); } else { - return QRect(newX, newY, zoomW + scrollAreaOffsetWidth, AppConfig::getInstance()->getZoomHeight(parW)); + qDebug() << QRect(newX, newY, zoomW, zoomH); + return QRect(newX, newY, zoomW, 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; +void PDFPresentationViewer::showPDF() { - setPixmap(currentPixmap); - alfa = 1; + setPixmap(currentPixmap); + alfa = 0; + if ( ! zoomed) { + move(origSize.center().x() - w/2, origSize.center().y() -h/2); + setGeometry(x(), y(), w, h); + } - // 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()); + //load also other pages + if ( nextPixmap.isNull()) { + getNextPage(); + } + if ( previousPixmap.isNull()) { + getPreviousPage(); + } update(); } @@ -336,10 +409,7 @@ break; case Qt::Key_PageDown: previousPage(); - break; - case Qt::Key_Return: - zoom(); - break; + break; case Qt::Key_Backspace: unzoom(); break; @@ -350,6 +420,29 @@ } } +/** Hide event reimplementation. It stops changing of pages. + @param event structure containing event information + */ + +void PDFPresentationViewer::hideEvent(QHideEvent * event) { + Q_UNUSED(event); + + nextTimer.stop(); +} + +/** Show event reimplementation. It starts changing of pages, if not started already + @param event structure containing event information + */ + +void PDFPresentationViewer::showEvent(QShowEvent * event) { + Q_UNUSED(event); + + if ( ! nextTimer.isActive() ) { + nextTimer.start(_period); + } +} + + void PDFPresentationViewer::unzoom() { if ( zoomed ) { emit unZoomEvent(); @@ -358,7 +451,6 @@ zoomed = false; setGeometry(origSize); getCurrentPage(); - showPDF(); setBorderFocused(); } } @@ -370,14 +462,35 @@ return; } emit zoomEvent(); - closeWatcher.start(1000); - toBeZoomed = true; + closeWatcher.start(1000); + zoomed = true; setGeometry(getZoomedGeometry()); getCurrentPage(); + setBorder(false); showPDF(); } } +void PDFPresentationViewer::manageMovements() { + if (inPageTransition) { //there are already other movements queued + return; + } + if ( ! pageChanges.empty() ) { + switch ( pageChanges.takeFirst()) { + case ElvysNs::Next: + nextPageReal(); + break; + case ElvysNs::Previous: + previousPageReal(); + break; + default: + break; + } + } + if ( ! pageChanges.empty() ) { + manageMovements(); + } +} void PDFPresentationViewer::mousePressEvent ( QMouseEvent * event ) { if (event->button() == Qt::LeftButton) { @@ -391,7 +504,7 @@ if (focused) { setFrameStyle(QFrame::Box | QFrame::Raised); setLineWidth(3); - setMidLineWidth(3); + setMidLineWidth(0); setPalette( AppConfig::getInstance()->getPaletteFocused() ); } else { setLineWidth(1); @@ -408,10 +521,14 @@ void PDFPresentationViewer::resizeEvent(QResizeEvent * event) { Q_UNUSED(event); - if (! zoomed ) { // I might get called in zoomed state - origSize = geometry(); + if (! zoomed ) { // I might get called in zoomed state + + origSize = geometry(); } + getNextPage(); + getPreviousPage(); + update(); } @@ -432,16 +549,11 @@ if ( zoomed ) { setFocus(); } + qDebug() << event->reason(); } -PDFPresentationViewer::~PDFPresentationViewer() { - closeWatcher.stop(); -} - - - -void PDFPresentationViewer::doFadeEffect() { - alfa += 15; +void PDFPresentationViewer::doFadeEffect() { + alfa += 20; update(); } @@ -472,38 +584,60 @@ void PDFPresentationViewer::stopFadeEffect() { if (fadeEffect.isActive()) { fadeEffect.stop(); - setGeometry(myGeometry); //restore geometry of small first page + inPageTransition = false; + alfa = 0; } - if (scroll) { - scroll->raise(); - } + update(); + manageMovements(); } void PDFPresentationViewer::paintEvent(QPaintEvent * event) { - Q_UNUSED(event); if (inPageTransition) { - QPainter p(&pixmapOpac); + if (alfa >= 255) { + alfa = 255; + } + +/* if ( pixmap() != NULL) { + setPixmap(NULL); + } +*/ QPainter painter(this); + QPixmap pixmap; - p.drawPixmap((zoomW - pageW)/2, 0, currentPixmap); + if (pageMovement == ElvysNs::Next) { + pixmap = previousPixmap; + } else if (pageMovement == ElvysNs::Previous) { + pixmap = nextPixmap; + } - p.setCompositionMode(QPainter::CompositionMode_DestinationIn); + QPoint change = rect().center() - pixmap.rect().center(); + QPoint change2 = rect().center() - currentPixmap.rect().center(); - p.fillRect(pixmapOpac.rect(), QColor(0, 0, 0, alfa)); - p.end(); - painter.drawPixmap(0,0,pixmapOpac); + painter.drawPixmap(change, pixmap); + painter.setOpacity((qreal)alfa / 255.0); + painter.drawPixmap(change2, currentPixmap); painter.end(); + + if (alfa == 255) { + stopFadeEffect(); + } +// QLabel::paintEvent(event); } else { - if ( QPixmapCache::find(getPageKey(size(), pageKeyBase)) == false) { + if ( QPixmapCache::find(getPageKey(size(), pageKeyCur)) == false) { getCurrentPage(); return; } + QLabel::paintEvent(event); } } +/** Sets period for presentation (page change). It will take effect at next timer's timeout (ie. it will not affect current period immediately) + @param period period to be set + */ + void PDFPresentationViewer::setPeriod(int period) { - _period = period; + _period = period; } int PDFPresentationViewer::period() { Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.h =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.h 2010-02-13 08:47:08 UTC (rev 1717) +++ branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.h 2010-02-13 22:19:20 UTC (rev 1718) @@ -18,6 +18,11 @@ #include <XpdfRasterizer.h> +namespace ElvysNs { + enum Position { Next, Current, Previous}; +} + + /** Trida zodpovedna za spravne zobrazeni pdfdokumentu..... */ class PDFPresentationViewer : public QLabel { @@ -33,8 +38,10 @@ public slots: void pageReady(PageSelector selector, PDFPage * page); void setZoomedSize(int, int); + void setSizeRect(int, int); void setKeyBase(QString keyBase); void nextPage(); + void nextPageTimer(); void previousPage(); private slots: @@ -59,14 +66,21 @@ void keyPressEvent( QKeyEvent * event ); void paintEvent(QPaintEvent * event); void resizeEvent(QResizeEvent * event); + void hideEvent(QHideEvent * event); + void showEvent(QShowEvent * event); virtual void focusInEvent ( QFocusEvent * event ); virtual void focusOutEvent ( QFocusEvent * event ); private: + int queuedChange(); + void nextPageReal(); + void previousPageReal(); void getNextPage(); void getPreviousPage(); void getCurrentPage(); + void manageMovements(); void stopFadeEffect(); + void startFadeEffect(); QRect getZoomedGeometry(); QString getPageKey(const QSize & size, const QString & identifier = ""); void zoom(); @@ -85,7 +99,12 @@ int currentPage; int _period; bool inPageTransition; + ElvysNs::Position pageMovement; + QList<ElvysNs::Position> pageChanges; + int w; + int h; + int zoomW; //maximalni sirka int zoomH; //celkova delka @@ -101,13 +120,12 @@ QVector<Page> pages; int alfa; - QPixmap pixmapOpac; - QScrollArea * scroll; QPixmap currentPixmap; QPixmap previousPixmap; - QPixmap nextPixmap; + QPixmap nextPixmap; QTimer fadeEffect; + QTimer nextTimer; QTimer closeWatcher; }; Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdfviewer.cpp =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/pdfviewer.cpp 2010-02-13 08:47:08 UTC (rev 1717) +++ branches/client/pdf-presentation-branch/elvys-client/src/pdfviewer.cpp 2010-02-13 22:19:20 UTC (rev 1718) @@ -33,7 +33,7 @@ scaled = 0; pdfZoomed = NULL; - alfa = 1; + alfa = 0; timeOpened = 0; scroll = NULL; setGeometry(origSize); @@ -195,7 +195,7 @@ this->setGeometry(rect); fadeEffect.start(15); } else { - alfa = 1; + alfa = 0; if (scroll != NULL ) { QWidget * wid = scroll->takeWidget(); wid->setParent(AppConfig::getInstance()->getMainWidget()); /** This deserves comment - this is to prevent zoomEvent to pdfZoomed (==wid) next time it will be zoomed.