Author: JirkaH Date: 2010-02-16 13:10:31 +0100 (Tue, 16 Feb 2010) New Revision: 1741 Added: branches/client/pdf-presentation-branch/elvys-client/src/pdfcommonviewer.cpp branches/client/pdf-presentation-branch/elvys-client/src/pdfcommonviewer.h Modified: branches/client/pdf-presentation-branch/elvys-client/Makefile branches/client/pdf-presentation-branch/elvys-client/bin/data/style.css branches/client/pdf-presentation-branch/elvys-client/elvys-client.pro.user branches/client/pdf-presentation-branch/elvys-client/src/Makefile branches/client/pdf-presentation-branch/elvys-client/src/category.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/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 branches/client/pdf-presentation-branch/elvys-client/src/pdfviewer.h branches/client/pdf-presentation-branch/elvys-client/src/src.pro Log: code refactoring. common ancestor to pdfViewer class introduced. Modified: branches/client/pdf-presentation-branch/elvys-client/Makefile =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/Makefile 2010-02-16 09:21:07 UTC (rev 1740) +++ branches/client/pdf-presentation-branch/elvys-client/Makefile 2010-02-16 12:10:31 UTC (rev 1741) @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: elvys-client -# Generated by qmake (2.01a) (Qt 4.5.3) on: Sun Feb 14 20:14:17 2010 +# Generated by qmake (2.01a) (Qt 4.5.3) on: Tue Feb 16 09:19:19 2010 # Project: elvys-client.pro # Template: subdirs # Command: /usr/bin/qmake -spec /usr/share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug_and_release -o Makefile elvys-client.pro Modified: branches/client/pdf-presentation-branch/elvys-client/bin/data/style.css =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/bin/data/style.css 2010-02-16 09:21:07 UTC (rev 1740) +++ branches/client/pdf-presentation-branch/elvys-client/bin/data/style.css 2010-02-16 12:10:31 UTC (rev 1741) @@ -33,14 +33,14 @@ /* BEWARE right is in fact left :-) Bug in QT? Maybe */ QTabBar::tab:right { - min-height: 20ex; + min-height: 15ex; min-width: 25px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; } QTabBar::tab:bottom { - min-width: 20ex; + min-width: 15ex; min-height: 25px; border-top-left-radius: 4px; border-top-right-radius: 4px; Modified: branches/client/pdf-presentation-branch/elvys-client/elvys-client.pro.user =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/elvys-client.pro.user 2010-02-16 09:21:07 UTC (rev 1740) +++ branches/client/pdf-presentation-branch/elvys-client/elvys-client.pro.user 2010-02-16 12:10:31 UTC (rev 1741) @@ -113,6 +113,7 @@ <value type="QString" >KDE_SESSION_VERSION=4</value> <value type="QString" >LADSPA_PATH=/usr/lib/ladspa</value> <value type="QString" >LANG=en_US.UTF-8</value> + <value type="QString" >LANGUAGE=</value> <value type="QString" >LC_CTYPE=en_US.UTF-8</value> <value type="QString" >LESS=-R -M --shift 5</value> <value type="QString" >LESSOPEN=|lesspipe.sh %s</value> @@ -190,6 +191,7 @@ <value type="QString" >KDE_SESSION_VERSION=4</value> <value type="QString" >LADSPA_PATH=/usr/lib/ladspa</value> <value type="QString" >LANG=en_US.UTF-8</value> + <value type="QString" >LANGUAGE=</value> <value type="QString" >LC_CTYPE=en_US.UTF-8</value> <value type="QString" >LESS=-R -M --shift 5</value> <value type="QString" >LESSOPEN=|lesspipe.sh %s</value> Modified: branches/client/pdf-presentation-branch/elvys-client/src/Makefile =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/Makefile 2010-02-16 09:21:07 UTC (rev 1740) +++ branches/client/pdf-presentation-branch/elvys-client/src/Makefile 2010-02-16 12:10:31 UTC (rev 1741) @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: ../bin/elvys-client -# Generated by qmake (2.01a) (Qt 4.5.3) on: Tue Feb 16 09:19:19 2010 +# Generated by qmake (2.01a) (Qt 4.5.3) on: Tue Feb 16 12:42:10 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/category.cpp =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/category.cpp 2010-02-16 09:21:07 UTC (rev 1740) +++ branches/client/pdf-presentation-branch/elvys-client/src/category.cpp 2010-02-16 12:10:31 UTC (rev 1741) @@ -327,7 +327,8 @@ */ QString Category::getPanelName(int position) { - return name() + QString(" %1").arg(position); + //return name() + QString(" %1").arg(position); + return QString(" %1").arg(position); } Added: branches/client/pdf-presentation-branch/elvys-client/src/pdfcommonviewer.cpp =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/pdfcommonviewer.cpp (rev 0) +++ branches/client/pdf-presentation-branch/elvys-client/src/pdfcommonviewer.cpp 2010-02-16 12:10:31 UTC (rev 1741) @@ -0,0 +1,186 @@ +#include "pdfcommonviewer.h" + +/** Class constructor. + @arg parent parent widget + @arg rect geometry that will be set as original size aka normal mode size. + */ + +PDFCommonViewer::PDFCommonViewer(QWidget * parent, const QRect & rect) : QLabel(parent) { + _acceptingPages = true; + origSize = rect; + + alpha = 0; + zoomed = false; + zoomable = true; + toBeZoomed = false; + + timeOpened = 0; + + setGeometry(origSize); + + 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); +} + +/** Class destructor */ + +PDFCommonViewer::~PDFCommonViewer() { +} + + +/** sets geometry of whole zoomed document, height is sum of height of all pages + +offsets among them. + @arg width width to be set + @arg height height to be set - sum of heigh of all pages + offsets among them. + */ + +void PDFCommonViewer::setZoomedSize(int width, int height) { + zoomW = width; + zoomH = height; +} + +/** Sets base of key to QPixmapCache to @a keyBase. Every key will contain this string + + @arg keyBase base of key to be set + */ + +void PDFCommonViewer::setKeyBase(QString keyBase) { + pageKeyBase = keyBase; +} + + +/** Slot to be called when doing fading effect between two pages (page transition). Increases + alpha value + */ + +void PDFCommonViewer::doFadeEffect() { + alpha += 25; + update(); +} + +/** Slot to be called when the document was zoomed for defined period of time without any user's interaction. + Unzoomes document. + */ + +void PDFCommonViewer::closeEnlargement() { + if ( timeOpened >= AppConfig::getInstance()->getDocumentTimeOut() ) { + unzoom(); + } else { + timeOpened++; + } +} + +/** Enables or disables zooming + @arg _zoomable true if zooming should be enabled, false otherwise + */ + +void PDFCommonViewer::setZoomable(bool _zoomable) { + zoomable = _zoomable; +} + +/** Returns true if widget is zoomed, false otherwise; + @return returns true if widget is zoomed, false otherwise; + */ + +bool PDFCommonViewer::isZoomed() { + return zoomed; +} + +/** Sets whether widget should accept rendered pages or not. Usefull in hideEvents and when + closing the widget. + @arg accept whether widget should accept new rendered pages or not + */ + +void PDFCommonViewer::setAcceptingPages(bool accept) { + _acceptingPages = accept; +} + +/** Returns whether widget accept new rendered pages or not. + @return whether widget accept new rendered pages or not + */ + +bool PDFCommonViewer::acceptingPages() { + return _acceptingPages; +} + +/** Sets border of the widget according to its focused state + @arg focused whether widget has focus or not + */ + +void PDFCommonViewer::setBorder(bool focused) { + if (focused) { + setFrameStyle(QFrame::Panel | QFrame::Plain); + setLineWidth(AppConfig::getInstance()->getAppWidth() / 380); + setPalette( AppConfig::getInstance()->getPaletteFocused() ); + } else { + setLineWidth(1); + setMidLineWidth(1); + setFrameStyle(QFrame::StyledPanel | QFrame::Plain); + setPalette( AppConfig::getInstance()->getPaletteNotFocused()); + } +} + +/** Convenient method. Sets border of the widget according to its focused state. + */ + +void PDFCommonViewer::setBorderFocused() { + setBorder(hasFocus()); +} + + +/** Returns key to QPixmap cache according to parameters given. + @arg size size of the pixmap + @arg identifier user defined identifier + @return key to QPixmap cache according to parameters given. + */ + +QString PDFCommonViewer::getPageKey(const QSize & size, const QString & identifier) { + return pageKeyBase + identifier + QString::number(size.width()) + KEY_SEPERATOR + QString::number(size.height()); +} + +/** Loads document. Actually, filename is unused, as it is managed by some PDFDocument class. + But it is important to call this function for proper inicialization. + @arg filename filename of the document. Unsued at the momment. + */ + +void PDFCommonViewer::load(QString & filename) { + Q_UNUSED(filename); + + zoomable = true; + _acceptingPages = true; + + setFocusPolicy(Qt::StrongFocus); + if ( QApplication::focusWidget() == NULL ) { + setFocus(); + } else { + if ( qobject_cast<Document *>(QApplication::focusWidget()) == NULL ) { //no document has focus + setFocus(); + } + } + update(); +} + +/** Closes currently opened document. + */ + +void PDFCommonViewer::close() { + _acceptingPages = false; + zoomable = false; + setPixmap(NULL); + setFocusPolicy(Qt::NoFocus); + clearFocus(); + update(); +} + + Added: branches/client/pdf-presentation-branch/elvys-client/src/pdfcommonviewer.h =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/pdfcommonviewer.h (rev 0) +++ branches/client/pdf-presentation-branch/elvys-client/src/pdfcommonviewer.h 2010-02-16 12:10:31 UTC (rev 1741) @@ -0,0 +1,80 @@ +#ifndef PDFCOMMONVIEWER_H +#define PDFCOMMONVIEWER_H + +#include <QLabel> +#include <QImage> +#include <QTimer> +#include <QApplication> +#include <QPixmapCache> +#include <QRect> + +#include "constants.h" +#include "document.h" +#include "pageselector.h" +#include "pdfpage.h" +#include "page.h" +#include "appconfig.h" + +class PDFCommonViewer : public QLabel { + Q_OBJECT + +signals: + void getPage(int pageNum, QSize size, QString desc); + void imageGenerated(PageSelector selector); + void imageGenerationStarted(); + void imageGenerationFinished(); + void unZoomEvent(); + void zoomEvent(); + + public slots: + virtual void pageReady(PageSelector selector, PDFPage * page) = 0; + void setZoomedSize(int, int); + void setKeyBase(QString keyBase); + + private slots: + void doFadeEffect(); + void closeEnlargement(); + + public: + PDFCommonViewer(QWidget * parent, const QRect & rect); //inicializuju dedene promene + ~PDFCommonViewer(); + bool isZoomed(); + void setZoomable(bool _zoomable); + void setAcceptingPages(bool accept); + bool acceptingPages(); + virtual void load(QString & filename); + virtual void close(); + + protected: + virtual void stopFadeEffect() = 0; + void setBorderFocused(); + void setBorder(bool focused); + virtual QString getPageKey(const QSize & size, const QString & identifier = ""); + virtual void zoom() = 0; + virtual void unzoom() = 0; + virtual void showPDF() = 0; + + + QRect origSize; + QRect myGeometry; + + QString pageKeyBase; + + bool _acceptingPages; + + int timeOpened; + + int zoomW; //maximalni sirka + int zoomH; //celkova delka + + int alpha; + + bool toBeZoomed; + bool zoomable; // pokud uz je nactena aspon first page big stranka a nejakej ten buffer + bool zoomed; + + QTimer fadeEffect; + QTimer closeWatcher; +}; + +#endif // PDFCOMMONVIEWER_H Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdfdocument.cpp =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/pdfdocument.cpp 2010-02-16 09:21:07 UTC (rev 1740) +++ branches/client/pdf-presentation-branch/elvys-client/src/pdfdocument.cpp 2010-02-16 12:10:31 UTC (rev 1741) @@ -32,7 +32,7 @@ qRegisterMetaType<PageSelector>( "PageSelector" ); pdfFiller = new PDFFiller(doc->width(), doc->height()); - pdfViewer = new PDFViewer(parentWidget(),doc->geometry().x(), doc->geometry().y(), doc->width(), doc->height()); + pdfViewer = new PDFViewer(parentWidget(), doc->geometry()); pdfZoomed = new PDFZoomed(); //connect(pdfFiller, SIGNAL(changeReady(bool)), pdfViewer, SLOT(setReady(bool ))); Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdffiller.cpp =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/pdffiller.cpp 2010-02-16 09:21:07 UTC (rev 1740) +++ branches/client/pdf-presentation-branch/elvys-client/src/pdffiller.cpp 2010-02-16 12:10:31 UTC (rev 1741) @@ -40,8 +40,7 @@ /** * Class desctructor. Waits for all threads to die. */ -PDFFiller::~PDFFiller() { - qWarning() << "pdffiller deleted" << filename; +PDFFiller::~PDFFiller() { quit = true; condition.wakeAll(); wait(); Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationdocument.cpp =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationdocument.cpp 2010-02-16 09:21:07 UTC (rev 1740) +++ branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationdocument.cpp 2010-02-16 12:10:31 UTC (rev 1741) @@ -176,6 +176,7 @@ Q_UNUSED(event); pdfPresViewer->setAcceptingPages(true); + pdfPresViewer->setAutoRotating(true); } Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.cpp =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.cpp 2010-02-16 09:21:07 UTC (rev 1740) +++ branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.cpp 2010-02-16 12:10:31 UTC (rev 1741) @@ -1,63 +1,29 @@ -#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) { - _acceptingPages = true; - origSize = rect; +PDFPresentationViewer::PDFPresentationViewer(QWidget * parent, const QRect & rect) : PDFCommonViewer(parent, rect) { + _autoRotating = true; currentPage = 0; _period = 10; - inPageTransition = false; - alfa = 0; + inPageTransition = false; - zoomed = false; - zoomable = true; - toBeZoomed = false; - alfa = 0; - timeOpened = 0; - setGeometry(origSize); - setParent(parent); + //setParent(parent); + pageKeyBase = "PDF_PRESENTATION_VIEWER"; pageKeyCur = "CUR"; pageKeyPrev = "PREV"; - pageKeyNext = "NEXT"; + 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); - - connect(&nextTimer, SIGNAL(timeout()), this, SLOT(nextPageTimer())); - nextTimer.start(_period*1000); + connect(&nextTimer, SIGNAL(timeout()), this, SLOT(nextPageTimer())); } PDFPresentationViewer::~PDFPresentationViewer() { @@ -75,10 +41,6 @@ } } -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; @@ -100,12 +62,6 @@ return change; } - -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. */ @@ -268,14 +224,6 @@ manageMovements(); } -void PDFPresentationViewer::setAcceptingPages(bool accept) { - _acceptingPages = accept; -} - -bool PDFPresentationViewer::acceptingPages() { - return _acceptingPages; -} - /** 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 @@ -287,11 +235,6 @@ h = height; } -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. @@ -390,7 +333,7 @@ void PDFPresentationViewer::showPDF() { setPixmap(currentPixmap); - alfa = 0; + alpha = 0; if ( ! zoomed) { move(origSize.center().x() - w/2, origSize.center().y() -h/2); setGeometry(x(), y(), w, h); @@ -449,49 +392,49 @@ } } -/** Stops or start rotating the pages. It does nothing if rotating is already stopped/started. - @arg enabled wheter rotating of pages should start or stop. +/** Starts or stops autorotating according to _setAutoRotating variable and zoomed state */ -void PDFPresentationViewer::setAutoRotating(bool enabled) { - if ( ! enabled) { + +void PDFPresentationViewer::manageAutoRotating() { + if ( ! _autoRotating ) { nextTimer.stop(); } else { - if ( ! nextTimer.isActive()) { - nextTimer.start(_period); + if ( ! zoomed ) { + if ( ! nextTimer.isActive()) { + nextTimer.start(_period); + } + } else { + nextTimer.stop(); } } } -/** Hide event reimplementation. It stops changing of pages. - @param event structure containing event information +/** Enables or disables auto rotating of the pages. It does nothing if rotating is already stopped/started. Please note that + rotating is alway disabled when zoomed. + @arg enabled whether rotating should be enabled or disabled */ -void PDFPresentationViewer::hideEvent(QHideEvent * event) { - - - nextTimer.stop(); +void PDFPresentationViewer::setAutoRotating(bool enabled) { + _autoRotating = enabled; + manageAutoRotating(); } -/** Show event reimplementation. It starts changing of pages, if not started already - @param event structure containing event information +/** Returns whether auto rotating of pages is enabled or not. Please note that rotating is alway disabled when zoomed. + @return true if auto rotating is enabled, false otherwise */ - -void PDFPresentationViewer::showEvent(QShowEvent * event) { - Q_UNUSED(event); - - if ( ! nextTimer.isActive() ) { - nextTimer.start(_period); - } +bool PDFPresentationViewer::autoRotating() { + return _autoRotating; } void PDFPresentationViewer::unzoom() { if ( zoomed ) { emit unZoomEvent(); - closeWatcher.stop(); + closeWatcher.stop(); timeOpened = 0; zoomed = false; + manageAutoRotating(); setGeometry(origSize); getCurrentPage(); setBorderFocused(); @@ -503,10 +446,11 @@ if ( ! zoomable ) { //qDebug() << "Nemuzu zvetsovat, nejsem ve stavu zoomable" ; return; - } + } emit zoomEvent(); - closeWatcher.start(1000); + closeWatcher.start(1000); zoomed = true; + manageAutoRotating(); setGeometry(getZoomedGeometry()); getCurrentPage(); setBorder(false); @@ -544,23 +488,6 @@ } } -void PDFPresentationViewer::setBorder(bool focused) { - if (focused) { - setFrameStyle(QFrame::Panel | QFrame::Plain); - setLineWidth(AppConfig::getInstance()->getAppWidth() / 380); - 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); @@ -595,40 +522,11 @@ //qDebug() << event->reason(); } -void PDFPresentationViewer::doFadeEffect() { - alfa += 25; - 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(); inPageTransition = false; - alfa = 0; + alpha = 0; } //setPixmap(currentPixmap); update(); @@ -638,8 +536,8 @@ void PDFPresentationViewer::paintEvent(QPaintEvent * event) { if (inPageTransition) { - if (alfa >= 255) { - alfa = 255; + if (alpha >= 255) { + alpha = 255; } if ( pixmap() != NULL) { @@ -659,11 +557,11 @@ QPoint change2 = rect().center() - currentPixmap.rect().center(); painter.drawPixmap(change, pixmap); - painter.setOpacity((qreal)alfa / 255.0); + painter.setOpacity((qreal)alpha / 255.0); painter.drawPixmap(change2, currentPixmap); painter.end(); - if (alfa == 255) { + if (alpha == 255) { stopFadeEffect(); } QLabel::paintEvent(event); @@ -690,29 +588,3 @@ int PDFPresentationViewer::period() { return _period; } - -void PDFPresentationViewer::close() { - _acceptingPages = false; - zoomable = false; - setPixmap(NULL); - setFocusPolicy(Qt::NoFocus); - clearFocus(); - update(); -} - -void PDFPresentationViewer::load(QString & filename) { - Q_UNUSED(filename); - - zoomable = true; - _acceptingPages = true; - - setFocusPolicy(Qt::StrongFocus); - if ( QApplication::focusWidget() == NULL ) { - setFocus(); - } else { - if ( qobject_cast<Document *>(QApplication::focusWidget()) == NULL ) { //no document has focus - setFocus(); - } - } - update(); -} Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.h =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.h 2010-02-16 09:21:07 UTC (rev 1740) +++ branches/client/pdf-presentation-branch/elvys-client/src/pdfpresentationviewer.h 2010-02-16 12:10:31 UTC (rev 1741) @@ -1,23 +1,16 @@ #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 "pdfcommonviewer.h" +//#include <XpdfRasterizer.h> -#include <XpdfRasterizer.h> - namespace ElvysNs { enum Position { Next, Current, Previous}; } @@ -25,57 +18,41 @@ /** Trida zodpovedna za spravne zobrazeni pdfdokumentu..... */ -class PDFPresentationViewer : public QLabel { +class PDFPresentationViewer : public PDFCommonViewer { Q_OBJECT - signals: - void getPage(int pageNum, QSize size, QString desc); - void imageGenerationStarted(); - void imageGenerationFinished(); - void imageGenerated(PageSelector selector); - void unZoomEvent(); - void zoomEvent(); - public slots: - void pageReady(PageSelector selector, PDFPage * page); - void setZoomedSize(int, int); - void setSizeRect(int, int); - void setKeyBase(QString keyBase); + virtual void pageReady(PageSelector selector, PDFPage * page); + void setSizeRect(int, int); void nextPage(); void nextPageTimer(); 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); + virtual ~PDFPresentationViewer(); void setPeriod(int period); int period(); void setAutoRotating(bool enabled); - void setPages(QList <int> & _pageNumbers); - void setAcceptingPages(bool accept); - bool acceptingPages(); + bool autoRotating(); + void setPages(QList <int> & _pageNumbers); protected: void mousePressEvent( QMouseEvent * event ); void keyPressEvent( QKeyEvent * event ); void paintEvent(QPaintEvent * event); - void resizeEvent(QResizeEvent * event); - void hideEvent(QHideEvent * event); - void showEvent(QShowEvent * event); + void resizeEvent(QResizeEvent * event); virtual void focusInEvent ( QFocusEvent * event ); virtual void focusOutEvent ( QFocusEvent * event ); private: + virtual void startFadeEffect(); + virtual void stopFadeEffect(); + void manageAutoRotating(); int queuedChange(); void nextPageReal(); void previousPageReal(); @@ -83,26 +60,19 @@ void getPreviousPage(); void getCurrentPage(); void manageMovements(); - void stopFadeEffect(); - void startFadeEffect(); - QRect getZoomedGeometry(); - QString getPageKey(const QSize & size, const QString & identifier = ""); + + QRect getZoomedGeometry(); void zoom(); void unzoom(); - void showPDF(); - void setBorderFocused(); - void setBorder(bool focused); + void showPDF(); - QRect origSize; - QRect myGeometry; - QString pageKeyBase; QString pageKeyCur; QString pageKeyNext; QString pageKeyPrev; int currentPage; - int _period; - bool _acceptingPages; + int _period; + bool _autoRotating; bool inPageTransition; ElvysNs::Position pageMovement; QList<ElvysNs::Position> pageChanges; @@ -110,28 +80,17 @@ int w; int h; - 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 currentPixmap; QPixmap previousPixmap; - QPixmap nextPixmap; - QTimer fadeEffect; + QPixmap nextPixmap; QTimer nextTimer; - QTimer closeWatcher; + }; #endif // PDFPRESENTATIONVIEWER_H Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdfviewer.cpp =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/pdfviewer.cpp 2010-02-16 09:21:07 UTC (rev 1740) +++ branches/client/pdf-presentation-branch/elvys-client/src/pdfviewer.cpp 2010-02-16 12:10:31 UTC (rev 1741) @@ -1,65 +1,33 @@ -#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 <QStyleOptionFocusRect> -#include <QPaintEngine> #include <math.h> #include "pdfviewer.h" -#include "appconfig.h" -#include "constants.h" -PDFViewer::PDFViewer(QWidget * parent, int _x, int _y, int _w, int _h) : QLabel (parent) { - origSize = QRect(_x, _y, _w, _h); +PDFViewer::PDFViewer(QWidget * parent, const QRect & rect) : PDFCommonViewer(parent,rect) { zoomed = false; zoomable = true; toBeZoomed = false; - closed = false; + scaled = 0; - pdfZoomed = NULL; - alfa = 0; + pdfZoomed = NULL; timeOpened = 0; scroll = NULL; - setGeometry(origSize); - setParent(parent); - pageKeyBase = "PDFVIEWER"; - 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); + //setParent(parent); + pageKeyBase = "PDFVIEWER"; } -void PDFViewer::setKeyBase(QString keyBase) { - pageKeyBase = keyBase; -} - QString PDFViewer::getPageKey(const QSize & size, const QString & identifier) { return pageKeyBase + identifier + QString::number(size.width()) + KEY_SEPERATOR + QString::number(size.height()); } @@ -79,7 +47,7 @@ return; } - if (closed) { + if ( ! _acceptingPages) { return; } @@ -109,12 +77,7 @@ } } -void PDFViewer::setZoomedSize(int width, int height) { - zoomW = width; - zoomH = height; -} - QRect PDFViewer::getScrollGeometry() { int newX; int newY; @@ -202,7 +165,7 @@ this->setGeometry(rect); fadeEffect.start(15); } else { - alfa = 0; + alpha = 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. @@ -343,23 +306,6 @@ } } -void PDFViewer::setBorder(bool focused) { - if (focused) { - setFrameStyle(QFrame::Panel | QFrame::Plain); - setLineWidth(AppConfig::getInstance()->getAppWidth() / 380); - setPalette( AppConfig::getInstance()->getPaletteFocused() ); - } else { - setLineWidth(1); - setMidLineWidth(1); - setFrameStyle(QFrame::StyledPanel | QFrame::Plain); - setPalette( AppConfig::getInstance()->getPaletteNotFocused()); - } -} - -void PDFViewer::setBorderFocused() { - setBorder(hasFocus()); -} - void PDFViewer::resizeEvent(QResizeEvent * event) { Q_UNUSED(event); @@ -394,6 +340,7 @@ } PDFViewer::~PDFViewer() { + _acceptingPages = false; setVisible(false); if (scroll != NULL) { delete scroll; @@ -402,41 +349,6 @@ closeWatcher.stop(); } - - -void PDFViewer::doFadeEffect() { -// if ( alfa < 240 ) { - alfa += 15; -// } else { -// alfa += 3; -// } - update(); -} - -void PDFViewer::closeEnlargement() { - if ( timeOpened >= AppConfig::getInstance()->getDocumentTimeOut() ) { - unzoom(); - } else { - timeOpened++; - } -} - -/** Enables or disables zooming - @arg _zoomable true if zooming should be enabled, false otherwise - */ - -void PDFViewer::setZoomable(bool _zoomable) { - zoomable = _zoomable; -} - -/** Returns true if widget is zoomed, false otherwise; - @return returns true if widget is zoomed, false otherwise; - */ - -bool PDFViewer::isZoomed() { - return zoomed; -} - void PDFViewer::stopFadeEffect() { if (fadeEffect.isActive()) { fadeEffect.stop(); @@ -457,7 +369,7 @@ } QLabel::paintEvent(event); } else { - if (alfa >= 255 ) { + if (alpha >= 255 ) { stopFadeEffect(); scroll->show(); @@ -469,36 +381,10 @@ p.setCompositionMode(QPainter::CompositionMode_DestinationIn); - p.fillRect(pixmapOpac.rect(), QColor(0, 0, 0, alfa)); + p.fillRect(pixmapOpac.rect(), QColor(0, 0, 0, alpha)); p.end(); painter.drawPixmap(0,0,pixmapOpac); painter.end(); } } } - -void PDFViewer::close() { - closed = true; - zoomable = false; - setPixmap(NULL); - setFocusPolicy(Qt::NoFocus); - clearFocus(); - update(); -} - -void PDFViewer::load(QString & filename) { - Q_UNUSED(filename); - - zoomable = true; - closed = false; - - setFocusPolicy(Qt::StrongFocus); - if ( QApplication::focusWidget() == NULL ) { - setFocus(); - } else { - if ( qobject_cast<Document *>(QApplication::focusWidget()) == NULL ) { //no document has focus - setFocus(); - } - } - update(); -} Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdfviewer.h =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/pdfviewer.h 2010-02-16 09:21:07 UTC (rev 1740) +++ branches/client/pdf-presentation-branch/elvys-client/src/pdfviewer.h 2010-02-16 12:10:31 UTC (rev 1741) @@ -1,59 +1,36 @@ #ifndef _ELVYS_PDFVIEWER_H_ #define _ELVYS_PDFVIEWER_H_ -#include <QImage> -#include <QLabel> #include <QScrollArea> -#include <QWidget> -#include <QToolButton> -#include <QTimer> + #include <QList> #include <QRect> -#include "document.h" -//#include "pdffiller.h" #include "pdfzoomed.h" +#include "pdfcommonviewer.h" +//#include <XpdfRasterizer.h> -#include <XpdfRasterizer.h> - #define SMALL_PAGE_IDENTIFIER "smallPAGE" #define BIG_PAGE_IDENTIFIER "bigPAGE" /** Trida zodpovedna za spravne zobrazeni pdfdokumentu..... */ -class PDFViewer : public QLabel { +class PDFViewer : public PDFCommonViewer { Q_OBJECT - signals: - void getPage(int pageNum, QSize size, QString desc); - void imageGenerationStarted(); - void imageGenerationFinished(); - void imageGenerated(PageSelector selector); - void unZoomEvent(); - void zoomEvent(); + signals: void scale(double scaleFactor); public slots: - void pageReady(PageSelector selector, PDFPage * page); - void setZoomedSize(int, int); - void setKeyBase(QString keyBase); + virtual void pageReady(PageSelector selector, PDFPage * page); - private slots: - void doFadeEffect(); - void closeEnlargement(); - public: - PDFViewer(QWidget * parent, int _x, int _y, int _w, int _h); //inicializuju dedene promene + PDFViewer(QWidget * parent, const QRect & rect); //inicializuju dedene promene void setPDFZoomed(PDFZoomed * _pdfZoomed); virtual ~PDFViewer(); - bool isZoomed(); - void setZoomable(bool _zoomable); - void close(); - void load(QString & filename); - protected: void mousePressEvent( QMouseEvent * event ); void keyPressEvent( QKeyEvent * event ); @@ -63,47 +40,26 @@ virtual void focusOutEvent ( QFocusEvent * event ); private: - void stopFadeEffect(); + virtual void stopFadeEffect(); void getFirstPageBig(); void getFirstPageSmall(); QRect getScrollGeometry(); - QString getPageKey(const QSize & size, const QString & identifier = ""); - void zoom(); - void unzoom(); - void showPDF(); - void setBorderFocused(); - void setBorder(bool focused); + virtual QString getPageKey(const QSize & size, const QString & identifier = ""); + virtual void zoom(); + virtual void unzoom(); + virtual void showPDF(); void adjustScrollBar(QScrollBar * scrollBar, double factor); - QRect origSize; - QRect myGeometry; - QString pageKeyBase; - - int zoomW; //maximalni sirka - int zoomH; //celkova delka - int pageW; //velikost prvni zvetsene stranky - int pageH; + int pageH; - int timeOpened; - - bool toBeZoomed; - bool zoomable; // pokud uz je nactena aspon first page big stranka a nejakej ten buffer - bool zoomed; - bool closed; - - - int alfa; - int scaled; ///< current level of scaling. 0 means zoomed to "normal" size PDFZoomed * pdfZoomed; QPixmap pixmapOpac; QScrollArea * scroll; - QPixmap myPixmap; - QTimer fadeEffect; - QTimer closeWatcher; + QPixmap myPixmap; }; #endif Modified: branches/client/pdf-presentation-branch/elvys-client/src/src.pro =================================================================== --- branches/client/pdf-presentation-branch/elvys-client/src/src.pro 2010-02-16 09:21:07 UTC (rev 1740) +++ branches/client/pdf-presentation-branch/elvys-client/src/src.pro 2010-02-16 12:10:31 UTC (rev 1741) @@ -48,7 +48,8 @@ filecachemaintainer.cpp \ logotabbar.cpp \ pdfpresentationdocument.cpp \ - pdfpresentationviewer.cpp + pdfpresentationviewer.cpp \ + pdfcommonviewer.cpp HEADERS += elvys.h \ pdfdocument.h \ pdffiller.h \ @@ -99,7 +100,8 @@ filecachemaintainer.h \ logotabbar.h \ pdfpresentationdocument.h \ - pdfpresentationviewer.h + pdfpresentationviewer.h \ + pdfcommonviewer.h TEMPLATE = app CONFIG += warn_on \ thread \