2004-09-26 23:39:39 +00:00
/***************************************************************************
2005-02-18 18:24:45 +00:00
* Copyright ( C ) 2004 - 2005 by Enrico Ros < eros . kde @ email . it > *
2006-02-18 12:06:52 +00:00
* Copyright ( C ) 2004 - 2006 by Albert Astals Cid < tsdgeos @ terra . es > *
2004-09-27 21:36:25 +00:00
* *
2005-01-02 14:29:37 +00:00
* With portions of code from kpdf / kpdf_pagewidget . cc by : *
2004-09-27 21:36:25 +00:00
* Copyright ( C ) 2002 by Wilco Greven < greven @ kde . org > *
* Copyright ( C ) 2003 by Christophe Devriese *
* < Christophe . Devriese @ student . kuleuven . ac . be > *
* Copyright ( C ) 2003 by Laurent Montel < montel @ kde . org > *
* Copyright ( C ) 2003 by Dirk Mueller < mueller @ kde . org > *
* Copyright ( C ) 2004 by James Ots < kde @ jamesots . com > *
2011-10-12 13:50:56 +00:00
* Copyright ( C ) 2011 by Jiri Baum - NICTA < jiri @ baum . com . au > *
2004-09-26 23:39:39 +00:00
* *
* This program is free software ; you can redistribute it and / or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation ; either version 2 of the License , or *
* ( at your option ) any later version . *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-04-19 18:30:20 +00:00
# include "pageview.h"
2005-01-02 14:55:14 +00:00
// qt/kde includes
2005-01-01 21:50:34 +00:00
# include <qcursor.h>
2006-03-24 20:40:02 +00:00
# include <qevent.h>
2006-10-17 21:26:43 +00:00
# include <qimage.h>
2004-09-26 23:39:39 +00:00
# include <qpainter.h>
# include <qtimer.h>
2006-09-26 22:22:01 +00:00
# include <qset.h>
2006-10-07 14:40:32 +00:00
# include <qscrollbar.h>
2006-09-27 10:28:03 +00:00
# include <qtooltip.h>
2004-10-14 20:21:59 +00:00
# include <qapplication.h>
# include <qclipboard.h>
2006-10-29 13:17:19 +00:00
2004-09-26 23:39:39 +00:00
# include <kaction.h>
2008-10-12 16:36:14 +00:00
# include <kactionmenu.h>
2006-12-19 12:23:43 +00:00
# include <kstandardaction.h>
2004-09-26 23:39:39 +00:00
# include <kactioncollection.h>
2006-03-24 20:40:02 +00:00
# include <kmenu.h>
2004-09-26 23:39:39 +00:00
# include <klocale.h>
2004-11-03 17:35:48 +00:00
# include <kfiledialog.h>
2006-12-20 20:37:50 +00:00
# include <kglobal.h>
2007-01-03 00:17:31 +00:00
# include <kglobalsettings.h>
2010-08-08 17:06:42 +00:00
# include <kinputdialog.h>
2006-05-08 19:00:23 +00:00
# include <kselectaction.h>
# include <ktoggleaction.h>
2004-11-08 13:13:46 +00:00
# include <kdebug.h>
2010-11-21 17:37:07 +00:00
# include <kdeversion.h>
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
# include <kmessagebox.h>
2006-08-05 10:35:03 +00:00
# include <kicon.h>
2010-09-11 13:34:22 +00:00
# include <kurifilter.h>
# include <kstringhandler.h>
# include <ktoolinvocation.h>
2006-06-05 15:47:35 +00:00
2005-01-02 14:55:14 +00:00
// system includes
2004-09-26 23:39:39 +00:00
# include <math.h>
2004-10-06 00:05:49 +00:00
# include <stdlib.h>
2004-09-26 23:39:39 +00:00
2005-01-02 14:55:14 +00:00
// local includes
2007-02-25 00:07:59 +00:00
# include "formwidgets.h"
2004-10-20 16:41:13 +00:00
# include "pageviewutils.h"
2005-01-27 17:31:07 +00:00
# include "pagepainter.h"
2006-08-08 15:31:13 +00:00
# include "core/annotations.h"
2007-05-06 15:10:16 +00:00
# include "annotwindow.h"
2007-12-24 00:54:21 +00:00
# include "guiutils.h"
2006-12-30 12:40:54 +00:00
# include "annotationpopup.h"
2005-03-04 23:06:24 +00:00
# include "pageviewannotator.h"
2007-09-14 10:02:33 +00:00
# include "toolaction.h"
2008-03-05 02:13:09 +00:00
# include "tts.h"
2008-08-25 01:59:23 +00:00
# include "videowidget.h"
2007-04-20 11:26:05 +00:00
# include "core/action.h"
2011-10-17 19:56:45 +00:00
# include "core/area.h"
2005-01-02 14:55:14 +00:00
# include "core/document.h"
2007-02-25 00:07:59 +00:00
# include "core/form.h"
2005-01-02 14:37:49 +00:00
# include "core/page.h"
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
# include "core/misc.h"
2005-01-02 14:37:49 +00:00
# include "core/generator.h"
2008-08-25 01:59:23 +00:00
# include "core/movie.h"
2009-07-27 14:15:33 +00:00
# include "core/sourcereference.h"
2012-11-08 20:29:09 +00:00
# include "core/tile.h"
2006-03-28 22:22:10 +00:00
# include "settings.h"
2012-10-15 22:27:42 +00:00
# include "settings_core.h"
2004-09-26 23:39:39 +00:00
2006-07-09 11:10:24 +00:00
static int pageflags = PagePainter : : Accessibility | PagePainter : : EnhanceLinks |
PagePainter : : EnhanceImages | PagePainter : : Highlights |
2006-09-26 22:22:01 +00:00
PagePainter : : TextSelection | PagePainter : : Annotations ;
2006-07-09 11:10:24 +00:00
2009-05-17 10:17:35 +00:00
static inline double normClamp ( double value , double def )
{
return ( value < 0.0 | | value > 1.0 ) ? def : value ;
}
2011-10-12 13:50:56 +00:00
struct TableSelectionPart {
PageViewItem * item ;
Okular : : NormalizedRect rectInItem ;
Okular : : NormalizedRect rectInSelection ;
2011-10-12 13:59:05 +00:00
TableSelectionPart ( PageViewItem * item_p , const Okular : : NormalizedRect & rectInItem_p , const Okular : : NormalizedRect & rectInSelection_p ) ;
2011-10-12 13:50:56 +00:00
} ;
2011-10-12 13:59:05 +00:00
TableSelectionPart : : TableSelectionPart ( PageViewItem * item_p , const Okular : : NormalizedRect & rectInItem_p , const Okular : : NormalizedRect & rectInSelection_p )
2011-10-12 13:50:56 +00:00
: item ( item_p ) , rectInItem ( rectInItem_p ) , rectInSelection ( rectInSelection_p )
{
}
2004-09-26 23:39:39 +00:00
// structure used internally by PageView for data storage
class PageViewPrivate
{
public :
2007-10-18 22:09:49 +00:00
PageViewPrivate ( PageView * qq ) ;
FormWidgetsController * formWidgetsController ( ) ;
2008-03-05 02:13:09 +00:00
OkularTTS * tts ( ) ;
2008-02-26 20:54:31 +00:00
QString selectedText ( ) const ;
2007-10-18 22:09:49 +00:00
2005-01-09 23:37:07 +00:00
// the document, pageviewItems and the 'visible cache'
2007-10-18 22:09:49 +00:00
PageView * q ;
2006-09-21 08:45:36 +00:00
Okular : : Document * document ;
2006-03-24 20:40:02 +00:00
QVector < PageViewItem * > items ;
QLinkedList < PageViewItem * > visibleItems ;
2004-09-26 23:39:39 +00:00
2005-03-05 15:59:15 +00:00
// view layout (columns and continuous in Settings), zoom and mouse
2004-09-26 23:39:39 +00:00
PageView : : ZoomMode zoomMode ;
float zoomFactor ;
QPoint mouseGrabPos ;
2005-01-29 12:32:59 +00:00
QPoint mousePressPos ;
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
QPoint mouseSelectPos ;
2005-03-24 19:10:41 +00:00
bool mouseMidZooming ;
int mouseMidLastY ;
2005-06-24 16:41:55 +00:00
bool mouseSelecting ;
2004-10-30 20:54:48 +00:00
QRect mouseSelectionRect ;
2005-06-24 16:41:55 +00:00
QColor mouseSelectionColor ;
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
bool mouseTextSelecting ;
2006-09-26 22:22:01 +00:00
QSet < int > pagesWithTextSelection ;
2005-06-24 16:41:55 +00:00
bool mouseOnRect ;
2007-07-17 20:58:38 +00:00
Okular : : Annotation * mouseAnn ;
QPoint mouseAnnPos ;
2012-05-13 18:10:55 +00:00
int mouseAnnPageNum ;
2006-10-07 14:40:32 +00:00
2011-10-12 13:50:56 +00:00
// table selection
QList < double > tableSelectionCols ;
QList < double > tableSelectionRows ;
QList < TableSelectionPart > tableSelectionParts ;
2011-10-31 15:33:03 +00:00
bool tableDividersGuessed ;
2011-10-12 13:50:56 +00:00
2005-02-01 18:24:16 +00:00
// viewport move
bool viewportMoveActive ;
QTime viewportMoveTime ;
QPoint viewportMoveDest ;
2011-10-17 19:56:45 +00:00
int lastSourceLocationViewportPageNumber ;
double lastSourceLocationViewportNormalizedX ;
double lastSourceLocationViewportNormalizedY ;
2005-02-01 18:24:16 +00:00
QTimer * viewportMoveTimer ;
// auto scroll
2004-10-06 00:05:49 +00:00
int scrollIncrement ;
2005-02-01 18:24:16 +00:00
QTimer * autoScrollTimer ;
2005-02-18 18:24:45 +00:00
// annotations
2005-03-04 23:06:24 +00:00
PageViewAnnotator * annotator ;
2006-08-08 15:31:13 +00:00
//text annotation dialogs list
2008-05-29 19:12:56 +00:00
QHash < Okular : : Annotation * , AnnotWindow * > m_annowindows ;
2005-02-01 18:24:16 +00:00
// other stuff
2011-03-17 15:24:44 +00:00
QTimer * delayResizeEventTimer ;
2004-09-30 18:04:09 +00:00
bool dirtyLayout ;
2005-02-01 18:24:16 +00:00
bool blockViewport ; // prevents changes to viewport
2005-01-21 20:05:36 +00:00
bool blockPixmapsRequest ; // prevent pixmap requests
PageViewMessage * messageWindow ; // in pageviewutils.h
2007-02-25 00:07:59 +00:00
bool m_formsVisible ;
2007-10-18 22:09:49 +00:00
FormWidgetsController * formsWidgetController ;
2008-03-05 02:13:09 +00:00
OkularTTS * m_tts ;
2008-03-07 16:09:08 +00:00
QTimer * refreshTimer ;
int refreshPage ;
2004-09-26 23:39:39 +00:00
2008-12-08 16:09:15 +00:00
// infinite resizing loop prevention
2010-07-20 22:24:57 +00:00
bool verticalScrollBarVisible ;
2008-12-08 16:09:15 +00:00
2006-11-22 21:32:21 +00:00
// drag scroll
QPoint dragScrollVector ;
QTimer dragScrollTimer ;
2010-03-25 20:59:16 +00:00
// left click depress
QTimer leftClickTimer ;
2004-09-26 23:39:39 +00:00
// actions
2007-01-19 21:43:53 +00:00
KAction * aRotateClockwise ;
KAction * aRotateCounterClockwise ;
KAction * aRotateOriginal ;
2007-01-05 23:12:06 +00:00
KSelectAction * aPageSizes ;
2008-05-27 14:00:59 +00:00
KToggleAction * aTrimMargins ;
2008-10-12 09:00:37 +00:00
KAction * aMouseNormal ;
KAction * aMouseSelect ;
KAction * aMouseTextSelect ;
2011-10-12 13:50:56 +00:00
KAction * aMouseTableSelect ;
2005-03-04 23:06:24 +00:00
KToggleAction * aToggleAnnotator ;
2004-10-29 21:52:06 +00:00
KSelectAction * aZoom ;
2008-10-12 09:00:37 +00:00
KAction * aZoomIn ;
KAction * aZoomOut ;
2004-10-29 21:52:06 +00:00
KToggleAction * aZoomFitWidth ;
KToggleAction * aZoomFitPage ;
2008-10-12 16:36:14 +00:00
KActionMenu * aViewMode ;
2005-03-05 15:59:15 +00:00
KToggleAction * aViewContinuous ;
2007-01-09 11:02:04 +00:00
QAction * aPrevAction ;
2007-02-25 00:07:59 +00:00
KAction * aToggleForms ;
2008-08-04 10:16:47 +00:00
KAction * aSpeakDoc ;
KAction * aSpeakPage ;
2008-03-05 12:05:48 +00:00
KAction * aSpeakStop ;
2006-06-25 16:34:11 +00:00
KActionCollection * actionCollection ;
2011-10-12 19:36:01 +00:00
QActionGroup * mouseModeActionGroup ;
2006-10-28 22:58:05 +00:00
2007-05-19 10:19:25 +00:00
int setting_viewCols ;
2012-10-15 18:11:47 +00:00
// Keep track of whether tablet pen is currently pressed down
bool penDown ;
2004-09-26 23:39:39 +00:00
} ;
2007-10-18 22:09:49 +00:00
PageViewPrivate : : PageViewPrivate ( PageView * qq )
: q ( qq )
{
}
FormWidgetsController * PageViewPrivate : : formWidgetsController ( )
{
if ( ! formsWidgetController )
{
formsWidgetController = new FormWidgetsController ( ) ;
2011-07-31 19:22:04 +00:00
QObject : : connect ( formsWidgetController , SIGNAL ( changed ( FormWidgetIface * ) ) ,
q , SLOT ( slotFormWidgetChanged ( FormWidgetIface * ) ) ) ;
QObject : : connect ( formsWidgetController , SIGNAL ( action ( Okular : : Action * ) ) ,
q , SLOT ( slotAction ( Okular : : Action * ) ) ) ;
2007-10-18 22:09:49 +00:00
}
return formsWidgetController ;
}
2008-03-05 02:13:09 +00:00
OkularTTS * PageViewPrivate : : tts ( )
{
if ( ! m_tts )
{
2008-08-23 11:09:04 +00:00
m_tts = new OkularTTS ( q ) ;
2008-03-05 12:05:48 +00:00
if ( aSpeakStop )
{
2011-07-31 19:22:04 +00:00
QObject : : connect ( m_tts , SIGNAL ( hasSpeechs ( bool ) ) ,
aSpeakStop , SLOT ( setEnabled ( bool ) ) ) ;
QObject : : connect ( m_tts , SIGNAL ( errorMessage ( QString ) ) ,
q , SLOT ( errorMessage ( QString ) ) ) ;
2008-03-05 12:05:48 +00:00
}
2008-03-05 02:13:09 +00:00
}
return m_tts ;
}
2007-10-18 22:09:49 +00:00
2004-09-30 18:16:12 +00:00
/* PageView. What's in this file? -> quick overview.
* Code weight ( in rows ) and meaning :
* 160 - constructor and creating actions plus their connected slots ( empty stuff )
* 70 - DocumentObserver inherited methodes ( important )
2005-01-09 23:37:07 +00:00
* 550 - events : mouse , keyboard , drag / drop
2005-03-05 15:59:15 +00:00
* 170 - slotRelayoutPages : set contents of the scrollview on continuous / single modes
2004-09-30 18:16:12 +00:00
* 100 - zoom : zooming pages in different ways , keeping update the toolbar actions , etc . .
2004-10-30 20:54:48 +00:00
* other misc functions : only slotRequestVisiblePixmaps and pickItemOnPoint noticeable ,
2004-09-30 18:16:12 +00:00
* and many insignificant stuff like this comment : - )
2004-09-26 23:39:39 +00:00
*/
2006-09-21 08:45:36 +00:00
PageView : : PageView ( QWidget * parent , Okular : : Document * document )
2009-06-29 20:55:50 +00:00
: QAbstractScrollArea ( parent )
2008-04-27 11:17:05 +00:00
, Okular : : View ( QString : : fromLatin1 ( " PageView " ) )
2004-09-26 23:39:39 +00:00
{
// create and initialize private storage structure
2007-10-18 22:09:49 +00:00
d = new PageViewPrivate ( this ) ;
2004-09-26 23:39:39 +00:00
d - > document = document ;
2007-01-19 21:43:53 +00:00
d - > aRotateClockwise = 0 ;
d - > aRotateCounterClockwise = 0 ;
d - > aRotateOriginal = 0 ;
2007-05-17 20:46:16 +00:00
d - > aViewMode = 0 ;
2008-09-10 11:26:53 +00:00
d - > zoomMode = PageView : : ZoomFitWidth ;
2008-05-31 20:45:30 +00:00
d - > zoomFactor = 1.0 ;
2005-03-24 19:10:41 +00:00
d - > mouseMidZooming = false ;
2005-06-24 16:41:55 +00:00
d - > mouseSelecting = false ;
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
d - > mouseTextSelecting = false ;
2004-12-10 16:04:45 +00:00
d - > mouseOnRect = false ;
2007-07-17 20:58:38 +00:00
d - > mouseAnn = 0 ;
2011-10-31 15:33:03 +00:00
d - > tableDividersGuessed = false ;
2005-02-01 18:24:16 +00:00
d - > viewportMoveActive = false ;
2011-11-05 09:18:08 +00:00
d - > lastSourceLocationViewportPageNumber = - 1 ;
d - > lastSourceLocationViewportNormalizedX = 0.0 ;
d - > lastSourceLocationViewportNormalizedY = 0.0 ;
2005-02-01 18:24:16 +00:00
d - > viewportMoveTimer = 0 ;
2004-10-06 00:05:49 +00:00
d - > scrollIncrement = 0 ;
2005-02-01 18:24:16 +00:00
d - > autoScrollTimer = 0 ;
2005-03-04 23:06:24 +00:00
d - > annotator = 0 ;
2004-09-30 18:04:09 +00:00
d - > dirtyLayout = false ;
2005-01-09 23:37:07 +00:00
d - > blockViewport = false ;
2005-01-21 20:05:36 +00:00
d - > blockPixmapsRequest = false ;
2004-10-20 16:41:13 +00:00
d - > messageWindow = new PageViewMessage ( this ) ;
2007-02-25 00:07:59 +00:00
d - > m_formsVisible = false ;
2007-10-18 22:09:49 +00:00
d - > formsWidgetController = 0 ;
2008-03-05 02:13:09 +00:00
d - > m_tts = 0 ;
2008-03-07 16:09:08 +00:00
d - > refreshTimer = 0 ;
d - > refreshPage = - 1 ;
2007-07-14 12:31:26 +00:00
d - > aRotateClockwise = 0 ;
d - > aRotateCounterClockwise = 0 ;
d - > aRotateOriginal = 0 ;
d - > aPageSizes = 0 ;
2008-05-27 14:00:59 +00:00
d - > aTrimMargins = 0 ;
2007-07-14 12:31:26 +00:00
d - > aMouseNormal = 0 ;
d - > aMouseSelect = 0 ;
d - > aMouseTextSelect = 0 ;
d - > aToggleAnnotator = 0 ;
d - > aZoomFitWidth = 0 ;
d - > aZoomFitPage = 0 ;
d - > aViewMode = 0 ;
d - > aViewContinuous = 0 ;
2005-01-28 17:21:28 +00:00
d - > aPrevAction = 0 ;
2007-06-05 20:49:00 +00:00
d - > aToggleForms = 0 ;
2008-08-04 10:16:47 +00:00
d - > aSpeakDoc = 0 ;
d - > aSpeakPage = 0 ;
2008-03-05 12:05:48 +00:00
d - > aSpeakStop = 0 ;
2007-07-14 12:31:26 +00:00
d - > actionCollection = 0 ;
2007-01-05 23:12:06 +00:00
d - > aPageSizes = 0 ;
2007-05-19 10:19:25 +00:00
d - > setting_viewCols = Okular : : Settings : : viewColumns ( ) ;
2011-10-12 19:36:01 +00:00
d - > mouseModeActionGroup = 0 ;
2012-10-15 18:11:47 +00:00
d - > penDown = false ;
2010-09-11 13:34:22 +00:00
2011-09-28 21:55:54 +00:00
switch ( Okular : : Settings : : zoomMode ( ) )
2011-09-28 21:54:03 +00:00
{
case 0 :
{
d - > zoomFactor = 1 ;
d - > zoomMode = PageView : : ZoomFixed ;
break ;
}
case 1 :
{
d - > zoomMode = PageView : : ZoomFitWidth ;
break ;
}
case 2 :
{
d - > zoomMode = PageView : : ZoomFitPage ;
break ;
}
}
2011-03-17 15:24:44 +00:00
d - > delayResizeEventTimer = new QTimer ( this ) ;
d - > delayResizeEventTimer - > setSingleShot ( true ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > delayResizeEventTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( delayedResizeEvent ( ) ) ) ;
2004-09-27 21:36:25 +00:00
2007-05-28 15:29:29 +00:00
setFrameStyle ( QFrame : : NoFrame ) ;
2006-06-03 13:01:15 +00:00
setAttribute ( Qt : : WA_StaticContents ) ;
2006-06-12 18:25:18 +00:00
setObjectName ( QLatin1String ( " okular::pageView " ) ) ;
2006-06-03 13:01:15 +00:00
2009-06-29 20:55:50 +00:00
// viewport setup: setup focus, accept drops and track mouse
2004-09-27 21:36:25 +00:00
viewport ( ) - > setFocusProxy ( this ) ;
2006-03-24 20:40:02 +00:00
viewport ( ) - > setFocusPolicy ( Qt : : StrongFocus ) ;
2009-06-29 20:55:50 +00:00
viewport ( ) - > setAttribute ( Qt : : WA_OpaquePaintEvent ) ;
viewport ( ) - > setAttribute ( Qt : : WA_NoSystemBackground ) ;
2004-09-26 23:39:39 +00:00
setAcceptDrops ( true ) ;
2009-06-29 20:55:50 +00:00
viewport ( ) - > setMouseTracking ( true ) ;
2009-07-07 16:53:33 +00:00
viewport ( ) - > setAutoFillBackground ( false ) ;
2009-06-29 20:55:50 +00:00
// the apparently "magic" value of 20 is the same used internally in QScrollArea
verticalScrollBar ( ) - > setSingleStep ( 20 ) ;
horizontalScrollBar ( ) - > setSingleStep ( 20 ) ;
2004-09-27 21:36:25 +00:00
// conntect the padding of the viewport to pixmaps requests
2008-04-16 11:04:59 +00:00
connect ( horizontalScrollBar ( ) , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( slotRequestVisiblePixmaps ( int ) ) ) ;
connect ( verticalScrollBar ( ) , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( slotRequestVisiblePixmaps ( int ) ) ) ;
2006-11-22 21:32:21 +00:00
connect ( & d - > dragScrollTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( slotDragScroll ( ) ) ) ;
2004-09-26 23:39:39 +00:00
2010-03-25 20:59:16 +00:00
d - > leftClickTimer . setSingleShot ( true ) ;
connect ( & d - > leftClickTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( slotShowSizeAllCursor ( ) ) ) ;
2004-09-26 23:39:39 +00:00
// set a corner button to resize the view to the page size
2004-10-29 21:52:06 +00:00
// QPushButton * resizeButton = new QPushButton( viewport() );
// resizeButton->setPixmap( SmallIcon("crop") );
// setCornerWidget( resizeButton );
// resizeButton->setEnabled( false );
2004-09-26 23:39:39 +00:00
// connect(...);
2006-08-30 14:17:22 +00:00
setAttribute ( Qt : : WA_InputMethodEnabled , true ) ;
2006-09-20 13:58:28 +00:00
2012-09-27 12:15:58 +00:00
connect ( document , SIGNAL ( processMovieAction ( const Okular : : MovieAction * ) ) , this , SLOT ( slotProcessMovieAction ( const Okular : : MovieAction * ) ) ) ;
connect ( document , SIGNAL ( processRenditionAction ( const Okular : : RenditionAction * ) ) , this , SLOT ( slotProcessRenditionAction ( const Okular : : RenditionAction * ) ) ) ;
2006-09-20 13:58:28 +00:00
// schedule the welcome message
2006-10-19 21:18:39 +00:00
QMetaObject : : invokeMethod ( this , " slotShowWelcome " , Qt : : QueuedConnection ) ;
2004-09-26 23:39:39 +00:00
}
PageView : : ~ PageView ( )
{
2008-03-05 15:40:36 +00:00
if ( d - > m_tts )
d - > m_tts - > stopAllSpeechs ( ) ;
2005-02-18 18:24:45 +00:00
// delete the local storage structure
2012-03-07 22:51:36 +00:00
// We need to assign it to a different list otherwise slotAnnotationWindowDestroyed
// will bite us and clear d->m_annowindows
QHash < Okular : : Annotation * , AnnotWindow * > annowindows = d - > m_annowindows ;
d - > m_annowindows . clear ( ) ;
qDeleteAll ( annowindows ) ;
2006-11-19 13:20:22 +00:00
// delete all widgets
2008-11-11 18:48:40 +00:00
QVector < PageViewItem * > : : const_iterator dIt = d - > items . constBegin ( ) , dEnd = d - > items . constEnd ( ) ;
2006-11-19 13:20:22 +00:00
for ( ; dIt ! = dEnd ; + + dIt )
delete * dIt ;
2007-10-18 22:09:49 +00:00
delete d - > formsWidgetController ;
2006-02-18 12:06:52 +00:00
d - > document - > removeObserver ( this ) ;
2004-09-26 23:39:39 +00:00
delete d ;
}
2007-07-14 12:31:26 +00:00
void PageView : : setupBaseActions ( KActionCollection * ac )
{
d - > actionCollection = ac ;
// Zoom actions ( higher scales takes lots of memory! )
2009-05-24 16:09:19 +00:00
d - > aZoom = new KSelectAction ( KIcon ( " page-zoom " ) , i18n ( " Zoom " ) , this ) ;
2007-07-14 12:31:26 +00:00
ac - > addAction ( " zoom_to " , d - > aZoom ) ;
d - > aZoom - > setEditable ( true ) ;
2012-12-01 00:34:54 +00:00
d - > aZoom - > setMaxComboViewCount ( 14 ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > aZoom , SIGNAL ( triggered ( QAction * ) ) , this , SLOT ( slotZoom ( ) ) ) ;
2007-07-14 12:31:26 +00:00
updateZoomText ( ) ;
2011-07-31 19:22:04 +00:00
d - > aZoomIn = KStandardAction : : zoomIn ( this , SLOT ( slotZoomIn ( ) ) , ac ) ;
2007-07-14 12:31:26 +00:00
2011-07-31 19:22:04 +00:00
d - > aZoomOut = KStandardAction : : zoomOut ( this , SLOT ( slotZoomOut ( ) ) , ac ) ;
2007-07-14 12:31:26 +00:00
}
2011-10-12 19:36:01 +00:00
void PageView : : setupViewerActions ( KActionCollection * ac )
2004-09-26 23:39:39 +00:00
{
2006-06-25 16:34:11 +00:00
d - > actionCollection = ac ;
2011-10-12 19:36:01 +00:00
d - > aZoomIn - > setShortcut ( QKeySequence ( Qt : : CTRL + Qt : : ALT + Qt : : Key_Plus ) ) ;
d - > aZoomOut - > setShortcut ( QKeySequence ( Qt : : CTRL + Qt : : ALT + Qt : : Key_Minus ) ) ;
2007-01-19 21:43:53 +00:00
// orientation menu actions
2010-10-12 18:05:21 +00:00
d - > aRotateClockwise = new KAction ( KIcon ( " object-rotate-right " ) , i18n ( " Rotate &Right " ) , this ) ;
2007-11-02 00:07:32 +00:00
d - > aRotateClockwise - > setIconText ( i18nc ( " Rotate right " , " Right " ) ) ;
2007-01-19 21:43:53 +00:00
ac - > addAction ( " view_orientation_rotate_cw " , d - > aRotateClockwise ) ;
2007-08-28 12:04:18 +00:00
d - > aRotateClockwise - > setEnabled ( false ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > aRotateClockwise , SIGNAL ( triggered ( ) ) , this , SLOT ( slotRotateClockwise ( ) ) ) ;
2010-10-12 18:05:21 +00:00
d - > aRotateCounterClockwise = new KAction ( KIcon ( " object-rotate-left " ) , i18n ( " Rotate &Left " ) , this ) ;
2007-11-02 00:07:32 +00:00
d - > aRotateCounterClockwise - > setIconText ( i18nc ( " Rotate left " , " Left " ) ) ;
2007-01-19 21:43:53 +00:00
ac - > addAction ( " view_orientation_rotate_ccw " , d - > aRotateCounterClockwise ) ;
2007-08-28 12:04:18 +00:00
d - > aRotateCounterClockwise - > setEnabled ( false ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > aRotateCounterClockwise , SIGNAL ( triggered ( ) ) , this , SLOT ( slotRotateCounterClockwise ( ) ) ) ;
2007-01-19 21:43:53 +00:00
d - > aRotateOriginal = new KAction ( i18n ( " Original Orientation " ) , this ) ;
ac - > addAction ( " view_orientation_original " , d - > aRotateOriginal ) ;
2007-08-28 12:04:18 +00:00
d - > aRotateOriginal - > setEnabled ( false ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > aRotateOriginal , SIGNAL ( triggered ( ) ) , this , SLOT ( slotRotateOriginal ( ) ) ) ;
2007-01-19 21:43:53 +00:00
2007-01-09 11:02:04 +00:00
d - > aPageSizes = new KSelectAction ( i18n ( " &Page Size " ) , this ) ;
ac - > addAction ( " view_pagesizes " , d - > aPageSizes ) ;
2007-08-28 12:04:18 +00:00
d - > aPageSizes - > setEnabled ( false ) ;
2007-01-19 21:43:53 +00:00
2011-07-31 19:22:04 +00:00
connect ( d - > aPageSizes , SIGNAL ( triggered ( int ) ) ,
this , SLOT ( slotPageSizes ( int ) ) ) ;
2005-07-20 22:28:23 +00:00
2008-08-25 03:32:18 +00:00
d - > aTrimMargins = new KToggleAction ( i18n ( " &Trim Margins " ) , this ) ;
2008-05-27 14:00:59 +00:00
ac - > addAction ( " view_trim_margins " , d - > aTrimMargins ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > aTrimMargins , SIGNAL ( toggled ( bool ) ) , SLOT ( slotTrimMarginsToggled ( bool ) ) ) ;
2008-05-27 14:00:59 +00:00
d - > aTrimMargins - > setChecked ( Okular : : Settings : : trimMargins ( ) ) ;
2008-05-19 00:37:14 +00:00
2008-05-14 09:41:12 +00:00
d - > aZoomFitWidth = new KToggleAction ( KIcon ( " zoom-fit-width " ) , i18n ( " Fit &Width " ) , this ) ;
2007-10-07 22:21:13 +00:00
ac - > addAction ( " view_fit_to_width " , d - > aZoomFitWidth ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > aZoomFitWidth , SIGNAL ( toggled ( bool ) ) , SLOT ( slotFitToWidthToggled ( bool ) ) ) ;
2004-09-26 23:39:39 +00:00
2008-05-14 09:41:12 +00:00
d - > aZoomFitPage = new KToggleAction ( KIcon ( " zoom-fit-best " ) , i18n ( " Fit &Page " ) , this ) ;
2007-10-07 22:21:13 +00:00
ac - > addAction ( " view_fit_to_page " , d - > aZoomFitPage ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > aZoomFitPage , SIGNAL ( toggled ( bool ) ) , SLOT ( slotFitToPageToggled ( bool ) ) ) ;
2004-09-26 23:39:39 +00:00
// View-Layout actions
2008-10-12 16:36:14 +00:00
d - > aViewMode = new KActionMenu ( KIcon ( " view-split-left-right " ) , i18n ( " &View Mode " ) , this ) ;
d - > aViewMode - > setDelayed ( false ) ;
# define ADD_VIEWMODE_ACTION( text, name, id ) \
do { \
KAction * vm = new KAction ( text , d - > aViewMode - > menu ( ) ) ; \
vm - > setCheckable ( true ) ; \
vm - > setData ( qVariantFromValue ( id ) ) ; \
d - > aViewMode - > addAction ( vm ) ; \
ac - > addAction ( name , vm ) ; \
vmGroup - > addAction ( vm ) ; \
} while ( 0 )
2007-05-17 20:46:16 +00:00
ac - > addAction ( " view_render_mode " , d - > aViewMode ) ;
2008-10-12 16:36:14 +00:00
QActionGroup * vmGroup = new QActionGroup ( d - > aViewMode - > menu ( ) ) ;
2010-01-10 01:19:16 +00:00
ADD_VIEWMODE_ACTION ( i18n ( " Single Page " ) , " view_render_mode_single " , ( int ) Okular : : Settings : : EnumViewMode : : Single ) ;
ADD_VIEWMODE_ACTION ( i18n ( " Facing Pages " ) , " view_render_mode_facing " , ( int ) Okular : : Settings : : EnumViewMode : : Facing ) ;
2010-07-30 18:22:37 +00:00
ADD_VIEWMODE_ACTION ( i18n ( " Facing Pages (Center First Page) " ) , " view_render_mode_facing_center_first " , ( int ) Okular : : Settings : : EnumViewMode : : FacingFirstCentered ) ;
2010-01-10 01:19:16 +00:00
ADD_VIEWMODE_ACTION ( i18n ( " Overview " ) , " view_render_mode_overview " , ( int ) Okular : : Settings : : EnumViewMode : : Summary ) ;
const QList < QAction * > viewModeActions = d - > aViewMode - > menu ( ) - > actions ( ) ;
foreach ( QAction * viewModeAction , viewModeActions )
{
if ( viewModeAction - > data ( ) . toInt ( ) = = Okular : : Settings : : viewMode ( ) )
{
viewModeAction - > setChecked ( true ) ;
}
}
2011-07-31 19:22:04 +00:00
connect ( vmGroup , SIGNAL ( triggered ( QAction * ) ) , this , SLOT ( slotViewMode ( QAction * ) ) ) ;
2008-10-12 16:36:14 +00:00
# undef ADD_VIEWMODE_ACTION
2004-09-26 23:39:39 +00:00
2008-01-01 12:25:48 +00:00
d - > aViewContinuous = new KToggleAction ( KIcon ( " view-list-text " ) , i18n ( " &Continuous " ) , this ) ;
2007-01-09 11:02:04 +00:00
ac - > addAction ( " view_continuous " , d - > aViewContinuous ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > aViewContinuous , SIGNAL ( toggled ( bool ) ) , SLOT ( slotContinuousToggled ( bool ) ) ) ;
2006-09-21 08:45:36 +00:00
d - > aViewContinuous - > setChecked ( Okular : : Settings : : viewContinuous ( ) ) ;
2004-09-26 23:39:39 +00:00
2011-10-12 19:36:01 +00:00
// Mouse mode actions for viewer mode
d - > mouseModeActionGroup = new QActionGroup ( this ) ;
d - > mouseModeActionGroup - > setExclusive ( true ) ;
2007-08-05 10:24:21 +00:00
d - > aMouseNormal = new KAction ( KIcon ( " input-mouse " ) , i18n ( " &Browse Tool " ) , this ) ;
2007-01-09 11:02:04 +00:00
ac - > addAction ( " mouse_drag " , d - > aMouseNormal ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > aMouseNormal , SIGNAL ( triggered ( ) ) , this , SLOT ( slotSetMouseNormal ( ) ) ) ;
2007-08-20 20:25:22 +00:00
d - > aMouseNormal - > setIconText ( i18nc ( " Browse Tool " , " Browse " ) ) ;
2006-04-01 15:12:32 +00:00
d - > aMouseNormal - > setCheckable ( true ) ;
2007-08-04 17:42:06 +00:00
d - > aMouseNormal - > setShortcut ( Qt : : CTRL + Qt : : Key_1 ) ;
2011-10-12 19:36:01 +00:00
d - > aMouseNormal - > setActionGroup ( d - > mouseModeActionGroup ) ;
2012-03-09 17:43:40 +00:00
d - > aMouseNormal - > setChecked ( Okular : : Settings : : mouseMode ( ) = = Okular : : Settings : : EnumMouseMode : : Browse ) ;
2004-09-26 23:39:39 +00:00
2009-05-24 16:09:19 +00:00
KAction * mz = new KAction ( KIcon ( " page-zoom " ) , i18n ( " &Zoom Tool " ) , this ) ;
2007-01-09 11:02:04 +00:00
ac - > addAction ( " mouse_zoom " , mz ) ;
2011-07-31 19:22:04 +00:00
connect ( mz , SIGNAL ( triggered ( ) ) , this , SLOT ( slotSetMouseZoom ( ) ) ) ;
2007-08-20 20:25:22 +00:00
mz - > setIconText ( i18nc ( " Zoom Tool " , " Zoom " ) ) ;
2006-04-01 15:12:32 +00:00
mz - > setCheckable ( true ) ;
2007-08-04 17:42:06 +00:00
mz - > setShortcut ( Qt : : CTRL + Qt : : Key_2 ) ;
2011-10-12 19:36:01 +00:00
mz - > setActionGroup ( d - > mouseModeActionGroup ) ;
2012-03-09 17:43:40 +00:00
mz - > setChecked ( Okular : : Settings : : mouseMode ( ) = = Okular : : Settings : : EnumMouseMode : : Zoom ) ;
2011-10-12 19:36:01 +00:00
}
// WARNING: 'setupViewerActions' must have been called before this method
void PageView : : setupActions ( KActionCollection * ac )
{
d - > actionCollection = ac ;
d - > aZoomIn - > setShortcut ( KStandardShortcut : : zoomIn ( ) ) ;
d - > aZoomOut - > setShortcut ( KStandardShortcut : : zoomOut ( ) ) ;
// Mouse-Mode actions
2008-01-03 20:05:17 +00:00
d - > aMouseSelect = new KAction ( KIcon ( " select-rectangular " ) , i18n ( " &Selection Tool " ) , this ) ;
2007-01-09 11:02:04 +00:00
ac - > addAction ( " mouse_select " , d - > aMouseSelect ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > aMouseSelect , SIGNAL ( triggered ( ) ) , this , SLOT ( slotSetMouseSelect ( ) ) ) ;
2007-11-13 22:46:44 +00:00
d - > aMouseSelect - > setIconText ( i18nc ( " Select Tool " , " Selection " ) ) ;
2006-04-01 15:12:32 +00:00
d - > aMouseSelect - > setCheckable ( true ) ;
2007-08-04 17:42:06 +00:00
d - > aMouseSelect - > setShortcut ( Qt : : CTRL + Qt : : Key_3 ) ;
2011-10-12 19:36:01 +00:00
d - > aMouseSelect - > setActionGroup ( d - > mouseModeActionGroup ) ;
2012-03-09 17:43:40 +00:00
d - > aMouseSelect - > setChecked ( Okular : : Settings : : mouseMode ( ) = = Okular : : Settings : : EnumMouseMode : : RectSelect ) ;
2004-11-03 17:35:48 +00:00
2008-01-03 19:55:37 +00:00
d - > aMouseTextSelect = new KAction ( KIcon ( " draw-text " ) , i18n ( " &Text Selection Tool " ) , this ) ;
2007-01-09 11:02:04 +00:00
ac - > addAction ( " mouse_textselect " , d - > aMouseTextSelect ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > aMouseTextSelect , SIGNAL ( triggered ( ) ) , this , SLOT ( slotSetMouseTextSelect ( ) ) ) ;
2007-08-20 20:25:22 +00:00
d - > aMouseTextSelect - > setIconText ( i18nc ( " Text Selection Tool " , " Text Selection " ) ) ;
2006-09-26 22:22:01 +00:00
d - > aMouseTextSelect - > setCheckable ( true ) ;
2007-08-04 17:42:06 +00:00
d - > aMouseTextSelect - > setShortcut ( Qt : : CTRL + Qt : : Key_4 ) ;
2011-10-12 19:36:01 +00:00
d - > aMouseTextSelect - > setActionGroup ( d - > mouseModeActionGroup ) ;
2012-03-09 17:43:40 +00:00
d - > aMouseTextSelect - > setChecked ( Okular : : Settings : : mouseMode ( ) = = Okular : : Settings : : EnumMouseMode : : TextSelect ) ;
2006-09-26 22:22:01 +00:00
2011-10-12 13:50:56 +00:00
d - > aMouseTableSelect = new KAction ( KIcon ( " select-table " ) , i18n ( " T&able Selection Tool " ) , this ) ;
ac - > addAction ( " mouse_tableselect " , d - > aMouseTableSelect ) ;
connect ( d - > aMouseTableSelect , SIGNAL ( triggered ( ) ) , this , SLOT ( slotSetMouseTableSelect ( ) ) ) ;
d - > aMouseTableSelect - > setIconText ( i18nc ( " Table Selection Tool " , " Table Selection " ) ) ;
d - > aMouseTableSelect - > setCheckable ( true ) ;
d - > aMouseTableSelect - > setShortcut ( Qt : : CTRL + Qt : : Key_5 ) ;
2011-10-12 19:36:01 +00:00
d - > aMouseTableSelect - > setActionGroup ( d - > mouseModeActionGroup ) ;
2012-03-09 17:43:40 +00:00
d - > aMouseTableSelect - > setChecked ( Okular : : Settings : : mouseMode ( ) = = Okular : : Settings : : EnumMouseMode : : TableSelect ) ;
2011-10-12 13:50:56 +00:00
2007-12-08 18:49:02 +00:00
d - > aToggleAnnotator = new KToggleAction ( KIcon ( " draw-freehand " ) , i18n ( " &Review " ) , this ) ;
2007-01-09 11:02:04 +00:00
ac - > addAction ( " mouse_toggle_annotate " , d - > aToggleAnnotator ) ;
2006-04-01 15:12:32 +00:00
d - > aToggleAnnotator - > setCheckable ( true ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > aToggleAnnotator , SIGNAL ( toggled ( bool ) ) , SLOT ( slotToggleAnnotator ( bool ) ) ) ;
2006-04-10 18:50:27 +00:00
d - > aToggleAnnotator - > setShortcut ( Qt : : Key_F6 ) ;
2004-09-26 23:39:39 +00:00
2007-09-14 10:02:33 +00:00
ToolAction * ta = new ToolAction ( this ) ;
ac - > addAction ( " mouse_selecttools " , ta ) ;
ta - > addAction ( d - > aMouseSelect ) ;
ta - > addAction ( d - > aMouseTextSelect ) ;
2011-10-12 14:35:04 +00:00
ta - > addAction ( d - > aMouseTableSelect ) ;
2007-09-14 10:02:33 +00:00
2008-03-05 11:06:55 +00:00
// speak actions
2008-08-04 10:16:47 +00:00
d - > aSpeakDoc = new KAction ( KIcon ( " text-speak " ) , i18n ( " Speak Whole Document " ) , this ) ;
ac - > addAction ( " speak_document " , d - > aSpeakDoc ) ;
d - > aSpeakDoc - > setEnabled ( false ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > aSpeakDoc , SIGNAL ( triggered ( ) ) , SLOT ( slotSpeakDocument ( ) ) ) ;
2008-03-05 11:06:55 +00:00
2008-08-04 10:16:47 +00:00
d - > aSpeakPage = new KAction ( KIcon ( " text-speak " ) , i18n ( " Speak Current Page " ) , this ) ;
ac - > addAction ( " speak_current_page " , d - > aSpeakPage ) ;
d - > aSpeakPage - > setEnabled ( false ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > aSpeakPage , SIGNAL ( triggered ( ) ) , SLOT ( slotSpeakCurrentPage ( ) ) ) ;
2008-03-05 11:06:55 +00:00
2008-03-05 12:05:48 +00:00
d - > aSpeakStop = new KAction ( KIcon ( " media-playback-stop " ) , i18n ( " Stop Speaking " ) , this ) ;
ac - > addAction ( " speak_stop_all " , d - > aSpeakStop ) ;
d - > aSpeakStop - > setEnabled ( false ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > aSpeakStop , SIGNAL ( triggered ( ) ) , SLOT ( slotStopSpeaks ( ) ) ) ;
2008-03-05 12:05:48 +00:00
2004-09-26 23:39:39 +00:00
// Other actions
2007-01-09 11:02:04 +00:00
KAction * su = new KAction ( i18n ( " Scroll Up " ) , this ) ;
ac - > addAction ( " view_scroll_up " , su ) ;
2012-09-05 20:12:11 +00:00
connect ( su , SIGNAL ( triggered ( ) ) , this , SLOT ( slotAutoScrollUp ( ) ) ) ;
2006-04-13 11:41:36 +00:00
su - > setShortcut ( QKeySequence ( Qt : : SHIFT + Qt : : Key_Up ) ) ;
2006-09-29 09:02:07 +00:00
addAction ( su ) ;
2004-10-06 00:05:49 +00:00
2007-01-09 11:02:04 +00:00
KAction * sd = new KAction ( i18n ( " Scroll Down " ) , this ) ;
ac - > addAction ( " view_scroll_down " , sd ) ;
2012-09-05 20:12:11 +00:00
connect ( sd , SIGNAL ( triggered ( ) ) , this , SLOT ( slotAutoScrollDown ( ) ) ) ;
2006-04-13 11:41:36 +00:00
sd - > setShortcut ( QKeySequence ( Qt : : SHIFT + Qt : : Key_Down ) ) ;
2006-09-29 09:02:07 +00:00
addAction ( sd ) ;
2007-02-25 00:07:59 +00:00
2012-09-05 20:12:11 +00:00
KAction * spu = new KAction ( i18n ( " Scroll Page Up " ) , this ) ;
ac - > addAction ( " view_scroll_page_up " , spu ) ;
connect ( spu , SIGNAL ( triggered ( ) ) , this , SLOT ( slotScrollUp ( ) ) ) ;
spu - > setShortcut ( QKeySequence ( Qt : : SHIFT + Qt : : Key_Space ) ) ;
addAction ( spu ) ;
KAction * spd = new KAction ( i18n ( " Scroll Page Down " ) , this ) ;
ac - > addAction ( " view_scroll_page_down " , spd ) ;
connect ( spd , SIGNAL ( triggered ( ) ) , this , SLOT ( slotScrollDown ( ) ) ) ;
spd - > setShortcut ( QKeySequence ( Qt : : Key_Space ) ) ;
addAction ( spd ) ;
2007-02-25 00:07:59 +00:00
d - > aToggleForms = new KAction ( this ) ;
ac - > addAction ( " view_toggle_forms " , d - > aToggleForms ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > aToggleForms , SIGNAL ( triggered ( ) ) , this , SLOT ( slotToggleForms ( ) ) ) ;
2007-08-28 12:04:18 +00:00
d - > aToggleForms - > setEnabled ( false ) ;
2007-02-25 00:07:59 +00:00
toggleFormWidgets ( false ) ;
2004-09-26 23:39:39 +00:00
}
2006-11-19 13:50:41 +00:00
bool PageView : : canFitPageWidth ( ) const
2005-01-10 13:43:44 +00:00
{
2010-01-10 01:19:16 +00:00
return Okular : : Settings : : viewMode ( ) ! = Okular : : Settings : : EnumViewMode : : Single | | d - > zoomMode ! = ZoomFitWidth ;
2005-01-10 13:43:44 +00:00
}
2005-01-09 23:37:07 +00:00
void PageView : : fitPageWidth ( int page )
2004-12-04 23:23:18 +00:00
{
2005-01-09 23:37:07 +00:00
// zoom: Fit Width, columns: 1. setActions + relayout + setPage + update
2004-12-04 23:23:18 +00:00
d - > zoomMode = ZoomFitWidth ;
2007-05-17 20:46:16 +00:00
Okular : : Settings : : setViewMode ( 0 ) ;
2004-12-04 23:23:18 +00:00
d - > aZoomFitWidth - > setChecked ( true ) ;
d - > aZoomFitPage - > setChecked ( false ) ;
2008-10-12 16:36:14 +00:00
d - > aViewMode - > menu ( ) - > actions ( ) . at ( 0 ) - > setChecked ( true ) ;
2004-12-04 23:23:18 +00:00
viewport ( ) - > setUpdatesEnabled ( false ) ;
slotRelayoutPages ( ) ;
viewport ( ) - > setUpdatesEnabled ( true ) ;
2005-01-09 23:37:07 +00:00
d - > document - > setViewportPage ( page ) ;
2005-01-10 13:43:44 +00:00
updateZoomText ( ) ;
2005-06-13 10:22:37 +00:00
setFocus ( ) ;
2004-12-04 23:23:18 +00:00
}
2012-01-17 22:46:37 +00:00
void PageView : : openAnnotationWindow ( Okular : : Annotation * annotation , int pageNumber )
2006-08-08 15:31:13 +00:00
{
2006-12-30 12:40:54 +00:00
if ( ! annotation )
2006-08-08 15:31:13 +00:00
return ;
2006-12-30 12:40:54 +00:00
// find the annot window
AnnotWindow * existWindow = 0 ;
2008-11-11 18:48:40 +00:00
QHash < Okular : : Annotation * , AnnotWindow * > : : ConstIterator it = d - > m_annowindows . constFind ( annotation ) ;
if ( it ! = d - > m_annowindows . constEnd ( ) )
2006-08-08 15:31:13 +00:00
{
2008-05-29 19:12:56 +00:00
existWindow = * it ;
2006-08-08 15:31:13 +00:00
}
2006-12-30 12:40:54 +00:00
if ( existWindow = = 0 )
2006-08-08 15:31:13 +00:00
{
2012-01-17 22:46:37 +00:00
existWindow = new AnnotWindow ( this , annotation , d - > document , pageNumber ) ;
connect ( existWindow , SIGNAL ( destroyed ( QObject * ) ) , this , SLOT ( slotAnnotationWindowDestroyed ( QObject * ) ) ) ;
2006-12-30 12:40:54 +00:00
2008-05-29 19:12:56 +00:00
d - > m_annowindows . insert ( annotation , existWindow ) ;
2006-08-08 15:31:13 +00:00
}
2006-12-30 12:40:54 +00:00
existWindow - > show ( ) ;
}
2012-01-17 22:46:37 +00:00
void PageView : : slotAnnotationWindowDestroyed ( QObject * window )
2006-12-30 12:40:54 +00:00
{
2012-01-17 22:46:37 +00:00
QHash < Okular : : Annotation * , AnnotWindow * > : : Iterator it = d - > m_annowindows . begin ( ) ;
QHash < Okular : : Annotation * , AnnotWindow * > : : Iterator itEnd = d - > m_annowindows . end ( ) ;
while ( it ! = itEnd )
2006-12-30 12:40:54 +00:00
{
2012-01-17 22:46:37 +00:00
if ( it . value ( ) = = window )
{
it = d - > m_annowindows . erase ( it ) ;
}
else
{
+ + it ;
}
2006-12-30 12:40:54 +00:00
}
2006-08-08 15:31:13 +00:00
}
2010-08-21 15:47:33 +00:00
void PageView : : displayMessage ( const QString & message , const QString & details , PageViewMessage : : Icon icon , int duration )
2005-03-04 23:06:24 +00:00
{
2006-09-21 08:45:36 +00:00
if ( ! Okular : : Settings : : showOSD ( ) )
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
{
if ( icon = = PageViewMessage : : Error )
2010-08-21 22:31:26 +00:00
{
if ( ! details . isEmpty ( ) )
KMessageBox : : detailedError ( this , message , details ) ;
else
KMessageBox : : error ( this , message ) ;
}
return ;
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
}
2005-03-04 23:06:24 +00:00
// hide messageWindow if string is empty
if ( message . isEmpty ( ) )
return d - > messageWindow - > hide ( ) ;
// display message (duration is length dependant)
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
if ( duration = = - 1 )
2010-08-21 15:47:33 +00:00
{
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
duration = 500 + 100 * message . length ( ) ;
2010-08-21 15:47:33 +00:00
if ( ! details . isEmpty ( ) )
duration + = 500 + 100 * details . length ( ) ;
}
d - > messageWindow - > display ( message , details , icon , duration ) ;
2005-03-04 23:06:24 +00:00
}
2006-10-28 22:58:05 +00:00
void PageView : : reparseConfig ( )
{
// set the scroll bars policies
Qt : : ScrollBarPolicy scrollBarMode = Okular : : Settings : : showScrollBars ( ) ?
Qt : : ScrollBarAsNeeded : Qt : : ScrollBarAlwaysOff ;
if ( horizontalScrollBarPolicy ( ) ! = scrollBarMode )
{
setHorizontalScrollBarPolicy ( scrollBarMode ) ;
setVerticalScrollBarPolicy ( scrollBarMode ) ;
}
2010-01-10 01:19:16 +00:00
if ( Okular : : Settings : : viewMode ( ) = = Okular : : Settings : : EnumViewMode : : Summary & &
( ( int ) Okular : : Settings : : viewColumns ( ) ! = d - > setting_viewCols ) )
2006-10-28 22:58:05 +00:00
{
2007-05-19 10:19:25 +00:00
d - > setting_viewCols = Okular : : Settings : : viewColumns ( ) ;
2006-10-28 22:58:05 +00:00
slotRelayoutPages ( ) ;
}
2011-09-07 22:43:30 +00:00
updatePageStep ( ) ;
2006-10-28 22:58:05 +00:00
}
2007-02-25 00:07:59 +00:00
KAction * PageView : : toggleFormsAction ( ) const
{
return d - > aToggleForms ;
}
2009-06-29 20:55:50 +00:00
int PageView : : contentAreaWidth ( ) const
{
return horizontalScrollBar ( ) - > maximum ( ) + viewport ( ) - > width ( ) ;
}
int PageView : : contentAreaHeight ( ) const
{
return verticalScrollBar ( ) - > maximum ( ) + viewport ( ) - > height ( ) ;
}
QPoint PageView : : contentAreaPosition ( ) const
{
return QPoint ( horizontalScrollBar ( ) - > value ( ) , verticalScrollBar ( ) - > value ( ) ) ;
}
QPoint PageView : : contentAreaPoint ( const QPoint & pos ) const
{
return pos + contentAreaPosition ( ) ;
}
2012-10-15 18:11:47 +00:00
QPointF PageView : : contentAreaPoint ( const QPointF & pos ) const
{
return pos + contentAreaPosition ( ) ;
}
2008-02-26 20:54:31 +00:00
QString PageViewPrivate : : selectedText ( ) const
2006-11-24 21:02:38 +00:00
{
2008-02-26 20:54:31 +00:00
if ( pagesWithTextSelection . isEmpty ( ) )
return QString ( ) ;
2006-11-24 21:02:38 +00:00
QString text ;
2008-02-26 20:54:31 +00:00
QList < int > selpages = pagesWithTextSelection . toList ( ) ;
2006-11-24 21:02:38 +00:00
qSort ( selpages ) ;
const Okular : : Page * pg = 0 ;
if ( selpages . count ( ) = = 1 )
{
2008-02-26 20:54:31 +00:00
pg = document - > page ( selpages . first ( ) ) ;
2009-11-12 21:57:00 +00:00
text . append ( pg - > text ( pg - > textSelection ( ) , Okular : : TextPage : : CentralPixelTextAreaInclusionBehaviour ) ) ;
2006-11-24 21:02:38 +00:00
}
else
{
2008-02-26 20:54:31 +00:00
pg = document - > page ( selpages . first ( ) ) ;
2009-11-12 21:57:00 +00:00
text . append ( pg - > text ( pg - > textSelection ( ) , Okular : : TextPage : : CentralPixelTextAreaInclusionBehaviour ) ) ;
2006-11-24 21:02:38 +00:00
int end = selpages . count ( ) - 1 ;
for ( int i = 1 ; i < end ; + + i )
{
2008-02-26 20:54:31 +00:00
pg = document - > page ( selpages . at ( i ) ) ;
2009-11-12 21:57:00 +00:00
text . append ( pg - > text ( 0 , Okular : : TextPage : : CentralPixelTextAreaInclusionBehaviour ) ) ;
2006-11-24 21:02:38 +00:00
}
2008-02-26 20:54:31 +00:00
pg = document - > page ( selpages . last ( ) ) ;
2009-11-12 21:57:00 +00:00
text . append ( pg - > text ( pg - > textSelection ( ) , Okular : : TextPage : : CentralPixelTextAreaInclusionBehaviour ) ) ;
2006-11-24 21:02:38 +00:00
}
2008-02-26 20:54:31 +00:00
return text ;
}
void PageView : : copyTextSelection ( ) const
{
const QString text = d - > selectedText ( ) ;
2006-11-24 21:02:38 +00:00
if ( ! text . isEmpty ( ) )
{
QClipboard * cb = QApplication : : clipboard ( ) ;
cb - > setText ( text , QClipboard : : Clipboard ) ;
}
}
2007-09-03 21:35:05 +00:00
void PageView : : selectAll ( )
{
2012-03-09 17:43:40 +00:00
if ( Okular : : Settings : : mouseMode ( ) = = Okular : : Settings : : EnumMouseMode : : TextSelect )
2007-09-03 21:35:05 +00:00
return ;
2008-11-11 18:48:40 +00:00
QVector < PageViewItem * > : : const_iterator it = d - > items . constBegin ( ) , itEnd = d - > items . constEnd ( ) ;
2007-09-03 21:35:05 +00:00
for ( ; it < itEnd ; + + it )
{
Okular : : RegularAreaRect * area = textSelectionForItem ( * it ) ;
d - > pagesWithTextSelection . insert ( ( * it ) - > pageNumber ( ) ) ;
d - > document - > setPageTextSelection ( ( * it ) - > pageNumber ( ) , area , palette ( ) . color ( QPalette : : Active , QPalette : : Highlight ) ) ;
}
}
2005-01-09 23:37:07 +00:00
//BEGIN DocumentObserver inherited methods
2007-09-09 10:50:36 +00:00
void PageView : : notifySetup ( const QVector < Okular : : Page * > & pageSet , int setupFlags )
2004-10-10 13:21:30 +00:00
{
2007-09-09 10:50:36 +00:00
bool documentChanged = setupFlags & Okular : : DocumentObserver : : DocumentChanged ;
2004-10-10 13:21:30 +00:00
// reuse current pages if nothing new
2007-09-09 10:50:36 +00:00
if ( ( pageSet . count ( ) = = d - > items . count ( ) ) & & ! documentChanged & & ! ( setupFlags & Okular : : DocumentObserver : : NewLayoutForPages ) )
2004-10-10 13:21:30 +00:00
{
int count = pageSet . count ( ) ;
for ( int i = 0 ; ( i < count ) & & ! documentChanged ; i + + )
2004-11-05 00:14:00 +00:00
if ( ( int ) pageSet [ i ] - > number ( ) ! = d - > items [ i ] - > pageNumber ( ) )
2004-10-10 13:21:30 +00:00
documentChanged = true ;
if ( ! documentChanged )
return ;
}
2008-11-21 10:50:16 +00:00
2004-10-10 13:21:30 +00:00
// delete all widgets (one for each page in pageSet)
2008-11-11 18:48:40 +00:00
QVector < PageViewItem * > : : const_iterator dIt = d - > items . constBegin ( ) , dEnd = d - > items . constEnd ( ) ;
2004-09-26 23:39:39 +00:00
for ( ; dIt ! = dEnd ; + + dIt )
delete * dIt ;
2004-11-05 00:14:00 +00:00
d - > items . clear ( ) ;
2005-01-03 01:10:27 +00:00
d - > visibleItems . clear ( ) ;
2007-12-31 18:28:02 +00:00
d - > pagesWithTextSelection . clear ( ) ;
2007-02-25 00:07:59 +00:00
toggleFormWidgets ( false ) ;
2008-02-11 10:41:04 +00:00
if ( d - > formsWidgetController )
d - > formsWidgetController - > dropRadioButtons ( ) ;
2004-09-26 23:39:39 +00:00
2007-08-28 12:04:18 +00:00
bool haspages = ! pageSet . isEmpty ( ) ;
2007-02-25 00:07:59 +00:00
bool hasformwidgets = false ;
2004-09-26 23:39:39 +00:00
// create children widgets
2008-11-11 18:48:40 +00:00
QVector < Okular : : Page * > : : const_iterator setIt = pageSet . constBegin ( ) , setEnd = pageSet . constEnd ( ) ;
2004-09-26 23:39:39 +00:00
for ( ; setIt ! = setEnd ; + + setIt )
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
{
2007-02-25 00:07:59 +00:00
PageViewItem * item = new PageViewItem ( * setIt ) ;
d - > items . push_back ( item ) ;
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
# ifdef PAGEVIEW_DEBUG
2008-05-19 00:37:14 +00:00
kDebug ( ) . nospace ( ) < < " cropped geom for " < < d - > items . last ( ) - > pageNumber ( ) < < " is " < < d - > items . last ( ) - > croppedGeometry ( ) ;
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
# endif
2007-02-25 00:07:59 +00:00
const QLinkedList < Okular : : FormField * > pageFields = ( * setIt ) - > formFields ( ) ;
2008-11-11 18:48:40 +00:00
QLinkedList < Okular : : FormField * > : : const_iterator ffIt = pageFields . constBegin ( ) , ffEnd = pageFields . constEnd ( ) ;
2007-02-25 00:07:59 +00:00
for ( ; ffIt ! = ffEnd ; + + ffIt )
{
Okular : : FormField * ff = * ffIt ;
2009-06-29 20:55:50 +00:00
FormWidgetIface * w = FormWidgetFactory : : createWidget ( ff , viewport ( ) ) ;
2007-02-25 00:07:59 +00:00
if ( w )
{
2007-10-18 22:09:49 +00:00
w - > setPageItem ( item ) ;
w - > setFormWidgetsController ( d - > formWidgetsController ( ) ) ;
2007-12-31 22:22:38 +00:00
w - > setVisibility ( false ) ;
2007-04-28 23:22:20 +00:00
w - > setCanBeFilled ( d - > document - > isAllowed ( Okular : : AllowFillForms ) ) ;
2008-02-11 01:37:02 +00:00
item - > formWidgets ( ) . insert ( ff - > id ( ) , w ) ;
2007-02-25 00:07:59 +00:00
hasformwidgets = true ;
}
}
2008-08-25 01:59:23 +00:00
const QLinkedList < Okular : : Annotation * > annotations = ( * setIt ) - > annotations ( ) ;
2008-11-11 18:48:40 +00:00
QLinkedList < Okular : : Annotation * > : : const_iterator aIt = annotations . constBegin ( ) , aEnd = annotations . constEnd ( ) ;
2008-08-25 01:59:23 +00:00
for ( ; aIt ! = aEnd ; + + aIt )
{
Okular : : Annotation * a = * aIt ;
if ( a - > subType ( ) = = Okular : : Annotation : : AMovie )
{
Okular : : MovieAnnotation * movieAnn = static_cast < Okular : : MovieAnnotation * > ( a ) ;
2012-09-27 11:02:14 +00:00
VideoWidget * vw = new VideoWidget ( movieAnn , movieAnn - > movie ( ) , d - > document , viewport ( ) ) ;
2008-08-25 01:59:23 +00:00
item - > videoWidgets ( ) . insert ( movieAnn - > movie ( ) , vw ) ;
2012-09-21 09:20:53 +00:00
vw - > pageInitialized ( ) ;
2008-08-25 01:59:23 +00:00
}
2012-09-27 12:15:58 +00:00
else if ( a - > subType ( ) = = Okular : : Annotation : : AScreen )
{
const Okular : : ScreenAnnotation * screenAnn = static_cast < Okular : : ScreenAnnotation * > ( a ) ;
Okular : : Movie * movie = GuiUtils : : renditionMovieFromScreenAnnotation ( screenAnn ) ;
if ( movie )
{
VideoWidget * vw = new VideoWidget ( screenAnn , movie , d - > document , viewport ( ) ) ;
item - > videoWidgets ( ) . insert ( movie , vw ) ;
vw - > pageInitialized ( ) ;
}
2008-08-25 01:59:23 +00:00
}
}
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
}
2004-09-26 23:39:39 +00:00
2005-01-09 23:37:07 +00:00
// invalidate layout so relayout/repaint will happen on next viewport change
2007-08-28 12:04:18 +00:00
if ( haspages )
2010-01-09 15:37:38 +00:00
{
// We do a delayed call to slotRelayoutPages but also set the dirtyLayout
// because we might end up in notifyViewportChanged while slotRelayoutPages
// has not been done and we don't want that to happen
d - > dirtyLayout = true ;
2011-03-17 15:24:44 +00:00
QMetaObject : : invokeMethod ( this , " slotRelayoutPages " , Qt : : QueuedConnection ) ;
2010-01-09 15:37:38 +00:00
}
2005-01-27 17:31:07 +00:00
else
2005-11-04 11:59:51 +00:00
{
// update the mouse cursor when closing because we may have close through a link and
// want the cursor to come back to the normal cursor
2009-06-29 20:55:50 +00:00
updateCursor ( contentAreaPosition ( ) + viewport ( ) - > mapFromGlobal ( QCursor : : pos ( ) ) ) ;
2011-12-07 22:05:36 +00:00
// then, make the message window and scrollbars disappear, and trigger a repaint
2011-10-18 20:36:42 +00:00
d - > messageWindow - > hide ( ) ;
resizeContentArea ( QSize ( 0 , 0 ) ) ;
2011-12-07 22:05:36 +00:00
viewport ( ) - > update ( ) ; // when there is no change to the scrollbars, no repaint would
// be done and the old document would still be shown
2005-11-04 11:59:51 +00:00
}
2004-10-29 20:20:21 +00:00
// OSD to display pages
2006-09-21 08:45:36 +00:00
if ( documentChanged & & pageSet . count ( ) > 0 & & Okular : : Settings : : showOSD ( ) )
2004-10-29 20:20:21 +00:00
d - > messageWindow - > display (
2006-04-10 18:50:27 +00:00
i18np ( " Loaded a one-page document. " ,
2007-02-13 17:45:54 +00:00
" Loaded a %1-page document. " ,
2004-11-30 20:03:45 +00:00
pageSet . count ( ) ) ,
2010-08-21 15:46:47 +00:00
QString ( ) ,
2004-10-29 20:20:21 +00:00
PageViewMessage : : Info , 4000 ) ;
2005-07-20 22:28:23 +00:00
2011-10-23 09:17:04 +00:00
updateActionState ( haspages , documentChanged , hasformwidgets ) ;
2012-03-07 22:51:36 +00:00
// We need to assign it to a different list otherwise slotAnnotationWindowDestroyed
// will bite us and clear d->m_annowindows
QHash < Okular : : Annotation * , AnnotWindow * > annowindows = d - > m_annowindows ;
2011-10-23 09:17:04 +00:00
d - > m_annowindows . clear ( ) ;
2012-03-07 22:51:36 +00:00
qDeleteAll ( annowindows ) ;
2011-10-23 09:17:04 +00:00
selectionClear ( ) ;
}
void PageView : : updateActionState ( bool haspages , bool documentChanged , bool hasformwidgets )
{
2007-06-05 20:49:00 +00:00
if ( d - > aPageSizes )
{ // may be null if dummy mode is on
bool pageSizes = d - > document - > supportsPageSizes ( ) ;
d - > aPageSizes - > setEnabled ( pageSizes ) ;
// set the new page sizes:
// - if the generator supports them
// - if the document changed
if ( pageSizes & & documentChanged )
{
QStringList items ;
foreach ( const Okular : : PageSize & p , d - > document - > pageSizes ( ) )
items . append ( p . name ( ) ) ;
d - > aPageSizes - > setItems ( items ) ;
}
}
2011-10-23 09:17:04 +00:00
if ( d - > aTrimMargins )
d - > aTrimMargins - > setEnabled ( haspages ) ;
if ( d - > aViewMode )
d - > aViewMode - > setEnabled ( haspages ) ;
if ( d - > aViewContinuous )
d - > aViewContinuous - > setEnabled ( haspages ) ;
if ( d - > aZoomFitWidth )
d - > aZoomFitWidth - > setEnabled ( haspages ) ;
if ( d - > aZoomFitPage )
d - > aZoomFitPage - > setEnabled ( haspages ) ;
2011-11-24 21:28:07 +00:00
if ( d - > aZoom )
{
d - > aZoom - > selectableActionGroup ( ) - > setEnabled ( haspages ) ;
d - > aZoom - > setEnabled ( haspages ) ;
}
2011-10-23 09:17:04 +00:00
if ( d - > aZoomIn )
d - > aZoomIn - > setEnabled ( haspages ) ;
if ( d - > aZoomOut )
d - > aZoomOut - > setEnabled ( haspages ) ;
if ( d - > mouseModeActionGroup )
d - > mouseModeActionGroup - > setEnabled ( haspages ) ;
2007-08-28 12:04:18 +00:00
if ( d - > aRotateClockwise )
d - > aRotateClockwise - > setEnabled ( haspages ) ;
if ( d - > aRotateCounterClockwise )
d - > aRotateCounterClockwise - > setEnabled ( haspages ) ;
if ( d - > aRotateOriginal )
d - > aRotateOriginal - > setEnabled ( haspages ) ;
2007-06-05 20:49:00 +00:00
if ( d - > aToggleForms )
{ // may be null if dummy mode is on
2007-08-28 12:04:18 +00:00
d - > aToggleForms - > setEnabled ( haspages & & hasformwidgets ) ;
2007-01-05 23:12:06 +00:00
}
2007-08-27 22:11:18 +00:00
bool allowAnnotations = d - > document - > isAllowed ( Okular : : AllowNotes ) ;
2007-04-30 17:40:53 +00:00
if ( d - > annotator )
2007-08-27 22:11:18 +00:00
{
2007-12-09 01:35:42 +00:00
bool allowTools = haspages & & allowAnnotations ;
d - > annotator - > setToolsEnabled ( allowTools ) ;
d - > annotator - > setTextToolsEnabled ( allowTools & & d - > document - > supportsSearching ( ) ) ;
}
if ( d - > aToggleAnnotator )
{
if ( ! allowAnnotations & & d - > aToggleAnnotator - > isChecked ( ) )
2007-08-27 22:11:18 +00:00
{
d - > aToggleAnnotator - > trigger ( ) ;
}
2007-08-28 12:04:18 +00:00
d - > aToggleAnnotator - > setEnabled ( allowAnnotations ) ;
2007-12-09 01:35:42 +00:00
}
2008-08-04 10:16:47 +00:00
if ( d - > aSpeakDoc )
{
const bool enablettsactions = haspages ? Okular : : Settings : : useKTTSD ( ) : false ;
d - > aSpeakDoc - > setEnabled ( enablettsactions ) ;
d - > aSpeakPage - > setEnabled ( enablettsactions ) ;
}
2004-09-26 23:39:39 +00:00
}
2011-11-07 21:07:10 +00:00
bool PageView : : areSourceLocationsShownGraphically ( ) const
{
return Okular : : Settings : : showSourceLocationsGraphically ( ) ;
}
void PageView : : setShowSourceLocationsGraphically ( bool show )
{
if ( show = = Okular : : Settings : : showSourceLocationsGraphically ( ) )
{
return ;
}
Okular : : Settings : : setShowSourceLocationsGraphically ( show ) ;
viewport ( ) - > update ( ) ;
}
2011-11-01 21:13:20 +00:00
void PageView : : setLastSourceLocationViewport ( const Okular : : DocumentViewport & vp )
{
if ( vp . rePos . enabled )
{
d - > lastSourceLocationViewportNormalizedX = normClamp ( vp . rePos . normalizedX , 0.5 ) ;
d - > lastSourceLocationViewportNormalizedY = normClamp ( vp . rePos . normalizedY , 0.0 ) ;
}
else
{
d - > lastSourceLocationViewportNormalizedX = 0.5 ;
d - > lastSourceLocationViewportNormalizedY = 0.0 ;
}
d - > lastSourceLocationViewportPageNumber = vp . pageNumber ;
2011-11-07 21:07:10 +00:00
viewport ( ) - > update ( ) ;
2011-11-01 21:13:20 +00:00
}
2011-11-05 09:18:08 +00:00
void PageView : : clearLastSourceLocationViewport ( )
{
d - > lastSourceLocationViewportPageNumber = - 1 ;
d - > lastSourceLocationViewportNormalizedX = 0.0 ;
d - > lastSourceLocationViewportNormalizedY = 0.0 ;
2011-11-07 21:07:10 +00:00
viewport ( ) - > update ( ) ;
2011-11-05 09:18:08 +00:00
}
2005-02-01 18:24:16 +00:00
void PageView : : notifyViewportChanged ( bool smoothMove )
2011-11-02 21:46:23 +00:00
{
QMetaObject : : invokeMethod ( this , " slotRealNotifyViewportChanged " , Qt : : QueuedConnection , Q_ARG ( bool , smoothMove ) ) ;
}
void PageView : : slotRealNotifyViewportChanged ( bool smoothMove )
2004-09-26 23:39:39 +00:00
{
2005-01-09 23:37:07 +00:00
// if we are the one changing viewport, skip this nofity
if ( d - > blockViewport )
return ;
// block setViewport outgoing calls
d - > blockViewport = true ;
// find PageViewItem matching the viewport description
2006-09-21 08:45:36 +00:00
const Okular : : DocumentViewport & vp = d - > document - > viewport ( ) ;
2005-01-09 23:37:07 +00:00
PageViewItem * item = 0 ;
2008-11-11 18:48:40 +00:00
QVector < PageViewItem * > : : const_iterator iIt = d - > items . constBegin ( ) , iEnd = d - > items . constEnd ( ) ;
2004-11-05 00:14:00 +00:00
for ( ; iIt ! = iEnd ; + + iIt )
2005-01-21 20:05:36 +00:00
if ( ( * iIt ) - > pageNumber ( ) = = vp . pageNumber )
2004-09-26 23:39:39 +00:00
{
2005-01-09 23:37:07 +00:00
item = * iIt ;
2004-09-26 23:39:39 +00:00
break ;
}
2005-01-09 23:37:07 +00:00
if ( ! item )
{
2007-07-31 10:19:48 +00:00
kWarning ( ) < < " viewport for page " < < vp . pageNumber < < " has no matching item! " ;
2005-11-04 11:59:51 +00:00
d - > blockViewport = false ;
2004-09-30 18:16:12 +00:00
return ;
2005-01-09 23:37:07 +00:00
}
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
# ifdef PAGEVIEW_DEBUG
2007-07-31 10:19:48 +00:00
kDebug ( ) < < " document viewport changed " ;
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
# endif
2004-10-10 13:21:30 +00:00
// relayout in "Single Pages" mode or if a relayout is pending
2005-01-21 20:05:36 +00:00
d - > blockPixmapsRequest = true ;
2006-09-21 08:45:36 +00:00
if ( ! Okular : : Settings : : viewContinuous ( ) | | d - > dirtyLayout )
2004-09-30 18:16:12 +00:00
slotRelayoutPages ( ) ;
2005-02-01 18:24:16 +00:00
// restore viewport center or use default {x-center,v-top} alignment
2008-05-19 00:37:14 +00:00
const QRect & r = item - > croppedGeometry ( ) ;
2005-02-01 18:24:16 +00:00
int newCenterX = r . left ( ) ,
newCenterY = r . top ( ) ;
2005-06-13 11:53:47 +00:00
if ( vp . rePos . enabled )
2004-11-05 18:14:20 +00:00
{
2006-09-21 08:45:36 +00:00
if ( vp . rePos . pos = = Okular : : DocumentViewport : : Center )
2005-06-13 11:53:47 +00:00
{
2009-05-17 10:17:35 +00:00
newCenterX + = ( int ) ( normClamp ( vp . rePos . normalizedX , 0.5 ) * ( double ) r . width ( ) ) ;
newCenterY + = ( int ) ( normClamp ( vp . rePos . normalizedY , 0.0 ) * ( double ) r . height ( ) ) ;
2005-06-13 11:53:47 +00:00
}
else
{
// TopLeft
2009-05-17 10:17:35 +00:00
newCenterX + = ( int ) ( normClamp ( vp . rePos . normalizedX , 0.0 ) * ( double ) r . width ( ) + viewport ( ) - > width ( ) / 2 ) ;
newCenterY + = ( int ) ( normClamp ( vp . rePos . normalizedY , 0.0 ) * ( double ) r . height ( ) + viewport ( ) - > height ( ) / 2 ) ;
2005-06-13 11:53:47 +00:00
}
2005-02-01 18:24:16 +00:00
}
else
{
newCenterX + = r . width ( ) / 2 ;
2006-10-07 14:40:32 +00:00
newCenterY + = viewport ( ) - > height ( ) / 2 - 10 ;
2005-02-01 18:24:16 +00:00
}
// if smooth movement requested, setup parameters and start it
if ( smoothMove )
{
d - > viewportMoveActive = true ;
d - > viewportMoveTime . start ( ) ;
d - > viewportMoveDest . setX ( newCenterX ) ;
d - > viewportMoveDest . setY ( newCenterY ) ;
if ( ! d - > viewportMoveTimer )
{
d - > viewportMoveTimer = new QTimer ( this ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > viewportMoveTimer , SIGNAL ( timeout ( ) ) ,
this , SLOT ( slotMoveViewport ( ) ) ) ;
2005-02-01 18:24:16 +00:00
}
d - > viewportMoveTimer - > start ( 25 ) ;
verticalScrollBar ( ) - > setEnabled ( false ) ;
horizontalScrollBar ( ) - > setEnabled ( false ) ;
2004-11-05 18:14:20 +00:00
}
2005-01-09 23:37:07 +00:00
else
2005-02-01 18:24:16 +00:00
center ( newCenterX , newCenterY ) ;
2005-01-21 20:05:36 +00:00
d - > blockPixmapsRequest = false ;
2005-01-09 23:37:07 +00:00
// request visible pixmaps in the current viewport and recompute it
2004-09-30 18:16:12 +00:00
slotRequestVisiblePixmaps ( ) ;
2005-01-09 23:37:07 +00:00
// enable setViewport calls
d - > blockViewport = false ;
2004-09-30 18:16:12 +00:00
// update zoom text if in a ZoomFit/* zoom mode
if ( d - > zoomMode ! = ZoomFixed )
updateZoomText ( ) ;
2005-01-01 21:50:34 +00:00
2011-10-31 21:41:50 +00:00
if ( viewport ( ) )
{
viewport ( ) - > update ( ) ;
2011-09-10 17:15:52 +00:00
}
2005-01-09 23:37:07 +00:00
// since the page has moved below cursor, update it
2009-06-29 20:55:50 +00:00
updateCursor ( contentAreaPosition ( ) + viewport ( ) - > mapFromGlobal ( QCursor : : pos ( ) ) ) ;
2004-09-26 23:39:39 +00:00
}
2004-12-21 12:38:52 +00:00
2005-01-30 00:58:16 +00:00
void PageView : : notifyPageChanged ( int pageNumber , int changedFlags )
2004-12-21 12:38:52 +00:00
{
2005-01-30 00:58:16 +00:00
// only handle pixmap / highlight changes notifies
if ( changedFlags & DocumentObserver : : Bookmark )
return ;
2004-12-21 12:38:52 +00:00
2008-03-24 00:08:08 +00:00
if ( changedFlags & DocumentObserver : : Annotations )
{
2008-05-29 19:12:56 +00:00
const QLinkedList < Okular : : Annotation * > annots = d - > document - > page ( pageNumber ) - > annotations ( ) ;
const QLinkedList < Okular : : Annotation * > : : ConstIterator annItEnd = annots . end ( ) ;
QHash < Okular : : Annotation * , AnnotWindow * > : : Iterator it = d - > m_annowindows . begin ( ) ;
for ( ; it ! = d - > m_annowindows . end ( ) ; )
2008-03-24 00:08:08 +00:00
{
2008-05-29 19:12:56 +00:00
QLinkedList < Okular : : Annotation * > : : ConstIterator annIt = qFind ( annots , it . key ( ) ) ;
if ( annIt ! = annItEnd )
{
( * it ) - > reloadInfo ( ) ;
+ + it ;
}
else
{
2012-01-17 22:46:37 +00:00
AnnotWindow * w = * it ;
2008-05-29 19:12:56 +00:00
it = d - > m_annowindows . erase ( it ) ;
2012-01-17 22:46:37 +00:00
// Need to delete after removing from the list
// otherwise deleting will call slotAnnotationWindowDestroyed wich will mess
// the list and the iterators
delete w ;
2008-05-29 19:12:56 +00:00
}
2008-03-24 00:08:08 +00:00
}
}
2008-05-19 00:37:14 +00:00
if ( changedFlags & DocumentObserver : : BoundingBox )
{
# ifdef PAGEVIEW_DEBUG
kDebug ( ) < < " BoundingBox change on page " < < pageNumber ;
# endif
slotRelayoutPages ( ) ;
slotRequestVisiblePixmaps ( ) ; // TODO: slotRelayoutPages() may have done this already!
// Repaint the whole widget since layout may have changed
2009-06-29 20:55:50 +00:00
viewport ( ) - > update ( ) ;
2008-05-19 00:37:14 +00:00
return ;
}
2005-01-09 23:37:07 +00:00
// iterate over visible items: if page(pageNumber) is one of them, repaint it
2008-11-11 18:48:40 +00:00
QLinkedList < PageViewItem * > : : const_iterator iIt = d - > visibleItems . constBegin ( ) , iEnd = d - > visibleItems . constEnd ( ) ;
2004-12-21 12:38:52 +00:00
for ( ; iIt ! = iEnd ; + + iIt )
2007-12-31 17:35:22 +00:00
if ( ( * iIt ) - > pageNumber ( ) = = pageNumber & & ( * iIt ) - > isVisible ( ) )
2004-12-21 12:38:52 +00:00
{
// update item's rectangle plus the little outline
2008-05-19 00:37:14 +00:00
QRect expandedRect = ( * iIt ) - > croppedGeometry ( ) ;
2009-06-29 20:55:50 +00:00
// a PageViewItem is placed in the global page layout,
// while we need to map its position in the viewport coordinates
// (to get the correct area to repaint)
expandedRect . translate ( - contentAreaPosition ( ) ) ;
2006-03-29 16:46:09 +00:00
expandedRect . adjust ( - 1 , - 1 , 3 , 3 ) ;
2009-06-29 20:55:50 +00:00
viewport ( ) - > update ( expandedRect ) ;
2005-01-02 11:50:38 +00:00
2005-01-02 13:40:40 +00:00
// if we were "zoom-dragging" do not overwrite the "zoom-drag" cursor
2005-01-09 23:37:07 +00:00
if ( cursor ( ) . shape ( ) ! = Qt : : SizeVerCursor )
2005-01-02 11:50:38 +00:00
{
2005-01-09 23:37:07 +00:00
// since the page has been regenerated below cursor, update it
2009-06-29 20:55:50 +00:00
updateCursor ( contentAreaPosition ( ) + viewport ( ) - > mapFromGlobal ( QCursor : : pos ( ) ) ) ;
2005-01-02 11:50:38 +00:00
}
2004-12-21 12:38:52 +00:00
break ;
}
}
2005-01-09 23:37:07 +00:00
void PageView : : notifyContentsCleared ( int changedFlags )
2004-12-21 12:38:52 +00:00
{
2005-01-09 23:37:07 +00:00
// if pixmaps were cleared, re-ask them
if ( changedFlags & DocumentObserver : : Pixmap )
2006-10-19 21:18:39 +00:00
QMetaObject : : invokeMethod ( this , " slotRequestVisiblePixmaps " , Qt : : QueuedConnection ) ;
2004-12-21 12:38:52 +00:00
}
2005-01-09 23:37:07 +00:00
2007-07-08 14:25:08 +00:00
void PageView : : notifyZoom ( int factor )
{
if ( factor > 0 )
updateZoom ( ZoomIn ) ;
else
updateZoom ( ZoomOut ) ;
}
2006-11-20 20:10:42 +00:00
bool PageView : : canUnloadPixmap ( int pageNumber ) const
2005-01-09 23:37:07 +00:00
{
2012-10-15 22:27:42 +00:00
if ( Okular : : SettingsCore : : memoryLevel ( ) = = Okular : : SettingsCore : : EnumMemoryLevel : : Low | |
Okular : : SettingsCore : : memoryLevel ( ) = = Okular : : SettingsCore : : EnumMemoryLevel : : Normal )
2006-11-24 19:29:52 +00:00
{
// if the item is visible, forbid unloading
2008-11-11 18:48:40 +00:00
QLinkedList < PageViewItem * > : : const_iterator vIt = d - > visibleItems . constBegin ( ) , vEnd = d - > visibleItems . constEnd ( ) ;
2006-11-24 19:29:52 +00:00
for ( ; vIt ! = vEnd ; + + vIt )
if ( ( * vIt ) - > pageNumber ( ) = = pageNumber )
return false ;
}
else
{
// forbid unloading of the visible items, and of the previous and next
2008-11-11 18:48:40 +00:00
QLinkedList < PageViewItem * > : : const_iterator vIt = d - > visibleItems . constBegin ( ) , vEnd = d - > visibleItems . constEnd ( ) ;
2006-11-24 19:29:52 +00:00
for ( ; vIt ! = vEnd ; + + vIt )
if ( abs ( ( * vIt ) - > pageNumber ( ) - pageNumber ) < = 1 )
return false ;
}
2005-01-09 23:37:07 +00:00
// if hidden premit unloading
return true ;
}
2012-09-21 09:20:53 +00:00
void PageView : : notifyCurrentPageChanged ( int previous , int current )
{
if ( previous ! = - 1 )
{
PageViewItem * item = d - > items . at ( previous ) ;
if ( item )
{
Q_FOREACH ( VideoWidget * videoWidget , item - > videoWidgets ( ) )
videoWidget - > pageLeft ( ) ;
}
}
if ( current ! = - 1 )
{
PageViewItem * item = d - > items . at ( current ) ;
if ( item )
{
Q_FOREACH ( VideoWidget * videoWidget , item - > videoWidgets ( ) )
videoWidget - > pageEntered ( ) ;
}
}
}
2005-01-09 23:37:07 +00:00
//END DocumentObserver inherited methods
2004-09-26 23:39:39 +00:00
2008-04-27 11:17:05 +00:00
//BEGIN View inherited methods
bool PageView : : supportsCapability ( ViewCapability capability ) const
{
switch ( capability )
{
case Zoom :
2008-05-31 20:45:30 +00:00
case ZoomModality :
2008-04-27 11:17:05 +00:00
return true ;
}
return false ;
}
Okular : : View : : CapabilityFlags PageView : : capabilityFlags ( ViewCapability capability ) const
{
switch ( capability )
{
case Zoom :
2008-05-31 20:45:30 +00:00
case ZoomModality :
2008-05-31 21:08:45 +00:00
return CapabilityRead | CapabilityWrite | CapabilitySerializable ;
2008-04-27 11:17:05 +00:00
}
return 0 ;
}
QVariant PageView : : capability ( ViewCapability capability ) const
{
switch ( capability )
{
case Zoom :
return d - > zoomFactor ;
2008-05-31 20:45:30 +00:00
case ZoomModality :
return d - > zoomMode ;
2008-04-27 11:17:05 +00:00
}
return QVariant ( ) ;
}
void PageView : : setCapability ( ViewCapability capability , const QVariant & option )
{
switch ( capability )
{
case Zoom :
{
bool ok = true ;
double factor = option . toDouble ( & ok ) ;
if ( ok & & factor > 0.0 )
{
d - > zoomFactor = static_cast < float > ( factor ) ;
updateZoom ( ZoomRefreshCurrent ) ;
}
break ;
}
2008-05-31 20:45:30 +00:00
case ZoomModality :
{
bool ok = true ;
int mode = option . toInt ( & ok ) ;
if ( ok )
{
if ( mode > = 0 & & mode < 3 )
updateZoom ( ( ZoomMode ) mode ) ;
}
break ;
}
2008-04-27 11:17:05 +00:00
}
}
//END View inherited methods
2004-10-10 12:42:42 +00:00
//BEGIN widget events
2009-06-29 20:55:50 +00:00
void PageView : : paintEvent ( QPaintEvent * pe )
2006-09-27 10:28:03 +00:00
{
2009-06-29 20:55:50 +00:00
const QPoint areaPos = contentAreaPosition ( ) ;
2006-10-07 14:40:32 +00:00
// create the rect into contents from the clipped screen rect
QRect viewportRect = viewport ( ) - > rect ( ) ;
2009-06-29 20:55:50 +00:00
viewportRect . translate ( areaPos ) ;
QRect contentsRect = pe - > rect ( ) . translated ( areaPos ) . intersect ( viewportRect ) ;
2006-10-07 14:40:32 +00:00
if ( ! contentsRect . isValid ( ) )
return ;
2006-09-27 10:28:03 +00:00
2006-10-22 13:49:11 +00:00
# ifdef PAGEVIEW_DEBUG
2007-07-31 10:19:48 +00:00
kDebug ( ) < < " paintevent " < < contentsRect ;
2006-10-22 13:49:11 +00:00
# endif
2006-10-07 14:40:32 +00:00
// create the screen painter. a pixel painted at contentsX,contentsY
// appears to the top-left corner of the scrollview.
2009-06-29 20:55:50 +00:00
QPainter screenPainter ( viewport ( ) ) ;
// translate to simulate the scrolled content widget
screenPainter . translate ( - areaPos ) ;
2006-10-07 14:40:32 +00:00
// selectionRect is the normalized mouse selection rect
QRect selectionRect = d - > mouseSelectionRect ;
if ( ! selectionRect . isNull ( ) )
selectionRect = selectionRect . normalized ( ) ;
// selectionRectInternal without the border
QRect selectionRectInternal = selectionRect ;
selectionRectInternal . adjust ( 1 , 1 , - 1 , - 1 ) ;
// color for blending
QColor selBlendColor = ( selectionRect . width ( ) > 8 | | selectionRect . height ( ) > 8 ) ?
d - > mouseSelectionColor : Qt : : red ;
// subdivide region into rects
2007-02-03 23:09:40 +00:00
const QVector < QRect > & allRects = pe - > region ( ) . rects ( ) ;
2006-10-07 14:40:32 +00:00
uint numRects = allRects . count ( ) ;
// preprocess rects area to see if it worths or not using subdivision
uint summedArea = 0 ;
for ( uint i = 0 ; i < numRects ; i + + )
2006-09-27 10:28:03 +00:00
{
2006-10-07 14:40:32 +00:00
const QRect & r = allRects [ i ] ;
summedArea + = r . width ( ) * r . height ( ) ;
2006-09-27 10:28:03 +00:00
}
2006-10-07 14:40:32 +00:00
// very elementary check: SUMj(Region[j].area) is less than boundingRect.area
bool useSubdivision = summedArea < ( 0.6 * contentsRect . width ( ) * contentsRect . height ( ) ) ;
if ( ! useSubdivision )
numRects = 1 ;
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
2006-10-07 14:40:32 +00:00
// iterate over the rects (only one loop if not using subdivision)
for ( uint i = 0 ; i < numRects ; i + + )
2004-11-01 14:37:15 +00:00
{
2006-10-07 14:40:32 +00:00
if ( useSubdivision )
{
// set 'contentsRect' to a part of the sub-divided region
2011-11-14 16:19:23 +00:00
contentsRect = allRects [ i ] . translated ( areaPos ) . intersect ( viewportRect ) ;
2006-10-07 14:40:32 +00:00
if ( ! contentsRect . isValid ( ) )
continue ;
}
2006-10-22 13:49:11 +00:00
# ifdef PAGEVIEW_DEBUG
2007-07-31 10:19:48 +00:00
kDebug ( ) < < contentsRect ;
2006-10-22 13:49:11 +00:00
# endif
2004-10-31 12:43:13 +00:00
2006-10-07 14:40:32 +00:00
// note: this check will take care of all things requiring alpha blending (not only selection)
bool wantCompositing = ! selectionRect . isNull ( ) & & contentsRect . intersects ( selectionRect ) ;
2011-10-12 13:50:56 +00:00
// also alpha-blend when there is a table selection...
wantCompositing | = ! d - > tableSelectionParts . isEmpty ( ) ;
2004-11-08 13:13:46 +00:00
2006-10-07 14:40:32 +00:00
if ( wantCompositing & & Okular : : Settings : : enableCompositing ( ) )
2004-10-31 13:55:07 +00:00
{
2006-10-07 14:40:32 +00:00
// create pixmap and open a painter over it (contents{left,top} becomes pixmap {0,0})
QPixmap doubleBuffer ( contentsRect . size ( ) ) ;
QPainter pixmapPainter ( & doubleBuffer ) ;
pixmapPainter . translate ( - contentsRect . left ( ) , - contentsRect . top ( ) ) ;
// 1) Layer 0: paint items and clear bg on unpainted rects
drawDocumentOnPainter ( contentsRect , & pixmapPainter ) ;
2011-10-12 13:50:56 +00:00
// 2a) Layer 1a: paint (blend) transparent selection (rectangle)
2006-10-07 14:40:32 +00:00
if ( ! selectionRect . isNull ( ) & & selectionRect . intersects ( contentsRect ) & &
! selectionRectInternal . contains ( contentsRect ) )
2004-10-31 17:04:04 +00:00
{
2006-10-07 14:40:32 +00:00
QRect blendRect = selectionRectInternal . intersect ( contentsRect ) ;
// skip rectangles covered by the selection's border
if ( blendRect . isValid ( ) )
{
// grab current pixmap into a new one to colorize contents
QPixmap blendedPixmap ( blendRect . width ( ) , blendRect . height ( ) ) ;
QPainter p ( & blendedPixmap ) ;
p . drawPixmap ( 0 , 0 , doubleBuffer ,
blendRect . left ( ) - contentsRect . left ( ) , blendRect . top ( ) - contentsRect . top ( ) ,
blendRect . width ( ) , blendRect . height ( ) ) ;
2006-10-17 21:26:43 +00:00
QColor blCol = selBlendColor . dark ( 140 ) ;
2007-05-19 10:42:10 +00:00
blCol . setAlphaF ( 0.2 ) ;
p . fillRect ( blendedPixmap . rect ( ) , blCol ) ;
2008-06-06 22:03:30 +00:00
p . end ( ) ;
2006-10-07 14:40:32 +00:00
// copy the blended pixmap back to its place
pixmapPainter . drawPixmap ( blendRect . left ( ) , blendRect . top ( ) , blendedPixmap ) ;
}
// draw border (red if the selection is too small)
pixmapPainter . setPen ( selBlendColor ) ;
2007-12-09 16:14:24 +00:00
pixmapPainter . drawRect ( selectionRect . adjusted ( 0 , 0 , - 1 , - 1 ) ) ;
2006-10-07 14:40:32 +00:00
}
2011-10-12 13:50:56 +00:00
// 2b) Layer 1b: paint (blend) transparent selection (table)
2011-10-12 14:04:23 +00:00
foreach ( const TableSelectionPart & tsp , d - > tableSelectionParts ) {
2011-10-12 13:50:56 +00:00
QRect selectionPartRect = tsp . rectInItem . geometry ( tsp . item - > uncroppedWidth ( ) , tsp . item - > uncroppedHeight ( ) ) ;
selectionPartRect . translate ( tsp . item - > uncroppedGeometry ( ) . topLeft ( ) ) ;
QRect selectionPartRectInternal = selectionPartRect ;
selectionPartRectInternal . adjust ( 1 , 1 , - 1 , - 1 ) ;
if ( ! selectionPartRect . isNull ( ) & & selectionPartRect . intersects ( contentsRect ) & &
! selectionPartRectInternal . contains ( contentsRect ) )
{
QRect blendRect = selectionPartRectInternal . intersect ( contentsRect ) ;
// skip rectangles covered by the selection's border
if ( blendRect . isValid ( ) )
{
// grab current pixmap into a new one to colorize contents
QPixmap blendedPixmap ( blendRect . width ( ) , blendRect . height ( ) ) ;
QPainter p ( & blendedPixmap ) ;
p . drawPixmap ( 0 , 0 , doubleBuffer ,
blendRect . left ( ) - contentsRect . left ( ) , blendRect . top ( ) - contentsRect . top ( ) ,
blendRect . width ( ) , blendRect . height ( ) ) ;
QColor blCol = d - > mouseSelectionColor . dark ( 140 ) ;
blCol . setAlphaF ( 0.2 ) ;
p . fillRect ( blendedPixmap . rect ( ) , blCol ) ;
p . end ( ) ;
// copy the blended pixmap back to its place
pixmapPainter . drawPixmap ( blendRect . left ( ) , blendRect . top ( ) , blendedPixmap ) ;
}
// draw border (red if the selection is too small)
pixmapPainter . setPen ( d - > mouseSelectionColor ) ;
pixmapPainter . drawRect ( selectionPartRect . adjusted ( 0 , 0 , - 1 , - 1 ) ) ;
}
}
drawTableDividers ( & pixmapPainter ) ;
2006-10-07 14:40:32 +00:00
// 3) Layer 1: give annotator painting control
if ( d - > annotator & & d - > annotator - > routePaints ( contentsRect ) )
d - > annotator - > routePaint ( & pixmapPainter , contentsRect ) ;
// 4) Layer 2: overlays
if ( Okular : : Settings : : debugDrawBoundaries ( ) )
{
pixmapPainter . setPen ( Qt : : blue ) ;
pixmapPainter . drawRect ( contentsRect ) ;
2004-10-31 17:04:04 +00:00
}
2011-10-17 19:56:45 +00:00
2006-10-07 14:40:32 +00:00
// finish painting and draw contents
pixmapPainter . end ( ) ;
screenPainter . drawPixmap ( contentsRect . left ( ) , contentsRect . top ( ) , doubleBuffer ) ;
2004-10-31 13:55:07 +00:00
}
2006-10-07 14:40:32 +00:00
else
2004-10-31 13:55:07 +00:00
{
2006-10-07 14:40:32 +00:00
// 1) Layer 0: paint items and clear bg on unpainted rects
drawDocumentOnPainter ( contentsRect , & screenPainter ) ;
2011-10-12 13:50:56 +00:00
// 2a) Layer 1a: paint opaque selection (rectangle)
2006-10-07 14:40:32 +00:00
if ( ! selectionRect . isNull ( ) & & selectionRect . intersects ( contentsRect ) & &
! selectionRectInternal . contains ( contentsRect ) )
{
screenPainter . setPen ( palette ( ) . color ( QPalette : : Active , QPalette : : Highlight ) . dark ( 110 ) ) ;
screenPainter . drawRect ( selectionRect ) ;
}
2011-10-12 13:50:56 +00:00
// 2b) Layer 1b: paint opaque selection (table)
2011-10-12 14:04:23 +00:00
foreach ( const TableSelectionPart & tsp , d - > tableSelectionParts ) {
2011-10-12 13:50:56 +00:00
QRect selectionPartRect = tsp . rectInItem . geometry ( tsp . item - > uncroppedWidth ( ) , tsp . item - > uncroppedHeight ( ) ) ;
selectionPartRect . translate ( tsp . item - > uncroppedGeometry ( ) . topLeft ( ) ) ;
QRect selectionPartRectInternal = selectionPartRect ;
selectionPartRectInternal . adjust ( 1 , 1 , - 1 , - 1 ) ;
if ( ! selectionPartRect . isNull ( ) & & selectionPartRect . intersects ( contentsRect ) & &
! selectionPartRectInternal . contains ( contentsRect ) )
{
screenPainter . setPen ( palette ( ) . color ( QPalette : : Active , QPalette : : Highlight ) . dark ( 110 ) ) ;
screenPainter . drawRect ( selectionPartRect ) ;
}
}
drawTableDividers ( & screenPainter ) ;
2006-10-07 14:40:32 +00:00
// 3) Layer 1: give annotator painting control
if ( d - > annotator & & d - > annotator - > routePaints ( contentsRect ) )
d - > annotator - > routePaint ( & screenPainter , contentsRect ) ;
// 4) Layer 2: overlays
if ( Okular : : Settings : : debugDrawBoundaries ( ) )
{
screenPainter . setPen ( Qt : : red ) ;
screenPainter . drawRect ( contentsRect ) ;
}
2004-10-31 13:55:07 +00:00
}
2004-10-31 12:43:13 +00:00
}
2004-10-29 21:52:06 +00:00
}
2011-10-12 13:50:56 +00:00
void PageView : : drawTableDividers ( QPainter * screenPainter )
{
if ( ! d - > tableSelectionParts . isEmpty ( ) ) {
screenPainter - > setPen ( d - > mouseSelectionColor . dark ( ) ) ;
2011-10-31 15:33:03 +00:00
if ( d - > tableDividersGuessed ) {
QPen p = screenPainter - > pen ( ) ;
p . setStyle ( Qt : : DashLine ) ;
screenPainter - > setPen ( p ) ;
}
2011-10-12 14:04:23 +00:00
foreach ( const TableSelectionPart & tsp , d - > tableSelectionParts ) {
2011-10-12 13:50:56 +00:00
QRect selectionPartRect = tsp . rectInItem . geometry ( tsp . item - > uncroppedWidth ( ) , tsp . item - > uncroppedHeight ( ) ) ;
selectionPartRect . translate ( tsp . item - > uncroppedGeometry ( ) . topLeft ( ) ) ;
QRect selectionPartRectInternal = selectionPartRect ;
selectionPartRectInternal . adjust ( 1 , 1 , - 1 , - 1 ) ;
2011-10-12 14:16:50 +00:00
foreach ( double col , d - > tableSelectionCols ) {
2011-10-12 13:50:56 +00:00
if ( col > = tsp . rectInSelection . left & & col < = tsp . rectInSelection . right ) {
col = ( col - tsp . rectInSelection . left ) / ( tsp . rectInSelection . right - tsp . rectInSelection . left ) ;
const int x = selectionPartRect . left ( ) + col * selectionPartRect . width ( ) + 0.5 ;
screenPainter - > drawLine (
x , selectionPartRectInternal . top ( ) ,
x , selectionPartRectInternal . top ( ) + selectionPartRectInternal . height ( )
) ;
}
}
2011-10-12 14:16:50 +00:00
foreach ( double row , d - > tableSelectionRows ) {
2011-10-12 13:50:56 +00:00
if ( row > = tsp . rectInSelection . top & & row < = tsp . rectInSelection . bottom ) {
row = ( row - tsp . rectInSelection . top ) / ( tsp . rectInSelection . bottom - tsp . rectInSelection . top ) ;
const int y = selectionPartRect . top ( ) + row * selectionPartRect . height ( ) + 0.5 ;
screenPainter - > drawLine (
selectionPartRectInternal . left ( ) , y ,
selectionPartRectInternal . left ( ) + selectionPartRectInternal . width ( ) , y
) ;
}
}
}
}
}
2006-11-19 00:04:16 +00:00
void PageView : : resizeEvent ( QResizeEvent * e )
2004-10-29 21:52:06 +00:00
{
2005-02-26 18:05:01 +00:00
if ( d - > items . isEmpty ( ) )
2006-11-19 00:04:16 +00:00
{
2009-06-29 20:55:50 +00:00
resizeContentArea ( e - > size ( ) ) ;
2005-02-26 18:05:01 +00:00
return ;
2006-11-19 00:04:16 +00:00
}
2005-02-26 18:05:01 +00:00
2010-07-20 22:24:57 +00:00
if ( d - > zoomMode = = ZoomFitWidth & & d - > verticalScrollBarVisible & & ! verticalScrollBar ( ) - > isVisible ( ) & & qAbs ( e - > oldSize ( ) . height ( ) - e - > size ( ) . height ( ) ) < verticalScrollBar ( ) - > width ( ) )
2008-12-08 16:09:15 +00:00
{
// this saves us from infinite resizing loop because of scrollbars appearing and disappearing
// see bug 160628 for more info
2010-09-11 13:34:22 +00:00
// TODO looks are still a bit ugly because things are left uncentered
2008-12-08 16:09:15 +00:00
// but better a bit ugly than unusable
2010-07-20 22:24:57 +00:00
d - > verticalScrollBarVisible = false ;
2009-06-29 20:55:50 +00:00
resizeContentArea ( e - > size ( ) ) ;
2008-12-08 16:09:15 +00:00
return ;
}
2005-03-24 19:10:41 +00:00
// start a timer that will refresh the pixmap after 0.2s
2011-03-17 15:24:44 +00:00
d - > delayResizeEventTimer - > start ( 200 ) ;
2010-07-20 22:24:57 +00:00
d - > verticalScrollBarVisible = verticalScrollBar ( ) - > isVisible ( ) ;
2004-10-29 21:52:06 +00:00
}
void PageView : : keyPressEvent ( QKeyEvent * e )
{
e - > accept ( ) ;
2005-01-18 16:43:36 +00:00
2005-02-01 18:24:16 +00:00
// if performing a selection or dyn zooming, disable keys handling
2006-10-28 23:27:44 +00:00
if ( ( d - > mouseSelecting & & e - > key ( ) ! = Qt : : Key_Escape ) | | d - > mouseMidZooming )
2005-02-01 18:24:16 +00:00
return ;
2005-02-02 18:18:26 +00:00
// if viewport is moving, disable keys handling
if ( d - > viewportMoveActive )
return ;
2004-10-29 21:52:06 +00:00
// move/scroll page by using keys
switch ( e - > key ( ) )
{
2008-11-29 13:22:32 +00:00
case Qt : : Key_J :
case Qt : : Key_K :
2006-03-24 20:40:02 +00:00
case Qt : : Key_Down :
case Qt : : Key_PageDown :
2007-07-20 12:18:55 +00:00
case Qt : : Key_Up :
case Qt : : Key_PageUp :
case Qt : : Key_Backspace :
if ( e - > key ( ) = = Qt : : Key_Down
| | e - > key ( ) = = Qt : : Key_PageDown
2012-09-05 20:12:11 +00:00
| | e - > key ( ) = = Qt : : Key_J )
2004-11-05 01:11:50 +00:00
{
2012-09-05 20:12:11 +00:00
bool singleStep = e - > key ( ) = = Qt : : Key_Down | | e - > key ( ) = = Qt : : Key_J ;
slotScrollDown ( singleStep ) ;
2004-11-05 01:11:50 +00:00
}
2007-07-20 12:18:55 +00:00
else
2005-01-09 23:37:07 +00:00
{
2012-09-05 20:12:11 +00:00
bool singleStep = e - > key ( ) = = Qt : : Key_Up | | e - > key ( ) = = Qt : : Key_K ;
slotScrollUp ( singleStep ) ;
2005-01-09 23:37:07 +00:00
}
2004-10-29 21:52:06 +00:00
break ;
2006-03-24 20:40:02 +00:00
case Qt : : Key_Left :
2008-11-29 13:22:32 +00:00
case Qt : : Key_H :
2012-05-22 22:23:36 +00:00
if ( horizontalScrollBar ( ) - > maximum ( ) = = 0 )
{
//if we cannot scroll we go to the previous page vertically
int next_page = d - > document - > currentPage ( ) - viewColumns ( ) ;
d - > document - > setViewportPage ( next_page ) ;
}
else
horizontalScrollBar ( ) - > triggerAction ( QScrollBar : : SliderSingleStepSub ) ;
2004-10-29 21:52:06 +00:00
break ;
2006-03-24 20:40:02 +00:00
case Qt : : Key_Right :
2008-11-29 13:22:32 +00:00
case Qt : : Key_L :
2012-05-22 22:23:36 +00:00
if ( horizontalScrollBar ( ) - > maximum ( ) = = 0 )
{
//if we cannot scroll we advance the page vertically
int next_page = d - > document - > currentPage ( ) + viewColumns ( ) ;
d - > document - > setViewportPage ( next_page ) ;
}
else
horizontalScrollBar ( ) - > triggerAction ( QScrollBar : : SliderSingleStepAdd ) ;
2004-10-29 21:52:06 +00:00
break ;
2006-10-28 23:27:44 +00:00
case Qt : : Key_Escape :
2012-07-12 18:46:24 +00:00
emit escPressed ( ) ;
2011-10-31 15:33:03 +00:00
selectionClear ( d - > tableDividersGuessed ? ClearOnlyDividers : ClearAllSelection ) ;
2006-10-28 23:27:44 +00:00
d - > mousePressPos = QPoint ( ) ;
if ( d - > aPrevAction )
{
d - > aPrevAction - > trigger ( ) ;
d - > aPrevAction = 0 ;
}
break ;
2006-03-24 20:40:02 +00:00
case Qt : : Key_Shift :
case Qt : : Key_Control :
2005-02-01 18:24:16 +00:00
if ( d - > autoScrollTimer )
2004-10-29 21:52:06 +00:00
{
2005-02-01 18:24:16 +00:00
if ( d - > autoScrollTimer - > isActive ( ) )
d - > autoScrollTimer - > stop ( ) ;
2004-10-29 21:52:06 +00:00
else
slotAutoScoll ( ) ;
return ;
}
2006-04-23 15:49:14 +00:00
// else fall trhough
2004-10-29 21:52:06 +00:00
default :
e - > ignore ( ) ;
return ;
}
// if a known key has been pressed, stop scrolling the page
2005-02-01 18:24:16 +00:00
if ( d - > autoScrollTimer )
2004-10-29 21:52:06 +00:00
{
d - > scrollIncrement = 0 ;
2005-02-01 18:24:16 +00:00
d - > autoScrollTimer - > stop ( ) ;
2004-10-29 21:52:06 +00:00
}
}
2007-09-23 17:45:36 +00:00
void PageView : : keyReleaseEvent ( QKeyEvent * e )
{
e - > accept ( ) ;
if ( d - > annotator & & d - > annotator - > routeEvents ( ) )
{
if ( d - > annotator - > routeKeyEvent ( e ) )
return ;
}
if ( e - > key ( ) = = Qt : : Key_Escape & & d - > autoScrollTimer )
{
d - > scrollIncrement = 0 ;
d - > autoScrollTimer - > stop ( ) ;
}
}
2006-08-14 15:03:12 +00:00
void PageView : : inputMethodEvent ( QInputMethodEvent * e )
{
2007-03-17 22:58:41 +00:00
Q_UNUSED ( e )
2006-08-14 15:03:12 +00:00
}
2007-07-17 20:58:38 +00:00
static QPoint rotateInRect ( const QPoint & rotated , Okular : : Rotation rotation )
{
QPoint ret ;
switch ( rotation )
{
case Okular : : Rotation90 :
ret = QPoint ( rotated . y ( ) , - rotated . x ( ) ) ;
break ;
case Okular : : Rotation180 :
ret = QPoint ( - rotated . x ( ) , - rotated . y ( ) ) ;
break ;
case Okular : : Rotation270 :
ret = QPoint ( - rotated . y ( ) , rotated . x ( ) ) ;
break ;
case Okular : : Rotation0 : // no modifications
default : // other cases
ret = rotated ;
}
return ret ;
}
2012-10-15 18:11:47 +00:00
void PageView : : tabletEvent ( QTabletEvent * e )
{
// Ignore tablet events that we don't care about
if ( ! ( e - > type ( ) = = QEvent : : TabletPress | |
e - > type ( ) = = QEvent : : TabletRelease | |
e - > type ( ) = = QEvent : : TabletMove ) )
{
e - > ignore ( ) ;
return ;
}
// Determine pen state
bool penReleased = false ;
if ( e - > type ( ) = = QEvent : : TabletPress )
{
d - > penDown = true ;
}
if ( e - > type ( ) = = QEvent : : TabletRelease )
{
d - > penDown = false ;
penReleased = true ;
}
// If we're editing an annotation and the tablet pen is either down or just released
// then dispatch event to annotator
if ( d - > annotator & & d - > annotator - > routeEvents ( ) & & ( d - > penDown | | penReleased ) )
{
const QPoint eventPos = contentAreaPoint ( e - > pos ( ) ) ;
PageViewItem * pageItem = pickItemOnPoint ( eventPos . x ( ) , eventPos . y ( ) ) ;
2012-10-15 18:21:43 +00:00
const QPoint localOriginInGlobal = mapToGlobal ( QPoint ( 0 , 0 ) ) ;
2012-10-15 18:11:47 +00:00
// routeTabletEvent will accept or ignore event as appropriate
d - > annotator - > routeTabletEvent ( e , pageItem , localOriginInGlobal ) ;
} else {
e - > ignore ( ) ;
}
}
2009-06-29 20:55:50 +00:00
void PageView : : mouseMoveEvent ( QMouseEvent * e )
2004-10-29 21:52:06 +00:00
{
2005-01-29 12:32:59 +00:00
// don't perform any mouse action when no document is shown
if ( d - > items . isEmpty ( ) )
return ;
2005-02-01 18:24:16 +00:00
// don't perform any mouse action when viewport is autoscrolling
if ( d - > viewportMoveActive )
return ;
2004-11-16 17:36:02 +00:00
// if holding mouse mid button, perform zoom
2006-08-30 14:17:22 +00:00
if ( d - > mouseMidZooming & & ( e - > buttons ( ) & Qt : : MidButton ) )
2004-11-16 17:36:02 +00:00
{
2005-03-24 19:10:41 +00:00
int mouseY = e - > globalPos ( ) . y ( ) ;
int deltaY = d - > mouseMidLastY - mouseY ;
// wrap mouse from top to bottom
2010-08-14 11:59:49 +00:00
const QRect mouseContainer = KGlobalSettings : : desktopGeometry ( this ) ;
const int absDeltaY = abs ( deltaY ) ;
if ( absDeltaY > mouseContainer . height ( ) / 2 )
{
deltaY = mouseContainer . height ( ) - absDeltaY ;
}
2010-09-11 13:34:22 +00:00
2012-11-15 22:18:59 +00:00
const float upperZoomLimit = d - > document - > supportsTiles ( ) ? 15.99 : 3.99 ;
2005-03-24 19:10:41 +00:00
if ( mouseY < = mouseContainer . top ( ) + 4 & &
2012-11-15 22:18:59 +00:00
d - > zoomFactor < upperZoomLimit )
2005-03-24 19:10:41 +00:00
{
mouseY = mouseContainer . bottom ( ) - 5 ;
QCursor : : setPos ( e - > globalPos ( ) . x ( ) , mouseY ) ;
}
// wrap mouse from bottom to top
else if ( mouseY > = mouseContainer . bottom ( ) - 4 & &
2012-06-16 17:57:30 +00:00
d - > zoomFactor > 0.101 )
2005-03-24 19:10:41 +00:00
{
mouseY = mouseContainer . top ( ) + 5 ;
QCursor : : setPos ( e - > globalPos ( ) . x ( ) , mouseY ) ;
}
// remember last position
d - > mouseMidLastY = mouseY ;
// update zoom level, perform zoom and redraw
if ( deltaY )
{
d - > zoomFactor * = ( 1.0 + ( ( double ) deltaY / 500.0 ) ) ;
updateZoom ( ZoomRefreshCurrent ) ;
2006-06-03 13:01:15 +00:00
viewport ( ) - > repaint ( ) ;
2005-03-24 19:10:41 +00:00
}
2004-11-16 17:36:02 +00:00
return ;
}
2004-10-29 21:52:06 +00:00
2009-06-29 20:55:50 +00:00
const QPoint eventPos = contentAreaPoint ( e - > pos ( ) ) ;
2005-02-18 18:24:45 +00:00
// if we're editing an annotation, dispatch event to it
2005-03-04 23:06:24 +00:00
if ( d - > annotator & & d - > annotator - > routeEvents ( ) )
2005-02-18 18:24:45 +00:00
{
2009-06-29 20:55:50 +00:00
PageViewItem * pageItem = pickItemOnPoint ( eventPos . x ( ) , eventPos . y ( ) ) ;
2012-10-15 18:11:47 +00:00
d - > annotator - > routeMouseEvent ( e , pageItem ) ;
2005-02-18 18:24:45 +00:00
return ;
}
2006-09-28 21:41:50 +00:00
bool leftButton = ( e - > buttons ( ) = = Qt : : LeftButton ) ;
2006-09-28 22:19:31 +00:00
bool rightButton = ( e - > buttons ( ) = = Qt : : RightButton ) ;
2012-03-09 17:43:40 +00:00
switch ( Okular : : Settings : : mouseMode ( ) )
2004-10-29 21:52:06 +00:00
{
2012-03-09 17:43:40 +00:00
case Okular : : Settings : : EnumMouseMode : : Browse :
2004-10-29 21:52:06 +00:00
if ( leftButton )
{
2010-03-25 20:59:16 +00:00
d - > leftClickTimer . stop ( ) ;
2007-07-17 20:58:38 +00:00
if ( d - > mouseAnn )
{
2009-06-29 20:55:50 +00:00
PageViewItem * pageItem = pickItemOnPoint ( eventPos . x ( ) , eventPos . y ( ) ) ;
2007-07-17 20:58:38 +00:00
if ( pageItem )
{
2008-05-19 00:37:14 +00:00
const QRect & itemRect = pageItem - > uncroppedGeometry ( ) ;
2009-06-29 20:55:50 +00:00
QPoint newpos = eventPos - itemRect . topLeft ( ) ;
2007-07-17 20:58:38 +00:00
QPoint p ( newpos - d - > mouseAnnPos ) ;
2008-12-17 21:46:11 +00:00
QPointF pf ( rotateInRect ( p , pageItem - > page ( ) - > rotation ( ) ) ) ;
if ( pageItem - > page ( ) - > rotation ( ) % 2 = = 0 )
2007-07-17 20:58:38 +00:00
{
2008-05-19 00:37:14 +00:00
pf . rx ( ) / = pageItem - > uncroppedWidth ( ) ;
pf . ry ( ) / = pageItem - > uncroppedHeight ( ) ;
2007-07-17 20:58:38 +00:00
}
else
{
2008-05-19 00:37:14 +00:00
pf . rx ( ) / = pageItem - > uncroppedHeight ( ) ;
pf . ry ( ) / = pageItem - > uncroppedWidth ( ) ;
2007-07-17 20:58:38 +00:00
}
d - > mouseAnn - > translate ( Okular : : NormalizedPoint ( pf . x ( ) , pf . y ( ) ) ) ;
d - > mouseAnnPos = newpos ;
2012-05-13 18:10:55 +00:00
d - > document - > modifyPageAnnotation ( d - > mouseAnnPageNum , d - > mouseAnn ) ;
2007-07-17 20:58:38 +00:00
}
}
2004-10-29 21:52:06 +00:00
// drag page
2007-07-17 20:58:38 +00:00
else if ( ! d - > mouseGrabPos . isNull ( ) )
2004-10-29 21:52:06 +00:00
{
2011-08-05 21:47:35 +00:00
setCursor ( Qt : : ClosedHandCursor ) ;
2010-03-25 20:59:16 +00:00
2005-03-24 19:10:41 +00:00
QPoint mousePos = e - > globalPos ( ) ;
QPoint delta = d - > mouseGrabPos - mousePos ;
// wrap mouse from top to bottom
2010-07-28 22:33:42 +00:00
const QRect mouseContainer = KGlobalSettings : : desktopGeometry ( this ) ;
// If the delta is huge it probably means we just wrapped in that direction
const QPoint absDelta ( abs ( delta . x ( ) ) , abs ( delta . y ( ) ) ) ;
if ( absDelta . y ( ) > mouseContainer . height ( ) / 2 )
{
delta . setY ( mouseContainer . height ( ) - absDelta . y ( ) ) ;
}
if ( absDelta . x ( ) > mouseContainer . width ( ) / 2 )
{
delta . setX ( mouseContainer . width ( ) - absDelta . x ( ) ) ;
}
2005-03-24 19:10:41 +00:00
if ( mousePos . y ( ) < = mouseContainer . top ( ) + 4 & &
2006-03-29 13:52:17 +00:00
verticalScrollBar ( ) - > value ( ) < verticalScrollBar ( ) - > maximum ( ) - 10 )
2005-03-24 19:10:41 +00:00
{
mousePos . setY ( mouseContainer . bottom ( ) - 5 ) ;
QCursor : : setPos ( mousePos ) ;
}
// wrap mouse from bottom to top
else if ( mousePos . y ( ) > = mouseContainer . bottom ( ) - 4 & &
verticalScrollBar ( ) - > value ( ) > 10 )
{
mousePos . setY ( mouseContainer . top ( ) + 5 ) ;
QCursor : : setPos ( mousePos ) ;
}
// remember last position
d - > mouseGrabPos = mousePos ;
2004-10-29 21:52:06 +00:00
// scroll page by position increment
2012-09-03 00:55:16 +00:00
scrollTo ( horizontalScrollBar ( ) - > value ( ) + delta . x ( ) , verticalScrollBar ( ) - > value ( ) + delta . y ( ) ) ;
2004-10-29 21:52:06 +00:00
}
}
2010-08-30 18:24:11 +00:00
else if ( rightButton & & ! d - > mousePressPos . isNull ( ) & & d - > aMouseSelect )
2006-09-28 22:19:31 +00:00
{
// if mouse moves 5 px away from the press point, switch to 'selection'
int deltaX = d - > mousePressPos . x ( ) - e - > globalPos ( ) . x ( ) ,
deltaY = d - > mousePressPos . y ( ) - e - > globalPos ( ) . y ( ) ;
if ( deltaX > 5 | | deltaX < - 5 | | deltaY > 5 | | deltaY < - 5 )
{
d - > aPrevAction = d - > aMouseNormal ;
d - > aMouseSelect - > trigger ( ) ;
2009-06-29 20:55:50 +00:00
QPoint newPos = eventPos + QPoint ( deltaX , deltaY ) ;
2006-09-28 22:19:31 +00:00
selectionStart ( newPos , palette ( ) . color ( QPalette : : Active , QPalette : : Highlight ) . light ( 120 ) , false ) ;
2012-09-28 15:57:03 +00:00
updateSelection ( eventPos ) ;
2006-09-28 22:19:31 +00:00
break ;
}
}
2005-01-29 12:32:59 +00:00
else
{
// only hovering the page, so update the cursor
2009-06-29 20:55:50 +00:00
updateCursor ( contentAreaPosition ( ) + viewport ( ) - > mapFromGlobal ( QCursor : : pos ( ) ) ) ;
2004-10-31 17:12:52 +00:00
}
2004-10-29 21:52:06 +00:00
break ;
2012-03-09 17:43:40 +00:00
case Okular : : Settings : : EnumMouseMode : : Zoom :
case Okular : : Settings : : EnumMouseMode : : RectSelect :
case Okular : : Settings : : EnumMouseMode : : TableSelect :
2005-01-28 17:21:28 +00:00
// set second corner of selection
2006-09-26 22:22:01 +00:00
if ( d - > mouseSelecting )
2012-09-28 15:57:03 +00:00
updateSelection ( eventPos ) ;
2006-09-26 22:22:01 +00:00
break ;
2012-03-09 17:43:40 +00:00
case Okular : : Settings : : EnumMouseMode : : TextSelect :
2006-09-26 22:22:01 +00:00
// if mouse moves 5 px away from the press point and the document soupports text extraction, do 'textselection'
2009-06-29 20:55:50 +00:00
if ( ! d - > mouseTextSelecting & & ! d - > mousePressPos . isNull ( ) & & d - > document - > supportsSearching ( ) & & ( ( eventPos - d - > mouseSelectPos ) . manhattanLength ( ) > 5 ) )
2006-09-26 22:22:01 +00:00
{
d - > mouseTextSelecting = true ;
}
2012-09-28 15:57:03 +00:00
updateSelection ( eventPos ) ;
2009-06-29 20:55:50 +00:00
updateCursor ( contentAreaPosition ( ) + viewport ( ) - > mapFromGlobal ( QCursor : : pos ( ) ) ) ;
2004-10-29 21:52:06 +00:00
break ;
}
}
2009-06-29 20:55:50 +00:00
void PageView : : mousePressEvent ( QMouseEvent * e )
2004-09-26 23:39:39 +00:00
{
2005-01-29 12:32:59 +00:00
// don't perform any mouse action when no document is shown
if ( d - > items . isEmpty ( ) )
return ;
// if performing a selection or dyn zooming, disable mouse press
2005-06-24 16:41:55 +00:00
if ( d - > mouseSelecting | | d - > mouseMidZooming | | d - > viewportMoveActive )
2005-01-29 12:32:59 +00:00
return ;
2005-02-01 18:24:16 +00:00
// if the page is scrolling, stop it
if ( d - > autoScrollTimer )
{
d - > scrollIncrement = 0 ;
d - > autoScrollTimer - > stop ( ) ;
}
2005-03-24 19:10:41 +00:00
// if pressing mid mouse button while not doing other things, begin 'continuous zoom' mode
2006-06-07 20:24:32 +00:00
if ( e - > button ( ) = = Qt : : MidButton )
2004-11-16 17:36:02 +00:00
{
2005-03-24 19:10:41 +00:00
d - > mouseMidZooming = true ;
d - > mouseMidLastY = e - > globalPos ( ) . y ( ) ;
2006-06-03 13:01:15 +00:00
setCursor ( Qt : : SizeVerCursor ) ;
2004-11-16 17:36:02 +00:00
return ;
}
2004-10-20 16:41:13 +00:00
2009-06-29 20:55:50 +00:00
const QPoint eventPos = contentAreaPoint ( e - > pos ( ) ) ;
2005-02-18 18:24:45 +00:00
// if we're editing an annotation, dispatch event to it
2005-03-04 23:06:24 +00:00
if ( d - > annotator & & d - > annotator - > routeEvents ( ) )
2005-02-18 18:24:45 +00:00
{
2009-06-29 20:55:50 +00:00
PageViewItem * pageItem = pickItemOnPoint ( eventPos . x ( ) , eventPos . y ( ) ) ;
2012-10-15 18:11:47 +00:00
d - > annotator - > routeMouseEvent ( e , pageItem ) ;
2005-02-18 18:24:45 +00:00
return ;
}
2012-07-10 16:45:23 +00:00
// trigger history navigation for additional mouse buttons
if ( e - > button ( ) = = Qt : : XButton1 )
{
emit mouseBackButtonClick ( ) ;
return ;
}
if ( e - > button ( ) = = Qt : : XButton2 )
{
emit mouseForwardButtonClick ( ) ;
return ;
}
2005-01-29 12:32:59 +00:00
// update press / 'start drag' mouse position
d - > mousePressPos = e - > globalPos ( ) ;
2004-10-20 16:41:13 +00:00
// handle mode dependant mouse press actions
2006-09-26 22:22:01 +00:00
bool leftButton = e - > button ( ) = = Qt : : LeftButton ,
rightButton = e - > button ( ) = = Qt : : RightButton ;
2008-11-21 10:50:16 +00:00
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
// Not sure we should erase the selection when clicking with left.
2012-03-09 17:43:40 +00:00
if ( Okular : : Settings : : mouseMode ( ) ! = Okular : : Settings : : EnumMouseMode : : TextSelect )
2006-06-10 17:06:03 +00:00
textSelectionClear ( ) ;
2008-11-21 10:50:16 +00:00
2012-03-09 17:43:40 +00:00
switch ( Okular : : Settings : : mouseMode ( ) )
2004-09-26 23:39:39 +00:00
{
2012-03-09 17:43:40 +00:00
case Okular : : Settings : : EnumMouseMode : : Browse : // drag start / click / link following
2004-10-20 16:41:13 +00:00
if ( leftButton )
2004-09-30 18:16:12 +00:00
{
2007-07-17 20:58:38 +00:00
PageViewItem * pageItem = 0 ;
2009-06-29 20:55:50 +00:00
if ( ( e - > modifiers ( ) & Qt : : ControlModifier ) & & ( pageItem = pickItemOnPoint ( eventPos . x ( ) , eventPos . y ( ) ) ) )
2007-07-17 20:58:38 +00:00
{
// find out normalized mouse coords inside current item
2008-05-19 00:37:14 +00:00
const QRect & itemRect = pageItem - > uncroppedGeometry ( ) ;
2009-06-29 20:55:50 +00:00
double nX = pageItem - > absToPageX ( eventPos . x ( ) ) ;
double nY = pageItem - > absToPageY ( eventPos . y ( ) ) ;
2007-07-17 20:58:38 +00:00
const Okular : : ObjectRect * orect = pageItem - > page ( ) - > objectRect ( Okular : : ObjectRect : : OAnnotation , nX , nY , itemRect . width ( ) , itemRect . height ( ) ) ;
2009-06-29 20:55:50 +00:00
d - > mouseAnnPos = eventPos - itemRect . topLeft ( ) ;
2007-07-17 20:58:38 +00:00
if ( orect )
d - > mouseAnn = ( ( Okular : : AnnotationObjectRect * ) orect ) - > annotation ( ) ;
// consider no annotation caught if its type is not movable
2008-05-01 20:59:51 +00:00
if ( d - > mouseAnn & & ! d - > mouseAnn - > canBeMoved ( ) )
2007-07-17 20:58:38 +00:00
d - > mouseAnn = 0 ;
}
2012-05-13 18:10:55 +00:00
if ( d - > mouseAnn )
{
d - > mouseAnn - > setFlags ( d - > mouseAnn - > flags ( ) | Okular : : Annotation : : BeingMoved ) ;
d - > mouseAnnPageNum = pageItem - > pageNumber ( ) ;
d - > document - > modifyPageAnnotation ( d - > mouseAnnPageNum , d - > mouseAnn ) ;
}
else
2007-07-17 20:58:38 +00:00
{
2012-05-13 18:10:55 +00:00
d - > mouseGrabPos = d - > mouseOnRect ? QPoint ( ) : d - > mousePressPos ;
if ( ! d - > mouseOnRect )
d - > leftClickTimer . start ( QApplication : : doubleClickInterval ( ) + 10 ) ;
2007-07-17 20:58:38 +00:00
}
2004-09-30 18:16:12 +00:00
}
2006-09-26 22:22:01 +00:00
else if ( rightButton )
{
2009-06-29 20:55:50 +00:00
PageViewItem * pageItem = pickItemOnPoint ( eventPos . x ( ) , eventPos . y ( ) ) ;
2006-09-26 22:22:01 +00:00
if ( pageItem )
{
// find out normalized mouse coords inside current item
2008-05-19 00:37:14 +00:00
const QRect & itemRect = pageItem - > uncroppedGeometry ( ) ;
2009-06-29 20:55:50 +00:00
double nX = pageItem - > absToPageX ( eventPos . x ( ) ) ;
double nY = pageItem - > absToPageY ( eventPos . y ( ) ) ;
2012-06-29 10:39:42 +00:00
const QLinkedList < const Okular : : ObjectRect * > orects = pageItem - > page ( ) - > objectRects ( Okular : : ObjectRect : : OAnnotation , nX , nY , itemRect . width ( ) , itemRect . height ( ) ) ;
if ( ! orects . isEmpty ( ) )
2006-09-26 22:22:01 +00:00
{
2012-08-15 17:21:25 +00:00
AnnotationPopup popup ( d - > document , AnnotationPopup : : MultiAnnotationMode , this ) ;
2012-06-29 10:39:42 +00:00
foreach ( const Okular : : ObjectRect * orect , orects )
{
Okular : : Annotation * ann = ( ( Okular : : AnnotationObjectRect * ) orect ) - > annotation ( ) ;
if ( ann )
popup . addAnnotation ( ann , pageItem - > pageNumber ( ) ) ;
}
2006-12-30 12:40:54 +00:00
2012-01-17 22:46:37 +00:00
connect ( & popup , SIGNAL ( openAnnotationWindow ( Okular : : Annotation * , int ) ) ,
this , SLOT ( openAnnotationWindow ( Okular : : Annotation * , int ) ) ) ;
2006-12-30 12:40:54 +00:00
popup . exec ( e - > globalPos ( ) ) ;
2006-09-26 22:22:01 +00:00
}
}
}
2004-10-20 16:41:13 +00:00
break ;
2004-09-26 23:39:39 +00:00
2012-03-09 17:43:40 +00:00
case Okular : : Settings : : EnumMouseMode : : Zoom : // set first corner of the zoom rect
2005-01-29 12:32:59 +00:00
if ( leftButton )
2009-06-29 20:55:50 +00:00
selectionStart ( eventPos , palette ( ) . color ( QPalette : : Active , QPalette : : Highlight ) , false ) ;
2005-01-29 12:32:59 +00:00
else if ( rightButton )
updateZoom ( ZoomOut ) ;
break ;
2012-03-09 17:43:40 +00:00
case Okular : : Settings : : EnumMouseMode : : RectSelect : // set first corner of the selection rect
2006-11-03 00:12:23 +00:00
if ( leftButton )
{
2009-06-29 20:55:50 +00:00
selectionStart ( eventPos , palette ( ) . color ( QPalette : : Active , QPalette : : Highlight ) . light ( 120 ) , false ) ;
2006-11-03 00:12:23 +00:00
}
2004-11-03 17:35:48 +00:00
break ;
2012-03-09 17:43:40 +00:00
case Okular : : Settings : : EnumMouseMode : : TableSelect :
2011-10-12 13:50:56 +00:00
if ( leftButton )
{
if ( d - > tableSelectionParts . isEmpty ( ) )
{
selectionStart ( eventPos , palette ( ) . color ( QPalette : : Active , QPalette : : Highlight ) . light ( 120 ) , false ) ;
} else {
QRect updatedRect ;
2011-10-12 14:04:23 +00:00
foreach ( const TableSelectionPart & tsp , d - > tableSelectionParts ) {
2011-10-12 13:50:56 +00:00
QRect selectionPartRect = tsp . rectInItem . geometry ( tsp . item - > uncroppedWidth ( ) , tsp . item - > uncroppedHeight ( ) ) ;
selectionPartRect . translate ( tsp . item - > uncroppedGeometry ( ) . topLeft ( ) ) ;
// This will update the whole table rather than just the added/removed divider
// (which can span more than one part).
updatedRect = updatedRect . united ( selectionPartRect ) ;
if ( ! selectionPartRect . contains ( eventPos ) )
continue ;
2011-10-31 15:33:03 +00:00
// At this point it's clear we're either adding or removing a divider manually, so obviously the user is happy with the guess (if any).
d - > tableDividersGuessed = false ;
2011-10-12 13:50:56 +00:00
// There's probably a neat trick to finding which edge it's closest to,
// but this way has the advantage of simplicity.
const int fromLeft = abs ( selectionPartRect . left ( ) - eventPos . x ( ) ) ;
const int fromRight = abs ( selectionPartRect . left ( ) + selectionPartRect . width ( ) - eventPos . x ( ) ) ;
const int fromTop = abs ( selectionPartRect . top ( ) - eventPos . y ( ) ) ;
const int fromBottom = abs ( selectionPartRect . top ( ) + selectionPartRect . height ( ) - eventPos . y ( ) ) ;
const int colScore = fromTop < fromBottom ? fromTop : fromBottom ;
const int rowScore = fromLeft < fromRight ? fromLeft : fromRight ;
if ( colScore < rowScore ) {
bool deleted = false ;
for ( int i = 0 ; i < d - > tableSelectionCols . length ( ) ; i + + ) {
const double col = ( d - > tableSelectionCols [ i ] - tsp . rectInSelection . left ) / ( tsp . rectInSelection . right - tsp . rectInSelection . left ) ;
const int colX = selectionPartRect . left ( ) + col * selectionPartRect . width ( ) + 0.5 ;
if ( abs ( colX - eventPos . x ( ) ) < = 3 ) {
d - > tableSelectionCols . removeAt ( i ) ;
deleted = true ;
break ;
}
}
if ( ! deleted ) {
double col = eventPos . x ( ) - selectionPartRect . left ( ) ;
col / = selectionPartRect . width ( ) ; // at this point, it's normalised within the part
col * = ( tsp . rectInSelection . right - tsp . rectInSelection . left ) ;
col + = tsp . rectInSelection . left ; // at this point, it's normalised within the whole table
d - > tableSelectionCols . append ( col ) ;
qSort ( d - > tableSelectionCols ) ;
}
} else {
bool deleted = false ;
for ( int i = 0 ; i < d - > tableSelectionRows . length ( ) ; i + + ) {
const double row = ( d - > tableSelectionRows [ i ] - tsp . rectInSelection . top ) / ( tsp . rectInSelection . bottom - tsp . rectInSelection . top ) ;
const int rowY = selectionPartRect . top ( ) + row * selectionPartRect . height ( ) + 0.5 ;
if ( abs ( rowY - eventPos . y ( ) ) < = 3 ) {
d - > tableSelectionRows . removeAt ( i ) ;
deleted = true ;
break ;
}
}
if ( ! deleted ) {
double row = eventPos . y ( ) - selectionPartRect . top ( ) ;
row / = selectionPartRect . height ( ) ; // at this point, it's normalised within the part
row * = ( tsp . rectInSelection . bottom - tsp . rectInSelection . top ) ;
row + = tsp . rectInSelection . top ; // at this point, it's normalised within the whole table
d - > tableSelectionRows . append ( row ) ;
qSort ( d - > tableSelectionRows ) ;
}
}
}
updatedRect . translate ( - contentAreaPosition ( ) ) ;
viewport ( ) - > update ( updatedRect ) ;
}
}
break ;
2012-03-09 17:43:40 +00:00
case Okular : : Settings : : EnumMouseMode : : TextSelect :
2009-06-29 20:55:50 +00:00
d - > mouseSelectPos = eventPos ;
2006-09-26 22:22:01 +00:00
if ( ! rightButton )
{
textSelectionClear ( ) ;
}
break ;
2004-09-26 23:39:39 +00:00
}
}
2009-06-29 20:55:50 +00:00
void PageView : : mouseReleaseEvent ( QMouseEvent * e )
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
{
2006-11-22 21:32:21 +00:00
// stop the drag scrolling
d - > dragScrollTimer . stop ( ) ;
2010-03-25 20:59:16 +00:00
d - > leftClickTimer . stop ( ) ;
2005-02-26 18:05:01 +00:00
// don't perform any mouse action when no document is shown..
2005-01-29 12:32:59 +00:00
if ( d - > items . isEmpty ( ) )
2005-02-26 18:05:01 +00:00
{
// ..except for right Clicks (emitted even it viewport is empty)
2006-03-24 20:40:02 +00:00
if ( e - > button ( ) = = Qt : : RightButton )
2005-02-26 18:05:01 +00:00
emit rightClick ( 0 , e - > globalPos ( ) ) ;
2005-01-29 12:32:59 +00:00
return ;
2005-02-26 18:05:01 +00:00
}
2005-01-29 12:32:59 +00:00
2005-02-01 18:24:16 +00:00
// don't perform any mouse action when viewport is autoscrolling
if ( d - > viewportMoveActive )
return ;
2009-06-29 20:55:50 +00:00
const QPoint eventPos = contentAreaPoint ( e - > pos ( ) ) ;
2004-11-16 17:36:02 +00:00
// handle mode indepent mid buttom zoom
2006-06-07 20:24:32 +00:00
if ( d - > mouseMidZooming & & ( e - > button ( ) = = Qt : : MidButton ) )
2004-11-16 17:36:02 +00:00
{
2005-03-24 19:10:41 +00:00
d - > mouseMidZooming = false ;
// request pixmaps since it was disabled during drag
slotRequestVisiblePixmaps ( ) ;
// the cursor may now be over a link.. update it
2009-06-29 20:55:50 +00:00
updateCursor ( eventPos ) ;
2004-11-16 17:36:02 +00:00
return ;
}
2005-02-18 18:24:45 +00:00
// if we're editing an annotation, dispatch event to it
2005-03-04 23:06:24 +00:00
if ( d - > annotator & & d - > annotator - > routeEvents ( ) )
2005-02-18 18:24:45 +00:00
{
2009-06-29 20:55:50 +00:00
PageViewItem * pageItem = pickItemOnPoint ( eventPos . x ( ) , eventPos . y ( ) ) ;
2012-10-15 18:11:47 +00:00
d - > annotator - > routeMouseEvent ( e , pageItem ) ;
2005-02-18 18:24:45 +00:00
return ;
}
2007-07-17 20:58:38 +00:00
if ( d - > mouseAnn )
{
2012-05-13 18:10:55 +00:00
// Just finished to move the annotation
d - > mouseAnn - > setFlags ( d - > mouseAnn - > flags ( ) & ~ Okular : : Annotation : : BeingMoved ) ;
d - > document - > modifyPageAnnotation ( d - > mouseAnnPageNum , d - > mouseAnn ) ;
2007-07-17 20:58:38 +00:00
setCursor ( Qt : : ArrowCursor ) ;
d - > mouseAnn = 0 ;
}
2006-09-26 22:22:01 +00:00
bool leftButton = e - > button ( ) = = Qt : : LeftButton ;
bool rightButton = e - > button ( ) = = Qt : : RightButton ;
2012-03-09 17:43:40 +00:00
switch ( Okular : : Settings : : mouseMode ( ) )
2004-09-26 23:39:39 +00:00
{
2012-03-09 17:43:40 +00:00
case Okular : : Settings : : EnumMouseMode : : Browse : {
2005-01-02 11:50:38 +00:00
// return the cursor to its normal state after dragging
2011-08-11 21:46:09 +00:00
if ( cursor ( ) . shape ( ) = = Qt : : ClosedHandCursor )
2009-06-29 20:55:50 +00:00
updateCursor ( eventPos ) ;
2005-01-02 11:50:38 +00:00
2009-06-29 20:55:50 +00:00
PageViewItem * pageItem = pickItemOnPoint ( eventPos . x ( ) , eventPos . y ( ) ) ;
2011-01-23 01:32:16 +00:00
const QPoint pressPos = contentAreaPoint ( mapFromGlobal ( d - > mousePressPos ) ) ;
const PageViewItem * pageItemPressPos = pickItemOnPoint ( pressPos . x ( ) , pressPos . y ( ) ) ;
2005-01-02 17:24:50 +00:00
2005-01-29 12:32:59 +00:00
// if the mouse has not moved since the press, that's a -click-
2011-01-23 01:32:16 +00:00
if ( leftButton & & pageItem & & pageItem = = pageItemPressPos & &
( ( d - > mousePressPos - e - > globalPos ( ) ) . manhattanLength ( ) < QApplication : : startDragDistance ( ) ) )
2004-10-02 14:30:30 +00:00
{
2009-06-29 20:55:50 +00:00
double nX = pageItem - > absToPageX ( eventPos . x ( ) ) ;
double nY = pageItem - > absToPageY ( eventPos . y ( ) ) ;
2006-09-21 08:45:36 +00:00
const Okular : : ObjectRect * rect ;
2008-05-19 00:37:14 +00:00
rect = pageItem - > page ( ) - > objectRect ( Okular : : ObjectRect : : Action , nX , nY , pageItem - > uncroppedWidth ( ) , pageItem - > uncroppedHeight ( ) ) ;
2004-12-10 16:04:45 +00:00
if ( rect )
2004-10-20 16:41:13 +00:00
{
2005-07-15 18:20:57 +00:00
// handle click over a link
2007-04-20 12:37:12 +00:00
const Okular : : Action * action = static_cast < const Okular : : Action * > ( rect - > object ( ) ) ;
2007-04-20 12:49:17 +00:00
d - > document - > processAction ( action ) ;
2004-10-20 16:41:13 +00:00
}
2009-03-23 12:10:11 +00:00
else if ( e - > modifiers ( ) = = Qt : : ShiftModifier )
2004-10-20 16:41:13 +00:00
{
2006-11-17 22:15:15 +00:00
// TODO: find a better way to activate the source reference "links"
// for the moment they are activated with Shift + left click
2009-03-23 12:10:11 +00:00
// Search the nearest source reference.
rect = pageItem - > page ( ) - > objectRect ( Okular : : ObjectRect : : SourceRef , nX , nY , pageItem - > uncroppedWidth ( ) , pageItem - > uncroppedHeight ( ) ) ;
if ( ! rect )
{
2009-04-19 22:34:29 +00:00
static const double s_minDistance = 0.025 ; // FIXME?: empirical value?
2009-03-23 12:10:11 +00:00
double distance = 0.0 ;
rect = pageItem - > page ( ) - > nearestObjectRect ( Okular : : ObjectRect : : SourceRef , nX , nY , pageItem - > uncroppedWidth ( ) , pageItem - > uncroppedHeight ( ) , & distance ) ;
if ( rect & & ( distance > s_minDistance ) )
rect = 0 ;
}
2006-11-17 22:15:15 +00:00
if ( rect )
{
2007-01-02 17:05:49 +00:00
const Okular : : SourceReference * ref = static_cast < const Okular : : SourceReference * > ( rect - > object ( ) ) ;
2006-11-17 22:15:15 +00:00
d - > document - > processSourceReference ( ref ) ;
}
2009-07-27 14:15:33 +00:00
else
{
const Okular : : SourceReference * ref = d - > document - > dynamicSourceReference ( pageItem - > pageNumber ( ) , nX * pageItem - > page ( ) - > width ( ) , nY * pageItem - > page ( ) - > height ( ) ) ;
if ( ref )
{
d - > document - > processSourceReference ( ref ) ;
delete ref ;
}
}
2009-03-23 12:10:11 +00:00
}
else
{
2012-03-12 16:05:43 +00:00
Okular : : Annotation * ann = 0 ;
rect = pageItem - > page ( ) - > objectRect ( Okular : : ObjectRect : : OAnnotation , nX , nY , pageItem - > uncroppedWidth ( ) , pageItem - > uncroppedHeight ( ) ) ;
if ( rect )
ann = ( ( Okular : : AnnotationObjectRect * ) rect ) - > annotation ( ) ;
2012-09-27 12:15:58 +00:00
if ( ann )
2012-03-12 16:05:43 +00:00
{
2012-09-27 12:15:58 +00:00
if ( ann - > subType ( ) = = Okular : : Annotation : : AMovie )
{
VideoWidget * vw = pageItem - > videoWidgets ( ) . value ( static_cast < Okular : : MovieAnnotation * > ( ann ) - > movie ( ) ) ;
vw - > show ( ) ;
vw - > play ( ) ;
}
else if ( ann - > subType ( ) = = Okular : : Annotation : : AScreen )
{
d - > document - > processAction ( static_cast < Okular : : ScreenAnnotation * > ( ann ) - > action ( ) ) ;
}
2012-03-12 16:05:43 +00:00
}
2006-11-17 22:15:15 +00:00
#if 0
2005-07-15 18:20:57 +00:00
// a link can move us to another page or even to another document, there's no point in trying to
// process the click on the image once we have processes the click on the link
2006-11-23 17:11:04 +00:00
rect = pageItem - > page ( ) - > objectRect ( Okular : : ObjectRect : : Image , nX , nY , pageItem - > width ( ) , pageItem - > height ( ) ) ;
2005-07-15 18:20:57 +00:00
if ( rect )
{
// handle click over a image
}
/* Enrico and me have decided this is not worth the trouble it generates
else
{
// if not on a rect, the click selects the page
// if ( pageItem->pageNumber() != (int)d->document->currentPage() )
d - > document - > setViewportPage ( pageItem - > pageNumber ( ) , PAGEVIEW_ID ) ;
} */
2006-11-17 22:15:15 +00:00
# endif
2004-10-20 16:41:13 +00:00
}
2004-10-02 14:30:30 +00:00
}
2004-12-04 23:23:18 +00:00
else if ( rightButton )
2004-09-28 13:53:47 +00:00
{
2011-01-23 01:32:16 +00:00
if ( pageItem & & pageItem = = pageItemPressPos & &
( ( d - > mousePressPos - e - > globalPos ( ) ) . manhattanLength ( ) < QApplication : : startDragDistance ( ) ) )
2006-09-26 22:22:01 +00:00
{
2009-06-29 20:55:50 +00:00
double nX = pageItem - > absToPageX ( eventPos . x ( ) ) ;
double nY = pageItem - > absToPageY ( eventPos . y ( ) ) ;
2006-09-26 22:22:01 +00:00
const Okular : : ObjectRect * rect ;
2008-05-19 00:37:14 +00:00
rect = pageItem - > page ( ) - > objectRect ( Okular : : ObjectRect : : Action , nX , nY , pageItem - > uncroppedWidth ( ) , pageItem - > uncroppedHeight ( ) ) ;
2006-09-26 22:22:01 +00:00
if ( rect )
{
// handle right click over a link
2007-04-20 12:37:12 +00:00
const Okular : : Action * link = static_cast < const Okular : : Action * > ( rect - > object ( ) ) ;
2006-09-26 22:22:01 +00:00
// creating the menu and its actions
KMenu menu ( this ) ;
QAction * actProcessLink = menu . addAction ( i18n ( " Follow This Link " ) ) ;
QAction * actCopyLinkLocation = 0 ;
2007-05-02 22:50:27 +00:00
if ( dynamic_cast < const Okular : : BrowseAction * > ( link ) )
2007-11-10 18:45:48 +00:00
actCopyLinkLocation = menu . addAction ( KIcon ( " edit-copy " ) , i18n ( " Copy Link Address " ) ) ;
2006-09-26 22:22:01 +00:00
QAction * res = menu . exec ( e - > globalPos ( ) ) ;
if ( res )
{
if ( res = = actProcessLink )
{
2007-04-20 12:49:17 +00:00
d - > document - > processAction ( link ) ;
2006-09-26 22:22:01 +00:00
}
else if ( res = = actCopyLinkLocation )
{
2007-05-02 22:50:27 +00:00
const Okular : : BrowseAction * browseLink = static_cast < const Okular : : BrowseAction * > ( link ) ;
2006-09-26 22:22:01 +00:00
QClipboard * cb = QApplication : : clipboard ( ) ;
cb - > setText ( browseLink - > url ( ) , QClipboard : : Clipboard ) ;
if ( cb - > supportsSelection ( ) )
cb - > setText ( browseLink - > url ( ) , QClipboard : : Selection ) ;
}
}
}
else
{
// a link can move us to another page or even to another document, there's no point in trying to
// process the click on the image once we have processes the click on the link
2008-05-19 00:37:14 +00:00
rect = pageItem - > page ( ) - > objectRect ( Okular : : ObjectRect : : Image , nX , nY , pageItem - > uncroppedWidth ( ) , pageItem - > uncroppedHeight ( ) ) ;
2006-09-26 22:22:01 +00:00
if ( rect )
{
// handle right click over a image
}
else
{
// right click (if not within 5 px of the press point, the mode
// had been already changed to 'Selection' instead of 'Normal')
emit rightClick ( pageItem - > page ( ) , e - > globalPos ( ) ) ;
}
}
}
else
{
// right click (if not within 5 px of the press point, the mode
// had been already changed to 'Selection' instead of 'Normal')
emit rightClick ( pageItem ? pageItem - > page ( ) : 0 , e - > globalPos ( ) ) ;
}
2004-09-28 13:53:47 +00:00
}
2004-11-16 17:36:02 +00:00
} break ;
2004-09-26 23:39:39 +00:00
2012-03-09 17:43:40 +00:00
case Okular : : Settings : : EnumMouseMode : : Zoom :
2005-01-29 12:32:59 +00:00
// if a selection rect has been defined, zoom into it
2005-06-24 16:41:55 +00:00
if ( leftButton & & d - > mouseSelecting )
2004-11-03 17:35:48 +00:00
{
2006-03-29 16:46:09 +00:00
QRect selRect = d - > mouseSelectionRect . normalized ( ) ;
2005-01-29 12:32:59 +00:00
if ( selRect . width ( ) < = 8 & & selRect . height ( ) < = 8 )
{
selectionClear ( ) ;
2004-11-05 01:11:50 +00:00
break ;
2005-01-29 12:32:59 +00:00
}
2004-11-03 17:35:48 +00:00
2004-11-05 01:11:50 +00:00
// find out new zoom ratio and normalized view center (relative to the contentsRect)
2006-10-07 14:40:32 +00:00
double zoom = qMin ( ( double ) viewport ( ) - > width ( ) / ( double ) selRect . width ( ) , ( double ) viewport ( ) - > height ( ) / ( double ) selRect . height ( ) ) ;
2009-06-29 20:55:50 +00:00
double nX = ( double ) ( selRect . left ( ) + selRect . right ( ) ) / ( 2.0 * ( double ) contentAreaWidth ( ) ) ;
double nY = ( double ) ( selRect . top ( ) + selRect . bottom ( ) ) / ( 2.0 * ( double ) contentAreaHeight ( ) ) ;
2004-11-03 17:35:48 +00:00
2012-11-15 22:18:59 +00:00
const float upperZoomLimit = d - > document - > supportsTiles ( ) ? 16.0 : 4.0 ;
if ( d - > zoomFactor < = upperZoomLimit | | zoom < = 1.0 )
2004-11-03 17:35:48 +00:00
{
d - > zoomFactor * = zoom ;
2004-11-05 01:11:50 +00:00
viewport ( ) - > setUpdatesEnabled ( false ) ;
2004-11-03 17:35:48 +00:00
updateZoom ( ZoomRefreshCurrent ) ;
2004-11-05 01:11:50 +00:00
viewport ( ) - > setUpdatesEnabled ( true ) ;
2004-11-03 17:35:48 +00:00
}
2004-11-05 01:11:50 +00:00
// recenter view and update the viewport
2009-06-29 20:55:50 +00:00
center ( ( int ) ( nX * contentAreaWidth ( ) ) , ( int ) ( nY * contentAreaHeight ( ) ) ) ;
viewport ( ) - > update ( ) ;
2004-11-03 17:35:48 +00:00
// hide message box and delete overlay window
selectionClear ( ) ;
}
break ;
2012-03-09 17:43:40 +00:00
case Okular : : Settings : : EnumMouseMode : : RectSelect :
2007-09-14 10:02:33 +00:00
{
2005-06-13 11:28:15 +00:00
// if mouse is released and selection is null this is a rightClick
2005-06-24 16:41:55 +00:00
if ( rightButton & & ! d - > mouseSelecting )
2005-03-05 15:59:15 +00:00
{
2009-06-29 20:55:50 +00:00
PageViewItem * pageItem = pickItemOnPoint ( eventPos . x ( ) , eventPos . y ( ) ) ;
2005-03-05 15:59:15 +00:00
emit rightClick ( pageItem ? pageItem - > page ( ) : 0 , e - > globalPos ( ) ) ;
2005-06-13 11:28:15 +00:00
break ;
2005-03-05 15:59:15 +00:00
}
2005-06-13 11:28:15 +00:00
2005-01-29 12:32:59 +00:00
// if a selection is defined, display a popup
2005-03-24 19:10:41 +00:00
if ( ( ! leftButton & & ! d - > aPrevAction ) | | ( ! rightButton & & d - > aPrevAction ) | |
2005-06-24 16:41:55 +00:00
! d - > mouseSelecting )
2004-11-16 17:36:02 +00:00
break ;
2004-10-20 16:41:13 +00:00
2006-03-29 16:46:09 +00:00
QRect selectionRect = d - > mouseSelectionRect . normalized ( ) ;
2005-01-29 12:32:59 +00:00
if ( selectionRect . width ( ) < = 8 & & selectionRect . height ( ) < = 8 )
2005-01-02 10:46:33 +00:00
{
selectionClear ( ) ;
2005-01-29 12:32:59 +00:00
if ( d - > aPrevAction )
{
2006-03-24 20:40:02 +00:00
d - > aPrevAction - > trigger ( ) ;
2005-01-29 12:32:59 +00:00
d - > aPrevAction = 0 ;
}
2004-11-16 17:36:02 +00:00
break ;
2005-01-02 10:46:33 +00:00
}
2004-11-03 17:35:48 +00:00
2008-11-21 10:50:16 +00:00
// if we support text generation
2006-05-26 14:32:35 +00:00
QString selectedText ;
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
if ( d - > document - > supportsSearching ( ) )
{
2006-09-13 12:11:42 +00:00
// grab text in selection by extracting it from all intersected pages
2006-09-21 08:45:36 +00:00
const Okular : : Page * okularPage = 0 ;
2008-11-11 18:48:40 +00:00
QVector < PageViewItem * > : : const_iterator iIt = d - > items . constBegin ( ) , iEnd = d - > items . constEnd ( ) ;
2006-09-13 12:11:42 +00:00
for ( ; iIt ! = iEnd ; + + iIt )
{
PageViewItem * item = * iIt ;
2008-05-16 13:15:23 +00:00
if ( ! item - > isVisible ( ) )
continue ;
2008-05-19 00:37:14 +00:00
const QRect & itemRect = item - > croppedGeometry ( ) ;
2006-09-13 12:11:42 +00:00
if ( selectionRect . intersects ( itemRect ) )
{
// request the textpage if there isn't one
2006-09-21 08:45:36 +00:00
okularPage = item - > page ( ) ;
2007-07-31 10:19:48 +00:00
kWarning ( ) < < " checking if page " < < item - > pageNumber ( ) < < " has text: " < < okularPage - > hasTextPage ( ) ;
2006-11-23 16:09:26 +00:00
if ( ! okularPage - > hasTextPage ( ) )
2006-09-21 08:45:36 +00:00
d - > document - > requestTextPage ( okularPage - > number ( ) ) ;
2006-09-13 12:11:42 +00:00
// grab text in the rect that intersects itemRect
QRect relativeRect = selectionRect . intersect ( itemRect ) ;
2008-05-19 00:37:14 +00:00
relativeRect . translate ( - item - > uncroppedGeometry ( ) . topLeft ( ) ) ;
2006-12-24 18:19:18 +00:00
Okular : : RegularAreaRect rects ;
2008-05-19 00:37:14 +00:00
rects . append ( Okular : : NormalizedRect ( relativeRect , item - > uncroppedWidth ( ) , item - > uncroppedHeight ( ) ) ) ;
2006-12-24 18:19:18 +00:00
selectedText + = okularPage - > text ( & rects ) ;
2006-09-13 12:11:42 +00:00
}
}
- Page/Link: tooltips for links backported
- Page: rotation does not switch height and width
- Document/Part/Generator:
1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel
also add possibility to merge an XML .rc file with menu layout. Relevant functions are:
QString Generator::getXMLFile(), returns a QString with your .rc file name.
void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface
2. Supporting backend settings:
If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings]
set to true) are found, a menu item: configure backends is created, clicking on it results in
loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg)
function should be overloaded by a generator and dlg->addPage should be used to add pages.
If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another.
3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration)
to the generator class, and sending a message to the user is as simple as emitting a signal!
4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your
event and return true if pageview is to proceed with its handling or false if not.
5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your
Generator::print()
6. PixmapRequest handling update:
a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async)
b.) Document::sendGeneratorRequests is a slot now
c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving)
is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is
run in three places:
1. in requestPixmaps when we receive a request
2. in requestDone if pixmapStack is not empty
3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async)
it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request
7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime
- TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks.
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
}
2004-11-03 17:35:48 +00:00
2004-11-16 17:36:02 +00:00
// popup that ask to copy:text and copy/save:image
2006-03-24 20:40:02 +00:00
KMenu menu ( this ) ;
QAction * textToClipboard = 0 , * speakText = 0 , * imageToClipboard = 0 , * imageToFile = 0 ;
2006-05-26 14:32:35 +00:00
if ( d - > document - > supportsSearching ( ) & & ! selectedText . isEmpty ( ) )
2004-11-16 17:36:02 +00:00
{
2007-02-13 17:45:54 +00:00
menu . addTitle ( i18np ( " Text (1 character) " , " Text (%1 characters) " , selectedText . length ( ) ) ) ;
2007-03-08 21:41:46 +00:00
textToClipboard = menu . addAction ( KIcon ( " edit-copy " ) , i18n ( " Copy to Clipboard " ) ) ;
2010-09-11 13:52:01 +00:00
bool copyAllowed = d - > document - > isAllowed ( Okular : : AllowCopy ) ;
if ( ! copyAllowed )
2006-05-19 18:22:54 +00:00
{
2006-04-05 17:49:44 +00:00
textToClipboard - > setEnabled ( false ) ;
2006-05-19 18:22:54 +00:00
textToClipboard - > setText ( i18n ( " Copy forbidden by DRM " ) ) ;
}
2006-09-21 08:45:36 +00:00
if ( Okular : : Settings : : useKTTSD ( ) )
2007-12-09 16:12:08 +00:00
speakText = menu . addAction ( KIcon ( " text-speak " ) , i18n ( " Speak Text " ) ) ;
2010-09-11 13:52:01 +00:00
if ( copyAllowed )
{
addWebShortcutsMenu ( & menu , selectedText ) ;
}
2004-11-16 17:36:02 +00:00
}
2006-04-10 19:50:00 +00:00
menu . addTitle ( i18n ( " Image (%1 by %2 pixels) " , selectionRect . width ( ) , selectionRect . height ( ) ) ) ;
2007-12-09 16:12:08 +00:00
imageToClipboard = menu . addAction ( KIcon ( " image-x-generic " ) , i18n ( " Copy to Clipboard " ) ) ;
2007-03-08 21:41:46 +00:00
imageToFile = menu . addAction ( KIcon ( " document-save " ) , i18n ( " Save to File... " ) ) ;
2006-03-24 20:40:02 +00:00
QAction * choice = menu . exec ( e - > globalPos ( ) ) ;
2006-06-02 10:32:29 +00:00
// check if the user really selected an action
2006-06-02 10:30:32 +00:00
if ( choice )
{
2006-10-21 22:07:05 +00:00
// IMAGE operation chosen
2006-03-24 20:40:02 +00:00
if ( choice = = imageToClipboard | | choice = = imageToFile )
2004-11-03 17:35:48 +00:00
{
2004-11-16 17:36:02 +00:00
// renders page into a pixmap
QPixmap copyPix ( selectionRect . width ( ) , selectionRect . height ( ) ) ;
QPainter copyPainter ( & copyPix ) ;
copyPainter . translate ( - selectionRect . left ( ) , - selectionRect . top ( ) ) ;
2005-04-01 16:24:11 +00:00
drawDocumentOnPainter ( selectionRect , & copyPainter ) ;
2008-06-06 22:03:30 +00:00
copyPainter . end ( ) ;
2004-11-16 17:36:02 +00:00
2006-03-24 20:40:02 +00:00
if ( choice = = imageToClipboard )
2004-11-03 17:35:48 +00:00
{
2004-11-16 17:36:02 +00:00
// [2] copy pixmap to clipboard
QClipboard * cb = QApplication : : clipboard ( ) ;
cb - > setPixmap ( copyPix , QClipboard : : Clipboard ) ;
if ( cb - > supportsSelection ( ) )
cb - > setPixmap ( copyPix , QClipboard : : Selection ) ;
2006-04-10 19:50:00 +00:00
d - > messageWindow - > display ( i18n ( " Image [%1x%2] copied to clipboard. " , copyPix . width ( ) , copyPix . height ( ) ) ) ;
2004-11-16 17:36:02 +00:00
}
2006-03-24 20:40:02 +00:00
else if ( choice = = imageToFile )
2004-11-16 17:36:02 +00:00
{
// [3] save pixmap to file
2009-12-26 20:47:58 +00:00
QString fileName = KFileDialog : : getSaveFileName ( KUrl ( ) , " image/png image/jpeg " , this , QString ( ) ,
KFileDialog : : ConfirmOverwrite ) ;
2006-06-12 10:51:07 +00:00
if ( fileName . isEmpty ( ) )
2010-08-21 15:46:47 +00:00
d - > messageWindow - > display ( i18n ( " File not saved. " ) , QString ( ) , PageViewMessage : : Warning ) ;
2004-11-16 17:36:02 +00:00
else
2004-11-03 17:35:48 +00:00
{
2006-08-29 21:09:55 +00:00
KMimeType : : Ptr mime = KMimeType : : findByUrl ( fileName ) ;
2006-03-24 20:40:02 +00:00
QString type ;
2008-10-01 13:12:51 +00:00
if ( ! mime | | mime = = KMimeType : : defaultMimeTypePtr ( ) )
2004-11-16 17:36:02 +00:00
type = " PNG " ;
2006-03-24 20:40:02 +00:00
else
2006-06-12 10:51:07 +00:00
type = mime - > name ( ) . section ( ' / ' , - 1 ) . toUpper ( ) ;
copyPix . save ( fileName , qPrintable ( type ) ) ;
d - > messageWindow - > display ( i18n ( " Image [%1x%2] saved to %3 file. " , copyPix . width ( ) , copyPix . height ( ) , type ) ) ;
2004-11-03 17:35:48 +00:00
}
}
2004-10-20 16:41:13 +00:00
}
2006-10-21 22:07:05 +00:00
// TEXT operation chosen
2005-01-29 12:32:59 +00:00
else
2004-11-16 17:36:02 +00:00
{
2006-03-24 20:40:02 +00:00
if ( choice = = textToClipboard )
2005-01-29 12:32:59 +00:00
{
// [1] copy text to clipboard
QClipboard * cb = QApplication : : clipboard ( ) ;
2006-05-26 14:32:35 +00:00
cb - > setText ( selectedText , QClipboard : : Clipboard ) ;
2005-01-29 12:32:59 +00:00
if ( cb - > supportsSelection ( ) )
2006-05-26 14:32:35 +00:00
cb - > setText ( selectedText , QClipboard : : Selection ) ;
2005-01-29 12:32:59 +00:00
}
2006-03-24 20:40:02 +00:00
else if ( choice = = speakText )
2005-01-29 12:32:59 +00:00
{
// [2] speech selection using KTTSD
2008-03-05 02:13:09 +00:00
d - > tts ( ) - > say ( selectedText ) ;
2005-01-29 12:32:59 +00:00
}
2004-11-16 17:36:02 +00:00
}
2006-06-02 10:30:32 +00:00
}
2004-11-16 17:36:02 +00:00
// clear widget selection and invalidate rect
selectionClear ( ) ;
2005-01-28 17:21:28 +00:00
// restore previous action if came from it using right button
if ( d - > aPrevAction )
{
2006-03-24 20:40:02 +00:00
d - > aPrevAction - > trigger ( ) ;
2005-01-28 17:21:28 +00:00
d - > aPrevAction = 0 ;
}
2004-11-16 17:36:02 +00:00
} break ;
2011-10-12 13:50:56 +00:00
2012-03-09 17:43:40 +00:00
case Okular : : Settings : : EnumMouseMode : : TableSelect :
2011-10-12 13:50:56 +00:00
{
// if mouse is released and selection is null this is a rightClick
if ( rightButton & & ! d - > mouseSelecting )
{
PageViewItem * pageItem = pickItemOnPoint ( eventPos . x ( ) , eventPos . y ( ) ) ;
emit rightClick ( pageItem ? pageItem - > page ( ) : 0 , e - > globalPos ( ) ) ;
break ;
}
QRect selectionRect = d - > mouseSelectionRect . normalized ( ) ;
if ( selectionRect . width ( ) < = 8 & & selectionRect . height ( ) < = 8 & & d - > tableSelectionParts . isEmpty ( ) )
{
selectionClear ( ) ;
if ( d - > aPrevAction )
{
d - > aPrevAction - > trigger ( ) ;
d - > aPrevAction = 0 ;
}
break ;
}
if ( d - > mouseSelecting ) {
// break up the selection into page-relative pieces
d - > tableSelectionParts . clear ( ) ;
const Okular : : Page * okularPage = 0 ;
QVector < PageViewItem * > : : const_iterator iIt = d - > items . constBegin ( ) , iEnd = d - > items . constEnd ( ) ;
for ( ; iIt ! = iEnd ; + + iIt )
{
PageViewItem * item = * iIt ;
if ( ! item - > isVisible ( ) )
continue ;
const QRect & itemRect = item - > croppedGeometry ( ) ;
if ( selectionRect . intersects ( itemRect ) )
{
// request the textpage if there isn't one
okularPage = item - > page ( ) ;
kWarning ( ) < < " checking if page " < < item - > pageNumber ( ) < < " has text: " < < okularPage - > hasTextPage ( ) ;
if ( ! okularPage - > hasTextPage ( ) )
d - > document - > requestTextPage ( okularPage - > number ( ) ) ;
// grab text in the rect that intersects itemRect
QRect rectInItem = selectionRect . intersect ( itemRect ) ;
rectInItem . translate ( - item - > uncroppedGeometry ( ) . topLeft ( ) ) ;
QRect rectInSelection = selectionRect . intersect ( itemRect ) ;
rectInSelection . translate ( - selectionRect . topLeft ( ) ) ;
d - > tableSelectionParts . append (
TableSelectionPart (
item ,
Okular : : NormalizedRect ( rectInItem , item - > uncroppedWidth ( ) , item - > uncroppedHeight ( ) ) ,
Okular : : NormalizedRect ( rectInSelection , selectionRect . width ( ) , selectionRect . height ( ) )
)
) ;
}
}
QRect updatedRect = d - > mouseSelectionRect . normalized ( ) . adjusted ( 0 , 0 , 1 , 1 ) ;
updatedRect . translate ( - contentAreaPosition ( ) ) ;
d - > mouseSelecting = false ;
d - > mouseSelectionRect . setCoords ( 0 , 0 , 0 , 0 ) ;
d - > tableSelectionCols . clear ( ) ;
d - > tableSelectionRows . clear ( ) ;
2011-10-31 15:33:03 +00:00
guessTableDividers ( ) ;
2011-10-12 13:50:56 +00:00
viewport ( ) - > update ( updatedRect ) ;
}
if ( ! d - > document - > isAllowed ( Okular : : AllowCopy ) ) {
d - > messageWindow - > display ( i18n ( " Copy forbidden by DRM " ) , QString ( ) , PageViewMessage : : Info , - 1 ) ;
break ;
}
QString selText ;
QString selHtml ;
QList < double > xs = d - > tableSelectionCols ;
QList < double > ys = d - > tableSelectionRows ;
xs . prepend ( 0.0 ) ;
xs . append ( 1.0 ) ;
ys . prepend ( 0.0 ) ;
ys . append ( 1.0 ) ;
selHtml = " <html><head> "
" <meta content= \" text/html; charset=utf-8 \" http-equiv= \" Content-Type \" > "
" </head><body><table> " ;
for ( int r = 0 ; r + 1 < ys . length ( ) ; r + + ) {
selHtml + = " <tr> " ;
for ( int c = 0 ; c + 1 < xs . length ( ) ; c + + ) {
Okular : : NormalizedRect cell ( xs [ c ] , ys [ r ] , xs [ c + 1 ] , ys [ r + 1 ] ) ;
if ( c ) selText + = ' \t ' ;
QString txt ;
2011-10-12 14:04:23 +00:00
foreach ( const TableSelectionPart & tsp , d - > tableSelectionParts ) {
2011-10-12 13:50:56 +00:00
// first, crop the cell to this part
if ( ! tsp . rectInSelection . intersects ( cell ) )
continue ;
Okular : : NormalizedRect cellPart = tsp . rectInSelection & cell ; // intersection
// second, convert it from table coordinates to part coordinates
cellPart . left - = tsp . rectInSelection . left ;
cellPart . left / = ( tsp . rectInSelection . right - tsp . rectInSelection . left ) ;
cellPart . right - = tsp . rectInSelection . left ;
cellPart . right / = ( tsp . rectInSelection . right - tsp . rectInSelection . left ) ;
cellPart . top - = tsp . rectInSelection . top ;
cellPart . top / = ( tsp . rectInSelection . bottom - tsp . rectInSelection . top ) ;
cellPart . bottom - = tsp . rectInSelection . top ;
cellPart . bottom / = ( tsp . rectInSelection . bottom - tsp . rectInSelection . top ) ;
// third, convert from part coordinates to item coordinates
cellPart . left * = ( tsp . rectInItem . right - tsp . rectInItem . left ) ;
cellPart . left + = tsp . rectInItem . left ;
cellPart . right * = ( tsp . rectInItem . right - tsp . rectInItem . left ) ;
cellPart . right + = tsp . rectInItem . left ;
cellPart . top * = ( tsp . rectInItem . bottom - tsp . rectInItem . top ) ;
cellPart . top + = tsp . rectInItem . top ;
cellPart . bottom * = ( tsp . rectInItem . bottom - tsp . rectInItem . top ) ;
cellPart . bottom + = tsp . rectInItem . top ;
// now get the text
Okular : : RegularAreaRect rects ;
rects . append ( cellPart ) ;
txt + = tsp . item - > page ( ) - > text ( & rects , Okular : : TextPage : : CentralPixelTextAreaInclusionBehaviour ) ;
}
QString html = txt ;
selText + = txt . replace ( ' \n ' , ' ' ) ;
html . replace ( ' & ' , " & " ) . replace ( ' < ' , " < " ) . replace ( ' > ' , " > " ) ;
// Remove newlines, do not turn them into <br>, because
// Excel interprets <br> within cell as new cell...
html . replace ( ' \n ' , " " ) ;
selHtml + = " <td> " + html + " </td> " ;
}
selText + = ' \n ' ;
selHtml + = " </tr> \n " ;
}
selHtml + = " </table></body></html> \n " ;
QClipboard * cb = QApplication : : clipboard ( ) ;
QMimeData * md = new QMimeData ( ) ;
md - > setText ( selText ) ;
md - > setHtml ( selHtml ) ;
cb - > setMimeData ( md , QClipboard : : Clipboard ) ;
if ( cb - > supportsSelection ( ) )
cb - > setMimeData ( md , QClipboard : : Selection ) ;
} break ;
2012-03-09 17:43:40 +00:00
case Okular : : Settings : : EnumMouseMode : : TextSelect :
2006-09-26 22:22:01 +00:00
if ( d - > mouseTextSelecting )
{
d - > mouseTextSelecting = false ;
// textSelectionClear();
2008-03-04 00:01:46 +00:00
if ( d - > document - > isAllowed ( Okular : : AllowCopy ) )
2008-02-26 20:54:31 +00:00
{
2008-03-04 00:01:46 +00:00
const QString text = d - > selectedText ( ) ;
if ( ! text . isEmpty ( ) )
{
QClipboard * cb = QApplication : : clipboard ( ) ;
if ( cb - > supportsSelection ( ) )
cb - > setText ( text , QClipboard : : Selection ) ;
}
2008-02-26 20:54:31 +00:00
}
2006-09-26 22:22:01 +00:00
}
2006-11-24 21:02:38 +00:00
else if ( ! d - > mousePressPos . isNull ( ) & & rightButton )
2006-09-26 22:22:01 +00:00
{
2011-08-14 02:57:15 +00:00
PageViewItem * item = pickItemOnPoint ( eventPos . x ( ) , eventPos . y ( ) ) ;
2011-11-23 23:59:41 +00:00
const Okular : : Page * page ;
2011-08-14 02:57:15 +00:00
//if there is text selected in the page
2011-11-23 23:59:41 +00:00
if ( item & & ( page = item - > page ( ) ) - > textSelection ( ) )
2006-11-24 21:02:38 +00:00
{
2011-08-22 17:22:09 +00:00
KMenu menu ( this ) ;
2011-08-14 02:57:15 +00:00
QAction * textToClipboard = menu . addAction ( KIcon ( " edit-copy " ) , i18n ( " Copy Text " ) ) ;
QAction * speakText = 0 ;
if ( Okular : : Settings : : useKTTSD ( ) )
speakText = menu . addAction ( KIcon ( " text-speak " ) , i18n ( " Speak Text " ) ) ;
if ( ! d - > document - > isAllowed ( Okular : : AllowCopy ) )
2011-06-25 05:11:33 +00:00
{
2011-08-14 02:57:15 +00:00
textToClipboard - > setEnabled ( false ) ;
textToClipboard - > setText ( i18n ( " Copy forbidden by DRM " ) ) ;
}
else
{
addWebShortcutsMenu ( & menu , d - > selectedText ( ) ) ;
}
QAction * choice = menu . exec ( e - > globalPos ( ) ) ;
// check if the user really selected an action
if ( choice )
2008-03-05 11:06:55 +00:00
{
2011-08-14 02:57:15 +00:00
if ( choice = = textToClipboard )
copyTextSelection ( ) ;
else if ( choice = = speakText )
{
const QString text = d - > selectedText ( ) ;
d - > tts ( ) - > say ( text ) ;
}
2008-03-05 11:06:55 +00:00
}
2006-09-26 22:22:01 +00:00
}
}
break ;
2004-09-26 23:39:39 +00:00
}
2005-01-29 12:32:59 +00:00
// reset mouse press / 'drag start' position
d - > mousePressPos = QPoint ( ) ;
2004-09-26 23:39:39 +00:00
}
2011-10-31 15:33:03 +00:00
void PageView : : guessTableDividers ( )
{
QList < QPair < double , int > > colTicks , rowTicks , colSelectionTicks , rowSelectionTicks ;
foreach ( const TableSelectionPart & tsp , d - > tableSelectionParts )
{
// add ticks for the edges of this area...
colSelectionTicks . append ( qMakePair ( tsp . rectInSelection . left , + 1 ) ) ;
colSelectionTicks . append ( qMakePair ( tsp . rectInSelection . right , - 1 ) ) ;
rowSelectionTicks . append ( qMakePair ( tsp . rectInSelection . top , + 1 ) ) ;
rowSelectionTicks . append ( qMakePair ( tsp . rectInSelection . bottom , - 1 ) ) ;
// get the words in this part
Okular : : RegularAreaRect rects ;
rects . append ( tsp . rectInItem ) ;
const Okular : : TextEntity : : List words = tsp . item - > page ( ) - > words ( & rects , Okular : : TextPage : : CentralPixelTextAreaInclusionBehaviour ) ;
foreach ( Okular : : TextEntity * te , words )
{
if ( te - > text ( ) . isEmpty ( ) ) {
delete te ;
continue ;
}
Okular : : NormalizedRect wordArea = * te - > area ( ) ;
// convert it from item coordinates to part coordinates
wordArea . left - = tsp . rectInItem . left ;
wordArea . left / = ( tsp . rectInItem . right - tsp . rectInItem . left ) ;
wordArea . right - = tsp . rectInItem . left ;
wordArea . right / = ( tsp . rectInItem . right - tsp . rectInItem . left ) ;
wordArea . top - = tsp . rectInItem . top ;
wordArea . top / = ( tsp . rectInItem . bottom - tsp . rectInItem . top ) ;
wordArea . bottom - = tsp . rectInItem . top ;
wordArea . bottom / = ( tsp . rectInItem . bottom - tsp . rectInItem . top ) ;
// convert from part coordinates to table coordinates
wordArea . left * = ( tsp . rectInSelection . right - tsp . rectInSelection . left ) ;
wordArea . left + = tsp . rectInSelection . left ;
wordArea . right * = ( tsp . rectInSelection . right - tsp . rectInSelection . left ) ;
wordArea . right + = tsp . rectInSelection . left ;
wordArea . top * = ( tsp . rectInSelection . bottom - tsp . rectInSelection . top ) ;
wordArea . top + = tsp . rectInSelection . top ;
wordArea . bottom * = ( tsp . rectInSelection . bottom - tsp . rectInSelection . top ) ;
wordArea . bottom + = tsp . rectInSelection . top ;
// add to the ticks arrays...
colTicks . append ( qMakePair ( wordArea . left , + 1 ) ) ;
colTicks . append ( qMakePair ( wordArea . right , - 1 ) ) ;
rowTicks . append ( qMakePair ( wordArea . top , + 1 ) ) ;
rowTicks . append ( qMakePair ( wordArea . bottom , - 1 ) ) ;
delete te ;
}
}
int tally = 0 ;
qSort ( colSelectionTicks ) ;
qSort ( rowSelectionTicks ) ;
for ( int i = 0 ; i < colSelectionTicks . length ( ) ; + + i )
{
tally + = colSelectionTicks [ i ] . second ;
if ( tally = = 0 & & i + 1 < colSelectionTicks . length ( ) & & colSelectionTicks [ i + 1 ] . first ! = colSelectionTicks [ i ] . first )
{
colTicks . append ( qMakePair ( colSelectionTicks [ i ] . first , + 1 ) ) ;
colTicks . append ( qMakePair ( colSelectionTicks [ i + 1 ] . first , - 1 ) ) ;
}
}
Q_ASSERT ( tally = = 0 ) ;
for ( int i = 0 ; i < rowSelectionTicks . length ( ) ; + + i )
{
tally + = rowSelectionTicks [ i ] . second ;
if ( tally = = 0 & & i + 1 < rowSelectionTicks . length ( ) & & rowSelectionTicks [ i + 1 ] . first ! = rowSelectionTicks [ i ] . first ) {
rowTicks . append ( qMakePair ( rowSelectionTicks [ i ] . first , + 1 ) ) ;
rowTicks . append ( qMakePair ( rowSelectionTicks [ i + 1 ] . first , - 1 ) ) ;
}
}
Q_ASSERT ( tally = = 0 ) ;
qSort ( colTicks ) ;
qSort ( rowTicks ) ;
for ( int i = 0 ; i < colTicks . length ( ) ; + + i )
{
tally + = colTicks [ i ] . second ;
if ( tally = = 0 & & i + 1 < colTicks . length ( ) & & colTicks [ i + 1 ] . first ! = colTicks [ i ] . first )
{
d - > tableSelectionCols . append ( ( colTicks [ i ] . first + colTicks [ i + 1 ] . first ) / 2 ) ;
d - > tableDividersGuessed = true ;
}
}
Q_ASSERT ( tally = = 0 ) ;
for ( int i = 0 ; i < rowTicks . length ( ) ; + + i )
{
tally + = rowTicks [ i ] . second ;
if ( tally = = 0 & & i + 1 < rowTicks . length ( ) & & rowTicks [ i + 1 ] . first ! = rowTicks [ i ] . first )
{
d - > tableSelectionRows . append ( ( rowTicks [ i ] . first + rowTicks [ i + 1 ] . first ) / 2 ) ;
d - > tableDividersGuessed = true ;
}
}
Q_ASSERT ( tally = = 0 ) ;
}
2010-03-23 20:21:42 +00:00
void PageView : : mouseDoubleClickEvent ( QMouseEvent * e )
{
if ( e - > button ( ) = = Qt : : LeftButton )
{
const QPoint eventPos = contentAreaPoint ( e - > pos ( ) ) ;
PageViewItem * pageItem = pickItemOnPoint ( eventPos . x ( ) , eventPos . y ( ) ) ;
if ( pageItem )
{
// find out normalized mouse coords inside current item
double nX = pageItem - > absToPageX ( eventPos . x ( ) ) ;
double nY = pageItem - > absToPageY ( eventPos . y ( ) ) ;
2012-03-25 21:48:07 +00:00
if ( Okular : : Settings : : mouseMode ( ) = = Okular : : Settings : : EnumMouseMode : : TextSelect ) {
textSelectionClear ( ) ;
Okular : : RegularAreaRect * wordRect = pageItem - > page ( ) - > wordAt ( Okular : : NormalizedPoint ( nX , nY ) ) ;
if ( wordRect )
{
// TODO words with hyphens across pages
d - > document - > setPageTextSelection ( pageItem - > pageNumber ( ) , wordRect , palette ( ) . color ( QPalette : : Active , QPalette : : Highlight ) ) ;
d - > pagesWithTextSelection < < pageItem - > pageNumber ( ) ;
2012-10-16 18:38:55 +00:00
if ( d - > document - > isAllowed ( Okular : : AllowCopy ) )
2012-10-16 18:36:52 +00:00
{
2012-10-16 18:38:55 +00:00
const QString text = d - > selectedText ( ) ;
if ( ! text . isEmpty ( ) )
{
QClipboard * cb = QApplication : : clipboard ( ) ;
if ( cb - > supportsSelection ( ) )
cb - > setText ( text , QClipboard : : Selection ) ;
}
2012-10-16 18:36:52 +00:00
}
2012-03-25 21:48:07 +00:00
return ;
}
}
const QRect & itemRect = pageItem - > uncroppedGeometry ( ) ;
2010-03-23 20:21:42 +00:00
Okular : : Annotation * ann = 0 ;
const Okular : : ObjectRect * orect = pageItem - > page ( ) - > objectRect ( Okular : : ObjectRect : : OAnnotation , nX , nY , itemRect . width ( ) , itemRect . height ( ) ) ;
if ( orect )
ann = ( ( Okular : : AnnotationObjectRect * ) orect ) - > annotation ( ) ;
if ( ann )
{
2012-01-17 22:46:37 +00:00
openAnnotationWindow ( ann , pageItem - > pageNumber ( ) ) ;
2010-03-23 20:21:42 +00:00
}
}
}
}
2004-09-26 23:39:39 +00:00
void PageView : : wheelEvent ( QWheelEvent * e )
{
2005-02-01 18:24:16 +00:00
// don't perform any mouse action when viewport is autoscrolling
if ( d - > viewportMoveActive )
return ;
2006-10-26 20:59:07 +00:00
if ( ! d - > document - > isOpened ( ) )
{
2009-06-29 20:55:50 +00:00
QAbstractScrollArea : : wheelEvent ( e ) ;
2006-10-26 20:59:07 +00:00
return ;
}
2004-10-29 21:52:06 +00:00
int delta = e - > delta ( ) ,
vScroll = verticalScrollBar ( ) - > value ( ) ;
2004-09-26 23:39:39 +00:00
e - > accept ( ) ;
2006-09-26 22:22:01 +00:00
if ( ( e - > modifiers ( ) & Qt : : ControlModifier ) = = Qt : : ControlModifier ) {
2004-10-24 07:06:04 +00:00
if ( e - > delta ( ) < 0 )
2004-09-26 23:39:39 +00:00
slotZoomOut ( ) ;
else
slotZoomIn ( ) ;
}
2006-09-21 08:45:36 +00:00
else if ( delta < = - 120 & & ! Okular : : Settings : : viewContinuous ( ) & & vScroll = = verticalScrollBar ( ) - > maximum ( ) )
2004-09-30 18:16:12 +00:00
{
2004-10-29 21:52:06 +00:00
// go to next page
2006-08-30 14:17:22 +00:00
if ( ( int ) d - > document - > currentPage ( ) < d - > items . count ( ) - 1 )
2005-01-09 23:37:07 +00:00
{
2005-06-13 11:53:47 +00:00
// more optimized than document->setNextPage and then move view to top
2006-09-21 08:45:36 +00:00
Okular : : DocumentViewport newViewport = d - > document - > viewport ( ) ;
2010-07-06 17:23:44 +00:00
newViewport . pageNumber + = viewColumns ( ) ;
2005-04-14 11:33:28 +00:00
if ( newViewport . pageNumber > = ( int ) d - > items . count ( ) )
newViewport . pageNumber = d - > items . count ( ) - 1 ;
2005-06-13 11:53:47 +00:00
newViewport . rePos . enabled = true ;
newViewport . rePos . normalizedY = 0.0 ;
2005-01-09 23:37:07 +00:00
d - > document - > setViewport ( newViewport ) ;
}
2004-09-30 18:16:12 +00:00
}
2006-09-21 08:45:36 +00:00
else if ( delta > = 120 & & ! Okular : : Settings : : viewContinuous ( ) & & vScroll = = verticalScrollBar ( ) - > minimum ( ) )
2004-10-29 21:52:06 +00:00
{
// go to prev page
2005-01-09 23:37:07 +00:00
if ( d - > document - > currentPage ( ) > 0 )
2004-12-12 22:57:54 +00:00
{
2005-06-13 11:53:47 +00:00
// more optimized than document->setPrevPage and then move view to bottom
2006-09-21 08:45:36 +00:00
Okular : : DocumentViewport newViewport = d - > document - > viewport ( ) ;
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
newViewport . pageNumber - = viewColumns ( ) ;
2005-04-14 11:33:28 +00:00
if ( newViewport . pageNumber < 0 )
newViewport . pageNumber = 0 ;
2005-06-13 11:53:47 +00:00
newViewport . rePos . enabled = true ;
newViewport . rePos . normalizedY = 1.0 ;
2005-01-09 23:37:07 +00:00
d - > document - > setViewport ( newViewport ) ;
2004-12-12 22:57:54 +00:00
}
2004-10-29 21:52:06 +00:00
}
else
2009-06-29 20:55:50 +00:00
QAbstractScrollArea : : wheelEvent ( e ) ;
2005-01-02 17:12:35 +00:00
2009-06-29 20:55:50 +00:00
updateCursor ( contentAreaPosition ( ) + viewport ( ) - > mapFromGlobal ( QCursor : : pos ( ) ) ) ;
2004-09-30 18:16:12 +00:00
}
2004-09-26 23:39:39 +00:00
void PageView : : dragEnterEvent ( QDragEnterEvent * ev )
{
ev - > accept ( ) ;
}
2006-09-26 22:22:01 +00:00
void PageView : : dragMoveEvent ( QDragMoveEvent * ev )
{
ev - > accept ( ) ;
}
2004-09-26 23:39:39 +00:00
void PageView : : dropEvent ( QDropEvent * ev )
{
2006-03-24 20:40:02 +00:00
if ( KUrl : : List : : canDecode ( ev - > mimeData ( ) ) )
2012-08-08 19:05:15 +00:00
{
const KUrl : : List list = KUrl : : List : : fromMimeData ( ev - > mimeData ( ) ) ;
if ( ! list . isEmpty ( ) )
emit urlDropped ( list . first ( ) ) ;
}
2004-09-26 23:39:39 +00:00
}
2009-06-29 20:55:50 +00:00
bool PageView : : viewportEvent ( QEvent * e )
{
2012-03-09 17:43:40 +00:00
if ( e - > type ( ) = = QEvent : : ToolTip & & Okular : : Settings : : mouseMode ( ) = = Okular : : Settings : : EnumMouseMode : : Browse )
2009-06-29 20:55:50 +00:00
{
QHelpEvent * he = static_cast < QHelpEvent * > ( e ) ;
const QPoint eventPos = contentAreaPoint ( he - > pos ( ) ) ;
PageViewItem * pageItem = pickItemOnPoint ( eventPos . x ( ) , eventPos . y ( ) ) ;
const Okular : : ObjectRect * rect = 0 ;
const Okular : : Action * link = 0 ;
const Okular : : Annotation * ann = 0 ;
if ( pageItem )
{
double nX = pageItem - > absToPageX ( eventPos . x ( ) ) ;
double nY = pageItem - > absToPageY ( eventPos . y ( ) ) ;
rect = pageItem - > page ( ) - > objectRect ( Okular : : ObjectRect : : OAnnotation , nX , nY , pageItem - > uncroppedWidth ( ) , pageItem - > uncroppedHeight ( ) ) ;
if ( rect )
ann = static_cast < const Okular : : AnnotationObjectRect * > ( rect ) - > annotation ( ) ;
else
{
rect = pageItem - > page ( ) - > objectRect ( Okular : : ObjectRect : : Action , nX , nY , pageItem - > uncroppedWidth ( ) , pageItem - > uncroppedHeight ( ) ) ;
if ( rect )
link = static_cast < const Okular : : Action * > ( rect - > object ( ) ) ;
}
}
if ( ann )
{
QRect r = rect - > boundingRect ( pageItem - > uncroppedWidth ( ) , pageItem - > uncroppedHeight ( ) ) ;
r . translate ( pageItem - > uncroppedGeometry ( ) . topLeft ( ) ) ;
r . translate ( - contentAreaPosition ( ) ) ;
QString tip = GuiUtils : : prettyToolTip ( ann ) ;
QToolTip : : showText ( he - > globalPos ( ) , tip , viewport ( ) , r ) ;
}
else if ( link )
{
QRect r = rect - > boundingRect ( pageItem - > uncroppedWidth ( ) , pageItem - > uncroppedHeight ( ) ) ;
r . translate ( pageItem - > uncroppedGeometry ( ) . topLeft ( ) ) ;
r . translate ( - contentAreaPosition ( ) ) ;
QString tip = link - > actionTip ( ) ;
if ( ! tip . isEmpty ( ) )
QToolTip : : showText ( he - > globalPos ( ) , tip , viewport ( ) , r ) ;
}
e - > accept ( ) ;
return true ;
}
else
// do not stop the event
return QAbstractScrollArea : : viewportEvent ( e ) ;
}
2009-07-07 16:53:33 +00:00
void PageView : : scrollContentsBy ( int dx , int dy )
{
const QRect r = viewport ( ) - > rect ( ) ;
viewport ( ) - > scroll ( dx , dy , r ) ;
// HACK manually repaint the damaged regions, as it seems some updates are missed
// thus leaving artifacts around
QRegion rgn ( r ) ;
rgn - = rgn & r . translated ( dx , dy ) ;
foreach ( const QRect & rect , rgn . rects ( ) )
viewport ( ) - > repaint ( rect ) ;
}
2004-09-26 23:39:39 +00:00
//END widget events
2006-10-03 17:13:42 +00:00
QList < Okular : : RegularAreaRect * > PageView : : textSelections ( const QPoint & start , const QPoint & end , int & firstpage )
{
firstpage = - 1 ;
QList < Okular : : RegularAreaRect * > ret ;
QSet < int > affectedItemsSet ;
QRect selectionRect = QRect ( start , end ) . normalized ( ) ;
foreach ( PageViewItem * item , d - > items )
{
2008-05-19 00:37:14 +00:00
if ( item - > isVisible ( ) & & selectionRect . intersects ( item - > croppedGeometry ( ) ) )
2006-10-03 17:13:42 +00:00
affectedItemsSet . insert ( item - > pageNumber ( ) ) ;
}
2006-12-23 16:36:08 +00:00
# ifdef PAGEVIEW_DEBUG
2007-07-31 10:19:48 +00:00
kDebug ( ) < < " >>>> item selected by mouse: " < < affectedItemsSet . count ( ) ;
2006-12-23 16:36:08 +00:00
# endif
2006-10-03 17:13:42 +00:00
if ( ! affectedItemsSet . isEmpty ( ) )
{
// is the mouse drag line the ne-sw diagonal of the selection rect?
bool direction_ne_sw = start = = selectionRect . topRight ( ) | | start = = selectionRect . bottomLeft ( ) ;
int tmpmin = d - > document - > pages ( ) ;
int tmpmax = 0 ;
foreach ( int p , affectedItemsSet )
{
if ( p < tmpmin ) tmpmin = p ;
if ( p > tmpmax ) tmpmax = p ;
}
PageViewItem * a = pickItemOnPoint ( ( int ) ( direction_ne_sw ? selectionRect . right ( ) : selectionRect . left ( ) ) , ( int ) selectionRect . top ( ) ) ;
int min = a & & ( a - > pageNumber ( ) ! = tmpmax ) ? a - > pageNumber ( ) : tmpmin ;
PageViewItem * b = pickItemOnPoint ( ( int ) ( direction_ne_sw ? selectionRect . left ( ) : selectionRect . right ( ) ) , ( int ) selectionRect . bottom ( ) ) ;
int max = b & & ( b - > pageNumber ( ) ! = tmpmin ) ? b - > pageNumber ( ) : tmpmax ;
QList < int > affectedItemsIds ;
for ( int i = min ; i < = max ; + + i )
affectedItemsIds . append ( i ) ;
2006-12-23 16:36:08 +00:00
# ifdef PAGEVIEW_DEBUG
2007-07-31 10:19:48 +00:00
kDebug ( ) < < " >>>> pages: " < < affectedItemsIds ;
2006-12-23 16:36:08 +00:00
# endif
2006-10-03 17:13:42 +00:00
firstpage = affectedItemsIds . first ( ) ;
if ( affectedItemsIds . count ( ) = = 1 )
{
PageViewItem * item = d - > items [ affectedItemsIds . first ( ) ] ;
2008-05-19 00:37:14 +00:00
selectionRect . translate ( - item - > uncroppedGeometry ( ) . topLeft ( ) ) ;
2006-10-03 17:13:42 +00:00
ret . append ( textSelectionForItem ( item ,
direction_ne_sw ? selectionRect . topRight ( ) : selectionRect . topLeft ( ) ,
direction_ne_sw ? selectionRect . bottomLeft ( ) : selectionRect . bottomRight ( ) ) ) ;
}
else if ( affectedItemsIds . count ( ) > 1 )
{
// first item
PageViewItem * first = d - > items [ affectedItemsIds . first ( ) ] ;
2008-05-19 00:37:14 +00:00
QRect geom = first - > croppedGeometry ( ) . intersect ( selectionRect ) . translated ( - first - > uncroppedGeometry ( ) . topLeft ( ) ) ;
2006-10-03 17:13:42 +00:00
ret . append ( textSelectionForItem ( first ,
selectionRect . bottom ( ) > geom . height ( ) ? ( direction_ne_sw ? geom . topRight ( ) : geom . topLeft ( ) ) : ( direction_ne_sw ? geom . bottomRight ( ) : geom . bottomLeft ( ) ) ,
QPoint ( ) ) ) ;
// last item
PageViewItem * last = d - > items [ affectedItemsIds . last ( ) ] ;
2008-05-19 00:37:14 +00:00
geom = last - > croppedGeometry ( ) . intersect ( selectionRect ) . translated ( - last - > uncroppedGeometry ( ) . topLeft ( ) ) ;
2006-10-03 17:13:42 +00:00
// the last item needs to appended at last...
Okular : : RegularAreaRect * lastArea = textSelectionForItem ( last ,
QPoint ( ) ,
selectionRect . bottom ( ) > geom . height ( ) ? ( direction_ne_sw ? geom . bottomLeft ( ) : geom . bottomRight ( ) ) : ( direction_ne_sw ? geom . topLeft ( ) : geom . topRight ( ) ) ) ;
affectedItemsIds . removeFirst ( ) ;
affectedItemsIds . removeLast ( ) ;
// item between the two above
foreach ( int page , affectedItemsIds )
{
ret . append ( textSelectionForItem ( d - > items [ page ] ) ) ;
}
ret . append ( lastArea ) ;
}
}
return ret ;
}
2005-04-01 16:24:11 +00:00
void PageView : : drawDocumentOnPainter ( const QRect & contentsRect , QPainter * p )
2004-10-30 20:54:48 +00:00
{
2011-02-09 21:24:09 +00:00
QColor backColor = viewport ( ) - > palette ( ) . color ( QPalette : : Dark ) ;
2004-10-30 20:54:48 +00:00
// when checking if an Item is contained in contentsRect, instead of
// growing PageViewItems rects (for keeping outline into account), we
// grow the contentsRect
QRect checkRect = contentsRect ;
2006-03-29 16:46:09 +00:00
checkRect . adjust ( - 3 , - 3 , 1 , 1 ) ;
2004-10-30 20:54:48 +00:00
2006-10-21 22:07:05 +00:00
// create a region from which we'll subtract painted rects
2004-11-03 17:35:48 +00:00
QRegion remainingArea ( contentsRect ) ;
2005-04-01 16:24:11 +00:00
// iterate over all items painting the ones intersecting contentsRect
2008-11-11 18:48:40 +00:00
QVector < PageViewItem * > : : const_iterator iIt = d - > items . constBegin ( ) , iEnd = d - > items . constEnd ( ) ;
2004-11-05 00:14:00 +00:00
for ( ; iIt ! = iEnd ; + + iIt )
2004-10-30 20:54:48 +00:00
{
// check if a piece of the page intersects the contents rect
2008-05-19 00:37:14 +00:00
if ( ! ( * iIt ) - > isVisible ( ) | | ! ( * iIt ) - > croppedGeometry ( ) . intersects ( checkRect ) )
2004-11-05 18:14:20 +00:00
continue ;
2004-10-30 20:54:48 +00:00
2005-04-01 16:24:11 +00:00
// get item and item's outline geometries
2004-11-05 18:14:20 +00:00
PageViewItem * item = * iIt ;
2008-05-19 00:37:14 +00:00
QRect itemGeometry = item - > croppedGeometry ( ) ,
2005-04-01 16:24:11 +00:00
outlineGeometry = itemGeometry ;
2006-03-29 16:46:09 +00:00
outlineGeometry . adjust ( - 1 , - 1 , 3 , 3 ) ;
2004-10-30 20:54:48 +00:00
2008-05-19 00:37:14 +00:00
// move the painter to the top-left corner of the real page
2004-11-05 18:14:20 +00:00
p - > save ( ) ;
2005-04-01 16:24:11 +00:00
p - > translate ( itemGeometry . left ( ) , itemGeometry . top ( ) ) ;
2004-11-05 18:14:20 +00:00
2005-04-01 16:24:11 +00:00
// draw the page outline (black border and 2px bottom-right shadow)
if ( ! itemGeometry . contains ( contentsRect ) )
2004-11-05 18:14:20 +00:00
{
2005-04-01 16:24:11 +00:00
int itemWidth = itemGeometry . width ( ) ,
itemHeight = itemGeometry . height ( ) ;
2004-11-05 18:14:20 +00:00
// draw simple outline
p - > setPen ( Qt : : black ) ;
2006-10-11 18:26:23 +00:00
p - > drawRect ( - 1 , - 1 , itemWidth + 1 , itemHeight + 1 ) ;
2004-11-05 18:14:20 +00:00
// draw bottom/right gradient
2006-10-11 18:26:23 +00:00
static int levels = 2 ;
2011-02-09 21:24:09 +00:00
int r = backColor . red ( ) / ( levels + 2 ) + 6 ,
g = backColor . green ( ) / ( levels + 2 ) + 6 ,
b = backColor . blue ( ) / ( levels + 2 ) + 6 ;
2004-11-05 18:14:20 +00:00
for ( int i = 0 ; i < levels ; i + + )
2004-10-30 20:54:48 +00:00
{
2004-11-05 18:14:20 +00:00
p - > setPen ( QColor ( r * ( i + 2 ) , g * ( i + 2 ) , b * ( i + 2 ) ) ) ;
2005-04-01 16:24:11 +00:00
p - > drawLine ( i , i + itemHeight + 1 , i + itemWidth + 1 , i + itemHeight + 1 ) ;
p - > drawLine ( i + itemWidth + 1 , i , i + itemWidth + 1 , i + itemHeight ) ;
2011-02-09 21:24:09 +00:00
p - > setPen ( backColor ) ;
2005-04-01 16:24:11 +00:00
p - > drawLine ( - 1 , i + itemHeight + 1 , i - 1 , i + itemHeight + 1 ) ;
p - > drawLine ( i + itemWidth + 1 , - 1 , i + itemWidth + 1 , i - 1 ) ;
2004-10-30 20:54:48 +00:00
}
2004-11-05 18:14:20 +00:00
}
2004-10-30 20:54:48 +00:00
2006-10-21 22:07:05 +00:00
// draw the page using the PagePainter with all flags active
2005-04-01 16:24:11 +00:00
if ( contentsRect . intersects ( itemGeometry ) )
2004-11-05 18:14:20 +00:00
{
2011-10-23 13:22:58 +00:00
Okular : : NormalizedPoint * viewPortPoint = 0 ;
2011-10-17 19:56:45 +00:00
Okular : : NormalizedPoint point ( d - > lastSourceLocationViewportNormalizedX , d - > lastSourceLocationViewportNormalizedY ) ;
if ( Okular : : Settings : : showSourceLocationsGraphically ( )
& & item - > pageNumber ( ) = = d - > lastSourceLocationViewportPageNumber )
{
viewPortPoint = & point ;
}
2005-04-01 16:24:11 +00:00
QRect pixmapRect = contentsRect . intersect ( itemGeometry ) ;
2008-05-19 00:37:14 +00:00
pixmapRect . translate ( - item - > croppedGeometry ( ) . topLeft ( ) ) ;
PagePainter : : paintCroppedPageOnPainter ( p , item - > page ( ) , PAGEVIEW_ID , pageflags ,
item - > uncroppedWidth ( ) , item - > uncroppedHeight ( ) , pixmapRect ,
2012-11-15 19:11:10 +00:00
item - > crop ( ) , viewPortPoint ) ;
2004-10-30 20:54:48 +00:00
}
2004-11-05 18:14:20 +00:00
// remove painted area from 'remainingArea' and restore painter
remainingArea - = outlineGeometry . intersect ( contentsRect ) ;
p - > restore ( ) ;
2004-10-30 20:54:48 +00:00
}
2004-11-03 17:35:48 +00:00
2005-04-01 16:24:11 +00:00
// fill with background color the unpainted area
2007-02-03 23:09:40 +00:00
const QVector < QRect > & backRects = remainingArea . rects ( ) ;
2006-03-24 20:40:02 +00:00
int backRectsNumber = backRects . count ( ) ;
for ( int jr = 0 ; jr < backRectsNumber ; jr + + )
2005-03-24 19:10:41 +00:00
p - > fillRect ( backRects [ jr ] , backColor ) ;
2004-10-30 20:54:48 +00:00
}
void PageView : : updateItemSize ( PageViewItem * item , int colWidth , int rowHeight )
{
2006-09-21 08:45:36 +00:00
const Okular : : Page * okularPage = item - > page ( ) ;
double width = okularPage - > width ( ) ,
height = okularPage - > height ( ) ,
2004-10-30 20:54:48 +00:00
zoom = d - > zoomFactor ;
2008-05-19 00:37:14 +00:00
Okular : : NormalizedRect crop ( 0. , 0. , 1. , 1. ) ;
// Handle cropping
2008-05-27 14:00:59 +00:00
if ( Okular : : Settings : : trimMargins ( ) & & okularPage - > isBoundingBoxKnown ( )
2008-05-19 00:37:14 +00:00
& & ! okularPage - > boundingBox ( ) . isNull ( ) )
{
crop = okularPage - > boundingBox ( ) ;
2009-10-22 20:51:18 +00:00
// Rotate the bounding box
for ( int i = okularPage - > rotation ( ) ; i > 0 ; - - i )
2008-05-19 00:37:14 +00:00
{
Okular : : NormalizedRect rot = crop ;
crop . left = 1 - rot . bottom ;
crop . top = rot . left ;
crop . right = 1 - rot . top ;
crop . bottom = rot . right ;
}
// Expand the crop slightly beyond the bounding box
static const double cropExpandRatio = 0.04 ;
double cropExpand = cropExpandRatio * ( ( crop . right - crop . left ) + ( crop . bottom - crop . top ) ) / 2 ;
crop = Okular : : NormalizedRect (
crop . left - cropExpand ,
crop . top - cropExpand ,
crop . right + cropExpand ,
crop . bottom + cropExpand ) & Okular : : NormalizedRect ( 0 , 0 , 1 , 1 ) ;
// We currently generate a larger image and then crop it, so if the
// crop rect is very small the generated image is huge. Hence, we shouldn't
// let the crop rect become too small.
// Make sure we crop by at most 50% in either dimension:
static const double minCropRatio = 0.5 ;
if ( ( crop . right - crop . left ) < minCropRatio )
{
double newLeft = ( crop . left + crop . right ) / 2 - minCropRatio / 2 ;
crop . left = qMax ( 0.0 , qMin ( 1.0 - minCropRatio , newLeft ) ) ;
crop . right = crop . left + minCropRatio ;
}
if ( ( crop . bottom - crop . top ) < minCropRatio )
{
double newTop = ( crop . top + crop . bottom ) / 2 - minCropRatio / 2 ;
crop . top = qMax ( 0.0 , qMin ( 1.0 - minCropRatio , newTop ) ) ;
crop . bottom = crop . top + minCropRatio ;
}
width * = ( crop . right - crop . left ) ;
height * = ( crop . bottom - crop . top ) ;
# ifdef PAGEVIEW_DEBUG
kDebug ( ) < < " Cropped page " < < okularPage - > number ( ) < < " to " < < crop
< < " width " < < width < < " height " < < height < < " by bbox " < < okularPage - > boundingBox ( ) ;
# endif
}
2004-10-30 20:54:48 +00:00
if ( d - > zoomMode = = ZoomFixed )
{
width * = zoom ;
height * = zoom ;
2008-05-19 00:37:14 +00:00
item - > setWHZC ( ( int ) width , ( int ) height , d - > zoomFactor , crop ) ;
2004-10-30 20:54:48 +00:00
}
else if ( d - > zoomMode = = ZoomFitWidth )
{
2008-05-19 00:37:14 +00:00
height = ( height / width ) * colWidth ;
zoom = ( double ) colWidth / width ;
item - > setWHZC ( colWidth , ( int ) height , zoom , crop ) ;
d - > zoomFactor = zoom ;
2004-10-30 20:54:48 +00:00
}
else if ( d - > zoomMode = = ZoomFitPage )
{
double scaleW = ( double ) colWidth / ( double ) width ;
double scaleH = ( double ) rowHeight / ( double ) height ;
2006-03-29 17:16:46 +00:00
zoom = qMin ( scaleW , scaleH ) ;
2008-05-19 00:37:14 +00:00
item - > setWHZC ( ( int ) ( zoom * width ) , ( int ) ( zoom * height ) , zoom , crop ) ;
2005-07-15 18:20:57 +00:00
d - > zoomFactor = zoom ;
2004-10-30 20:54:48 +00:00
}
# ifndef NDEBUG
else
2007-07-31 10:19:48 +00:00
kDebug ( ) < < " calling updateItemSize with unrecognized d->zoomMode! " ;
2004-10-30 20:54:48 +00:00
# endif
}
PageViewItem * PageView : : pickItemOnPoint ( int x , int y )
{
PageViewItem * item = 0 ;
2007-02-03 23:09:40 +00:00
QLinkedList < PageViewItem * > : : const_iterator iIt = d - > visibleItems . constBegin ( ) , iEnd = d - > visibleItems . constEnd ( ) ;
2004-11-05 00:14:00 +00:00
for ( ; iIt ! = iEnd ; + + iIt )
2004-10-30 20:54:48 +00:00
{
2004-11-05 00:14:00 +00:00
PageViewItem * i = * iIt ;
2008-05-19 00:37:14 +00:00
const QRect & r = i - > croppedGeometry ( ) ;
2004-10-30 20:54:48 +00:00
if ( x < r . right ( ) & & x > r . left ( ) & & y < r . bottom ( ) )
{
if ( y > r . top ( ) )
item = i ;
break ;
}
}
return item ;
}
2006-09-26 22:22:01 +00:00
void PageView : : textSelectionClear ( )
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
{
2006-09-26 22:22:01 +00:00
// something to clear
if ( ! d - > pagesWithTextSelection . isEmpty ( ) )
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
{
2006-09-26 22:22:01 +00:00
QSet < int > : : ConstIterator it = d - > pagesWithTextSelection . constBegin ( ) , itEnd = d - > pagesWithTextSelection . constEnd ( ) ;
for ( ; it ! = itEnd ; + + it )
d - > document - > setPageTextSelection ( * it , 0 , QColor ( ) ) ;
d - > pagesWithTextSelection . clear ( ) ;
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
}
2006-09-26 22:22:01 +00:00
}
void PageView : : selectionStart ( const QPoint & pos , const QColor & color , bool /*aboveAll*/ )
{
selectionClear ( ) ;
d - > mouseSelecting = true ;
d - > mouseSelectionRect . setRect ( pos . x ( ) , pos . y ( ) , 1 , 1 ) ;
d - > mouseSelectionColor = color ;
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
// ensures page doesn't scroll
if ( d - > autoScrollTimer )
{
d - > scrollIncrement = 0 ;
d - > autoScrollTimer - > stop ( ) ;
}
}
2006-09-26 22:22:01 +00:00
2012-09-28 15:57:03 +00:00
void PageView : : scrollPosIntoView ( const QPoint & pos )
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
{
2006-11-22 21:32:21 +00:00
if ( pos . x ( ) < horizontalScrollBar ( ) - > value ( ) ) d - > dragScrollVector . setX ( pos . x ( ) - horizontalScrollBar ( ) - > value ( ) ) ;
else if ( horizontalScrollBar ( ) - > value ( ) + viewport ( ) - > width ( ) < pos . x ( ) ) d - > dragScrollVector . setX ( pos . x ( ) - horizontalScrollBar ( ) - > value ( ) - viewport ( ) - > width ( ) ) ;
else d - > dragScrollVector . setX ( 0 ) ;
if ( pos . y ( ) < verticalScrollBar ( ) - > value ( ) ) d - > dragScrollVector . setY ( pos . y ( ) - verticalScrollBar ( ) - > value ( ) ) ;
else if ( verticalScrollBar ( ) - > value ( ) + viewport ( ) - > height ( ) < pos . y ( ) ) d - > dragScrollVector . setY ( pos . y ( ) - verticalScrollBar ( ) - > value ( ) - viewport ( ) - > height ( ) ) ;
else d - > dragScrollVector . setY ( 0 ) ;
if ( d - > dragScrollVector ! = QPoint ( 0 , 0 ) )
{
if ( ! d - > dragScrollTimer . isActive ( ) ) d - > dragScrollTimer . start ( 100 ) ;
}
else d - > dragScrollTimer . stop ( ) ;
2012-09-28 15:57:03 +00:00
}
2006-11-22 21:32:21 +00:00
2012-09-28 15:57:03 +00:00
void PageView : : updateSelection ( const QPoint & pos )
{
if ( d - > mouseSelecting )
{
scrollPosIntoView ( pos ) ;
// update the selection rect
QRect updateRect = d - > mouseSelectionRect ;
d - > mouseSelectionRect . setBottomLeft ( pos ) ;
updateRect | = d - > mouseSelectionRect ;
updateRect . translate ( - contentAreaPosition ( ) ) ;
viewport ( ) - > update ( updateRect . adjusted ( - 1 , - 1 , 1 , 1 ) ) ;
}
else if ( d - > mouseTextSelecting )
{
scrollPosIntoView ( pos ) ;
int first = - 1 ;
const QList < Okular : : RegularAreaRect * > selections = textSelections ( pos , d - > mouseSelectPos , first ) ;
QSet < int > pagesWithSelectionSet ;
for ( int i = 0 ; i < selections . count ( ) ; + + i )
pagesWithSelectionSet . insert ( i + first ) ;
const QSet < int > noMoreSelectedPages = d - > pagesWithTextSelection - pagesWithSelectionSet ;
// clear the selection from pages not selected anymore
foreach ( int p , noMoreSelectedPages )
{
d - > document - > setPageTextSelection ( p , 0 , QColor ( ) ) ;
}
// set the new selection for the selected pages
foreach ( int p , pagesWithSelectionSet )
{
d - > document - > setPageTextSelection ( p , selections [ p - first ] , palette ( ) . color ( QPalette : : Active , QPalette : : Highlight ) ) ;
}
d - > pagesWithTextSelection = pagesWithSelectionSet ;
}
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
}
2007-09-03 19:35:55 +00:00
static Okular : : NormalizedPoint rotateInNormRect ( const QPoint & rotated , const QRect & rect , Okular : : Rotation rotation )
{
Okular : : NormalizedPoint ret ;
switch ( rotation )
{
case Okular : : Rotation0 :
ret = Okular : : NormalizedPoint ( rotated . x ( ) , rotated . y ( ) , rect . width ( ) , rect . height ( ) ) ;
break ;
case Okular : : Rotation90 :
ret = Okular : : NormalizedPoint ( rotated . y ( ) , rect . width ( ) - rotated . x ( ) , rect . height ( ) , rect . width ( ) ) ;
break ;
case Okular : : Rotation180 :
ret = Okular : : NormalizedPoint ( rect . width ( ) - rotated . x ( ) , rect . height ( ) - rotated . y ( ) , rect . width ( ) , rect . height ( ) ) ;
break ;
case Okular : : Rotation270 :
ret = Okular : : NormalizedPoint ( rect . height ( ) - rotated . y ( ) , rotated . x ( ) , rect . height ( ) , rect . width ( ) ) ;
break ;
}
return ret ;
}
2006-10-03 17:13:42 +00:00
Okular : : RegularAreaRect * PageView : : textSelectionForItem ( PageViewItem * item , const QPoint & startPoint , const QPoint & endPoint )
2004-09-26 23:39:39 +00:00
{
2008-05-19 00:37:14 +00:00
const QRect & geometry = item - > uncroppedGeometry ( ) ;
2006-09-26 22:22:01 +00:00
Okular : : NormalizedPoint startCursor ( 0.0 , 0.0 ) ;
if ( ! startPoint . isNull ( ) )
2004-10-29 21:52:06 +00:00
{
2007-09-03 19:35:55 +00:00
startCursor = rotateInNormRect ( startPoint , geometry , item - > page ( ) - > rotation ( ) ) ;
2004-10-29 21:52:06 +00:00
}
2006-09-26 22:22:01 +00:00
Okular : : NormalizedPoint endCursor ( 1.0 , 1.0 ) ;
if ( ! endPoint . isNull ( ) )
{
2007-09-03 19:35:55 +00:00
endCursor = rotateInNormRect ( endPoint , geometry , item - > page ( ) - > rotation ( ) ) ;
2006-09-26 22:22:01 +00:00
}
Okular : : TextSelection mouseTextSelectionInfo ( startCursor , endCursor ) ;
2004-09-26 23:39:39 +00:00
2006-09-26 22:22:01 +00:00
const Okular : : Page * okularPage = item - > page ( ) ;
2006-11-23 16:09:26 +00:00
if ( ! okularPage - > hasTextPage ( ) )
2006-09-26 22:22:01 +00:00
d - > document - > requestTextPage ( okularPage - > number ( ) ) ;
2006-11-23 17:11:04 +00:00
Okular : : RegularAreaRect * selectionArea = okularPage - > textArea ( & mouseTextSelectionInfo ) ;
2006-12-23 16:36:08 +00:00
# ifdef PAGEVIEW_DEBUG
2007-07-31 10:19:48 +00:00
kDebug ( ) . nospace ( ) < < " text areas ( " < < okularPage - > number ( ) < < " ): " < < ( selectionArea ? QString : : number ( selectionArea - > count ( ) ) : " (none) " ) ;
2006-12-23 16:36:08 +00:00
# endif
2006-10-03 17:13:42 +00:00
return selectionArea ;
2004-11-03 17:35:48 +00:00
}
2011-10-31 15:33:03 +00:00
void PageView : : selectionClear ( const ClearMode mode )
2004-11-03 17:35:48 +00:00
{
2006-06-11 23:38:12 +00:00
QRect updatedRect = d - > mouseSelectionRect . normalized ( ) . adjusted ( 0 , 0 , 1 , 1 ) ;
2005-06-24 16:41:55 +00:00
d - > mouseSelecting = false ;
2006-06-11 23:38:12 +00:00
d - > mouseSelectionRect . setCoords ( 0 , 0 , 0 , 0 ) ;
2011-10-12 13:50:56 +00:00
d - > tableSelectionCols . clear ( ) ;
d - > tableSelectionRows . clear ( ) ;
2011-10-31 15:33:03 +00:00
d - > tableDividersGuessed = false ;
2011-10-12 14:04:23 +00:00
foreach ( const TableSelectionPart & tsp , d - > tableSelectionParts ) {
2011-10-12 13:50:56 +00:00
QRect selectionPartRect = tsp . rectInItem . geometry ( tsp . item - > uncroppedWidth ( ) , tsp . item - > uncroppedHeight ( ) ) ;
selectionPartRect . translate ( tsp . item - > uncroppedGeometry ( ) . topLeft ( ) ) ;
// should check whether this is on-screen here?
updatedRect = updatedRect . united ( selectionPartRect ) ;
}
2011-10-31 15:33:03 +00:00
if ( mode ! = ClearOnlyDividers ) {
d - > tableSelectionParts . clear ( ) ;
}
2011-10-12 13:50:56 +00:00
d - > tableSelectionParts . clear ( ) ;
updatedRect . translate ( - contentAreaPosition ( ) ) ;
2009-06-29 20:55:50 +00:00
viewport ( ) - > update ( updatedRect ) ;
2004-11-03 17:35:48 +00:00
}
void PageView : : updateZoom ( ZoomMode newZoomMode )
{
2004-10-29 21:52:06 +00:00
if ( newZoomMode = = ZoomFixed )
{
if ( d - > aZoom - > currentItem ( ) = = 0 )
newZoomMode = ZoomFitWidth ;
else if ( d - > aZoom - > currentItem ( ) = = 1 )
newZoomMode = ZoomFitPage ;
}
2004-09-26 23:39:39 +00:00
2004-10-29 21:52:06 +00:00
float newFactor = d - > zoomFactor ;
2007-01-09 11:02:04 +00:00
QAction * checkedZoomAction = 0 ;
2004-10-29 21:52:06 +00:00
switch ( newZoomMode )
{
2004-11-03 17:35:48 +00:00
case ZoomFixed : { //ZoomFixed case
2004-10-29 21:52:06 +00:00
QString z = d - > aZoom - > currentText ( ) ;
2006-07-29 12:52:35 +00:00
// kdelibs4 sometimes adds accelerators to actions' text directly :(
z . remove ( ' & ' ) ;
z . remove ( ' % ' ) ;
newFactor = KGlobal : : locale ( ) - > readNumber ( z ) / 100.0 ;
2004-10-29 21:52:06 +00:00
} break ;
case ZoomIn :
2004-11-05 01:11:50 +00:00
newFactor + = ( newFactor > 0.99 ) ? ( newFactor > 1.99 ? 0.5 : 0.2 ) : 0.1 ;
2004-10-29 21:52:06 +00:00
newZoomMode = ZoomFixed ;
break ;
case ZoomOut :
2007-09-03 21:29:09 +00:00
newFactor - = ( newFactor > 1.01 ) ? ( newFactor > 2.01 ? 0.5 : 0.2 ) : 0.1 ;
2004-10-29 21:52:06 +00:00
newZoomMode = ZoomFixed ;
break ;
case ZoomFitWidth :
checkedZoomAction = d - > aZoomFitWidth ;
break ;
case ZoomFitPage :
checkedZoomAction = d - > aZoomFitPage ;
break ;
case ZoomRefreshCurrent :
newZoomMode = ZoomFixed ;
d - > zoomFactor = - 1 ;
break ;
}
2012-11-15 22:18:59 +00:00
const float upperZoomLimit = d - > document - > supportsTiles ( ) ? 16.0 : 4.0 ;
if ( newFactor > upperZoomLimit )
newFactor = upperZoomLimit ;
2004-10-30 23:59:09 +00:00
if ( newFactor < 0.1 )
newFactor = 0.1 ;
2004-09-26 23:39:39 +00:00
2004-10-29 21:52:06 +00:00
if ( newZoomMode ! = d - > zoomMode | | ( newZoomMode = = ZoomFixed & & newFactor ! = d - > zoomFactor ) )
{
2004-10-30 23:59:09 +00:00
// rebuild layout and update the whole viewport
2004-10-29 21:52:06 +00:00
d - > zoomMode = newZoomMode ;
d - > zoomFactor = newFactor ;
2005-01-09 23:37:07 +00:00
// be sure to block updates to document's viewport
bool prevState = d - > blockViewport ;
d - > blockViewport = true ;
2004-10-29 21:52:06 +00:00
slotRelayoutPages ( ) ;
2005-01-09 23:37:07 +00:00
d - > blockViewport = prevState ;
2004-10-30 23:59:09 +00:00
// request pixmaps
slotRequestVisiblePixmaps ( ) ;
// update zoom text
2004-10-29 21:52:06 +00:00
updateZoomText ( ) ;
// update actions checked state
2007-07-14 12:31:26 +00:00
if ( d - > aZoomFitWidth )
{
2010-07-26 22:22:59 +00:00
d - > aZoomFitWidth - > setChecked ( checkedZoomAction = = d - > aZoomFitWidth ) ;
d - > aZoomFitPage - > setChecked ( checkedZoomAction = = d - > aZoomFitPage ) ;
2007-07-14 12:31:26 +00:00
}
2004-10-29 21:52:06 +00:00
}
2010-07-26 22:22:59 +00:00
else if ( newZoomMode = = ZoomFixed & & newFactor = = d - > zoomFactor )
updateZoomText ( ) ;
2007-01-28 16:29:48 +00:00
2012-11-15 22:18:59 +00:00
d - > aZoomIn - > setEnabled ( d - > zoomFactor < upperZoomLimit - 0.001 ) ;
2012-06-16 17:57:30 +00:00
d - > aZoomOut - > setEnabled ( d - > zoomFactor > 0.101 ) ;
2004-09-26 23:39:39 +00:00
}
2004-10-29 21:52:06 +00:00
void PageView : : updateZoomText ( )
2004-09-26 23:39:39 +00:00
{
2004-10-29 21:52:06 +00:00
// use current page zoom as zoomFactor if in ZoomFit/* mode
2004-11-05 00:14:00 +00:00
if ( d - > zoomMode ! = ZoomFixed & & d - > items . count ( ) > 0 )
2006-03-29 17:16:46 +00:00
d - > zoomFactor = d - > items [ qMax ( 0 , ( int ) d - > document - > currentPage ( ) ) ] - > zoomFactor ( ) ;
2004-10-29 21:52:06 +00:00
float newFactor = d - > zoomFactor ;
2006-04-13 11:24:57 +00:00
d - > aZoom - > removeAllActions ( ) ;
2004-09-26 23:39:39 +00:00
2004-10-29 21:52:06 +00:00
// add items that describe fit actions
QStringList translated ;
2012-09-08 18:33:54 +00:00
translated < < i18n ( " Fit Width " ) < < i18n ( " Fit Page " ) ;
2004-10-20 16:41:13 +00:00
2004-10-29 21:52:06 +00:00
// add percent items
QString double_oh ( " 00 " ) ;
2012-06-16 17:57:30 +00:00
const float zoomValue [ 13 ] = { 0.12 , 0.25 , 0.33 , 0.50 , 0.66 , 0.75 , 1.00 , 1.25 , 1.50 , 2.00 , 4.00 , 8.00 , 16.00 } ;
2012-09-08 18:33:54 +00:00
int idx = 0 , selIdx = 2 ;
2004-10-29 21:52:06 +00:00
bool inserted = false ; //use: "d->zoomMode != ZoomFixed" to hide Fit/* zoom ratio
2012-12-01 00:34:54 +00:00
int zoomValueCount = 11 ;
2012-11-15 22:18:59 +00:00
if ( d - > document - > supportsTiles ( ) )
zoomValueCount = 13 ;
while ( idx < zoomValueCount | | ! inserted )
2004-09-28 13:53:47 +00:00
{
2012-11-15 22:18:59 +00:00
float value = idx < zoomValueCount ? zoomValue [ idx ] : newFactor ;
2004-10-29 21:52:06 +00:00
if ( ! inserted & & newFactor < ( value - 0.0001 ) )
value = newFactor ;
else
idx + + ;
if ( value > ( newFactor - 0.0001 ) & & value < ( newFactor + 0.0001 ) )
inserted = true ;
if ( ! inserted )
selIdx + + ;
QString localValue ( KGlobal : : locale ( ) - > formatNumber ( value * 100.0 , 2 ) ) ;
localValue . remove ( KGlobal : : locale ( ) - > decimalSymbol ( ) + double_oh ) ;
2006-11-03 22:09:16 +00:00
// remove a trailing zero in numbers like 66.70
if ( localValue . right ( 1 ) = = QLatin1String ( " 0 " ) & & localValue . indexOf ( KGlobal : : locale ( ) - > decimalSymbol ( ) ) > - 1 )
localValue . chop ( 1 ) ;
2004-10-29 21:52:06 +00:00
translated < < QString ( " %1% " ) . arg ( localValue ) ;
2004-09-28 13:53:47 +00:00
}
2004-10-29 21:52:06 +00:00
d - > aZoom - > setItems ( translated ) ;
// select current item in list
if ( d - > zoomMode = = ZoomFitWidth )
selIdx = 0 ;
else if ( d - > zoomMode = = ZoomFitPage )
selIdx = 1 ;
2011-11-24 21:28:07 +00:00
// we have to temporarily enable the actions as otherwise we can't set a new current item
d - > aZoom - > setEnabled ( true ) ;
d - > aZoom - > selectableActionGroup ( ) - > setEnabled ( true ) ;
2004-10-29 21:52:06 +00:00
d - > aZoom - > setCurrentItem ( selIdx ) ;
2011-11-24 21:28:07 +00:00
d - > aZoom - > setEnabled ( d - > items . size ( ) > 0 ) ;
d - > aZoom - > selectableActionGroup ( ) - > setEnabled ( d - > items . size ( ) > 0 ) ;
2004-09-26 23:39:39 +00:00
}
2004-12-26 21:20:17 +00:00
void PageView : : updateCursor ( const QPoint & p )
{
// detect the underlaying page (if present)
PageViewItem * pageItem = pickItemOnPoint ( p . x ( ) , p . y ( ) ) ;
2007-09-07 19:57:46 +00:00
if ( pageItem )
2004-12-26 21:20:17 +00:00
{
2008-05-19 00:37:14 +00:00
double nX = pageItem - > absToPageX ( p . x ( ) ) ;
double nY = pageItem - > absToPageY ( p . y ( ) ) ;
2004-12-26 21:20:17 +00:00
2005-02-09 17:45:16 +00:00
// if over a ObjectRect (of type Link) change cursor to hand
2012-03-09 17:43:40 +00:00
if ( Okular : : Settings : : mouseMode ( ) = = Okular : : Settings : : EnumMouseMode : : TextSelect )
2006-09-26 22:22:01 +00:00
setCursor ( Qt : : IBeamCursor ) ;
2012-03-09 17:43:40 +00:00
else if ( Okular : : Settings : : mouseMode ( ) = = Okular : : Settings : : EnumMouseMode : : RectSelect )
2011-08-05 21:47:35 +00:00
setCursor ( Qt : : CrossCursor ) ;
2007-07-17 20:58:38 +00:00
else if ( d - > mouseAnn )
setCursor ( Qt : : ClosedHandCursor ) ;
2005-01-02 11:50:38 +00:00
else
2006-09-26 22:22:01 +00:00
{
2008-05-19 00:37:14 +00:00
const Okular : : ObjectRect * linkobj = pageItem - > page ( ) - > objectRect ( Okular : : ObjectRect : : Action , nX , nY , pageItem - > uncroppedWidth ( ) , pageItem - > uncroppedHeight ( ) ) ;
const Okular : : ObjectRect * annotobj = pageItem - > page ( ) - > objectRect ( Okular : : ObjectRect : : OAnnotation , nX , nY , pageItem - > uncroppedWidth ( ) , pageItem - > uncroppedHeight ( ) ) ;
2006-10-16 19:19:42 +00:00
if ( linkobj & & ! annotobj )
{
d - > mouseOnRect = true ;
2006-09-26 22:22:01 +00:00
setCursor ( Qt : : PointingHandCursor ) ;
2006-10-16 19:19:42 +00:00
}
2006-09-26 22:22:01 +00:00
else
2006-11-11 13:45:44 +00:00
{
d - > mouseOnRect = false ;
2012-03-12 16:05:43 +00:00
if ( annotobj )
2007-07-17 20:58:38 +00:00
{
2012-09-27 12:15:58 +00:00
const Okular : : Annotation * annotation = static_cast < const Okular : : AnnotationObjectRect * > ( annotobj ) - > annotation ( ) ;
2012-03-12 16:05:43 +00:00
if ( ( QApplication : : keyboardModifiers ( ) & Qt : : ControlModifier )
2012-09-27 12:15:58 +00:00
& & annotation - > canBeMoved ( ) )
2012-03-12 16:05:43 +00:00
{
setCursor ( Qt : : OpenHandCursor ) ;
}
2012-09-27 12:15:58 +00:00
else if ( annotation - > subType ( ) = = Okular : : Annotation : : AMovie )
2012-03-12 16:05:43 +00:00
{
d - > mouseOnRect = true ;
setCursor ( Qt : : PointingHandCursor ) ;
}
2012-09-27 12:15:58 +00:00
else if ( annotation - > subType ( ) = = Okular : : Annotation : : AScreen )
{
if ( GuiUtils : : renditionMovieFromScreenAnnotation ( static_cast < const Okular : : ScreenAnnotation * > ( annotation ) ) ! = 0 )
{
d - > mouseOnRect = true ;
setCursor ( Qt : : PointingHandCursor ) ;
}
}
2007-07-17 20:58:38 +00:00
}
2012-03-09 17:43:40 +00:00
else if ( Okular : : Settings : : mouseMode ( ) = = Okular : : Settings : : EnumMouseMode : : Browse )
2011-08-05 21:47:35 +00:00
{
setCursor ( Qt : : OpenHandCursor ) ;
}
2007-07-17 20:58:38 +00:00
else
{
setCursor ( Qt : : ArrowCursor ) ;
}
2006-11-11 13:45:44 +00:00
}
2006-09-26 22:22:01 +00:00
}
2004-12-26 21:20:17 +00:00
}
else
{
// if there's no page over the cursor and we were showing the pointingHandCursor
// go back to the normal one
2005-01-02 11:50:38 +00:00
d - > mouseOnRect = false ;
2006-06-03 13:01:15 +00:00
setCursor ( Qt : : ArrowCursor ) ;
2004-12-26 21:20:17 +00:00
}
}
2006-10-16 19:47:20 +00:00
int PageView : : viewColumns ( ) const
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
{
2010-01-10 01:19:16 +00:00
int vm = Okular : : Settings : : viewMode ( ) ;
if ( vm = = Okular : : Settings : : EnumViewMode : : Single ) return 1 ;
else if ( vm = = Okular : : Settings : : EnumViewMode : : Facing | |
vm = = Okular : : Settings : : EnumViewMode : : FacingFirstCentered ) return 2 ;
else return Okular : : Settings : : viewColumns ( ) ;
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
}
2006-10-07 14:40:32 +00:00
void PageView : : center ( int cx , int cy )
{
2012-09-03 00:55:16 +00:00
scrollTo ( cx - viewport ( ) - > width ( ) / 2 , cy - viewport ( ) - > height ( ) / 2 ) ;
}
void PageView : : scrollTo ( int x , int y )
{
bool prevState = d - > blockPixmapsRequest ;
2012-11-12 02:09:12 +00:00
2012-09-03 00:55:16 +00:00
int newValue = - 1 ;
2012-11-12 02:09:12 +00:00
if ( x ! = horizontalScrollBar ( ) - > value ( ) | | y ! = verticalScrollBar ( ) - > value ( ) )
newValue = 1 ; // Pretend this call is the result of a scrollbar event
2012-09-03 00:55:16 +00:00
d - > blockPixmapsRequest = true ;
horizontalScrollBar ( ) - > setValue ( x ) ;
verticalScrollBar ( ) - > setValue ( y ) ;
d - > blockPixmapsRequest = prevState ;
slotRequestVisiblePixmaps ( newValue ) ;
2006-10-07 14:40:32 +00:00
}
2007-02-25 00:07:59 +00:00
void PageView : : toggleFormWidgets ( bool on )
{
2007-02-25 14:59:26 +00:00
bool somehadfocus = false ;
2008-11-11 18:48:40 +00:00
QVector < PageViewItem * > : : const_iterator dIt = d - > items . constBegin ( ) , dEnd = d - > items . constEnd ( ) ;
2007-02-25 00:07:59 +00:00
for ( ; dIt ! = dEnd ; + + dIt )
{
2007-10-18 20:35:34 +00:00
bool hadfocus = ( * dIt ) - > setFormWidgetsVisible ( on ) ;
somehadfocus = somehadfocus | | hadfocus ;
2007-02-25 00:07:59 +00:00
}
2007-02-25 14:59:26 +00:00
if ( somehadfocus )
setFocus ( ) ;
2007-02-25 00:07:59 +00:00
d - > m_formsVisible = on ;
2007-06-05 20:49:00 +00:00
if ( d - > aToggleForms ) // it may not exist if we are on dummy mode
2007-02-25 00:07:59 +00:00
{
2007-06-05 20:49:00 +00:00
if ( d - > m_formsVisible )
{
d - > aToggleForms - > setText ( i18n ( " Hide Forms " ) ) ;
}
else
{
d - > aToggleForms - > setText ( i18n ( " Show Forms " ) ) ;
}
2007-02-25 00:07:59 +00:00
}
}
2009-06-29 20:55:50 +00:00
void PageView : : resizeContentArea ( const QSize & newSize )
{
const QSize vs = viewport ( ) - > size ( ) ;
horizontalScrollBar ( ) - > setRange ( 0 , newSize . width ( ) - vs . width ( ) ) ;
verticalScrollBar ( ) - > setRange ( 0 , newSize . height ( ) - vs . height ( ) ) ;
2011-09-07 22:43:30 +00:00
updatePageStep ( ) ;
}
void PageView : : updatePageStep ( ) {
const QSize vs = viewport ( ) - > size ( ) ;
horizontalScrollBar ( ) - > setPageStep ( vs . width ( ) ) ;
2011-09-07 22:46:03 +00:00
verticalScrollBar ( ) - > setPageStep ( vs . height ( ) * ( 100 - Okular : : Settings : : scrollOverlap ( ) ) / 100 ) ;
2009-06-29 20:55:50 +00:00
}
2010-09-11 13:34:22 +00:00
void PageView : : addWebShortcutsMenu ( KMenu * menu , const QString & text )
{
2010-11-21 17:37:07 +00:00
# if KDE_IS_VERSION(4,5,70)
2010-09-11 13:34:22 +00:00
if ( text . isEmpty ( ) )
{
return ;
}
QString searchText = text ;
searchText = searchText . replace ( ' \n ' , ' ' ) . replace ( ' \r ' , ' ' ) . simplified ( ) ;
if ( searchText . isEmpty ( ) )
{
return ;
}
KUriFilterData filterData ( searchText ) ;
filterData . setSearchFilteringOptions ( KUriFilterData : : RetrievePreferredSearchProvidersOnly ) ;
if ( KUriFilter : : self ( ) - > filterSearchUri ( filterData , KUriFilter : : NormalTextFilter ) )
{
const QStringList searchProviders = filterData . preferredSearchProviders ( ) ;
if ( ! searchProviders . isEmpty ( ) )
{
KMenu * webShortcutsMenu = new KMenu ( menu ) ;
webShortcutsMenu - > setIcon ( KIcon ( " preferences-web-browser-shortcuts " ) ) ;
const QString squeezedText = KStringHandler : : rsqueeze ( searchText , 21 ) ;
webShortcutsMenu - > setTitle ( i18n ( " Search for '%1' with " , squeezedText ) ) ;
KAction * action = 0 ;
foreach ( const QString & searchProvider , searchProviders )
{
action = new KAction ( searchProvider , webShortcutsMenu ) ;
action - > setIcon ( KIcon ( filterData . iconNameForPreferredSearchProvider ( searchProvider ) ) ) ;
action - > setData ( filterData . queryForPreferredSearchProvider ( searchProvider ) ) ;
2011-07-31 19:22:04 +00:00
connect ( action , SIGNAL ( triggered ( ) ) , this , SLOT ( slotHandleWebShortcutAction ( ) ) ) ;
2010-09-11 13:34:22 +00:00
webShortcutsMenu - > addAction ( action ) ;
}
webShortcutsMenu - > addSeparator ( ) ;
action = new KAction ( i18n ( " Configure Web Shortcuts... " ) , webShortcutsMenu ) ;
action - > setIcon ( KIcon ( " configure " ) ) ;
2011-07-31 19:22:04 +00:00
connect ( action , SIGNAL ( triggered ( ) ) , this , SLOT ( slotConfigureWebShortcuts ( ) ) ) ;
2010-09-11 13:34:22 +00:00
webShortcutsMenu - > addAction ( action ) ;
menu - > addMenu ( webShortcutsMenu ) ;
}
}
2010-11-21 17:37:07 +00:00
# endif
2010-09-11 13:34:22 +00:00
}
2004-10-29 21:52:06 +00:00
//BEGIN private SLOTS
2004-09-30 18:04:09 +00:00
void PageView : : slotRelayoutPages ( )
2007-05-17 20:46:16 +00:00
// called by: notifySetup, viewportResizeEvent, slotViewMode, slotContinuousToggled, updateZoom
2004-09-27 21:36:25 +00:00
{
// set an empty container if we have no pages
2011-12-25 23:47:31 +00:00
const int pageCount = d - > items . count ( ) ;
2004-09-27 21:36:25 +00:00
if ( pageCount < 1 )
{
return ;
}
2005-02-01 18:24:16 +00:00
// if viewport was auto-moving, stop it
if ( d - > viewportMoveActive )
{
2008-08-10 20:26:33 +00:00
center ( d - > viewportMoveDest . x ( ) , d - > viewportMoveDest . y ( ) ) ;
2005-02-01 18:24:16 +00:00
d - > viewportMoveActive = false ;
d - > viewportMoveTimer - > stop ( ) ;
verticalScrollBar ( ) - > setEnabled ( true ) ;
horizontalScrollBar ( ) - > setEnabled ( true ) ;
}
2004-11-05 00:14:00 +00:00
// common iterator used in this method and viewport parameters
2008-11-11 18:48:40 +00:00
QVector < PageViewItem * > : : const_iterator iIt , iEnd = d - > items . constEnd ( ) ;
2006-10-07 14:40:32 +00:00
int viewportWidth = viewport ( ) - > width ( ) ,
viewportHeight = viewport ( ) - > height ( ) ,
2004-09-30 18:16:12 +00:00
fullWidth = 0 ,
fullHeight = 0 ;
2006-10-07 14:40:32 +00:00
QRect viewportRect ( horizontalScrollBar ( ) - > value ( ) , verticalScrollBar ( ) - > value ( ) , viewportWidth , viewportHeight ) ;
2004-11-05 00:14:00 +00:00
2005-04-14 11:33:28 +00:00
// handle the 'center first page in row' stuff
2012-08-29 23:03:16 +00:00
const bool facing = Okular : : Settings : : viewMode ( ) = = Okular : : Settings : : EnumViewMode : : Facing & & pageCount > 1 ;
const bool facingCentered = Okular : : Settings : : viewMode ( ) = = Okular : : Settings : : EnumViewMode : : FacingFirstCentered | |
( Okular : : Settings : : viewMode ( ) = = Okular : : Settings : : EnumViewMode : : Facing & & pageCount = = 1 ) ;
2011-12-21 00:44:33 +00:00
const bool overrideCentering = facingCentered & & pageCount < 3 ;
const bool centerFirstPage = facingCentered & & ! overrideCentering ;
const bool facingPages = facing | | centerFirstPage ;
const bool centerLastPage = centerFirstPage & & pageCount % 2 = = 0 ;
2007-12-31 17:35:22 +00:00
const bool continuousView = Okular : : Settings : : viewContinuous ( ) ;
2011-12-25 23:47:31 +00:00
const int nCols = overrideCentering ? 1 : viewColumns ( ) ;
2005-04-14 11:33:28 +00:00
2005-03-05 15:59:15 +00:00
// set all items geometry and resize contents. handle 'continuous' and 'single' modes separately
2007-12-31 17:35:22 +00:00
PageViewItem * currentItem = d - > items [ qMax ( 0 , ( int ) d - > document - > currentPage ( ) ) ] ;
2004-09-27 21:36:25 +00:00
// Here we find out column's width and row's height to compute a table
// so we can place widgets 'centered in virtual cells'.
2011-12-25 23:47:31 +00:00
const int nRows = ( int ) ceil ( ( float ) ( centerFirstPage ? ( pageCount + nCols - 1 ) : pageCount ) / ( float ) nCols ) ;
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
int * colWidth = new int [ nCols ] ,
2004-09-27 21:36:25 +00:00
* rowHeight = new int [ nRows ] ,
cIdx = 0 ,
rIdx = 0 ;
for ( int i = 0 ; i < nCols ; i + + )
colWidth [ i ] = viewportWidth / nCols ;
for ( int i = 0 ; i < nRows ; i + + )
rowHeight [ i ] = 0 ;
2005-04-14 11:33:28 +00:00
// handle the 'centering on first row' stuff
if ( centerFirstPage )
2007-12-31 17:35:22 +00:00
cIdx + = nCols - 1 ;
2004-09-27 21:36:25 +00:00
// 1) find the maximum columns width and rows height for a grid in
// which each page must well-fit inside a cell
2008-11-11 18:48:40 +00:00
for ( iIt = d - > items . constBegin ( ) ; iIt ! = iEnd ; + + iIt )
2004-09-26 23:39:39 +00:00
{
2004-11-05 00:14:00 +00:00
PageViewItem * item = * iIt ;
2004-10-30 20:54:48 +00:00
// update internal page size (leaving a little margin in case of Fit* modes)
2005-04-14 11:33:28 +00:00
updateItemSize ( item , colWidth [ cIdx ] - 6 , viewportHeight - 12 ) ;
2004-09-27 21:36:25 +00:00
// find row's maximum height and column's max width
2008-05-19 00:37:14 +00:00
if ( item - > croppedWidth ( ) + 6 > colWidth [ cIdx ] )
colWidth [ cIdx ] = item - > croppedWidth ( ) + 6 ;
if ( item - > croppedHeight ( ) + 12 > rowHeight [ rIdx ] )
rowHeight [ rIdx ] = item - > croppedHeight ( ) + 12 ;
2005-04-14 11:33:28 +00:00
// handle the 'centering on first row' stuff
2004-09-27 21:36:25 +00:00
// update col/row indices
if ( + + cIdx = = nCols )
2004-09-26 23:39:39 +00:00
{
2004-09-27 21:36:25 +00:00
cIdx = 0 ;
rIdx + + ;
2004-09-26 23:39:39 +00:00
}
}
2004-09-27 21:36:25 +00:00
2007-12-31 17:35:22 +00:00
const int pageRowIdx = ( ( centerFirstPage ? nCols - 1 : 0 ) + currentItem - > pageNumber ( ) ) / nCols ;
2005-04-14 11:33:28 +00:00
// 2) compute full size
for ( int i = 0 ; i < nCols ; i + + )
fullWidth + = colWidth [ i ] ;
2007-12-31 17:35:22 +00:00
if ( continuousView )
{
for ( int i = 0 ; i < nRows ; i + + )
fullHeight + = rowHeight [ i ] ;
}
else
fullHeight = rowHeight [ pageRowIdx ] ;
2005-04-14 11:33:28 +00:00
// 3) arrange widgets inside cells (and refine fullHeight if needed)
2004-09-27 21:36:25 +00:00
int insertX = 0 ,
2005-04-14 11:33:28 +00:00
insertY = fullHeight < viewportHeight ? ( viewportHeight - fullHeight ) / 2 : 0 ;
2007-12-31 17:35:22 +00:00
const int origInsertY = insertY ;
2004-10-30 20:54:48 +00:00
cIdx = 0 ;
rIdx = 0 ;
2007-12-31 17:35:22 +00:00
if ( centerFirstPage )
{
cIdx + = nCols - 1 ;
for ( int i = 0 ; i < cIdx ; + + i )
insertX + = colWidth [ i ] ;
}
2008-11-11 18:48:40 +00:00
for ( iIt = d - > items . constBegin ( ) ; iIt ! = iEnd ; + + iIt )
2004-09-27 21:36:25 +00:00
{
2004-11-05 00:14:00 +00:00
PageViewItem * item = * iIt ;
2004-10-30 20:54:48 +00:00
int cWidth = colWidth [ cIdx ] ,
2004-09-27 21:36:25 +00:00
rHeight = rowHeight [ rIdx ] ;
2007-12-31 17:35:22 +00:00
if ( continuousView | | rIdx = = pageRowIdx )
2005-04-14 11:33:28 +00:00
{
2007-12-31 17:35:22 +00:00
const bool reallyDoCenterFirst = item - > pageNumber ( ) = = 0 & & centerFirstPage ;
2011-12-21 00:44:33 +00:00
const bool reallyDoCenterLast = item - > pageNumber ( ) = = pageCount - 1 & & centerLastPage ;
2011-12-04 11:44:51 +00:00
int actualX = 0 ;
if ( reallyDoCenterFirst | | reallyDoCenterLast )
{
// page is centered across entire viewport
actualX = ( fullWidth - item - > croppedWidth ( ) ) / 2 ;
}
else if ( facingPages )
{
// page edges 'touch' the center of the viewport
actualX = ( ( centerFirstPage & & item - > pageNumber ( ) % 2 = = 1 ) | |
( ! centerFirstPage & & item - > pageNumber ( ) % 2 = = 0 ) ) ?
( fullWidth / 2 ) - item - > croppedWidth ( ) - 1 : ( fullWidth / 2 ) + 1 ;
}
else
{
// page is centered within its virtual column
actualX = insertX + ( cWidth - item - > croppedWidth ( ) ) / 2 ;
}
item - > moveTo ( actualX ,
2008-05-19 00:37:14 +00:00
( continuousView ? insertY : origInsertY ) + ( rHeight - item - > croppedHeight ( ) ) / 2 ) ;
2007-12-31 17:35:22 +00:00
item - > setVisible ( true ) ;
2005-04-14 11:33:28 +00:00
}
else
{
2007-12-31 17:35:22 +00:00
item - > moveTo ( 0 , 0 ) ;
item - > setVisible ( false ) ;
2005-04-14 11:33:28 +00:00
}
2007-12-31 22:22:38 +00:00
item - > setFormWidgetsVisible ( d - > m_formsVisible ) ;
2004-09-27 21:36:25 +00:00
// advance col/row index
insertX + = cWidth ;
if ( + + cIdx = = nCols )
{
cIdx = 0 ;
rIdx + + ;
insertX = 0 ;
2005-04-14 11:33:28 +00:00
insertY + = rHeight ;
2004-09-27 21:36:25 +00:00
}
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
# ifdef PAGEVIEW_DEBUG
2008-05-19 00:37:14 +00:00
kWarning ( ) < < " updating size for pageno " < < item - > pageNumber ( ) < < " cropped " < < item - > croppedGeometry ( ) < < " uncropped " < < item - > uncroppedGeometry ( ) ;
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
# endif
2004-09-27 21:36:25 +00:00
}
delete [ ] colWidth ;
delete [ ] rowHeight ;
2004-09-30 18:16:12 +00:00
2004-11-05 00:14:00 +00:00
// 3) reset dirty state
d - > dirtyLayout = false ;
// 4) update scrollview's contents size and recenter view
2006-03-30 15:27:27 +00:00
bool wasUpdatesEnabled = viewport ( ) - > updatesEnabled ( ) ;
2009-06-29 20:55:50 +00:00
if ( fullWidth ! = contentAreaWidth ( ) | | fullHeight ! = contentAreaHeight ( ) )
2004-09-30 18:16:12 +00:00
{
2009-11-20 20:52:51 +00:00
const Okular : : DocumentViewport vp = d - > document - > viewport ( ) ;
2005-01-09 23:37:07 +00:00
// disable updates and resize the viewportContents
2005-01-10 13:43:44 +00:00
if ( wasUpdatesEnabled )
viewport ( ) - > setUpdatesEnabled ( false ) ;
2009-06-29 20:55:50 +00:00
resizeContentArea ( QSize ( fullWidth , fullHeight ) ) ;
2005-01-10 13:43:44 +00:00
// restore previous viewport if defined and updates enabled
if ( wasUpdatesEnabled )
2004-11-05 00:14:00 +00:00
{
2005-01-10 13:43:44 +00:00
if ( vp . pageNumber > = 0 )
{
2006-10-07 14:40:32 +00:00
int prevX = horizontalScrollBar ( ) - > value ( ) ,
prevY = verticalScrollBar ( ) - > value ( ) ;
2008-05-19 00:37:14 +00:00
const QRect & geometry = d - > items [ vp . pageNumber ] - > croppedGeometry ( ) ;
2009-05-17 10:17:35 +00:00
double nX = vp . rePos . enabled ? normClamp ( vp . rePos . normalizedX , 0.5 ) : 0.5 ,
nY = vp . rePos . enabled ? normClamp ( vp . rePos . normalizedY , 0.0 ) : 0.0 ;
2006-10-29 13:42:07 +00:00
center ( geometry . left ( ) + qRound ( nX * ( double ) geometry . width ( ) ) ,
geometry . top ( ) + qRound ( nY * ( double ) geometry . height ( ) ) ) ;
2005-06-13 10:37:41 +00:00
// center() usually moves the viewport, that requests pixmaps too.
// if that doesn't happen we have to request them by hand
2006-10-07 14:40:32 +00:00
if ( prevX = = horizontalScrollBar ( ) - > value ( ) & & prevY = = verticalScrollBar ( ) - > value ( ) )
2005-06-13 10:37:41 +00:00
slotRequestVisiblePixmaps ( ) ;
2005-01-10 13:43:44 +00:00
}
// or else go to center page
else
center ( fullWidth / 2 , 0 ) ;
viewport ( ) - > setUpdatesEnabled ( true ) ;
2004-11-05 00:14:00 +00:00
}
2004-09-26 23:39:39 +00:00
}
2004-09-27 21:36:25 +00:00
2005-01-10 13:43:44 +00:00
// 5) update the whole viewport if updated enabled
if ( wasUpdatesEnabled )
2009-06-29 20:55:50 +00:00
viewport ( ) - > update ( ) ;
2004-09-30 18:04:09 +00:00
}
2011-03-17 15:24:44 +00:00
void PageView : : delayedResizeEvent ( )
{
// If we already got here we don't need to execute the timer slot again
d - > delayResizeEventTimer - > stop ( ) ;
slotRelayoutPages ( ) ;
slotRequestVisiblePixmaps ( ) ;
}
2008-04-16 11:04:59 +00:00
void PageView : : slotRequestVisiblePixmaps ( int newValue )
2004-09-30 18:16:12 +00:00
{
2005-01-21 20:05:36 +00:00
// if requests are blocked (because raised by an unwanted event), exit
2005-03-24 19:10:41 +00:00
if ( d - > blockPixmapsRequest | | d - > viewportMoveActive | |
d - > mouseMidZooming )
2005-01-21 20:05:36 +00:00
return ;
2011-12-13 18:52:33 +00:00
// precalc view limits for intersecting with page coords inside the loop
2011-12-13 18:52:19 +00:00
const bool isEvent = newValue ! = - 1 & & ! d - > blockViewport ;
const QRect viewportRect ( horizontalScrollBar ( ) - > value ( ) ,
verticalScrollBar ( ) - > value ( ) ,
viewport ( ) - > width ( ) , viewport ( ) - > height ( ) ) ;
2011-12-13 18:50:46 +00:00
const QRect viewportRectAtZeroZero ( 0 , 0 , viewport ( ) - > width ( ) , viewport ( ) - > height ( ) ) ;
2004-09-30 18:16:12 +00:00
2005-01-09 23:37:07 +00:00
// some variables used to determine the viewport
2005-01-28 17:21:28 +00:00
int nearPageNumber = - 1 ;
2011-12-13 18:52:19 +00:00
const double viewportCenterX = ( viewportRect . left ( ) + viewportRect . right ( ) ) / 2.0 ;
const double viewportCenterY = ( viewportRect . top ( ) + viewportRect . bottom ( ) ) / 2.0 ;
double focusedX = 0.5 ,
2005-01-09 23:37:07 +00:00
focusedY = 0.0 ,
minDistance = - 1.0 ;
2012-11-12 02:09:12 +00:00
// Margin (in pixels) around the viewport to preload
const int pixelsToExpand = 512 ;
2005-01-09 23:37:07 +00:00
// iterate over all items
2004-12-21 12:38:52 +00:00
d - > visibleItems . clear ( ) ;
2006-09-21 08:45:36 +00:00
QLinkedList < Okular : : PixmapRequest * > requestedPixmaps ;
QVector < Okular : : VisiblePageRect * > visibleRects ;
2008-11-11 18:48:40 +00:00
QVector < PageViewItem * > : : const_iterator iIt = d - > items . constBegin ( ) , iEnd = d - > items . constEnd ( ) ;
2004-11-05 00:14:00 +00:00
for ( ; iIt ! = iEnd ; + + iIt )
2004-09-30 18:16:12 +00:00
{
2004-12-22 18:21:36 +00:00
PageViewItem * i = * iIt ;
2009-06-29 20:55:50 +00:00
foreach ( FormWidgetIface * fwi , i - > formWidgets ( ) )
{
Okular : : NormalizedRect r = fwi - > rect ( ) ;
fwi - > moveTo (
qRound ( i - > uncroppedGeometry ( ) . left ( ) + i - > uncroppedWidth ( ) * r . left ) + 1 - viewportRect . left ( ) ,
qRound ( i - > uncroppedGeometry ( ) . top ( ) + i - > uncroppedHeight ( ) * r . top ) + 1 - viewportRect . top ( ) ) ;
}
Q_FOREACH ( VideoWidget * vw , i - > videoWidgets ( ) )
{
const Okular : : NormalizedRect r = vw - > normGeometry ( ) ;
vw - > move (
qRound ( i - > uncroppedGeometry ( ) . left ( ) + i - > uncroppedWidth ( ) * r . left ) + 1 - viewportRect . left ( ) ,
qRound ( i - > uncroppedGeometry ( ) . top ( ) + i - > uncroppedHeight ( ) * r . top ) + 1 - viewportRect . top ( ) ) ;
2011-12-13 18:50:46 +00:00
if ( vw - > isPlaying ( ) & & viewportRectAtZeroZero . intersect ( vw - > geometry ( ) ) . isEmpty ( ) ) {
vw - > stop ( ) ;
2012-06-29 09:16:28 +00:00
vw - > pageLeft ( ) ;
2011-12-13 18:50:46 +00:00
}
2009-06-29 20:55:50 +00:00
}
2007-12-31 17:35:22 +00:00
if ( ! i - > isVisible ( ) )
continue ;
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
# ifdef PAGEVIEW_DEBUG
2007-07-31 10:19:48 +00:00
kWarning ( ) < < " checking page " < < i - > pageNumber ( ) ;
2008-05-19 00:37:14 +00:00
kWarning ( ) . nospace ( ) < < " viewportRect is " < < viewportRect < < " , page item is " < < i - > croppedGeometry ( ) < < " intersect : " < < viewportRect . intersects ( i - > croppedGeometry ( ) ) ;
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
# endif
2005-01-09 23:37:07 +00:00
// if the item doesn't intersect the viewport, skip it
2008-05-19 00:37:14 +00:00
QRect intersectionRect = viewportRect . intersect ( i - > croppedGeometry ( ) ) ;
2006-06-23 21:11:52 +00:00
if ( intersectionRect . isEmpty ( ) )
2012-08-20 01:43:59 +00:00
{
2004-12-22 18:21:36 +00:00
continue ;
2012-08-20 01:43:59 +00:00
}
2004-12-22 18:21:36 +00:00
2005-01-09 23:37:07 +00:00
// add the item to the 'visible list'
2004-12-22 18:21:36 +00:00
d - > visibleItems . push_back ( i ) ;
2008-05-19 00:37:14 +00:00
Okular : : VisiblePageRect * vItem = new Okular : : VisiblePageRect ( i - > pageNumber ( ) , Okular : : NormalizedRect ( intersectionRect . translated ( - i - > uncroppedGeometry ( ) . topLeft ( ) ) , i - > uncroppedWidth ( ) , i - > uncroppedHeight ( ) ) ) ;
2006-06-23 21:11:52 +00:00
visibleRects . push_back ( vItem ) ;
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
# ifdef PAGEVIEW_DEBUG
2008-05-19 00:37:14 +00:00
kWarning ( ) < < " checking for pixmap for page " < < i - > pageNumber ( ) < < " = " < < i - > page ( ) - > hasPixmap ( PAGEVIEW_ID , i - > uncroppedWidth ( ) , i - > uncroppedHeight ( ) ) ;
2007-07-31 10:19:48 +00:00
kWarning ( ) < < " checking for text for page " < < i - > pageNumber ( ) < < " = " < < i - > page ( ) - > hasTextPage ( ) ;
2006-11-24 21:44:25 +00:00
# endif
2012-08-10 19:00:50 +00:00
2012-08-24 16:23:37 +00:00
Okular : : NormalizedRect expandedVisibleRect = vItem - > rect ;
2012-11-08 20:29:09 +00:00
if ( i - > page ( ) - > hasTilesManager ( ) & & Okular : : Settings : : memoryLevel ( ) ! = Okular : : Settings : : EnumMemoryLevel : : Low )
2012-08-10 19:00:50 +00:00
{
2012-08-20 03:40:47 +00:00
double rectMargin = pixelsToExpand / ( double ) i - > uncroppedHeight ( ) ;
expandedVisibleRect . left = qMax ( 0.0 , vItem - > rect . left - rectMargin ) ;
expandedVisibleRect . top = qMax ( 0.0 , vItem - > rect . top - rectMargin ) ;
expandedVisibleRect . right = qMin ( 1.0 , vItem - > rect . right + rectMargin ) ;
expandedVisibleRect . bottom = qMin ( 1.0 , vItem - > rect . bottom + rectMargin ) ;
2012-08-10 19:00:50 +00:00
}
2005-01-09 23:37:07 +00:00
// if the item has not the right pixmap, add a request for it
2012-08-10 19:00:50 +00:00
if ( ! i - > page ( ) - > hasPixmap ( PAGEVIEW_ID , i - > uncroppedWidth ( ) , i - > uncroppedHeight ( ) , expandedVisibleRect ) )
2005-01-18 16:43:36 +00:00
{
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
# ifdef PAGEVIEW_DEBUG
2007-07-31 10:19:48 +00:00
kWarning ( ) < < " rerequesting visible pixmaps for page " < < i - > pageNumber ( ) < < " ! " ;
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
# endif
2012-07-19 03:30:03 +00:00
Okular : : PixmapRequest * p = new Okular : : PixmapRequest (
PAGEVIEW_ID , i - > pageNumber ( ) , i - > uncroppedWidth ( ) , i - > uncroppedHeight ( ) , PAGEVIEW_PRIO , true ) ;
requestedPixmaps . push_back ( p ) ;
2012-11-08 20:29:09 +00:00
if ( i - > page ( ) - > hasTilesManager ( ) )
2012-07-07 17:40:52 +00:00
{
2012-11-12 14:55:13 +00:00
p - > setNormalizedRect ( expandedVisibleRect ) ;
2012-08-24 16:32:39 +00:00
p - > setTile ( true ) ;
2012-07-07 17:40:52 +00:00
}
2012-11-12 02:09:12 +00:00
else
p - > setNormalizedRect ( vItem - > rect ) ;
2005-01-18 16:43:36 +00:00
}
2005-01-09 23:37:07 +00:00
// look for the item closest to viewport center and the relative
// position between the item and the viewport center
if ( isEvent )
{
2008-05-19 00:37:14 +00:00
const QRect & geometry = i - > croppedGeometry ( ) ;
2005-04-14 11:33:28 +00:00
// compute distance between item center and viewport center (slightly moved left)
double distance = hypot ( ( geometry . left ( ) + geometry . right ( ) ) / 2 - ( viewportCenterX - 4 ) ,
2005-01-10 13:43:44 +00:00
( geometry . top ( ) + geometry . bottom ( ) ) / 2 - viewportCenterY ) ;
2005-01-09 23:37:07 +00:00
if ( distance > = minDistance & & nearPageNumber ! = - 1 )
continue ;
nearPageNumber = i - > pageNumber ( ) ;
minDistance = distance ;
if ( geometry . height ( ) > 0 & & geometry . width ( ) > 0 )
{
2005-01-28 17:21:28 +00:00
focusedX = ( viewportCenterX - ( double ) geometry . left ( ) ) / ( double ) geometry . width ( ) ;
focusedY = ( viewportCenterY - ( double ) geometry . top ( ) ) / ( double ) geometry . height ( ) ;
2005-01-09 23:37:07 +00:00
}
}
2004-12-21 12:38:52 +00:00
}
2005-01-20 17:33:05 +00:00
// if preloading is enabled, add the pages before and after in preloading
if ( ! d - > visibleItems . isEmpty ( ) & &
2012-10-15 22:27:42 +00:00
Okular : : SettingsCore : : memoryLevel ( ) ! = Okular : : SettingsCore : : EnumMemoryLevel : : Low )
2005-01-18 16:43:36 +00:00
{
2007-01-04 21:47:54 +00:00
// as the requests are done in the order as they appear in the list,
// request first the next page and then the previous
2009-10-23 18:04:03 +00:00
int pagesToPreload = viewColumns ( ) ;
2012-03-08 23:12:20 +00:00
// if the greedy option is set, preload all pages
2012-10-15 22:27:42 +00:00
if ( Okular : : SettingsCore : : memoryLevel ( ) = = Okular : : SettingsCore : : EnumMemoryLevel : : Greedy )
2012-03-08 23:12:20 +00:00
pagesToPreload = d - > items . count ( ) ;
2012-08-20 03:40:47 +00:00
QRect expandedViewportRect = viewportRect . adjusted ( 0 , - pixelsToExpand , 0 , pixelsToExpand ) ;
2009-10-23 18:04:03 +00:00
for ( int j = 1 ; j < = pagesToPreload ; j + + )
2005-01-18 16:43:36 +00:00
{
2009-10-23 18:04:03 +00:00
// add the page after the 'visible series' in preload
int tailRequest = d - > visibleItems . last ( ) - > pageNumber ( ) + j ;
2012-08-10 19:00:50 +00:00
2009-10-23 18:04:03 +00:00
if ( tailRequest < ( int ) d - > items . count ( ) )
{
PageViewItem * i = d - > items [ tailRequest ] ;
2012-08-24 16:32:39 +00:00
2012-08-10 19:00:50 +00:00
Okular : : NormalizedRect preRenderRegion ;
2012-08-24 16:32:39 +00:00
QRect intersectionRect = expandedViewportRect . intersect ( i - > croppedGeometry ( ) ) ;
if ( ! intersectionRect . isEmpty ( ) )
preRenderRegion = Okular : : NormalizedRect ( intersectionRect . translated ( - i - > uncroppedGeometry ( ) . topLeft ( ) ) , i - > uncroppedWidth ( ) , i - > uncroppedHeight ( ) ) ;
2012-08-10 19:00:50 +00:00
2009-10-23 18:04:03 +00:00
// request the pixmap if not already present
2012-08-10 19:00:50 +00:00
if ( ! i - > page ( ) - > hasPixmap ( PAGEVIEW_ID , i - > uncroppedWidth ( ) , i - > uncroppedHeight ( ) , preRenderRegion ) & & i - > uncroppedWidth ( ) > 0 )
{
2012-11-12 02:09:12 +00:00
const bool pageHasTilesManager = i - > page ( ) - > hasTilesManager ( ) ;
if ( pageHasTilesManager & & ! preRenderRegion . isNull ( ) )
2012-08-10 19:00:50 +00:00
{
2012-08-20 03:40:47 +00:00
Okular : : PixmapRequest * p = new Okular : : PixmapRequest ( PAGEVIEW_ID , i - > pageNumber ( ) , i - > uncroppedWidth ( ) , i - > uncroppedHeight ( ) , PAGEVIEW_PRELOAD_PRIO , true ) ;
requestedPixmaps . push_back ( p ) ;
2012-11-12 14:55:13 +00:00
p - > setNormalizedRect ( preRenderRegion ) ;
2012-08-24 16:32:39 +00:00
p - > setTile ( true ) ;
2012-08-10 19:00:50 +00:00
}
2012-11-12 02:09:12 +00:00
else if ( ! pageHasTilesManager )
2012-08-20 03:40:47 +00:00
{
Okular : : PixmapRequest * p = new Okular : : PixmapRequest ( PAGEVIEW_ID , i - > pageNumber ( ) , i - > uncroppedWidth ( ) , i - > uncroppedHeight ( ) , PAGEVIEW_PRELOAD_PRIO , true ) ;
requestedPixmaps . push_back ( p ) ;
2012-08-24 16:32:39 +00:00
p - > setNormalizedRect ( preRenderRegion ) ;
2012-08-20 03:40:47 +00:00
}
2012-08-10 19:00:50 +00:00
}
2009-10-23 18:04:03 +00:00
}
2005-01-20 17:33:05 +00:00
2009-10-23 18:04:03 +00:00
// add the page before the 'visible series' in preload
int headRequest = d - > visibleItems . first ( ) - > pageNumber ( ) - j ;
if ( headRequest > = 0 )
{
PageViewItem * i = d - > items [ headRequest ] ;
2012-08-24 16:32:39 +00:00
2012-08-10 19:00:50 +00:00
Okular : : NormalizedRect preRenderRegion ;
2012-08-24 16:32:39 +00:00
QRect intersectionRect = expandedViewportRect . intersect ( i - > croppedGeometry ( ) ) ;
if ( ! intersectionRect . isEmpty ( ) )
preRenderRegion = Okular : : NormalizedRect ( intersectionRect . translated ( - i - > uncroppedGeometry ( ) . topLeft ( ) ) , i - > uncroppedWidth ( ) , i - > uncroppedHeight ( ) ) ;
2012-08-10 19:00:50 +00:00
2009-10-23 18:04:03 +00:00
// request the pixmap if not already present
2012-08-10 19:00:50 +00:00
if ( ! i - > page ( ) - > hasPixmap ( PAGEVIEW_ID , i - > uncroppedWidth ( ) , i - > uncroppedHeight ( ) , preRenderRegion ) & & i - > uncroppedWidth ( ) > 0 )
{
2012-11-12 02:09:12 +00:00
const bool pageHasTilesManager = i - > page ( ) - > hasTilesManager ( ) ;
if ( pageHasTilesManager & & ! preRenderRegion . isNull ( ) )
2012-08-10 19:00:50 +00:00
{
2012-08-20 03:40:47 +00:00
Okular : : PixmapRequest * p = new Okular : : PixmapRequest ( PAGEVIEW_ID , i - > pageNumber ( ) , i - > uncroppedWidth ( ) , i - > uncroppedHeight ( ) , PAGEVIEW_PRELOAD_PRIO , true ) ;
requestedPixmaps . push_back ( p ) ;
2012-11-12 14:55:13 +00:00
p - > setNormalizedRect ( preRenderRegion ) ;
2012-08-24 16:32:39 +00:00
p - > setTile ( true ) ;
2012-08-10 19:00:50 +00:00
}
2012-11-12 02:09:12 +00:00
else if ( ! pageHasTilesManager )
2012-08-20 03:40:47 +00:00
{
Okular : : PixmapRequest * p = new Okular : : PixmapRequest ( PAGEVIEW_ID , i - > pageNumber ( ) , i - > uncroppedWidth ( ) , i - > uncroppedHeight ( ) , PAGEVIEW_PRELOAD_PRIO , true ) ;
requestedPixmaps . push_back ( p ) ;
2012-08-24 16:32:39 +00:00
p - > setNormalizedRect ( preRenderRegion ) ;
2012-08-20 03:40:47 +00:00
}
2012-08-10 19:00:50 +00:00
}
2009-10-23 18:04:03 +00:00
}
2012-07-02 06:28:23 +00:00
// stop if we've already reached both ends of the document
if ( headRequest < 0 & & tailRequest > = ( int ) d - > items . count ( ) )
break ;
2005-01-18 16:43:36 +00:00
}
}
2005-01-09 23:37:07 +00:00
2005-01-20 17:33:05 +00:00
// send requests to the document
if ( ! requestedPixmaps . isEmpty ( ) )
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
{
2005-01-20 17:33:05 +00:00
d - > document - > requestPixmaps ( requestedPixmaps ) ;
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
}
2005-01-28 17:21:28 +00:00
// if this functions was invoked by viewport events, send update to document
2005-01-09 23:37:07 +00:00
if ( isEvent & & nearPageNumber ! = - 1 )
{
// determine the document viewport
2006-09-21 08:45:36 +00:00
Okular : : DocumentViewport newViewport ( nearPageNumber ) ;
2005-06-13 11:53:47 +00:00
newViewport . rePos . enabled = true ;
newViewport . rePos . normalizedX = focusedX ;
newViewport . rePos . normalizedY = focusedY ;
2005-01-09 23:37:07 +00:00
// set the viewport to other observers
2005-01-10 13:43:44 +00:00
d - > document - > setViewport ( newViewport , PAGEVIEW_ID ) ;
2005-01-09 23:37:07 +00:00
}
2006-06-23 21:11:52 +00:00
d - > document - > setVisiblePageRects ( visibleRects , PAGEVIEW_ID ) ;
2004-09-30 18:16:12 +00:00
}
2004-10-06 00:05:49 +00:00
2005-02-01 18:24:16 +00:00
void PageView : : slotMoveViewport ( )
{
// converge to viewportMoveDest in 1 second
int diffTime = d - > viewportMoveTime . elapsed ( ) ;
if ( diffTime > = 667 | | ! d - > viewportMoveActive )
{
center ( d - > viewportMoveDest . x ( ) , d - > viewportMoveDest . y ( ) ) ;
d - > viewportMoveTimer - > stop ( ) ;
d - > viewportMoveActive = false ;
slotRequestVisiblePixmaps ( ) ;
verticalScrollBar ( ) - > setEnabled ( true ) ;
horizontalScrollBar ( ) - > setEnabled ( true ) ;
return ;
}
2005-04-04 23:55:40 +00:00
// move the viewport smoothly (kmplot: p(x)=1+0.47*(x-1)^3-0.25*(x-1)^4)
2005-02-01 18:24:16 +00:00
float convergeSpeed = ( float ) diffTime / 667.0 ,
2006-10-07 14:40:32 +00:00
x = ( ( float ) viewport ( ) - > width ( ) / 2.0 ) + horizontalScrollBar ( ) - > value ( ) ,
y = ( ( float ) viewport ( ) - > height ( ) / 2.0 ) + verticalScrollBar ( ) - > value ( ) ,
2005-02-01 18:24:16 +00:00
diffX = ( float ) d - > viewportMoveDest . x ( ) - x ,
diffY = ( float ) d - > viewportMoveDest . y ( ) - y ;
convergeSpeed * = convergeSpeed * ( 1.4 - convergeSpeed ) ;
center ( ( int ) ( x + diffX * convergeSpeed ) ,
( int ) ( y + diffY * convergeSpeed ) ) ;
}
2004-10-06 00:05:49 +00:00
void PageView : : slotAutoScoll ( )
{
// the first time create the timer
2005-02-01 18:24:16 +00:00
if ( ! d - > autoScrollTimer )
2004-10-06 00:05:49 +00:00
{
2005-02-01 18:24:16 +00:00
d - > autoScrollTimer = new QTimer ( this ) ;
2006-05-28 21:52:36 +00:00
d - > autoScrollTimer - > setSingleShot ( true ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > autoScrollTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( slotAutoScoll ( ) ) ) ;
2004-10-06 00:05:49 +00:00
}
// if scrollIncrement is zero, stop the timer
if ( ! d - > scrollIncrement )
{
2005-02-01 18:24:16 +00:00
d - > autoScrollTimer - > stop ( ) ;
2004-10-06 00:05:49 +00:00
return ;
}
// compute delay between timer ticks and scroll amount per tick
int index = abs ( d - > scrollIncrement ) - 1 ; // 0..9
const int scrollDelay [ 10 ] = { 200 , 100 , 50 , 30 , 20 , 30 , 25 , 20 , 30 , 20 } ;
const int scrollOffset [ 10 ] = { 1 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 4 , 4 } ;
2006-05-28 21:52:36 +00:00
d - > autoScrollTimer - > start ( scrollDelay [ index ] ) ;
2006-10-07 14:40:32 +00:00
int delta = d - > scrollIncrement > 0 ? scrollOffset [ index ] : - scrollOffset [ index ] ;
verticalScrollBar ( ) - > setValue ( verticalScrollBar ( ) - > value ( ) + delta ) ;
2004-10-06 00:05:49 +00:00
}
2004-09-30 18:16:12 +00:00
2006-11-22 21:32:21 +00:00
void PageView : : slotDragScroll ( )
{
2012-09-03 00:55:16 +00:00
scrollTo ( horizontalScrollBar ( ) - > value ( ) + d - > dragScrollVector . x ( ) , verticalScrollBar ( ) - > value ( ) + d - > dragScrollVector . y ( ) ) ;
2009-06-29 20:55:50 +00:00
QPoint p = contentAreaPosition ( ) + viewport ( ) - > mapFromGlobal ( QCursor : : pos ( ) ) ;
2012-09-28 15:57:03 +00:00
updateSelection ( p ) ;
2006-11-22 21:32:21 +00:00
}
2006-09-20 13:58:28 +00:00
void PageView : : slotShowWelcome ( )
{
// show initial welcome text
2010-08-21 15:46:47 +00:00
d - > messageWindow - > display ( i18n ( " Welcome " ) , QString ( ) , PageViewMessage : : Info , 2000 ) ;
2006-09-20 13:58:28 +00:00
}
2010-03-25 20:59:16 +00:00
void PageView : : slotShowSizeAllCursor ( )
{
setCursor ( Qt : : SizeAllCursor ) ;
}
2010-09-11 13:34:22 +00:00
void PageView : : slotHandleWebShortcutAction ( )
{
2010-11-21 17:37:07 +00:00
# if KDE_IS_VERSION(4,5,70)
2010-09-11 13:34:22 +00:00
KAction * action = qobject_cast < KAction * > ( sender ( ) ) ;
if ( action )
{
KUriFilterData filterData ( action - > data ( ) . toString ( ) ) ;
if ( KUriFilter : : self ( ) - > filterSearchUri ( filterData , KUriFilter : : WebShortcutFilter ) )
{
KToolInvocation : : invokeBrowser ( filterData . uri ( ) . url ( ) ) ;
}
}
2010-11-21 17:37:07 +00:00
# endif
2010-09-11 13:34:22 +00:00
}
void PageView : : slotConfigureWebShortcuts ( )
{
KToolInvocation : : kdeinitExec ( " kcmshell4 " , QStringList ( ) < < " ebrowsing " ) ;
}
2004-10-29 21:52:06 +00:00
void PageView : : slotZoom ( )
2004-09-30 18:04:09 +00:00
{
2011-10-23 09:17:04 +00:00
if ( ! d - > aZoom - > selectableActionGroup ( ) - > isEnabled ( ) )
return ;
2004-12-13 18:21:37 +00:00
setFocus ( ) ;
2004-10-29 21:52:06 +00:00
updateZoom ( ZoomFixed ) ;
}
2004-10-20 16:41:13 +00:00
2004-10-29 21:52:06 +00:00
void PageView : : slotZoomIn ( )
{
updateZoom ( ZoomIn ) ;
}
2004-09-30 18:04:09 +00:00
2004-10-29 21:52:06 +00:00
void PageView : : slotZoomOut ( )
{
updateZoom ( ZoomOut ) ;
}
2004-09-30 18:04:09 +00:00
2004-10-29 21:52:06 +00:00
void PageView : : slotFitToWidthToggled ( bool on )
{
if ( on ) updateZoom ( ZoomFitWidth ) ;
2004-09-30 18:04:09 +00:00
}
2004-10-29 21:52:06 +00:00
void PageView : : slotFitToPageToggled ( bool on )
2004-09-30 18:04:09 +00:00
{
2004-10-29 21:52:06 +00:00
if ( on ) updateZoom ( ZoomFitPage ) ;
}
2004-09-30 18:04:09 +00:00
2008-10-12 16:36:14 +00:00
void PageView : : slotViewMode ( QAction * action )
2004-10-29 21:52:06 +00:00
{
2008-10-12 16:36:14 +00:00
const int nr = action - > data ( ) . toInt ( ) ;
2007-05-17 20:46:16 +00:00
if ( ( int ) Okular : : Settings : : viewMode ( ) ! = nr )
2004-09-30 18:04:09 +00:00
{
2007-05-17 20:46:16 +00:00
Okular : : Settings : : setViewMode ( nr ) ;
2007-05-23 21:59:12 +00:00
Okular : : Settings : : self ( ) - > writeConfig ( ) ;
2004-10-29 21:52:06 +00:00
if ( d - > document - > pages ( ) > 0 )
slotRelayoutPages ( ) ;
2004-09-30 18:04:09 +00:00
}
2004-09-26 23:39:39 +00:00
}
2005-03-05 15:59:15 +00:00
void PageView : : slotContinuousToggled ( bool on )
2004-09-28 13:53:47 +00:00
{
2006-09-21 08:45:36 +00:00
if ( Okular : : Settings : : viewContinuous ( ) ! = on )
2004-09-28 13:53:47 +00:00
{
2006-09-21 08:45:36 +00:00
Okular : : Settings : : setViewContinuous ( on ) ;
2007-05-23 21:59:12 +00:00
Okular : : Settings : : self ( ) - > writeConfig ( ) ;
2004-10-29 21:52:06 +00:00
if ( d - > document - > pages ( ) > 0 )
slotRelayoutPages ( ) ;
2004-09-28 13:53:47 +00:00
}
}
2004-10-29 21:52:06 +00:00
void PageView : : slotSetMouseNormal ( )
2004-09-26 23:39:39 +00:00
{
2012-03-09 17:43:40 +00:00
Okular : : Settings : : setMouseMode ( Okular : : Settings : : EnumMouseMode : : Browse ) ;
2005-02-12 17:42:54 +00:00
// hide the messageWindow
2004-11-03 17:35:48 +00:00
d - > messageWindow - > hide ( ) ;
2012-08-27 18:59:03 +00:00
// reshow the annotator toolbar if hiding was forced (and if it is not already visible)
if ( d - > annotator & & d - > annotator - > hidingWasForced ( ) & & d - > aToggleAnnotator & & ! d - > aToggleAnnotator - > isChecked ( ) )
d - > aToggleAnnotator - > trigger ( ) ;
2007-09-14 16:02:02 +00:00
// force an update of the cursor
2009-06-29 20:55:50 +00:00
updateCursor ( contentAreaPosition ( ) + viewport ( ) - > mapFromGlobal ( QCursor : : pos ( ) ) ) ;
2012-03-09 17:43:40 +00:00
Okular : : Settings : : self ( ) - > writeConfig ( ) ;
2004-11-03 17:35:48 +00:00
}
void PageView : : slotSetMouseZoom ( )
{
2012-03-09 17:43:40 +00:00
Okular : : Settings : : setMouseMode ( Okular : : Settings : : EnumMouseMode : : Zoom ) ;
2005-02-12 17:42:54 +00:00
// change the text in messageWindow (and show it if hidden)
2010-08-21 15:46:47 +00:00
d - > messageWindow - > display ( i18n ( " Select zooming area. Right-click to zoom out. " ) , QString ( ) , PageViewMessage : : Info , - 1 ) ;
2005-03-04 23:06:24 +00:00
// force hiding of annotator toolbar
2012-08-27 18:59:03 +00:00
if ( d - > aToggleAnnotator & & d - > aToggleAnnotator - > isChecked ( ) )
{
d - > aToggleAnnotator - > trigger ( ) ;
d - > annotator - > setHidingForced ( true ) ;
}
2007-09-14 16:02:02 +00:00
// force an update of the cursor
2009-06-29 20:55:50 +00:00
updateCursor ( contentAreaPosition ( ) + viewport ( ) - > mapFromGlobal ( QCursor : : pos ( ) ) ) ;
2012-03-09 17:43:40 +00:00
Okular : : Settings : : self ( ) - > writeConfig ( ) ;
2004-09-26 23:39:39 +00:00
}
2004-11-16 17:36:02 +00:00
void PageView : : slotSetMouseSelect ( )
2004-09-26 23:39:39 +00:00
{
2012-03-09 17:43:40 +00:00
Okular : : Settings : : setMouseMode ( Okular : : Settings : : EnumMouseMode : : RectSelect ) ;
2005-02-12 17:42:54 +00:00
// change the text in messageWindow (and show it if hidden)
2010-08-21 15:46:47 +00:00
d - > messageWindow - > display ( i18n ( " Draw a rectangle around the text/graphics to copy. " ) , QString ( ) , PageViewMessage : : Info , - 1 ) ;
2005-03-04 23:06:24 +00:00
// force hiding of annotator toolbar
2012-08-27 18:59:03 +00:00
if ( d - > aToggleAnnotator & & d - > aToggleAnnotator - > isChecked ( ) )
{
d - > aToggleAnnotator - > trigger ( ) ;
d - > annotator - > setHidingForced ( true ) ;
}
2007-09-14 16:02:02 +00:00
// force an update of the cursor
2009-06-29 20:55:50 +00:00
updateCursor ( contentAreaPosition ( ) + viewport ( ) - > mapFromGlobal ( QCursor : : pos ( ) ) ) ;
2012-03-09 17:43:40 +00:00
Okular : : Settings : : self ( ) - > writeConfig ( ) ;
2005-02-18 18:24:45 +00:00
}
2006-09-26 22:22:01 +00:00
void PageView : : slotSetMouseTextSelect ( )
{
2012-03-09 17:43:40 +00:00
Okular : : Settings : : setMouseMode ( Okular : : Settings : : EnumMouseMode : : TextSelect ) ;
2006-09-26 22:22:01 +00:00
// change the text in messageWindow (and show it if hidden)
2010-08-21 15:46:47 +00:00
d - > messageWindow - > display ( i18n ( " Select text " ) , QString ( ) , PageViewMessage : : Info , - 1 ) ;
2006-09-26 22:22:01 +00:00
// force hiding of annotator toolbar
2012-08-27 18:59:03 +00:00
if ( d - > aToggleAnnotator & & d - > aToggleAnnotator - > isChecked ( ) )
{
d - > aToggleAnnotator - > trigger ( ) ;
d - > annotator - > setHidingForced ( true ) ;
}
2007-09-14 16:02:02 +00:00
// force an update of the cursor
2009-06-29 20:55:50 +00:00
updateCursor ( contentAreaPosition ( ) + viewport ( ) - > mapFromGlobal ( QCursor : : pos ( ) ) ) ;
2012-03-09 17:43:40 +00:00
Okular : : Settings : : self ( ) - > writeConfig ( ) ;
2006-09-26 22:22:01 +00:00
}
2011-10-12 13:50:56 +00:00
void PageView : : slotSetMouseTableSelect ( )
{
2012-03-09 17:43:40 +00:00
Okular : : Settings : : setMouseMode ( Okular : : Settings : : EnumMouseMode : : TableSelect ) ;
2011-10-12 13:50:56 +00:00
// change the text in messageWindow (and show it if hidden)
d - > messageWindow - > display ( i18n (
" Draw a rectangle around the table, then click near edges to divide up; press Esc to clear. "
) , QString ( ) , PageViewMessage : : Info , - 1 ) ;
// force hiding of annotator toolbar
2012-08-27 18:59:03 +00:00
if ( d - > aToggleAnnotator & & d - > aToggleAnnotator - > isChecked ( ) )
{
d - > aToggleAnnotator - > trigger ( ) ;
d - > annotator - > setHidingForced ( true ) ;
}
2011-10-12 13:50:56 +00:00
// force an update of the cursor
updateCursor ( contentAreaPosition ( ) + viewport ( ) - > mapFromGlobal ( QCursor : : pos ( ) ) ) ;
2012-03-09 17:43:40 +00:00
Okular : : Settings : : self ( ) - > writeConfig ( ) ;
2011-10-12 13:50:56 +00:00
}
2005-03-04 23:06:24 +00:00
void PageView : : slotToggleAnnotator ( bool on )
2005-02-18 18:24:45 +00:00
{
2006-11-19 01:23:06 +00:00
// the 'inHere' trick is needed as the slotSetMouseZoom() calls this
static bool inHere = false ;
if ( inHere )
2005-03-04 23:06:24 +00:00
return ;
2006-11-19 01:23:06 +00:00
inHere = true ;
// the annotator can be used in normal mouse mode only, so if asked for it,
// switch to normal mode
2012-03-09 17:43:40 +00:00
if ( on & & Okular : : Settings : : mouseMode ( ) ! = Okular : : Settings : : EnumMouseMode : : Browse )
2006-11-19 01:23:06 +00:00
d - > aMouseNormal - > trigger ( ) ;
2005-02-18 18:24:45 +00:00
2010-08-08 17:06:42 +00:00
// ask for Author's name if not already set
if ( Okular : : Settings : : identityAuthor ( ) . isEmpty ( ) )
{
// get default username from the kdelibs/kdecore/KUser
KUser currentUser ;
QString userName = currentUser . property ( KUser : : FullName ) . toString ( ) ;
// ask the user for confirmation/change
if ( userName . isEmpty ( ) )
{
bool ok = false ;
userName = KInputDialog : : getText (
i18n ( " Annotations author " ) ,
i18n ( " Please insert your name or initials: " ) ,
QString ( ) ,
& ok ) ;
if ( ! ok )
{
d - > aToggleAnnotator - > trigger ( ) ;
inHere = false ;
return ;
}
}
// save the name
Okular : : Settings : : setIdentityAuthor ( userName ) ;
Okular : : Settings : : self ( ) - > writeConfig ( ) ;
}
2005-03-04 23:06:24 +00:00
// create the annotator object if not present
if ( ! d - > annotator )
2007-04-30 17:40:53 +00:00
{
2005-03-04 23:06:24 +00:00
d - > annotator = new PageViewAnnotator ( this , d - > document ) ;
2007-12-09 01:35:42 +00:00
bool allowTools = d - > document - > pages ( ) > 0 & & d - > document - > isAllowed ( Okular : : AllowNotes ) ;
d - > annotator - > setToolsEnabled ( allowTools ) ;
d - > annotator - > setTextToolsEnabled ( allowTools & & d - > document - > supportsSearching ( ) ) ;
2007-04-30 17:40:53 +00:00
}
2005-03-04 23:06:24 +00:00
// initialize/reset annotator (and show/hide toolbar)
d - > annotator - > setEnabled ( on ) ;
2012-08-27 18:59:03 +00:00
d - > annotator - > setHidingForced ( false ) ;
2006-11-19 01:23:06 +00:00
inHere = false ;
2004-09-26 23:39:39 +00:00
}
2012-09-05 20:12:11 +00:00
void PageView : : slotAutoScrollUp ( )
2004-09-26 23:39:39 +00:00
{
2004-10-29 21:52:06 +00:00
if ( d - > scrollIncrement < - 9 )
return ;
d - > scrollIncrement - - ;
slotAutoScoll ( ) ;
2004-10-30 20:54:48 +00:00
setFocus ( ) ;
2004-10-29 21:52:06 +00:00
}
2012-09-05 20:12:11 +00:00
void PageView : : slotAutoScrollDown ( )
2004-10-29 21:52:06 +00:00
{
if ( d - > scrollIncrement > 9 )
return ;
d - > scrollIncrement + + ;
slotAutoScoll ( ) ;
2004-10-30 20:54:48 +00:00
setFocus ( ) ;
2004-09-26 23:39:39 +00:00
}
2007-01-19 21:43:53 +00:00
2012-09-05 20:12:11 +00:00
void PageView : : slotScrollUp ( bool singleStep )
{
// if in single page mode and at the top of the screen, go to \ page
if ( Okular : : Settings : : viewContinuous ( ) | | verticalScrollBar ( ) - > value ( ) > verticalScrollBar ( ) - > minimum ( ) )
{
if ( singleStep )
verticalScrollBar ( ) - > triggerAction ( QScrollBar : : SliderSingleStepSub ) ;
else
verticalScrollBar ( ) - > triggerAction ( QScrollBar : : SliderPageStepSub ) ;
}
else if ( d - > document - > currentPage ( ) > 0 )
{
// more optimized than document->setPrevPage and then move view to bottom
Okular : : DocumentViewport newViewport = d - > document - > viewport ( ) ;
newViewport . pageNumber - = viewColumns ( ) ;
if ( newViewport . pageNumber < 0 )
newViewport . pageNumber = 0 ;
newViewport . rePos . enabled = true ;
newViewport . rePos . normalizedY = 1.0 ;
d - > document - > setViewport ( newViewport ) ;
}
}
void PageView : : slotScrollDown ( bool singleStep )
{
// if in single page mode and at the bottom of the screen, go to next page
if ( Okular : : Settings : : viewContinuous ( ) | | verticalScrollBar ( ) - > value ( ) < verticalScrollBar ( ) - > maximum ( ) )
{
if ( singleStep )
verticalScrollBar ( ) - > triggerAction ( QScrollBar : : SliderSingleStepAdd ) ;
else
verticalScrollBar ( ) - > triggerAction ( QScrollBar : : SliderPageStepAdd ) ;
}
else if ( ( int ) d - > document - > currentPage ( ) < d - > items . count ( ) - 1 )
{
// more optimized than document->setNextPage and then move view to top
Okular : : DocumentViewport newViewport = d - > document - > viewport ( ) ;
newViewport . pageNumber + = viewColumns ( ) ;
if ( newViewport . pageNumber > = ( int ) d - > items . count ( ) )
newViewport . pageNumber = d - > items . count ( ) - 1 ;
newViewport . rePos . enabled = true ;
newViewport . rePos . normalizedY = 0.0 ;
d - > document - > setViewport ( newViewport ) ;
}
}
2007-01-19 21:43:53 +00:00
void PageView : : slotRotateClockwise ( )
{
int id = ( ( int ) d - > document - > rotation ( ) + 1 ) % 4 ;
2007-05-01 23:09:45 +00:00
d - > document - > setRotation ( id ) ;
2007-01-19 21:43:53 +00:00
}
void PageView : : slotRotateCounterClockwise ( )
{
int id = ( ( int ) d - > document - > rotation ( ) + 3 ) % 4 ;
2007-05-01 23:09:45 +00:00
d - > document - > setRotation ( id ) ;
2007-01-19 21:43:53 +00:00
}
void PageView : : slotRotateOriginal ( )
{
2007-05-01 23:09:45 +00:00
d - > document - > setRotation ( 0 ) ;
2007-01-19 21:43:53 +00:00
}
2007-02-25 00:07:59 +00:00
2007-05-01 23:21:29 +00:00
void PageView : : slotPageSizes ( int newsize )
{
if ( newsize < 0 | | newsize > = d - > document - > pageSizes ( ) . count ( ) )
return ;
d - > document - > setPageSize ( d - > document - > pageSizes ( ) . at ( newsize ) ) ;
}
2008-05-27 14:00:59 +00:00
void PageView : : slotTrimMarginsToggled ( bool on )
2008-05-19 00:37:14 +00:00
{
2008-05-27 14:00:59 +00:00
if ( Okular : : Settings : : trimMargins ( ) ! = on )
2008-05-19 00:37:14 +00:00
{
2008-05-27 14:00:59 +00:00
Okular : : Settings : : setTrimMargins ( on ) ;
2008-05-19 00:37:14 +00:00
Okular : : Settings : : self ( ) - > writeConfig ( ) ;
if ( d - > document - > pages ( ) > 0 )
{
slotRelayoutPages ( ) ;
slotRequestVisiblePixmaps ( ) ; // TODO: slotRelayoutPages() may have done this already!
}
}
}
2007-02-25 00:07:59 +00:00
void PageView : : slotToggleForms ( )
{
toggleFormWidgets ( ! d - > m_formsVisible ) ;
}
2007-10-18 22:09:49 +00:00
void PageView : : slotFormWidgetChanged ( FormWidgetIface * w )
{
2008-03-07 16:09:08 +00:00
if ( ! d - > refreshTimer )
{
d - > refreshTimer = new QTimer ( this ) ;
d - > refreshTimer - > setSingleShot ( true ) ;
2011-07-31 19:22:04 +00:00
connect ( d - > refreshTimer , SIGNAL ( timeout ( ) ) ,
this , SLOT ( slotRefreshPage ( ) ) ) ;
2008-03-07 16:09:08 +00:00
}
d - > refreshPage = w - > pageItem ( ) - > pageNumber ( ) ;
d - > refreshTimer - > start ( 1000 ) ;
}
void PageView : : slotRefreshPage ( )
{
const int req = d - > refreshPage ;
if ( req < 0 )
return ;
d - > refreshPage = - 1 ;
QMetaObject : : invokeMethod ( d - > document , " refreshPixmaps " , Qt : : QueuedConnection ,
Q_ARG ( int , req ) ) ;
2007-10-18 22:09:49 +00:00
}
2008-03-05 11:06:55 +00:00
void PageView : : slotSpeakDocument ( )
{
QString text ;
2008-11-11 18:48:40 +00:00
QVector < PageViewItem * > : : const_iterator it = d - > items . constBegin ( ) , itEnd = d - > items . constEnd ( ) ;
2008-03-05 11:06:55 +00:00
for ( ; it < itEnd ; + + it )
{
Okular : : RegularAreaRect * area = textSelectionForItem ( * it ) ;
text . append ( ( * it ) - > page ( ) - > text ( area ) ) ;
text . append ( ' \n ' ) ;
delete area ;
}
d - > tts ( ) - > say ( text ) ;
}
void PageView : : slotSpeakCurrentPage ( )
{
const int currentPage = d - > document - > viewport ( ) . pageNumber ;
PageViewItem * item = d - > items . at ( currentPage ) ;
Okular : : RegularAreaRect * area = textSelectionForItem ( item ) ;
const QString text = item - > page ( ) - > text ( area ) ;
delete area ;
d - > tts ( ) - > say ( text ) ;
}
2008-03-05 12:05:48 +00:00
void PageView : : slotStopSpeaks ( )
{
if ( ! d - > m_tts )
return ;
d - > m_tts - > stopAllSpeechs ( ) ;
}
2008-03-20 17:45:37 +00:00
void PageView : : slotAction ( Okular : : Action * action )
{
d - > document - > processAction ( action ) ;
}
2011-06-08 05:47:57 +00:00
void PageView : : externalKeyPressEvent ( QKeyEvent * e )
{
keyPressEvent ( e ) ;
}
2012-04-03 12:18:10 +00:00
void PageView : : slotProcessMovieAction ( const Okular : : MovieAction * action )
{
const Okular : : MovieAnnotation * movieAnnotation = action - > annotation ( ) ;
if ( ! movieAnnotation )
return ;
Okular : : Movie * movie = movieAnnotation - > movie ( ) ;
if ( ! movie )
return ;
const int currentPage = d - > document - > viewport ( ) . pageNumber ;
PageViewItem * item = d - > items . at ( currentPage ) ;
if ( ! item )
return ;
VideoWidget * vw = item - > videoWidgets ( ) . value ( movie ) ;
if ( ! vw )
return ;
vw - > show ( ) ;
switch ( action - > operation ( ) )
{
case Okular : : MovieAction : : Play :
vw - > stop ( ) ;
vw - > play ( ) ;
break ;
case Okular : : MovieAction : : Stop :
vw - > stop ( ) ;
break ;
case Okular : : MovieAction : : Pause :
vw - > pause ( ) ;
break ;
case Okular : : MovieAction : : Resume :
vw - > play ( ) ;
break ;
} ;
}
2012-09-27 12:15:58 +00:00
void PageView : : slotProcessRenditionAction ( const Okular : : RenditionAction * action )
{
Okular : : Movie * movie = action - > movie ( ) ;
if ( ! movie )
return ;
const int currentPage = d - > document - > viewport ( ) . pageNumber ;
PageViewItem * item = d - > items . at ( currentPage ) ;
if ( ! item )
return ;
VideoWidget * vw = item - > videoWidgets ( ) . value ( movie ) ;
if ( ! vw )
return ;
if ( action - > operation ( ) = = Okular : : RenditionAction : : None )
return ;
vw - > show ( ) ;
switch ( action - > operation ( ) )
{
case Okular : : RenditionAction : : Play :
vw - > stop ( ) ;
vw - > play ( ) ;
break ;
case Okular : : RenditionAction : : Stop :
vw - > stop ( ) ;
break ;
case Okular : : RenditionAction : : Pause :
vw - > pause ( ) ;
break ;
case Okular : : RenditionAction : : Resume :
vw - > play ( ) ;
break ;
} ;
}
2004-10-29 21:52:06 +00:00
//END private SLOTS
2004-09-26 23:39:39 +00:00
# include "pageview.moc"
2008-04-11 18:50:26 +00:00
/* kate: replace-tabs on; indent-width 4; */