Author: JirkaH Date: 2010-02-17 18:49:36 +0100 (Wed, 17 Feb 2010) New Revision: 1764 Added: trunk/client/elvys-client/src/pdfcommonviewer.cpp trunk/client/elvys-client/src/pdfcommonviewer.h Modified: trunk/client/elvys-client/ trunk/client/elvys-client/Makefile trunk/client/elvys-client/bin/appconfig.xml trunk/client/elvys-client/bin/data/ trunk/client/elvys-client/bin/data/style.css trunk/client/elvys-client/elvys-client.pro.user trunk/client/elvys-client/src/ trunk/client/elvys-client/src/Makefile trunk/client/elvys-client/src/category.cpp trunk/client/elvys-client/src/document.h trunk/client/elvys-client/src/main.cpp trunk/client/elvys-client/src/panel.cpp trunk/client/elvys-client/src/pdfdocument.cpp trunk/client/elvys-client/src/pdfdocument.h trunk/client/elvys-client/src/pdffiller.cpp trunk/client/elvys-client/src/pdffiller.h trunk/client/elvys-client/src/pdfpresentationdocument.cpp trunk/client/elvys-client/src/pdfpresentationdocument.h trunk/client/elvys-client/src/pdfpresentationviewer.cpp trunk/client/elvys-client/src/pdfpresentationviewer.h trunk/client/elvys-client/src/pdfviewer.cpp trunk/client/elvys-client/src/pdfviewer.h trunk/client/elvys-client/src/pdfzoomed.cpp trunk/client/elvys-client/src/pdfzoomed.h trunk/client/elvys-client/src/src.pro trunk/client/elvys-client/src/videodocument.cpp trunk/client/elvys-client/src/videodocument.h Log: merge with pdf-presentation branch Property changes on: trunk/client/elvys-client ___________________________________________________________________ Modified: svn:mergeinfo - /branches/client/elvys-client-tabs:1423-1590 /branches/client/elvys-client-video:1597-1641 + /branches/client/elvys-client-tabs:1423-1590 /branches/client/elvys-client-video:1597-1641 /branches/client/pdf-presentation-branch/elvys-client:1705-1763 /branches/client/pdf-prezentation-branch/elvys-client:1704 Modified: trunk/client/elvys-client/Makefile =================================================================== --- trunk/client/elvys-client/Makefile 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/Makefile 2010-02-17 17:49:36 UTC (rev 1764) @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: elvys-client -# Generated by qmake (2.01a) (Qt 4.5.3) on: Mon Feb 15 21:52:21 2010 +# Generated by qmake (2.01a) (Qt 4.5.3) on: Wed Feb 17 09:52:32 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: trunk/client/elvys-client/bin/appconfig.xml =================================================================== --- trunk/client/elvys-client/bin/appconfig.xml 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/bin/appconfig.xml 2010-02-17 17:49:36 UTC (rev 1764) @@ -2,30 +2,30 @@ <a:app_config elvysVersion="1.0-b1" xmlns:a="cz/elvys/jaxbgen/app"> <a:machine_id>13</a:machine_id> <a:data_url> - <a:http_address>http://elvys.farm.particle.cz/dataIntegrationNew/4</a:http_address> + <a:http_address>http://elvys.farm.particle.xx/dataIntegrationNew/4</a:http_address> </a:data_url> <a:statistics> - <a:http_address>http://elvys.farm.particle.cz:8081/dispatcher/statistic</a:http_address> - <a:period>60000</a:period> + <a:http_address>http://elvys.farm.particle.xx:8081/dispatcher/statistic</a:http_address> + <a:period>100000</a:period> </a:statistics> <a:screenshot> - <a:http_address>http://elvys.farm.particle.cz:8081/dispatcher/img</a:http_address> - <a:period>60000</a:period> + <a:http_address>http://elvys.farm.particle.xx:8081/dispatcher/img</a:http_address> + <a:period>100000</a:period> </a:screenshot> <a:category_config> - <a:http_address>http://elvys.farm.particle.cz:8081/dispatcher/categoryConfig</a:http_address> - <a:period>20000</a:period> + <a:http_address>http://elvys.farm.particle.xx:8081/dispatcher/categoryConfig</a:http_address> + <a:period>100000</a:period> </a:category_config> <a:document_config> - <a:http_address>http://elvys.farm.particle.cz:8081/dispatcher/documentConfig</a:http_address> - <a:period>20000</a:period> + <a:http_address>http://elvys.farm.particle.xx:8081/dispatcher/documentConfig</a:http_address> + <a:period>100000</a:period> </a:document_config> <a:filecache_config> - <a:http_address>http://elvys.farm.particle.cz:8081/dispatcher/filecacheConfig</a:http_address> - <a:period>10000</a:period> + <a:http_address>http://elvys.farm.particle.xx:8081/dispatcher/filecacheConfig</a:http_address> + <a:period>100000</a:period> </a:filecache_config> <a:night_mode enabled="false"/> <a:app_config_source> - <a:http_address>http://elvys.farm.particle.cz:8081/dispatcher/appConfig</a:http_address> + <a:http_address>http://elvys.farm.particle.xx:8081/dispatcher/appConfig</a:http_address> </a:app_config_source> </a:app_config> Property changes on: trunk/client/elvys-client/bin/data ___________________________________________________________________ Deleted: svn:mergeinfo - /branches/client/pdf-presentation-branch/elvys-client/bin/data:1705-1732 /branches/client/pdf-prezentation-branch/elvys-client/bin/data:1704 Modified: trunk/client/elvys-client/bin/data/style.css =================================================================== --- trunk/client/elvys-client/bin/data/style.css 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/bin/data/style.css 2010-02-17 17:49:36 UTC (rev 1764) @@ -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: trunk/client/elvys-client/elvys-client.pro.user =================================================================== --- trunk/client/elvys-client/elvys-client.pro.user 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/elvys-client.pro.user 2010-02-17 17:49:36 UTC (rev 1764) @@ -6,7 +6,7 @@ </data> <data> <variable>RunConfiguration0-Executable</variable> - <value type="QString" >/home/keruom/elvys/trunk/client/elvys-client/bin/elvys-client</value> + <value type="QString" >/home/keruom/elvys/branches/client/pdf-presentation-branch/elvys-client/bin/elvys-client</value> </data> <data> <variable>RunConfiguration0-RunConfiguration.name</variable> @@ -30,7 +30,7 @@ </data> <data> <variable>RunConfiguration0-WorkingDirectory</variable> - <value type="QString" >/home/keruom/elvys/trunk/client/elvys-client/bin</value> + <value type="QString" >/home/keruom/elvys/branches/client/pdf-presentation-branch/elvys-client/bin</value> </data> <data> <variable>RunConfiguration0-type</variable> @@ -52,7 +52,7 @@ <value key="ToolChain" type="int" >0</value> <value key="addQDumper" type="" ></value> <value key="buildConfiguration" type="int" >2</value> - <value key="buildDirectory" type="QString" >/home/keruom/elvys/trunk/client/elvys-client</value> + <value key="buildDirectory" type="QString" >/home/keruom/elvys/branches/client/pdf-presentation-branch/elvys-client</value> </valuemap> </data> <data> @@ -113,7 +113,6 @@ <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> @@ -144,7 +143,7 @@ <value type="QString" >_=/usr/bin/kdeinit4</value> </valuelist> <valuelist key="abstractProcess.arguments" type="QVariantList" > - <value type="QString" >/home/keruom/elvys/trunk/client/elvys-client/elvys-client.pro</value> + <value type="QString" >/home/keruom/elvys/branches/client/pdf-presentation-branch/elvys-client/elvys-client.pro</value> <value type="QString" >-spec</value> <value type="QString" >/usr/share/qt4/mkspecs/linux-g++</value> <value type="QString" >-r</value> @@ -152,7 +151,7 @@ </valuelist> <value key="abstractProcess.command" type="QString" >/usr/bin/qmake</value> <value key="abstractProcess.enabled" type="bool" >false</value> - <value key="abstractProcess.workingDirectory" type="QString" >/home/keruom/elvys/trunk/client/elvys-client</value> + <value key="abstractProcess.workingDirectory" type="QString" >/home/keruom/elvys/branches/client/pdf-presentation-branch/elvys-client</value> <value key="buildConfiguration" type="" ></value> </valuemap> </data> @@ -191,7 +190,6 @@ <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> @@ -227,7 +225,7 @@ </valuelist> <value key="abstractProcess.command" type="QString" >/usr/bin/make</value> <value key="abstractProcess.enabled" type="bool" >true</value> - <value key="abstractProcess.workingDirectory" type="QString" >/home/keruom/elvys/trunk/client/elvys-client</value> + <value key="abstractProcess.workingDirectory" type="QString" >/home/keruom/elvys/branches/client/pdf-presentation-branch/elvys-client</value> </valuemap> </data> <data> @@ -240,8 +238,9 @@ <value type="QString" >CONFIG_PROTECT=/usr/share/X11/xkb /var/lib/hsqldb /usr/share/config</value> <value type="QString" >CONFIG_PROTECT_MASK=/etc/sandbox.d /etc/env.d/java/ /etc/php/cli-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/apache2-php5/ext-active/ /etc/udev/rules.d /etc/fonts/fonts.conf /etc/gconf /etc/terminfo /etc/ca-certificates.conf /etc/texmf/web2c /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/revdep-rebuild</value> <value type="QString" >CVS_RSH=ssh</value> - <value type="QString" >DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-1SoPYY2czp,guid=26aa2cfe5b5382bf987831eb4b56bb12</value> + <value type="QString" >DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-A0hB8LLrnq,guid=2030e7ed54f71619069908f64b74ffdf</value> <value type="QString" >DESKTOP_SESSION=KDE-4</value> + <value type="QString" >DESKTOP_STARTUP_ID=</value> <value type="QString" >DISPLAY=:0.0</value> <value type="QString" >DM_CONTROL=/var/run/xdmctl</value> <value type="QString" >EDITOR=/usr/bin/vim</value> @@ -275,11 +274,11 @@ <value type="QString" >PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.3.4:/usr/qt/3/bin:/usr/libexec/gpc/i686-pc-linux-gnu/3.4:/usr/games/bin</value> <value type="QString" >PWD=/home/keruom</value> <value type="QString" >QMAKESPEC=linux-g++</value> - <value type="QString" >QTDIR=/usr/share/qt4</value> + <value type="QString" >QTDIR=/usr</value> <value type="QString" >QT_PLUGIN_PATH=/home/keruom/.kde4/lib/kde4/plugins/:/usr/lib/kde4/plugins/</value> <value type="QString" >RUBYOPT=-rauto_gem</value> <value type="QString" >R_HOME=/usr/lib/R</value> - <value type="QString" >SESSION_MANAGER=local/LenR61:@/tmp/.ICE-unix/6151,unix/LenR61:/tmp/.ICE-unix/6151</value> + <value type="QString" >SESSION_MANAGER=local/LenR61:@/tmp/.ICE-unix/6926,unix/LenR61:/tmp/.ICE-unix/6926</value> <value type="QString" >SGML_CATALOG_FILES=/etc/sgml/sgml-lite.cat:/etc/sgml/openjade-1.3.2.cat:/etc/sgml/dsssl-docbook-stylesheets.cat:/etc/sgml/sgml-docbook.cat:/etc/sgml/sgml-docbook-3.1.cat:/etc/sgml/sgml-ent.cat</value> <value type="QString" >SHELL=/bin/bash</value> <value type="QString" >SHLVL=1</value> @@ -290,7 +289,7 @@ <value type="QString" >XCURSOR_THEME=Oxygen_Black</value> <value type="QString" >XDG_CONFIG_DIRS=/etc/xdg</value> <value type="QString" >XDG_DATA_DIRS=/usr/share:/usr/local/share:/usr/share</value> - <value type="QString" >XDG_SESSION_COOKIE=d9adc4154425c11fe992e29e4870ae75-1263975186.463903-863096380</value> + <value type="QString" >XDG_SESSION_COOKIE=d9adc4154425c11fe992e29e4870ae75-1265958879.158627-1510381767</value> <value type="QString" >XDM_MANAGED=method=classic</value> <value type="QString" >_=/usr/bin/kdeinit4</value> </valuelist> @@ -301,7 +300,7 @@ </valuelist> <value key="abstractProcess.command" type="QString" >/usr/bin/make</value> <value key="abstractProcess.enabled" type="bool" >true</value> - <value key="abstractProcess.workingDirectory" type="QString" >/home/keruom/elvys/trunk/client/elvys-client</value> + <value key="abstractProcess.workingDirectory" type="QString" >/home/keruom/elvys/branches/client/pdf-presentation-branch/elvys-client</value> <value key="cleanConfig" type="bool" >true</value> <valuelist key="makeargs" type="QVariantList" > <value type="QString" >clean</value> Property changes on: trunk/client/elvys-client/src ___________________________________________________________________ Deleted: svn:mergeinfo - /branches/client/pdf-presentation-branch/elvys-client/src:1705-1727 /branches/client/pdf-prezentation-branch/elvys-client/src:1704 Modified: trunk/client/elvys-client/src/Makefile =================================================================== --- trunk/client/elvys-client/src/Makefile 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/Makefile 2010-02-17 17:49:36 UTC (rev 1764) @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: ../bin/elvys-client -# Generated by qmake (2.01a) (Qt 4.5.3) on: Mon Feb 15 21:52:21 2010 +# Generated by qmake (2.01a) (Qt 4.5.3) on: Wed Feb 17 09:52:32 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: trunk/client/elvys-client/src/category.cpp =================================================================== --- trunk/client/elvys-client/src/category.cpp 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/category.cpp 2010-02-17 17:49:36 UTC (rev 1764) @@ -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); } Modified: trunk/client/elvys-client/src/document.h =================================================================== --- trunk/client/elvys-client/src/document.h 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/document.h 2010-02-17 17:49:36 UTC (rev 1764) @@ -59,14 +59,22 @@ virtual bool isZoomable() { return _zoomable; }; //vraci jestli je dokument zvetseny nebo neni virtual void setZoomable(bool zoomable) { _zoomable = zoomable; }; + virtual void setNormalGeometry(QRect rect) { + _normalGeometry = rect; + if (! _zoomed) { + setGeometry(rect); + } + } + protected: virtual void resizeEvent ( QResizeEvent * event ) {Q_UNUSED(event)}; virtual void hideEvent(QHideEvent * event) { Q_UNUSED(event)}; virtual void showEvent(QShowEvent * event) { Q_UNUSED(event)}; QString _name; // name of document QRectF _rectF; //relative dimensions of document + QRect _normalGeometry; bool _zoomed; bool _zoomable; }; Modified: trunk/client/elvys-client/src/main.cpp =================================================================== --- trunk/client/elvys-client/src/main.cpp 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/main.cpp 2010-02-17 17:49:36 UTC (rev 1764) @@ -76,9 +76,9 @@ // Saver * saver = new Saver(); // saver->setWidget(&elvys); - elvys.showFullScreen(); -// elvys.setGeometry(0,0,400,300); -// elvys.show(); + //elvys.showFullScreen(); + elvys.setGeometry(0,0,400,300); + elvys.show(); return app.exec(); // QObject::connect(&timer, SIGNAL(timeout()), saver, SLOT(render())); Modified: trunk/client/elvys-client/src/panel.cpp =================================================================== --- trunk/client/elvys-client/src/panel.cpp 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/panel.cpp 2010-02-17 17:49:36 UTC (rev 1764) @@ -166,7 +166,8 @@ y = rectF.y() * height(); w = rectF.width() * width(); h = rectF.height() * height(); - document->setGeometry(x,y,w,h); + QRect rect(x,y,w,h); + document->setNormalGeometry(rect); } } Copied: trunk/client/elvys-client/src/pdfcommonviewer.cpp (from rev 1763, branches/client/pdf-presentation-branch/elvys-client/src/pdfcommonviewer.cpp) =================================================================== --- trunk/client/elvys-client/src/pdfcommonviewer.cpp (rev 0) +++ trunk/client/elvys-client/src/pdfcommonviewer.cpp 2010-02-17 17:49:36 UTC (rev 1764) @@ -0,0 +1,192 @@ +#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; + _normalGeometry = rect; + + alpha = 0; + zoomed = false; + zoomable = true; + toBeZoomed = false; + + timeOpened = 0; + + setGeometry(_normalGeometry); + + 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 PDFCommonViewer::setNormalGeometry(QRect rect) { + _normalGeometry = rect; + if ( ! zoomed ) { + setGeometry(_normalGeometry); + } +} + +/** Class destructor */ + +PDFCommonViewer::~PDFCommonViewer() { +} + + +/** sets geometry of whole zoomed document, height is sum of height of all pages. + @arg width width to be set + @arg height height to be set - sum of heigh of all pages. + */ + +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(); +} + + Copied: trunk/client/elvys-client/src/pdfcommonviewer.h (from rev 1763, branches/client/pdf-presentation-branch/elvys-client/src/pdfcommonviewer.h) =================================================================== --- trunk/client/elvys-client/src/pdfcommonviewer.h (rev 0) +++ trunk/client/elvys-client/src/pdfcommonviewer.h 2010-02-17 17:49:36 UTC (rev 1764) @@ -0,0 +1,81 @@ +#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(); + void setNormalGeometry(QRect rect); + 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 _normalGeometry; + 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: trunk/client/elvys-client/src/pdfdocument.cpp =================================================================== --- trunk/client/elvys-client/src/pdfdocument.cpp 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/pdfdocument.cpp 2010-02-17 17:49:36 UTC (rev 1764) @@ -29,29 +29,34 @@ docId = _docId; mainPage = 0; + _scaleFactor = 1; 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 ))); connect(pdfFiller, SIGNAL(requestPages()), this, SLOT(setPages())); - connect(pdfFiller, SIGNAL(zoomedSize(int, int)), pdfZoomed, SLOT(setZoomedSize(int, int))); + connect(pdfFiller, SIGNAL(zoomedSize(int, int)), pdfZoomed, SLOT(setPagesRect(int,int))); connect(pdfFiller, SIGNAL(zoomedSize(int, int)), pdfViewer, SLOT(setZoomedSize(int, int))); connect(pdfFiller, SIGNAL(pageLoaded(PageSelector , PDFPage *)), pdfViewer, SLOT(pageReady(PageSelector , PDFPage *))); //connect(pdfFiller, SIGNAL(zoomChanged(bool)), pdfViewer, SLOT(allowZoom(bool))); connect(pdfViewer, SIGNAL(scale(double)), pdfZoomed, SLOT(scale(double))); + connect(pdfViewer, SIGNAL(scale(double)), this, SLOT(scale(double))); + connect(pdfViewer, SIGNAL(getPage(int, QSize, QString)), pdfFiller, SLOT(loadPage(int, QSize, QString))); connect(pdfZoomed, SIGNAL(getPage(int, QSize, QString)), pdfFiller, SLOT(loadPage(int, QSize, QString))); connect(pdfFiller, SIGNAL(pageLoaded(PageSelector , PDFPage *)), pdfZoomed, SLOT(pageReady(PageSelector , PDFPage *))); connect(pdfFiller, SIGNAL(pageDimension(int,int,int)), pdfZoomed, SLOT(setPageDimension(int, int, int))); + connect(pdfFiller, SIGNAL(pageDimension(int,int,int)), pdfViewer, SLOT(setPageDimension(int, int, int))); // event oriented connects connect(pdfViewer, SIGNAL(zoomEvent()), this, SLOT(zoomEventHandler())); connect(pdfViewer, SIGNAL(unZoomEvent()), this, SLOT(unZoomEventHandler())); + connect(pdfZoomed, SIGNAL(getAllPagesDimensions(int, int)), pdfFiller, SLOT(updatePageSizesZoomed(int,int))); connect(pdfFiller, SIGNAL(badPDF(QString )), this, SLOT(handleBadPDF(QString ))); connect(pdfViewer, SIGNAL(imageGenerated(PageSelector)), pdfFiller, SLOT(cachePage(PageSelector))); @@ -82,7 +87,8 @@ bool retval; retval = pdfFiller->setPages(pages, mainPage); - pdfZoomed->setPages(pages); + pdfViewer->setPages(pages); + pdfZoomed->setPages(pages); if ( retval) { @@ -200,10 +206,20 @@ int offset = 2 * area.frameWidth(); pdfFiller->clear(); - pdfFiller->updatePageSizes(width(), height(), AppConfig::getInstance()->getZoomWidth(parentWidget()),AppConfig::getInstance()->getZoomHeight(parentWidget()) -offset); + pdfFiller->updatePageSizes(width(), height(), AppConfig::getInstance()->getZoomWidth(parentWidget()) * _scaleFactor, + AppConfig::getInstance()->getZoomHeight(parentWidget()) * _scaleFactor - offset); pdfViewer->setGeometry(geometry()); } +void PDFDocument::scale(double factor) { + QScrollArea area; + int offset = 2 * area.frameWidth(); + _scaleFactor *= factor; + + pdfFiller->updatePageSizesZoomed(AppConfig::getInstance()->getZoomWidth(parentWidget()) * _scaleFactor, + AppConfig::getInstance()->getZoomHeight(parentWidget()) * _scaleFactor - offset); +} + void PDFDocument::hideEvent(QHideEvent * event) { Q_UNUSED(event); Modified: trunk/client/elvys-client/src/pdfdocument.h =================================================================== --- trunk/client/elvys-client/src/pdfdocument.h 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/pdfdocument.h 2010-02-17 17:49:36 UTC (rev 1764) @@ -27,6 +27,7 @@ public slots: virtual void load(QString name); void load(QString _name, int _docId); + void scale(double factor); void reLoad(); void zoomEventHandler(); void unZoomEventHandler(); @@ -64,6 +65,7 @@ QList<int> pages; int mainPage; int docId; + double _scaleFactor; QMutex imgMtx; QMutex mtx; }; Modified: trunk/client/elvys-client/src/pdffiller.cpp =================================================================== --- trunk/client/elvys-client/src/pdffiller.cpp 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/pdffiller.cpp 2010-02-17 17:49:36 UTC (rev 1764) @@ -40,7 +40,8 @@ /** * Class desctructor. Waits for all threads to die. */ -PDFFiller::~PDFFiller() { + +PDFFiller::~PDFFiller() { quit = true; condition.wakeAll(); wait(); @@ -51,8 +52,7 @@ if (pageNormal) { delete pageNormal; } - cache.clear(); - //qDebug() << "pdffiller deleted"; + cache.clear(); } @@ -456,26 +456,27 @@ return false; } - //silly waiting for pdf to get ready - while (restart || pdf == NULL ) { //wait for initialization - if ( ! ready ) { + //silly waiting for pdf to get ready + mutexPDF.lock(); + mutexCond.lock(); + if (restart || pdf == NULL ) { //wait for initialization + mutexCond.unlock(); + mutexPDF.unlock(); mutexPages->unlock(); - return false; - } + return false; } + mutexCond.unlock(); - mutexPDF.lock(); numPages = pdfGetNumPages(pdf); - mutexPDF.unlock(); + mutexPDF.unlock(); + // new page numbers - // new page numbers4 - pages.clear(); for (int i = 0; i < _pages.size(); ++i) { if ( _pages[i] <= numPages ) { pages.insert(i, _pages[i]); } else { - qWarning() << "Trying to set up page no." << _pages[i] << ", but document " << filename << "doesn't contain"; + qWarning() << "Trying to set up page no." << _pages[i] << ", but document " << filename << "doesn't contain it"; } } if ( _mainPage <= numPages ) { @@ -514,13 +515,49 @@ * pages in document */ void PDFFiller::updatePageSizes(int w, int h, int zoomedW, int zoomedH) { - int sumZoomedHeight = 0; + updatePageSizesNormal(w, h); + updatePageSizesZoomed(zoomedW, zoomedH); +} + +void PDFFiller::updatePageSizesNormal(int w, int h) { int maxWidth = 0; int maxHeight = 0; + int docW; + int docH; + double docW72, docH72; + double dpi; + + while (restart || pdf == NULL ) { //wait for initialization + if ( ! ready ) { + return; + } + } + + mutexPDF.lock(); + + for (int i = 0; i < pages.size(); ++i) { + docW72 = pdfGetPageWidth(pdf, pages[i]); + docH72 = pdfGetPageHeight(pdf, pages[i]); + normalizeDimensions(docW72, docH72, w, h, docW, docH, dpi); + + if (docW > maxWidth) { + maxWidth = docW; + } + if (docH > maxHeight) { + maxHeight = docH; + } + } + mutexPDF.unlock(); + + emit sizeRect(maxWidth, maxHeight); +} + +void PDFFiller::updatePageSizesZoomed(int zoomedW, int zoomedH) { + int sumZoomedHeight = 0; int maxZoomedWidth = 0; int maxZoomedHeight = 0; - int docZoomedW, docW; - int docZoomedH, docH; + int docZoomedW; + int docZoomedH; double docW72, docH72; double dpi; @@ -535,38 +572,28 @@ for (int i = 0; i < pages.size(); ++i) { docW72 = pdfGetPageWidth(pdf, pages[i]); docH72 = pdfGetPageHeight(pdf, pages[i]); - normalizeDimensions(docW72, docH72, zoomedW, zoomedH, docZoomedW, docZoomedH, dpi); - normalizeDimensions(docW72, docH72, w, h, docW, docH, dpi); + normalizeDimensions(docW72, docH72, zoomedW, zoomedH, docZoomedW, docZoomedH, 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, docZoomedW, docZoomedH); } mutexPDF.unlock(); - emit zoomedSize(maxZoomedWidth, sumZoomedHeight + SEP_HEIGHT*(pages.size()-1)); + emit zoomedSize(maxZoomedWidth, sumZoomedHeight); emit zoomedSizeRect(maxZoomedWidth, maxZoomedHeight); - emit sizeRect(maxWidth, maxHeight); } - /** * Closes current document and clears cache. */ -void PDFFiller::close() { - ready = false; +void PDFFiller::close() { mutexCond.lock(); //while it is rendering @@ -592,10 +619,12 @@ cache.clear(); pages.clear(); mutexPages->unlock(); + mutexPDF.lock(); if ( pdf ) { pdfFree(pdf); } pdf = NULL; + mutexPDF.unlock(); } /** Modified: trunk/client/elvys-client/src/pdffiller.h =================================================================== --- trunk/client/elvys-client/src/pdffiller.h 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/pdffiller.h 2010-02-17 17:49:36 UTC (rev 1764) @@ -55,8 +55,11 @@ void requestPages(); public slots: - void loadPage(int pageNum, QSize size, QString desc); + void loadPage(int pageNum, QSize size, QString desc); void cachePage(PageSelector selector); + void updatePageSizes(int w, int h, int zoomedW, int zoomedH); + void updatePageSizesNormal(int w, int h); + void updatePageSizesZoomed(int zoomedW, int zoomedH); public: @@ -65,7 +68,6 @@ ~PDFFiller(); void load(QString name); bool setPages(QList <int> & _pages, int _mainPage); - void updatePageSizes(int w, int h, int zoomedW, int zoomedH); bool makeInit(); void clear(); void close(); Modified: trunk/client/elvys-client/src/pdfpresentationdocument.cpp =================================================================== --- trunk/client/elvys-client/src/pdfpresentationdocument.cpp 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/pdfpresentationdocument.cpp 2010-02-17 17:49:36 UTC (rev 1764) @@ -165,14 +165,31 @@ } void PDFPresentationDocument::resizeEvent(QResizeEvent *event) { - Q_UNUSED(event); + Q_UNUSED(event); pdfFiller->clear(); pdfFiller->updatePageSizes(width(), height(), AppConfig::getInstance()->getZoomWidth(parentWidget()),AppConfig::getInstance()->getZoomHeight(parentWidget())); - pdfPresViewer->setGeometry(geometry()); + + pdfPresViewer->setNormalGeometry(_normalGeometry); + if ( ! pdfPresViewer->isZoomed() ) { + pdfPresViewer->setGeometry(_normalGeometry); + } + + } +void PDFPresentationDocument::showEvent(QShowEvent * event) { + Q_UNUSED(event); + + pdfPresViewer->setAcceptingPages(true); + pdfPresViewer->setAutoRotating(true); +} + + void PDFPresentationDocument::hideEvent(QHideEvent * event) { + Q_UNUSED(event); + + pdfPresViewer->setAcceptingPages(false); pdfPresViewer->setAutoRotating(false); pdfFiller->clearCache(); } Modified: trunk/client/elvys-client/src/pdfpresentationdocument.h =================================================================== --- trunk/client/elvys-client/src/pdfpresentationdocument.h 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/pdfpresentationdocument.h 2010-02-17 17:49:36 UTC (rev 1764) @@ -43,6 +43,7 @@ protected: virtual void resizeEvent(QResizeEvent * event); virtual void hideEvent(QHideEvent *event); + virtual void showEvent(QShowEvent * event); private: PDFPresentationViewer * pdfPresViewer; Modified: trunk/client/elvys-client/src/pdfpresentationviewer.cpp =================================================================== --- trunk/client/elvys-client/src/pdfpresentationviewer.cpp 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/pdfpresentationviewer.cpp 2010-02-17 17:49:36 UTC (rev 1764) @@ -1,67 +1,35 @@ -#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) { - closed = false; - 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() { - closed = true; + _acceptingPages = false; + qWarning() << "pdfpresviewer closed"; + if (nextTimer.isActive()) { nextTimer.stop(); } @@ -73,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; @@ -98,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. */ @@ -222,7 +180,7 @@ QPixmap myPixmap; QString key; - if (closed) { + if ( ! _acceptingPages) { return; } @@ -277,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. @@ -343,7 +296,7 @@ int overlap = 0; QWidget * parW = parentWidget(); - int centerX = origSize.x() + origSize.width() / 2; ///< center of my widget + int centerX = _normalGeometry.x() + _normalGeometry.width() / 2; ///< center of my widget int zoomWHalf = zoomW / 2; ///< half width of zoomed image if ( (overlap = (centerX + zoomWHalf) - parW->width()) > 0 ) { // it wouldnt fit the screen! Move left @@ -356,10 +309,10 @@ newX = centerX - zoomWHalf; } - if ( (origSize.y() + AppConfig::getInstance()->getZoomHeight(parW)) > parW->height() ) { + if ( (_normalGeometry.y() + AppConfig::getInstance()->getZoomHeight(parW)) > parW->height() ) { newY = 0; } else { - newY = origSize.y(); + newY = _normalGeometry.y(); } if (zoomH < AppConfig::getInstance()->getZoomHeight(parW) ) { @@ -380,9 +333,9 @@ void PDFPresentationViewer::showPDF() { setPixmap(currentPixmap); - alfa = 0; + alpha = 0; if ( ! zoomed) { - move(origSize.center().x() - w/2, origSize.center().y() -h/2); + move(_normalGeometry.center().x() - w/2, _normalGeometry.center().y() -h/2); setGeometry(x(), y(), w, h); } @@ -439,50 +392,50 @@ } } -/** 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; - setGeometry(origSize); + manageAutoRotating(); + setGeometry(_normalGeometry); getCurrentPage(); setBorderFocused(); } @@ -493,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); @@ -534,29 +488,12 @@ } } -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); if (! zoomed ) { // I might get called in zoomed state - - origSize = geometry(); + setBorderFocused(); + _normalGeometry = geometry(); } getNextPage(); @@ -585,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(); @@ -628,8 +536,8 @@ void PDFPresentationViewer::paintEvent(QPaintEvent * event) { if (inPageTransition) { - if (alfa >= 255) { - alfa = 255; + if (alpha >= 255) { + alpha = 255; } if ( pixmap() != NULL) { @@ -649,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); @@ -680,29 +588,3 @@ int PDFPresentationViewer::period() { return _period; } - -void PDFPresentationViewer::close() { - closed = true; - zoomable = false; - setPixmap(NULL); - setFocusPolicy(Qt::NoFocus); - clearFocus(); - update(); -} - -void PDFPresentationViewer::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: trunk/client/elvys-client/src/pdfpresentationviewer.h =================================================================== --- trunk/client/elvys-client/src/pdfpresentationviewer.h 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/pdfpresentationviewer.h 2010-02-17 17:49:36 UTC (rev 1764) @@ -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,55 +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); + 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(); @@ -81,55 +60,36 @@ 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 inPageTransition; - bool closed; + int _period; + bool _autoRotating; + bool inPageTransition; ElvysNs::Position pageMovement; QList<ElvysNs::Position> pageChanges; 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: trunk/client/elvys-client/src/pdfviewer.cpp =================================================================== --- trunk/client/elvys-client/src/pdfviewer.cpp 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/pdfviewer.cpp 2010-02-17 17:49:36 UTC (rev 1764) @@ -1,69 +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()); -} - void PDFViewer::getFirstPageBig() { QSize zoomSize(zoomW, zoomH); @@ -79,14 +43,14 @@ return; } - if (closed) { + if ( ! _acceptingPages) { 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 fails here + myPixmap = QPixmap::fromImage(*page->getImage()); emit imageGenerationFinished(); emit imageGenerated(selector); @@ -109,15 +73,16 @@ } } -void PDFViewer::setZoomedSize(int width, int height) { - zoomW = width; - zoomH = height; -} +/** Returns geometry for scroll area, when in zoomed mode and scale == 1. It makes sure that whole first page is visible, if it is possible. + @return geometry for scroll area + */ + QRect PDFViewer::getScrollGeometry() { int newX; int newY; + int myZoomW; int overlap = 0; QWidget * parW = parentWidget(); QScrollArea area; @@ -146,13 +111,20 @@ scrollAreaOffsetWidth = scrollAreaOffsetVisibleWidth; if (zoomW + scrollAreaOffsetVisibleWidth > AppConfig::getInstance()->getZoomWidth(parW)) { //there will be horizontal scrollbar for sure scrollAreaOffsetHeight = scrollAreaOffsetVisibleHeight; - } + } } - } + } + + if (zoomW - scrollAreaOffsetVisibleWidth > parentWidget()->width()) { // zoomed area is wider then maximum + myZoomW = parentWidget()->width() - scrollAreaOffsetWidth; + } else { + myZoomW = zoomW; + } - int centerX = origSize.x() + origSize.width() / 2; ///< center of my widget - int zoomWHalf = zoomW / 2; ///< half width of zoomed image + int centerX = _normalGeometry.x() + _normalGeometry.width() / 2; ///< center of my widget + int zoomWHalf = myZoomW / 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 @@ -163,16 +135,16 @@ newX = centerX - zoomWHalf; } - if ( (origSize.y() + AppConfig::getInstance()->getZoomHeight(parW)) + scrollAreaOffsetHeight > parW->height() ) { + if ( (_normalGeometry.y() + AppConfig::getInstance()->getZoomHeight(parW)) + scrollAreaOffsetHeight > parW->height() ) { newY = 0; } else { - newY = origSize.y(); + newY = _normalGeometry.y(); } if (zoomH + scrollAreaOffsetHeight < AppConfig::getInstance()->getZoomHeight(parW) ) { - return QRect(newX, newY, zoomW + scrollAreaOffsetWidth, zoomH + scrollAreaOffsetHeight); + return QRect(newX, newY, myZoomW + scrollAreaOffsetWidth, zoomH + scrollAreaOffsetHeight); } else { - return QRect(newX, newY, zoomW + scrollAreaOffsetWidth, AppConfig::getInstance()->getZoomHeight(parW)); + return QRect(newX, newY, myZoomW + scrollAreaOffsetWidth, AppConfig::getInstance()->getZoomHeight(parW)); } } @@ -188,9 +160,11 @@ if (zoomed) { // zoomed image rect = getScrollGeometry(); scroll = new QScrollArea(parentWidget()); - scroll->setAlignment(Qt::AlignCenter); + scroll->setAlignment(Qt::AlignCenter); scroll->setGeometry(rect); - scroll->setWidget(pdfZoomed); + scroll->setWidget(pdfZoomed); + scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); scroll->verticalScrollBar()->setSingleStep(AppConfig::getInstance()->getAppHeight() / 10); scroll->verticalScrollBar()->setPageStep(rect.height()); scroll->horizontalScrollBar()->setSingleStep(AppConfig::getInstance()->getAppWidth() / 10); @@ -202,7 +176,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. @@ -211,7 +185,7 @@ delete scroll; scroll = NULL; } - move(origSize.center() - myPixmap.rect().center()); + move(_normalGeometry.center() - myPixmap.rect().center()); setGeometry(x(), y(),myPixmap.width(), myPixmap.height()); } update(); @@ -250,23 +224,23 @@ break; case Qt::Key_Left: if ( scaled == 0 ) { - scroll->verticalScrollBar()->setValue(value - scroll->verticalScrollBar()->pageStep() - SEP_HEIGHT); + scrollByOnePage(ElvysNs::Up); } else { scroll->horizontalScrollBar()->triggerAction(QScrollBar::SliderSingleStepSub); } break; case Qt::Key_PageUp: - scroll->verticalScrollBar()->setValue(value - scroll->verticalScrollBar()->pageStep() - SEP_HEIGHT); + scrollByOnePage(ElvysNs::Up); break; case Qt::Key_Right: if ( scaled == 0 ) { - scroll->verticalScrollBar()->setValue(value + scroll->verticalScrollBar()->pageStep() + SEP_HEIGHT); + scrollByOnePage(ElvysNs::Down); } else { scroll->horizontalScrollBar()->triggerAction(QScrollBar::SliderSingleStepAdd); } break; case Qt::Key_PageDown: - scroll->verticalScrollBar()->setValue(value + scroll->verticalScrollBar()->pageStep() + SEP_HEIGHT); + scrollByOnePage(ElvysNs::Down); break; case Qt::Key_Return: zoom(); @@ -281,17 +255,100 @@ } } -void PDFViewer::adjustScrollBar(QScrollBar * scrollBar, double factor) { - scrollBar->setValue(int(factor * scrollBar->value() + ((factor - 1) * scrollBar->pageStep()/2))); + +/** Scrolls down in such a way that a next page will be in the top of the zoomed area. It does nothing + if not zoomed. + + @arg direction direction in which scrolling should occur. Only left and right are applicable. + */ + +void PDFViewer::scrollByOnePage(ElvysNs::Direction direction) { + int curY; + int nextY; + int curPage; + bool aligned; + + if ( ! zoomed || scroll == NULL) { + return; + } + + curY = scroll->verticalScrollBar()->value(); + + curPage = pdfZoomed->whichPage(curY, aligned); + + mtx.lock(); + + if ( lengths.size() == curPage + 1 && direction == ElvysNs::Down) { // I am already at the last page + nextY = pdfZoomed->pageTop(curPage) - pdfZoomed->pageHeight(curPage); + scroll->verticalScrollBar()->setValue(nextY); + mtx.unlock(); + return; + } + + if ( curPage == 0 && direction == ElvysNs::Up) { // I am on already at the first page + nextY = pdfZoomed->pageTop(curPage) - pdfZoomed->pageHeight(curPage); + scroll->verticalScrollBar()->setValue(nextY); + mtx.unlock(); + return; + } + + if ( lengths.size() <= curPage ) { + qWarning() << "Cannot properly scroll the zoomed area as I am not aware of page" << curPage << "dimensions. Falling back to default."; + + if (direction == ElvysNs::Up) { + scroll->verticalScrollBar()->triggerAction(QScrollBar::SliderPageStepSub); + } else if ( direction == ElvysNs::Down ) { + scroll->verticalScrollBar()->triggerAction(QScrollBar::SliderPageStepAdd); + } + + mtx.unlock(); + return; + } + + if (direction == ElvysNs::Up) { + if (aligned) { + nextY = pdfZoomed->pageTop(curPage-1); + scroll->verticalScrollBar()->setValue(nextY); + } else { + nextY = pdfZoomed->pageTop(curPage); + scroll->verticalScrollBar()->setValue(nextY); + } + } else if ( direction == ElvysNs::Down) { + nextY = pdfZoomed->pageTop(curPage+1); + scroll->verticalScrollBar()->setValue(nextY); + } + + mtx.unlock(); } +/** Adjusts given @a scrollBar by @a factor. This is usefull when content of scroll area is zoomed. This function + makes sure that the same visible content will be displayed. + @arg scrollBar scrollBar to be adjusted + @arg factor by which is content zoomed + @return value that was set to scrollBar + */ + +int PDFViewer::adjustScrollBar(QScrollBar * scrollBar, double factor) { + int value = int(factor * scrollBar->value() + ((factor - 1) * scrollBar->pageStep()/2)); + + scrollBar->setValue(value); + return value; +} + void PDFViewer::unzoom() { + int val1, val2; + if ( zoomed ) { if ( scaled != 0 ) { + val1 = adjustScrollBar(scroll->verticalScrollBar(), 1.0/SCALE_FACTOR); + val2 = adjustScrollBar(scroll->horizontalScrollBar(), 1.0/SCALE_FACTOR); emit scale(1.0/SCALE_FACTOR); - adjustScrollBar(scroll->verticalScrollBar(), 1.0/SCALE_FACTOR); - adjustScrollBar(scroll->horizontalScrollBar(), 1.0/SCALE_FACTOR); + //scaling could move the bars out, so make sure they are in correct position. + scroll->verticalScrollBar()->setValue(val1); + scroll->horizontalScrollBar()->setValue(val2); scaled--; + QRect rect = getScrollGeometry(); + scroll->setGeometry(rect); } else { if (fadeEffect.isActive()) { stopFadeEffect(); @@ -306,11 +363,18 @@ } } +void PDFViewer::debug(int aa) { + qDebug() << aa; +} + void PDFViewer::zoom() { + int val1, val2; + double factor; + if (pdfZoomed == NULL ) { //qDebug() << "Nemuzu zvetsovat, neni nastaveny widget PDFZoomed" ; return; - } + } if ( ! zoomed ) { if ( ! zoomable ) { @@ -321,16 +385,24 @@ closeWatcher.start(1000); toBeZoomed = true; getFirstPageBig(); - } else { - if ( scaled >= SCALE_MAX ) { // do not allow to zoom too much (SCALE_FACTOR^5) + } else { + if ( scaled >= SCALE_MAX ) { // do not allow to zoom too much return; } + scaled++; - emit scale(SCALE_FACTOR); - //qDebug() << "vertical slider poss:" << scroll->verticalScrollBar()->sliderPosition(); + //let's take care of image position - we will try to keep focus on the middle of an image - adjustScrollBar(scroll->verticalScrollBar(), SCALE_FACTOR); - adjustScrollBar(scroll->horizontalScrollBar(), SCALE_FACTOR); + val1 = adjustScrollBar(scroll->verticalScrollBar(), SCALE_FACTOR); + val2 = adjustScrollBar(scroll->horizontalScrollBar(), SCALE_FACTOR); + //connect(scroll->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(debug(int))); + emit scale(SCALE_FACTOR); + //scaling could move the bars out, so make sure they are in correct position. + scroll->verticalScrollBar()->setValue(val1); + scroll->horizontalScrollBar()->setValue(val2); + + QRect rect = getScrollGeometry(); + scroll->setGeometry(rect); } } @@ -343,28 +415,12 @@ } } -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); if (! zoomed ) { // I might get called in zoomed state - origSize = geometry(); + _normalGeometry = geometry(); + setBorderFocused(); } if (scroll) { scroll->setGeometry(getScrollGeometry()); @@ -394,6 +450,7 @@ } PDFViewer::~PDFViewer() { + _acceptingPages = false; setVisible(false); if (scroll != NULL) { delete scroll; @@ -402,51 +459,108 @@ closeWatcher.stop(); } +void PDFViewer::stopFadeEffect() { + if (fadeEffect.isActive()) { + fadeEffect.stop(); + setGeometry(myGeometry); //restore geometry of small first page + } + if (scroll) { + scroll->raise(); + } +} +/** Sets list of pages to display. + * @param _pageNumbers list of pages + */ -void PDFViewer::doFadeEffect() { -// if ( alfa < 240 ) { - alfa += 15; -// } else { -// alfa += 3; -// } - update(); -} +void PDFViewer::setPages(QList<int> & _pageNumbers) { + bool same = true; + Page page; -void PDFViewer::closeEnlargement() { - if ( timeOpened >= AppConfig::getInstance()->getDocumentTimeOut() ) { - unzoom(); + // do we have the same list, so no change is needed? + if (pages.size() < _pageNumbers.size()) { + same = false; } else { - timeOpened++; + for (int i = 0; i < _pageNumbers.size(); ++i) { + if ( pages.at(i).num != _pageNumbers[i]) { + same = false; + //qDebug() << "Nestejne cisla stranek"; + break; + } + } } -} -/** Enables or disables zooming - @arg _zoomable true if zooming should be enabled, false otherwise - */ + if (same) { + //qDebug() << "Stejne cisla stranek"; + return; + } -void PDFViewer::setZoomable(bool _zoomable) { - zoomable = _zoomable; + pages.clear(); + + page.h = 0; + page.w = 0; + + for (int i = 0; i < _pageNumbers.size(); ++i) { + page.num = _pageNumbers[i]; + pages.insert(i,page); + } } -/** Returns true if widget is zoomed, false otherwise; - @return returns true if widget is zoomed, false otherwise; + +/** Updates lenghts array. This function doesnt NOT lock anything, it is up to caller to handle it. + * This function can potentionally fail due to the lack of information (you cannot determine y position of + * end of page no.i if you don't have same information for all pages before). + * @param page number + * @return true if updated successfully, or false if not */ -bool PDFViewer::isZoomed() { - return zoomed; -} +bool PDFViewer::updateLengths(int page) { + while (page >= lengths.size()) { //make sure our array is long enough so we can use [] operator to assign + if (lengths.size() != 0 ) { + lengths.resize(2*lengths.size()); + } else { + lengths.resize(100); + } + } -void PDFViewer::stopFadeEffect() { - if (fadeEffect.isActive()) { - fadeEffect.stop(); - setGeometry(myGeometry); //restore geometry of small first page + if (page < 0 ) { + return false; + } else if ( page == 0) { + lengths[0] = pages[page].h; + return true; } - if (scroll) { - scroll->raise(); + + + if (lengths.value(page-1, 0) == 0) { + if ( ! updateLengths(page-1)) { + return false; + } + } else { + lengths[page] = (lengths[page-1] + SEP_HEIGHT + pages[page].h); + return true; } + return true; } + +/** Sets dimension of page. + @param page page number + @param w width of page + @param h height of page + */ + +void PDFViewer::setPageDimension(int page, int w, int h) { + mtx.lock(); + + Q_ASSERT (page < pages.size()); //make sure that we are not out of bounds, ie. pages was set before this call + + pages[page].w = w; + pages[page].h = h; + updateLengths(page); + mtx.unlock(); +} + + void PDFViewer::paintEvent(QPaintEvent * event) { Q_UNUSED(event); @@ -457,7 +571,7 @@ } QLabel::paintEvent(event); } else { - if (alfa >= 255 ) { + if (alpha >= 255 ) { stopFadeEffect(); scroll->show(); @@ -469,36 +583,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: trunk/client/elvys-client/src/pdfviewer.h =================================================================== --- trunk/client/elvys-client/src/pdfviewer.h 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/pdfviewer.h 2010-02-17 17:49:36 UTC (rev 1764) @@ -1,59 +1,43 @@ #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" +namespace ElvysNs { + enum Direction{ Left, Right, Up, Down}; +} + /** 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); + void setPageDimension(int page, int w, int h); + void debug(int aa); - private slots: - void doFadeEffect(); - void closeEnlargement(); - public: - PDFViewer(QWidget * parent, int _x, int _y, int _w, int _h); //inicializuju dedene promene - void setPDFZoomed(PDFZoomed * _pdfZoomed); + PDFViewer(QWidget * parent, const QRect & rect); //inicializuju dedene promene + void setPDFZoomed(PDFZoomed * _pdfZoomed); + void setPages(QList <int> & _pageNumbers); 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 +47,30 @@ virtual void focusOutEvent ( QFocusEvent * event ); private: - void stopFadeEffect(); + bool updateLengths(int page); + 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); - void adjustScrollBar(QScrollBar * scrollBar, double factor); + QRect getScrollGeometry(); + virtual void zoom(); + virtual void unzoom(); + virtual void showPDF(); + int adjustScrollBar(QScrollBar * scrollBar, double factor); + void scrollByOnePage(ElvysNs::Direction); - 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; + QMutex mtx; + QVector<Page> pages; + QVector<int> lengths; ///< vector of y-point of page's ends }; #endif Modified: trunk/client/elvys-client/src/pdfzoomed.cpp =================================================================== --- trunk/client/elvys-client/src/pdfzoomed.cpp 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/pdfzoomed.cpp 2010-02-17 17:49:36 UTC (rev 1764) @@ -20,7 +20,8 @@ /** Contructor. */ -PDFZoomed::PDFZoomed() { +PDFZoomed::PDFZoomed() { + sepHeight = SEP_HEIGHT; scaleI = 1000; scaleD = (double)scaleI/1000.0L; keyBase = "PDFZOOMED"; @@ -55,11 +56,29 @@ void PDFZoomed::scale(double scaleFactor) { scaleI = round(scaleI * scaleFactor); scaleD = (double)scaleI / 1000.0L; + int h, w; - setZoomedSize(round(width()*scaleFactor), round(height()*scaleFactor)); + sepHeight *= scaleFactor; + + h = round(height()*scaleFactor); + w = round(width()*scaleFactor); + + setZoomedSize(h, w); + update(); } +/** This slot is to be called when dimensions of pages changes. It set the right dimensions of whole widget + according to page separator height. + +@arg maxPageWidth maximum width of pages +@arg sumPagesHeight sum of height of all pages + */ + +void PDFZoomed::setPagesRect(int maxPageWidth, int sumPagesHeight) { + this->setGeometry(0,0, maxPageWidth, sumPagesHeight + sepHeight * (pages.size()-1)); +} + /** Sets total base(scale == 1000) size of zoomed area. * @param width width of area * @param height height of area @@ -70,17 +89,64 @@ this->setGeometry(0,0, width, height); } -/** Computes which ould lay at point y. + +/** + Returns y coordinate of top of the page @a page taking into account current scale. + @arg page page of which coordinates to return + @return y y coordinate of top of the given page + */ + +int PDFZoomed::pageTop(int page) { + if (page == 0) { + return 0; + } + + if (page < lengths.size() ) { + return (lengths[page-1] + sepHeight); + } else { + return 0; + } +} + +/** Returns height of the @a page taking into account current scale. + @arg page which page's height to return + @return height of the given page + */ + +int PDFZoomed::pageHeight(int page) { + + if (page < pages.size() && page >= 0) { + return pages[page].h; + } else { + return 0; + } +} + + +/** Computes which page lay at point y. * * @param y point at which page should lay + * @param aligned serves for returning whether argument @a y was at the page boundary or not * @return page number or zero if conversion fails */ -int PDFZoomed::whichPage(int y) { - int y2 = round((double)y / scaleD); +int PDFZoomed::whichPage(int y, bool & aligned) { for( int i = 0; i < lengths.size(); ++i ) { - if ( y2 <= lengths[i] ) { + if ( y <= lengths[i] ) { + if ( i != 0) { + if (y == lengths[i-1] + sepHeight ) { + aligned = true; + } else { + aligned = false; + } + } else { + if (y == 0) { + aligned = true; + } else { + aligned = false; + } + } return i; } } @@ -117,7 +183,7 @@ return false; } } else { - lengths[page] = (lengths[page-1] + SEP_HEIGHT + pages[page].h); + lengths[page] = (lengths[page-1] + sepHeight + pages[page].h); return true; } return true; @@ -140,11 +206,11 @@ if ( page == 0 ) { rect.setTop(0); } else { - rect.setTop(round( (lengths[page-1] + SEP_HEIGHT) * scaleD)); + rect.setTop(round( (lengths[page-1] + sepHeight))); } - rect.setLeft( round( ((width()/scaleD - pages[page].w)/ 2) * scaleD)); - rect.setWidth(round(pages[page].w * scaleD)); + rect.setLeft( round( ((width() - pages[page].w)/ 2))); + rect.setWidth(round(pages[page].w)); if (rect.left() < 0 ) { rect.setLeft(0); @@ -156,7 +222,7 @@ } } - rect.setHeight( round((lengths[page]*scaleD - rect.top()) *scaleD)); + rect.setHeight( round((lengths[page] - rect.top()))); return rect; } @@ -169,15 +235,6 @@ return geometry().size(); } -/** Handles resize event of the widget - @param event class containing event description - */ - -void PDFZoomed::resizeEvent(QResizeEvent * event) { - //pageKeyBase.append(geometry().width()); -} - - /** Paints zoomed area. This function is reimplementation of QWidget's paintEvent. It paints already rendered pages and emit signals in * advance, when page image is not available (pre-rendering). While the page is not ready, it displays transparent rect instead. * @param event Event structure containg rect to display. @@ -186,25 +243,29 @@ void PDFZoomed::paintEvent(QPaintEvent * event) { QPainter painter; QPixmap pixmap; - int x, y; + int x, y, eventHeight; QRect rect; int pageTop, pageBottom; + bool aligned; //zjistim kterou oblast ( == ktere stranky ) mam zobrazovat QRect eventRect = event->rect(); y = eventRect.y(); x = eventRect.x(); + eventHeight = eventRect.height(); + painter.begin(this); - pageTop = whichPage(y); - pageBottom = whichPage(y + eventRect.height()); + pageTop = whichPage(y, aligned); + pageBottom = whichPage(y + eventHeight, aligned); for (int i = 0; i < pages.size(); ++i) { - if ( i != pageTop && i != pageBottom ) { + if ( i < pageTop || i > pageBottom ) { continue; } + mtx.lock(); // we have to protect lenghts and pages... rect = getPageRect(i); @@ -240,7 +301,7 @@ //draw page separator painter.setPen(Qt::transparent); painter.setBrush(Qt::transparent); - painter.drawRect(0, rect.bottom(), width(), SEP_HEIGHT*scaleD); + painter.drawRect(0, rect.bottom(), width(), sepHeight); } painter.end(); } Modified: trunk/client/elvys-client/src/pdfzoomed.h =================================================================== --- trunk/client/elvys-client/src/pdfzoomed.h 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/pdfzoomed.h 2010-02-17 17:49:36 UTC (rev 1764) @@ -23,32 +23,41 @@ public slots: void pageReady(PageSelector selector, PDFPage * page); void setZoomedSize(int width, int height); + void setPagesRect(int maxPageWidth, int sumPagesHeight); void setPageDimension(int page, int w, int h); void scale(double scaleFactor); // void clearPages(); + signals: - void getPage(int pageNum, QSize size, QString desc); + ///< request dimensions of all pages. They must fit into width/height specified. + void getAllPagesDimensions(int width, int height); + void getPage(int pageNum, QSize size, QString desc); + public: PDFZoomed(); ~PDFZoomed(); void setKeyBase(QString & _key); void setPages(QList <int> & _pageNumbers); - protected: + int whichPage(int y, bool & aligned); + int pageTop(int page); + int pageHeight(int page); + + protected: void paintEvent(QPaintEvent * event); - void resizeEvent(QResizeEvent * event); + private: QString getPageKey(int pageNumber, const QSize & size, const QString & identifier = ""); QSize getPageBoundingRect(); QRect getPageRect(int page); - bool updateLengths(int page); - int whichPage(int y); + bool updateLengths(int page); QVector<Page> pages; - QVector<int> lengths; ///< vector of y-point of page's ends + QVector<int> lengths; ///< vector of y-point of pages' ends QMutex mtx; QString keyBase; int scaleI; double scaleD; + int sepHeight; }; Modified: trunk/client/elvys-client/src/src.pro =================================================================== --- trunk/client/elvys-client/src/src.pro 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/src.pro 2010-02-17 17:49:36 UTC (rev 1764) @@ -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 \ Modified: trunk/client/elvys-client/src/videodocument.cpp =================================================================== --- trunk/client/elvys-client/src/videodocument.cpp 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/videodocument.cpp 2010-02-17 17:49:36 UTC (rev 1764) @@ -1,11 +1,14 @@ #include "videodocument.h" +#include "math.h" + /** class contructor - @arg doc another document from which construct geometry + @arg doc another document from which geometry is constructed @arg id of this document */ VideoDocument::VideoDocument(Document *doc, int docId) : Document(doc) { + scaled = 0; _docId = docId; _autoStart = false; _startAt = 0; @@ -26,11 +29,12 @@ vlayout->addWidget(slider); this->setLayout(vlayout); + connect(player, SIGNAL(finished()), this, SLOT(completelyUnZoom())); connect(player, SIGNAL(finished()), this, SLOT(replay())); setBorder(false); } -/** class descrutor. +/** class destructor. */ VideoDocument::~VideoDocument() { @@ -38,6 +42,13 @@ delete vlayout; } + + +void VideoDocument::managePlayerState() { + +} + + /** Loads document to play. It does nothing if the same file is already loaded. @arg name name of the file to load */ @@ -53,6 +64,7 @@ fullName = AppConfig::getInstance()->getLocalDataDir() + _name; MediaSource source(fullName); player->load(source); + connect(player->mediaObject(), SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(managePlayerState())); player->setVolume(0); slider->setMediaObject(player->mediaObject()); @@ -126,7 +138,7 @@ void VideoDocument::seek(qint64 pos) { if (player->isPlaying()) { - player->seek(pos); // do not disturb audience + player->seek(pos); } else { player->play(); player->seek(pos); @@ -174,23 +186,88 @@ return _startAt; } +QRect VideoDocument::getZoomedGeometry(int scale) { + int newX; + int newY; + int overlap = 0; + int zoomW; + int zoomH; + QWidget * parW = parentWidget(); + if ( scale == 0) { + zoomW = AppConfig::getInstance()->getZoomWidth(parW); + zoomH = AppConfig::getInstance()->getZoomHeight(parW); + } else { //we must be zoomed already + zoomW = AppConfig::getInstance()->getZoomWidth(parW) * pow(SCALE_FACTOR, scale); + zoomH = AppConfig::getInstance()->getZoomHeight(parW) * pow(SCALE_FACTOR, scale); + } + + if ( zoomW > parW->width()) { + zoomW = parW->width(); + } + + if ( zoomH > parW->height()) { + zoomH = parW->height(); + } + + int zoomWHalf = zoomW / 2; ///< half width of zoomed size + + int centerX = _normalGeometry.x() + _normalGeometry.width() / 2; ///< center of my widget + + + if ( (overlap = (centerX + zoomWHalf) - parW->width()) > 0 ) { // it wouldnt fit the screen! Move left + //we know that center needs to be in centerX - overlap + newX = (centerX - overlap) - zoomWHalf; + } else if ( (overlap = (centerX - zoomWHalf)) < 0 ) { //we are of the screen + newX = 0; + } else { //center it + newX = centerX - zoomWHalf; + } + + if ( (_normalGeometry.y() + AppConfig::getInstance()->getZoomHeight(parW)) > parW->height() ) { + newY = 0; + } else { + newY = _normalGeometry.y(); + } + + return QRect(newX, newY, zoomW, zoomH); +} + + +void VideoDocument::completelyUnZoom() { + if ( ! _zoomed ) { + return; + } + + scaled = 0; + unZoom(); +} + + /** Enlarges widget geometry and starts playing widget, if not playing */ void VideoDocument::zoom() { - if (_zoomable && ! _zoomed) { - _zoomed = true; - normalGeometry = geometry(); - playingBeforeZoom = player->isPlaying(); - slider->show(); - play(); - ///< @todo zoomed geometry should be computed more complexly - raise(); - player->raise(); - player->videoWidget()->raise(); - setGeometry(0, 0, AppConfig::getInstance()->getZoomWidth(parentWidget()), AppConfig::getInstance()->getZoomHeight(parentWidget())); - setBorder(false); + if (_zoomable) { + if ( ! _zoomed ) { + _zoomed = true; + _normalGeometry = geometry(); + playingBeforeZoom = player->isPlaying(); + slider->show(); + play(); + ///< @todo zoomed geometry should be computed more complexly + raise(); + player->raise(); + player->videoWidget()->raise(); + setGeometry(getZoomedGeometry(scaled)); + setBorder(false); + } else { + if ( width() == parentWidget()->width() && height() == parentWidget()->height()) { //we are zoomed maximaly already + return; + } + scaled++; + setGeometry(getZoomedGeometry(scaled)); + } } } @@ -199,19 +276,39 @@ void VideoDocument::unZoom() { if ( _zoomed ) { - _zoomed = false; - emit unZoomEvent(); - if (! playingBeforeZoom) { - player->stop(); - seek(_startAt); - } - setGeometry(normalGeometry); - manageAutoStart(); - setBorder(true); + if ( scaled != 0) { + scaled--; + setGeometry(getZoomedGeometry(scaled)); + } else { + _zoomed = false; + emit unZoomEvent(); + if (! playingBeforeZoom) { + player->stop(); + seek(_startAt); + } + setGeometry(_normalGeometry); + manageAutoStart(); + setBorder(true); + } } } +/** Reimplementation of resizeEvent + @arg event structure containing information of the event + */ +void VideoDocument::resizeEvent(QResizeEvent * event) { + Q_UNUSED(event); + + if (! _zoomed ) { // I might get called in zoomed state + setBorder(hasFocus()); + _normalGeometry = geometry(); + } + + update(); +} + + /** Reimplementation of keyPressEvent @arg event structure containing information of the pressed key */ @@ -232,6 +329,13 @@ event->ignore(); } break; + case Qt::Key_Up: + if ( _zoomed ) { + seek(0); + } else { + event->ignore(); + } + break; case Qt::Key_Return: zoom(); break; Modified: trunk/client/elvys-client/src/videodocument.h =================================================================== --- trunk/client/elvys-client/src/videodocument.h 2010-02-17 17:41:11 UTC (rev 1763) +++ trunk/client/elvys-client/src/videodocument.h 2010-02-17 17:49:36 UTC (rev 1764) @@ -10,6 +10,7 @@ #include "appconfig.h" #include "document.h" +#include "constants.h" using namespace Phonon; @@ -29,14 +30,13 @@ virtual int close(); void setAutoStart(bool autoStart); void setStartAt(qint64 startAt); - void manageAutoStart(); + void manageAutoStart(); signals: void zoomEvent(int documentId, int layoutPos); void unZoomEvent(int documentId, int layoutPos); - public: - /// @todo delete this constructor + public: VideoDocument(Document * doc, int docId); virtual ~VideoDocument(); virtual QString getFileName(); @@ -51,13 +51,17 @@ virtual void mousePressEvent(QMouseEvent *); virtual void focusInEvent(QFocusEvent *); virtual void focusOutEvent(QFocusEvent *); + virtual void resizeEvent(QResizeEvent * event); private slots: + void managePlayerState(); void replay(); void play(); + void completelyUnZoom(); void seek(qint64 pos); private: + QRect getZoomedGeometry(int scaled); void zoom(); void unZoom(); void setBorder(bool focused); @@ -65,8 +69,8 @@ int _docId; bool _autoStart; ///< should we start playing in normal state too? int _startAt; + int scaled; bool playingBeforeZoom; - QRect normalGeometry; QVBoxLayout * vlayout; SeekSlider * slider;