2004-09-26 23:39:39 +00:00
|
|
|
/***************************************************************************
|
2004-09-27 21:36:25 +00:00
|
|
|
* Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> *
|
2004-09-26 23:39:39 +00:00
|
|
|
* Copyright (C) 2004 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> *
|
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. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2005-01-02 14:55:14 +00:00
|
|
|
// qt/kde includes
|
2005-01-01 21:50:34 +00:00
|
|
|
#include <qcursor.h>
|
2004-09-26 23:39:39 +00:00
|
|
|
#include <qpainter.h>
|
|
|
|
#include <qtimer.h>
|
|
|
|
#include <qpushbutton.h>
|
2004-10-14 20:21:59 +00:00
|
|
|
#include <qapplication.h>
|
|
|
|
#include <qclipboard.h>
|
2004-09-26 23:39:39 +00:00
|
|
|
#include <kiconloader.h>
|
|
|
|
#include <kurldrag.h>
|
|
|
|
#include <kaction.h>
|
|
|
|
#include <kactioncollection.h>
|
2004-09-28 13:53:47 +00:00
|
|
|
#include <kpopupmenu.h>
|
2004-09-26 23:39:39 +00:00
|
|
|
#include <klocale.h>
|
2004-11-03 17:35:48 +00:00
|
|
|
#include <kfiledialog.h>
|
2004-10-31 17:04:04 +00:00
|
|
|
#include <kimageeffect.h>
|
2004-11-03 17:35:48 +00:00
|
|
|
#include <kimageio.h>
|
2004-11-08 13:13:46 +00:00
|
|
|
#include <kdebug.h>
|
2004-09-26 23:39:39 +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
|
2004-09-26 23:39:39 +00:00
|
|
|
#include "pageview.h"
|
2004-10-20 16:41:13 +00:00
|
|
|
#include "pageviewutils.h"
|
2005-01-02 14:55:14 +00:00
|
|
|
#include "core/document.h"
|
2005-01-02 14:37:49 +00:00
|
|
|
#include "core/page.h"
|
|
|
|
#include "core/link.h"
|
|
|
|
#include "core/generator.h"
|
|
|
|
#include "conf/settings.h"
|
2004-09-26 23:39:39 +00:00
|
|
|
|
2004-11-25 19:42:04 +00:00
|
|
|
#define ROUND(x) (int(x + 0.5))
|
|
|
|
|
2004-09-26 23:39:39 +00:00
|
|
|
// structure used internally by PageView for data storage
|
|
|
|
class PageViewPrivate
|
|
|
|
{
|
|
|
|
public:
|
2005-01-09 23:37:07 +00:00
|
|
|
// the document, pageviewItems and the 'visible cache'
|
2004-09-26 23:39:39 +00:00
|
|
|
KPDFDocument * document;
|
2004-11-05 00:14:00 +00:00
|
|
|
QValueVector< PageViewItem * > items;
|
2004-12-21 12:38:52 +00:00
|
|
|
QValueList< PageViewItem * > visibleItems;
|
2004-09-26 23:39:39 +00:00
|
|
|
|
2004-10-29 13:33:51 +00:00
|
|
|
// view layout (columns and continous in Settings), zoom and mouse
|
2004-09-26 23:39:39 +00:00
|
|
|
PageView::ZoomMode zoomMode;
|
|
|
|
float zoomFactor;
|
|
|
|
PageView::MouseMode mouseMode;
|
|
|
|
QPoint mouseGrabPos;
|
2004-09-28 13:53:47 +00:00
|
|
|
QPoint mouseStartPos;
|
2004-11-16 17:36:02 +00:00
|
|
|
int mouseMidStartY;
|
2004-12-10 16:04:45 +00:00
|
|
|
bool mouseOnRect;
|
2004-10-30 20:54:48 +00:00
|
|
|
QRect mouseSelectionRect;
|
2004-09-27 21:36:25 +00:00
|
|
|
|
|
|
|
// other stuff
|
2004-10-29 21:52:06 +00:00
|
|
|
QTimer * delayTimer;
|
|
|
|
QTimer * scrollTimer;
|
2004-10-06 00:05:49 +00:00
|
|
|
int scrollIncrement;
|
2004-09-30 18:04:09 +00:00
|
|
|
bool dirtyLayout;
|
2005-01-09 23:37:07 +00:00
|
|
|
bool blockViewport;
|
2004-10-20 16:41:13 +00:00
|
|
|
PageViewMessage * messageWindow; //in pageviewutils.h
|
2004-09-26 23:39:39 +00:00
|
|
|
|
|
|
|
// actions
|
2004-10-29 21:52:06 +00:00
|
|
|
KToggleAction * aMouseEdit;
|
|
|
|
KSelectAction * aZoom;
|
|
|
|
KToggleAction * aZoomFitWidth;
|
|
|
|
KToggleAction * aZoomFitPage;
|
|
|
|
KToggleAction * aZoomFitText;
|
|
|
|
KToggleAction * aViewTwoPages;
|
|
|
|
KToggleAction * aViewContinous;
|
2004-09-26 23:39:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-10-20 16:41:13 +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
|
2004-09-30 18:16:12 +00:00
|
|
|
* 170 - slotRelayoutPages: set contents of the scrollview on continous/single modes
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
PageView::PageView( QWidget *parent, KPDFDocument *document )
|
2004-10-29 21:52:06 +00:00
|
|
|
: QScrollView( parent, "KPDF::pageView", WStaticContents | WNoAutoErase )
|
2004-09-26 23:39:39 +00:00
|
|
|
{
|
|
|
|
// create and initialize private storage structure
|
|
|
|
d = new PageViewPrivate();
|
|
|
|
d->document = document;
|
2004-10-02 14:30:30 +00:00
|
|
|
d->zoomMode = ZoomFixed;
|
2004-09-30 18:04:09 +00:00
|
|
|
d->zoomFactor = 1.0;
|
2004-09-26 23:39:39 +00:00
|
|
|
d->mouseMode = MouseNormal;
|
2004-11-16 17:36:02 +00:00
|
|
|
d->mouseMidStartY = -1;
|
2004-12-10 16:04:45 +00:00
|
|
|
d->mouseOnRect = false;
|
2004-09-26 23:39:39 +00:00
|
|
|
d->delayTimer = 0;
|
2004-10-06 00:05:49 +00:00
|
|
|
d->scrollTimer = 0;
|
|
|
|
d->scrollIncrement = 0;
|
2004-09-30 18:04:09 +00:00
|
|
|
d->dirtyLayout = false;
|
2005-01-09 23:37:07 +00:00
|
|
|
d->blockViewport = false;
|
2004-10-20 16:41:13 +00:00
|
|
|
d->messageWindow = new PageViewMessage(this);
|
2004-09-27 21:36:25 +00:00
|
|
|
|
|
|
|
// widget setup: setup focus, accept drops and track mouse
|
|
|
|
viewport()->setFocusProxy( this );
|
|
|
|
viewport()->setFocusPolicy( StrongFocus );
|
2004-11-16 17:36:02 +00:00
|
|
|
//viewport()->setPaletteBackgroundColor( Qt::white );
|
|
|
|
viewport()->setBackgroundMode( Qt::NoBackground );
|
2004-09-27 21:36:25 +00:00
|
|
|
setResizePolicy( Manual );
|
2004-09-26 23:39:39 +00:00
|
|
|
setAcceptDrops( true );
|
2004-09-30 18:16:12 +00:00
|
|
|
setDragAutoScroll( false );
|
2004-09-26 23:39:39 +00:00
|
|
|
viewport()->setMouseTracking( true );
|
2004-09-27 21:36:25 +00:00
|
|
|
|
|
|
|
// conntect the padding of the viewport to pixmaps requests
|
|
|
|
connect( this, SIGNAL(contentsMoving(int, int)), this, SLOT(slotRequestVisiblePixmaps(int, int)) );
|
2004-09-26 23:39:39 +00:00
|
|
|
|
2005-01-02 14:29:37 +00:00
|
|
|
// show initial welcome text
|
|
|
|
d->messageWindow->display( i18n( "Welcome" ), PageViewMessage::Info, 2000 );
|
2004-12-10 16:04:45 +00:00
|
|
|
|
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(...);
|
|
|
|
}
|
|
|
|
|
|
|
|
PageView::~PageView()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2004-10-27 14:13:17 +00:00
|
|
|
void PageView::setupActions( KActionCollection * ac )
|
2004-09-26 23:39:39 +00:00
|
|
|
{
|
2004-09-30 18:04:09 +00:00
|
|
|
// Zoom actions ( higher scales takes lots of memory! )
|
2004-09-30 18:16:12 +00:00
|
|
|
d->aZoom = new KSelectAction( i18n( "Zoom" ), "viewmag", 0, this, SLOT( slotZoom() ), ac, "zoom_to" );
|
2004-09-30 18:04:09 +00:00
|
|
|
d->aZoom->setEditable( true );
|
|
|
|
updateZoomText();
|
2004-09-26 23:39:39 +00:00
|
|
|
|
|
|
|
KStdAction::zoomIn( this, SLOT( slotZoomIn() ), ac, "zoom_in" );
|
|
|
|
|
|
|
|
KStdAction::zoomOut( this, SLOT( slotZoomOut() ), ac, "zoom_out" );
|
|
|
|
|
|
|
|
d->aZoomFitWidth = new KToggleAction( i18n("Fit to Page &Width"), "viewmagfit", 0, ac, "zoom_fit_width" );
|
|
|
|
connect( d->aZoomFitWidth, SIGNAL( toggled( bool ) ), SLOT( slotFitToWidthToggled( bool ) ) );
|
|
|
|
|
|
|
|
d->aZoomFitPage = new KToggleAction( i18n("Fit to &Page"), "viewmagfit", 0, ac, "zoom_fit_page" );
|
|
|
|
connect( d->aZoomFitPage, SIGNAL( toggled( bool ) ), SLOT( slotFitToPageToggled( bool ) ) );
|
|
|
|
|
2004-09-30 18:16:12 +00:00
|
|
|
d->aZoomFitText = new KToggleAction( i18n("Fit to &Text"), "viewmagfit", 0, ac, "zoom_fit_text" );
|
2004-09-30 18:04:09 +00:00
|
|
|
connect( d->aZoomFitText, SIGNAL( toggled( bool ) ), SLOT( slotFitToTextToggled( bool ) ) );
|
|
|
|
|
2004-09-26 23:39:39 +00:00
|
|
|
// View-Layout actions
|
2005-01-11 17:35:07 +00:00
|
|
|
d->aViewTwoPages = new KToggleAction( i18n("&Two Pages"), "view_left_right", 0, ac, "view_twopages" );
|
2004-09-27 21:36:25 +00:00
|
|
|
connect( d->aViewTwoPages, SIGNAL( toggled( bool ) ), SLOT( slotTwoPagesToggled( bool ) ) );
|
2004-10-29 13:33:51 +00:00
|
|
|
d->aViewTwoPages->setChecked( Settings::viewColumns() > 1 );
|
2004-09-26 23:39:39 +00:00
|
|
|
|
2005-01-11 17:35:07 +00:00
|
|
|
d->aViewContinous = new KToggleAction( i18n("&Continous"), "view_text", 0, ac, "view_continous" );
|
2004-09-27 21:36:25 +00:00
|
|
|
connect( d->aViewContinous, SIGNAL( toggled( bool ) ), SLOT( slotContinousToggled( bool ) ) );
|
2004-10-27 14:13:17 +00:00
|
|
|
d->aViewContinous->setChecked( Settings::viewContinous() );
|
2004-09-26 23:39:39 +00:00
|
|
|
|
|
|
|
// Mouse-Mode actions
|
2005-01-11 17:35:07 +00:00
|
|
|
KToggleAction * mn = new KRadioAction( i18n("&Normal"), "mouse", 0, this, SLOT( slotSetMouseNormal() ), ac, "mouse_drag" );
|
2004-11-03 17:35:48 +00:00
|
|
|
mn->setExclusiveGroup( "MouseType" );
|
2004-09-26 23:39:39 +00:00
|
|
|
mn->setChecked( true );
|
|
|
|
|
2005-01-11 17:35:07 +00:00
|
|
|
KToggleAction * mz = new KRadioAction( i18n("&Zoom Tool"), "viewmag", 0, this, SLOT( slotSetMouseZoom() ), ac, "mouse_zoom" );
|
2004-11-03 17:35:48 +00:00
|
|
|
mz->setExclusiveGroup( "MouseType" );
|
|
|
|
|
2005-01-11 17:35:07 +00:00
|
|
|
KToggleAction * mst = new KRadioAction( i18n("&Select"), "frame_edit", 0, this, SLOT( slotSetMouseSelect() ), ac, "mouse_select" );
|
2004-11-03 17:35:48 +00:00
|
|
|
mst->setExclusiveGroup( "MouseType" );
|
|
|
|
|
2004-10-29 21:52:06 +00:00
|
|
|
d->aMouseEdit = new KRadioAction( i18n("Draw"), "edit", 0, this, SLOT( slotSetMouseDraw() ), ac, "mouse_draw" );
|
|
|
|
d->aMouseEdit->setExclusiveGroup("MouseType");
|
|
|
|
d->aMouseEdit->setEnabled( false ); // implement feature before removing this line
|
2004-09-26 23:39:39 +00:00
|
|
|
|
|
|
|
// Other actions
|
2004-10-06 00:05:49 +00:00
|
|
|
KAction * su = new KAction( i18n("Scroll Up"), 0, this, SLOT( slotScrollUp() ), ac, "view_scroll_up" );
|
|
|
|
su->setShortcut( "Shift+Up" );
|
|
|
|
|
|
|
|
KAction * sd = new KAction( i18n("Scroll Down"), 0, this, SLOT( slotScrollDown() ), ac, "view_scroll_down" );
|
|
|
|
sd->setShortcut( "Shift+Down" );
|
2004-09-26 23:39:39 +00:00
|
|
|
}
|
|
|
|
|
2005-01-10 13:43:44 +00:00
|
|
|
bool PageView::canFitPageWidth()
|
|
|
|
{
|
|
|
|
return Settings::viewColumns() != 1 || d->zoomMode != ZoomFitWidth;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
Settings::setViewColumns( 1 );
|
|
|
|
d->aZoomFitWidth->setChecked( true );
|
|
|
|
d->aZoomFitPage->setChecked( false );
|
|
|
|
d->aZoomFitText->setChecked( false );
|
|
|
|
d->aViewTwoPages->setChecked( false );
|
|
|
|
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();
|
2004-12-04 23:23:18 +00:00
|
|
|
}
|
|
|
|
|
2004-09-26 23:39:39 +00:00
|
|
|
|
2005-01-09 23:37:07 +00:00
|
|
|
//BEGIN DocumentObserver inherited methods
|
|
|
|
void PageView::notifySetup( const QValueVector< KPDFPage * > & pageSet, bool documentChanged )
|
2004-10-10 13:21:30 +00:00
|
|
|
{
|
|
|
|
// reuse current pages if nothing new
|
2004-11-05 00:14:00 +00:00
|
|
|
if ( ( pageSet.count() == d->items.count() ) && !documentChanged )
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete all widgets (one for each page in pageSet)
|
2004-11-05 00:14:00 +00:00
|
|
|
QValueVector< PageViewItem * >::iterator dIt = d->items.begin(), dEnd = d->items.end();
|
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();
|
2004-09-26 23:39:39 +00:00
|
|
|
|
|
|
|
// create children widgets
|
|
|
|
QValueVector< KPDFPage * >::const_iterator setIt = pageSet.begin(), setEnd = pageSet.end();
|
|
|
|
for ( ; setIt != setEnd; ++setIt )
|
2004-11-05 00:14:00 +00:00
|
|
|
d->items.push_back( new PageViewItem( *setIt ) );
|
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
|
2004-09-30 18:04:09 +00:00
|
|
|
d->dirtyLayout = true;
|
2004-10-29 20:20:21 +00:00
|
|
|
|
|
|
|
// OSD to display pages
|
2004-12-30 22:43:15 +00:00
|
|
|
if ( documentChanged && pageSet.count() > 0 && Settings::showOSD() )
|
2004-10-29 20:20:21 +00:00
|
|
|
d->messageWindow->display(
|
2004-12-10 16:04:45 +00:00
|
|
|
i18n(" Loaded a one page document.",
|
|
|
|
" Loaded a %n pages document.",
|
2004-11-30 20:03:45 +00:00
|
|
|
pageSet.count() ),
|
2004-10-29 20:20:21 +00:00
|
|
|
PageViewMessage::Info, 4000 );
|
2004-09-26 23:39:39 +00:00
|
|
|
}
|
|
|
|
|
2005-01-09 23:37:07 +00:00
|
|
|
void PageView::notifyViewportChanged()
|
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
|
|
|
|
const DocumentViewport & viewport = d->document->viewport();
|
|
|
|
PageViewItem * item = 0;
|
2004-11-05 00:14:00 +00:00
|
|
|
QValueVector< PageViewItem * >::iterator iIt = d->items.begin(), iEnd = d->items.end();
|
|
|
|
for ( ; iIt != iEnd; ++iIt )
|
2005-01-09 23:37:07 +00:00
|
|
|
if ( (*iIt)->pageNumber() == viewport.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 )
|
|
|
|
{
|
|
|
|
kdDebug() << "viewport has no matching item!" << endl;
|
2004-09-30 18:16:12 +00:00
|
|
|
return;
|
2005-01-09 23:37:07 +00:00
|
|
|
}
|
2004-09-26 23:39:39 +00:00
|
|
|
|
2004-10-10 13:21:30 +00:00
|
|
|
// relayout in "Single Pages" mode or if a relayout is pending
|
2004-10-29 13:33:51 +00:00
|
|
|
if ( !Settings::viewContinous() || d->dirtyLayout )
|
2004-09-30 18:16:12 +00:00
|
|
|
slotRelayoutPages();
|
|
|
|
|
2005-01-09 23:37:07 +00:00
|
|
|
// restore viewport or use default x-center, v-top alignment
|
|
|
|
const QRect & r = item->geometry();
|
|
|
|
if ( viewport.reCenter.enabled )
|
2004-11-05 18:14:20 +00:00
|
|
|
{
|
2005-01-09 23:37:07 +00:00
|
|
|
int xCenter = (int)( viewport.reCenter.normalizedCenterX * (float)r.width() );
|
|
|
|
int yCenter = (int)( viewport.reCenter.normalizedCenterY * (float)r.height() );
|
|
|
|
center( r.left() + xCenter, r.top() + yCenter );
|
2004-11-05 18:14:20 +00:00
|
|
|
}
|
2005-01-09 23:37:07 +00:00
|
|
|
else
|
|
|
|
center( r.left() + r.width() / 2, r.top() + visibleHeight() / 2 - 10 );
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2005-01-09 23:37:07 +00:00
|
|
|
// since the page has moved below cursor, update it
|
2005-01-01 21:50:34 +00:00
|
|
|
updateCursor( viewportToContents( mapFromGlobal( QCursor::pos() ) ) );
|
2004-09-26 23:39:39 +00:00
|
|
|
}
|
2004-12-21 12:38:52 +00:00
|
|
|
|
2005-01-10 13:43:44 +00:00
|
|
|
void PageView::notifyPageChanged( int pageNumber, int /*changedFlags*/ )
|
2004-12-21 12:38:52 +00:00
|
|
|
{
|
2005-01-09 23:37:07 +00:00
|
|
|
// only handle pixmap changed notifies (the only defined for now)
|
|
|
|
//if ( !(changedFlags & DocumentObserver::Pixmap) )
|
|
|
|
// return;
|
2004-12-21 12:38:52 +00:00
|
|
|
|
2005-01-09 23:37:07 +00:00
|
|
|
// iterate over visible items: if page(pageNumber) is one of them, repaint it
|
|
|
|
QValueList< PageViewItem * >::iterator iIt = d->visibleItems.begin(), iEnd = d->visibleItems.end();
|
2004-12-21 12:38:52 +00:00
|
|
|
for ( ; iIt != iEnd; ++iIt )
|
|
|
|
if ( (*iIt)->pageNumber() == pageNumber )
|
|
|
|
{
|
|
|
|
// update item's rectangle plus the little outline
|
|
|
|
QRect expandedRect = (*iIt)->geometry();
|
|
|
|
expandedRect.addCoords( -1, -1, 3, 3 );
|
|
|
|
updateContents( 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
|
2005-01-02 11:50:38 +00:00
|
|
|
updateCursor( viewportToContents( mapFromGlobal( QCursor::pos() ) ) );
|
|
|
|
}
|
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 )
|
|
|
|
slotRequestVisiblePixmaps();
|
2004-12-21 12:38:52 +00:00
|
|
|
}
|
2005-01-09 23:37:07 +00:00
|
|
|
|
|
|
|
bool PageView::canUnloadPixmap( int pageNumber )
|
|
|
|
{
|
|
|
|
// if the item is visible, forbid unloading
|
|
|
|
QValueList< PageViewItem * >::iterator vIt = d->visibleItems.begin(), vEnd = d->visibleItems.end();
|
|
|
|
for ( ; vIt != vEnd; ++vIt )
|
|
|
|
if ( (*vIt)->pageNumber() == pageNumber )
|
|
|
|
return false;
|
|
|
|
// if hidden premit unloading
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//END DocumentObserver inherited methods
|
2004-09-26 23:39:39 +00:00
|
|
|
|
2004-10-10 12:42:42 +00:00
|
|
|
//BEGIN widget events
|
2004-10-31 12:43:13 +00:00
|
|
|
void PageView::viewportPaintEvent( QPaintEvent * pe )
|
2004-11-01 14:22:24 +00:00
|
|
|
{
|
2004-10-31 12:43:13 +00:00
|
|
|
// create the rect into contents from the clipped screen rect
|
2004-10-31 13:55:07 +00:00
|
|
|
QRect viewportRect = viewport()->rect();
|
|
|
|
QRect contentsRect = pe->rect().intersect( viewportRect );
|
2004-10-31 12:43:13 +00:00
|
|
|
contentsRect.moveBy( contentsX(), contentsY() );
|
|
|
|
if ( !contentsRect.isValid() )
|
2004-10-30 23:59:09 +00:00
|
|
|
return;
|
2004-10-30 20:54:48 +00:00
|
|
|
|
2004-10-31 12:43:13 +00:00
|
|
|
// create the screen painter. a pixel painted ar contentsX,contentsY
|
|
|
|
// appears to the top-left corner of the scrollview.
|
|
|
|
QPainter screenPainter( viewport(), true );
|
|
|
|
screenPainter.translate( -contentsX(), -contentsY() );
|
2004-10-30 20:54:48 +00:00
|
|
|
|
2004-10-31 17:04:04 +00:00
|
|
|
// selectionRect is the normalized mouse selection rect
|
|
|
|
QRect selectionRect = d->mouseSelectionRect;
|
|
|
|
if ( !selectionRect.isNull() )
|
|
|
|
selectionRect = selectionRect.normalize();
|
|
|
|
// selectionRectInternal without the border
|
|
|
|
QRect selectionRectInternal = selectionRect;
|
|
|
|
selectionRectInternal.addCoords( 1, 1, -1, -1 );
|
|
|
|
// color for blending
|
|
|
|
QColor selBlendColor = (selectionRect.width() > 20 || selectionRect.height() > 20) ?
|
|
|
|
palette().active().highlight() : Qt::red;
|
|
|
|
|
2004-11-01 14:37:15 +00:00
|
|
|
// subdivide region into rects
|
2004-10-31 13:55:07 +00:00
|
|
|
QMemArray<QRect> allRects = pe->region().rects();
|
2004-10-31 17:04:04 +00:00
|
|
|
uint numRects = allRects.count();
|
2004-11-01 14:37:15 +00:00
|
|
|
|
|
|
|
// preprocess rects area to see if it worths or not using subdivision
|
|
|
|
uint summedArea = 0;
|
2004-10-31 13:55:07 +00:00
|
|
|
for ( uint i = 0; i < numRects; i++ )
|
2004-10-30 20:54:48 +00:00
|
|
|
{
|
2004-11-01 14:37:15 +00:00
|
|
|
const QRect & r = allRects[i];
|
|
|
|
summedArea += r.width() * r.height();
|
|
|
|
}
|
|
|
|
// very elementary check: SUMj(Region[j].area) is less than boundingRect.area
|
|
|
|
bool useSubdivision = summedArea < (0.7 * contentsRect.width() * contentsRect.height());
|
|
|
|
if ( !useSubdivision )
|
|
|
|
numRects = 1;
|
2004-11-08 13:13:46 +00:00
|
|
|
|
|
|
|
// iterate over the rects (only one loop if not using subdivision)
|
2004-11-01 14:37:15 +00:00
|
|
|
for ( uint i = 0; i < numRects; i++ )
|
|
|
|
{
|
|
|
|
if ( useSubdivision )
|
|
|
|
{
|
|
|
|
// set 'contentsRect' to a part of the sub-divided region
|
|
|
|
contentsRect = allRects[i].normalize().intersect( viewportRect );
|
|
|
|
contentsRect.moveBy( contentsX(), contentsY() );
|
|
|
|
if ( !contentsRect.isValid() )
|
|
|
|
continue;
|
|
|
|
}
|
2004-10-31 12:43:13 +00:00
|
|
|
|
2004-11-08 13:13:46 +00:00
|
|
|
// note: this check will take care of all things requiring alpha blending (not only selection)
|
|
|
|
bool wantCompositing = !selectionRect.isNull() && contentsRect.intersects( selectionRect );
|
|
|
|
|
|
|
|
if ( wantCompositing && !Settings::disableCompositing() )
|
2004-10-30 20:54:48 +00:00
|
|
|
{
|
2004-11-08 13:13:46 +00:00
|
|
|
// create pixmap and open a painter over it (contents{left,top} becomes pixmap {0,0})
|
2004-10-31 13:55:07 +00:00
|
|
|
QPixmap doubleBuffer( contentsRect.size() );
|
|
|
|
QPainter pixmapPainter( &doubleBuffer );
|
|
|
|
pixmapPainter.translate( -contentsRect.left(), -contentsRect.top() );
|
|
|
|
|
2004-11-01 14:22:24 +00:00
|
|
|
// 1) Layer 0: paint items and clear bg on unpainted rects
|
2004-11-03 17:35:48 +00:00
|
|
|
paintItems( &pixmapPainter, contentsRect );
|
2004-11-01 14:22:24 +00:00
|
|
|
// 2) Layer 1: pixmap manipulated areas
|
|
|
|
// 3) Layer 2: paint (blend) transparent selection
|
2004-11-08 13:13:46 +00:00
|
|
|
if ( !selectionRect.isNull() && selectionRect.intersects( contentsRect ) &&
|
|
|
|
!selectionRectInternal.contains( contentsRect ) )
|
2004-10-31 13:55:07 +00:00
|
|
|
{
|
2004-10-31 17:04:04 +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() );
|
|
|
|
copyBlt( &blendedPixmap, 0,0, &doubleBuffer,
|
|
|
|
blendRect.left() - contentsRect.left(), blendRect.top() - contentsRect.top(),
|
|
|
|
blendRect.width(), blendRect.height() );
|
|
|
|
// blend selBlendColor into the background pixmap
|
|
|
|
QImage blendedImage = blendedPixmap.convertToImage();
|
|
|
|
KImageEffect::blend( selBlendColor.dark(140), blendedImage, 0.2 );
|
|
|
|
// copy the blended pixmap back to its place
|
|
|
|
pixmapPainter.drawPixmap( blendRect.left(), blendRect.top(), blendedImage );
|
|
|
|
}
|
|
|
|
// draw border (red if the selection is too small)
|
|
|
|
pixmapPainter.setPen( selBlendColor );
|
|
|
|
pixmapPainter.drawRect( selectionRect );
|
2004-10-31 13:55:07 +00:00
|
|
|
}
|
2004-11-01 14:22:24 +00:00
|
|
|
// 4) Layer 3: overlays
|
2004-12-30 22:43:15 +00:00
|
|
|
if ( Settings::debugDrawBoundaries() )
|
2004-10-31 13:55:07 +00:00
|
|
|
{
|
|
|
|
pixmapPainter.setPen( Qt::blue );
|
|
|
|
pixmapPainter.drawRect( contentsRect );
|
|
|
|
}
|
2004-10-30 20:54:48 +00:00
|
|
|
|
2004-10-31 13:55:07 +00:00
|
|
|
// finish painting and draw contents
|
|
|
|
pixmapPainter.end();
|
|
|
|
screenPainter.drawPixmap( contentsRect.left(), contentsRect.top(), doubleBuffer );
|
|
|
|
}
|
2004-11-08 13:13:46 +00:00
|
|
|
else
|
2004-10-31 12:43:13 +00:00
|
|
|
{
|
2004-11-01 14:22:24 +00:00
|
|
|
// 1) Layer 0: paint items and clear bg on unpainted rects
|
2004-11-03 17:35:48 +00:00
|
|
|
paintItems( &screenPainter, contentsRect );
|
2004-11-01 14:22:24 +00:00
|
|
|
// 2) Layer 1: opaque manipulated ares (filled / contours)
|
|
|
|
// 3) Layer 2: paint opaque selection
|
2004-11-08 13:13:46 +00:00
|
|
|
if ( !selectionRect.isNull() && selectionRect.intersects( contentsRect ) &&
|
|
|
|
!selectionRectInternal.contains( contentsRect ) )
|
2004-10-31 13:55:07 +00:00
|
|
|
{
|
|
|
|
screenPainter.setPen( palette().active().highlight().dark(110) );
|
2004-11-08 13:13:46 +00:00
|
|
|
screenPainter.drawRect( selectionRect );
|
2004-10-31 13:55:07 +00:00
|
|
|
}
|
2004-11-01 14:22:24 +00:00
|
|
|
// 4) Layer 3: overlays
|
2004-12-30 22:43:15 +00:00
|
|
|
if ( Settings::debugDrawBoundaries() )
|
2004-10-31 13:55:07 +00:00
|
|
|
{
|
|
|
|
screenPainter.setPen( Qt::red );
|
|
|
|
screenPainter.drawRect( contentsRect );
|
|
|
|
}
|
2004-10-31 12:43:13 +00:00
|
|
|
}
|
2004-10-30 20:54:48 +00:00
|
|
|
}
|
2004-10-29 21:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PageView::viewportResizeEvent( QResizeEvent * )
|
|
|
|
{
|
|
|
|
// start a timer that will refresh the pixmap after 0.5s
|
|
|
|
if ( !d->delayTimer )
|
|
|
|
{
|
|
|
|
d->delayTimer = new QTimer( this );
|
|
|
|
connect( d->delayTimer, SIGNAL( timeout() ), this, SLOT( slotRelayoutPages() ) );
|
|
|
|
}
|
2005-01-09 23:37:07 +00:00
|
|
|
d->delayTimer->start( 333, true );
|
2004-10-29 21:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PageView::keyPressEvent( QKeyEvent * e )
|
|
|
|
{
|
|
|
|
e->accept();
|
|
|
|
// move/scroll page by using keys
|
|
|
|
switch ( e->key() )
|
|
|
|
{
|
|
|
|
case Key_Up:
|
2004-11-05 01:11:50 +00:00
|
|
|
case Key_PageUp:
|
2004-10-29 21:52:06 +00:00
|
|
|
// if in single page mode and at the top of the screen, go to previous page
|
2004-11-05 01:11:50 +00:00
|
|
|
if ( Settings::viewContinous() || verticalScrollBar()->value() > verticalScrollBar()->minValue() )
|
|
|
|
{
|
|
|
|
if ( e->key() == Key_Up )
|
|
|
|
verticalScrollBar()->subtractLine();
|
|
|
|
else
|
|
|
|
verticalScrollBar()->subtractPage();
|
|
|
|
}
|
2005-01-09 23:37:07 +00:00
|
|
|
else if ( d->document->currentPage() > 0 )
|
|
|
|
{
|
|
|
|
// more optimized than document->setPrevPage and then move view to bottom
|
|
|
|
DocumentViewport newViewport = d->document->viewport();
|
|
|
|
newViewport.pageNumber -= 1;
|
|
|
|
newViewport.reCenter.enabled = true;
|
|
|
|
newViewport.reCenter.normalizedCenterY = 1.0;
|
|
|
|
d->document->setViewport( newViewport );
|
|
|
|
}
|
2004-10-29 21:52:06 +00:00
|
|
|
break;
|
|
|
|
case Key_Down:
|
2004-11-05 01:11:50 +00:00
|
|
|
case Key_PageDown:
|
2004-10-29 21:52:06 +00:00
|
|
|
// if in single page mode and at the bottom of the screen, go to next page
|
2004-11-05 01:11:50 +00:00
|
|
|
if ( Settings::viewContinous() || verticalScrollBar()->value() < verticalScrollBar()->maxValue() )
|
|
|
|
{
|
|
|
|
if ( e->key() == Key_Down )
|
|
|
|
verticalScrollBar()->addLine();
|
|
|
|
else
|
|
|
|
verticalScrollBar()->addPage();
|
|
|
|
}
|
2005-01-09 23:37:07 +00:00
|
|
|
else if ( d->document->currentPage() < d->items.count() - 1 )
|
|
|
|
{
|
|
|
|
// more optmized than document->setNextPage and then move view to top
|
|
|
|
DocumentViewport newViewport = d->document->viewport();
|
|
|
|
newViewport.pageNumber += 1;
|
|
|
|
newViewport.reCenter.enabled = true;
|
|
|
|
newViewport.reCenter.normalizedCenterY = 0.0;
|
|
|
|
d->document->setViewport( newViewport );
|
|
|
|
}
|
2004-10-29 21:52:06 +00:00
|
|
|
break;
|
|
|
|
case Key_Left:
|
|
|
|
horizontalScrollBar()->subtractLine();
|
|
|
|
break;
|
|
|
|
case Key_Right:
|
|
|
|
horizontalScrollBar()->addLine();
|
|
|
|
break;
|
|
|
|
case Key_Shift:
|
|
|
|
case Key_Control:
|
|
|
|
if ( d->scrollTimer )
|
|
|
|
{
|
|
|
|
if ( d->scrollTimer->isActive() )
|
|
|
|
d->scrollTimer->stop();
|
|
|
|
else
|
|
|
|
slotAutoScoll();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
e->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// if a known key has been pressed, stop scrolling the page
|
|
|
|
if ( d->scrollTimer )
|
|
|
|
{
|
|
|
|
d->scrollIncrement = 0;
|
|
|
|
d->scrollTimer->stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageView::contentsMouseMoveEvent( QMouseEvent * e )
|
|
|
|
{
|
2004-11-16 17:36:02 +00:00
|
|
|
// if holding mouse mid button, perform zoom
|
|
|
|
if ( (e->state() & MidButton) && d->mouseMidStartY > 0 )
|
|
|
|
{
|
|
|
|
int deltaY = d->mouseMidStartY - e->globalPos().y();
|
|
|
|
d->mouseMidStartY = e->globalPos().y();
|
|
|
|
d->zoomFactor *= ( 1.0 + ( (double)deltaY / 500.0 ) );
|
|
|
|
updateZoom( ZoomRefreshCurrent );
|
2004-12-10 16:04:45 +00:00
|
|
|
// uncomment following line to force a complete redraw
|
|
|
|
viewport()->repaint( false );
|
2004-11-16 17:36:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-10-29 21:52:06 +00:00
|
|
|
|
2004-11-16 17:36:02 +00:00
|
|
|
bool leftButton = e->state() & LeftButton;
|
2004-10-29 21:52:06 +00:00
|
|
|
switch ( d->mouseMode )
|
|
|
|
{
|
|
|
|
case MouseNormal:
|
|
|
|
if ( leftButton )
|
|
|
|
{
|
|
|
|
// drag page
|
|
|
|
if ( !d->mouseGrabPos.isNull() )
|
|
|
|
{
|
|
|
|
// scroll page by position increment
|
|
|
|
QPoint delta = d->mouseGrabPos - e->globalPos();
|
|
|
|
scrollBy( delta.x(), delta.y() );
|
|
|
|
d->mouseGrabPos = e->globalPos();
|
|
|
|
// if the page was scrolling, stop it
|
|
|
|
if ( d->scrollTimer )
|
|
|
|
{
|
|
|
|
d->scrollIncrement = 0;
|
|
|
|
d->scrollTimer->stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-11-03 17:35:48 +00:00
|
|
|
else // only hovering the page
|
2004-10-29 21:52:06 +00:00
|
|
|
{
|
2004-12-26 21:20:17 +00:00
|
|
|
updateCursor( e->pos() );
|
2004-10-31 17:12:52 +00:00
|
|
|
}
|
2004-10-29 21:52:06 +00:00
|
|
|
break;
|
|
|
|
|
2004-11-03 17:35:48 +00:00
|
|
|
case MouseZoom:
|
2004-11-16 17:36:02 +00:00
|
|
|
case MouseSelect:
|
2004-10-30 20:54:48 +00:00
|
|
|
// set second corner of selection in selection pageItem
|
2004-11-03 17:35:48 +00:00
|
|
|
if ( leftButton && !d->mouseSelectionRect.isNull() )
|
|
|
|
selectionEndPoint( e->x(), e->y() );
|
2004-10-29 21:52:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MouseEdit: // ? update graphics ?
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-26 23:39:39 +00:00
|
|
|
void PageView::contentsMousePressEvent( QMouseEvent * e )
|
|
|
|
{
|
2004-11-16 17:36:02 +00:00
|
|
|
// if pressing mid mouse button while not doing other things, begin 'comtinous zoom' mode
|
|
|
|
if ( (e->button() & MidButton) && d->mouseSelectionRect.isNull() )
|
|
|
|
{
|
|
|
|
d->mouseMidStartY = e->globalPos().y();
|
|
|
|
setCursor( sizeVerCursor );
|
|
|
|
return;
|
|
|
|
}
|
2004-10-20 16:41:13 +00:00
|
|
|
|
|
|
|
// handle mode dependant mouse press actions
|
2004-11-16 17:36:02 +00:00
|
|
|
bool leftButton = e->button() & LeftButton;
|
2004-09-26 23:39:39 +00:00
|
|
|
switch ( d->mouseMode )
|
|
|
|
{
|
2004-10-20 16:41:13 +00:00
|
|
|
case MouseNormal: // drag start / click / link following
|
|
|
|
if ( leftButton )
|
2004-09-30 18:16:12 +00:00
|
|
|
{
|
2004-10-20 16:41:13 +00:00
|
|
|
d->mouseStartPos = e->globalPos();
|
2004-12-10 16:04:45 +00:00
|
|
|
d->mouseGrabPos = d->mouseOnRect ? QPoint() : d->mouseStartPos;
|
|
|
|
if ( !d->mouseOnRect )
|
2004-10-20 16:41:13 +00:00
|
|
|
setCursor( sizeAllCursor );
|
2004-09-30 18:16:12 +00:00
|
|
|
}
|
2004-10-20 16:41:13 +00:00
|
|
|
break;
|
2004-09-26 23:39:39 +00:00
|
|
|
|
2004-11-03 17:35:48 +00:00
|
|
|
case MouseZoom:
|
2004-11-16 17:36:02 +00:00
|
|
|
case MouseSelect: // set first corner of the selection rect
|
2004-11-03 17:35:48 +00:00
|
|
|
if ( leftButton )
|
|
|
|
selectionStart( e->x(), e->y(), false );
|
|
|
|
break;
|
|
|
|
|
2004-10-20 16:41:13 +00:00
|
|
|
case MouseEdit: // ? place the beginning of [tool] ?
|
|
|
|
break;
|
2004-09-26 23:39:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-28 13:53:47 +00:00
|
|
|
void PageView::contentsMouseReleaseEvent( QMouseEvent * e )
|
2004-09-26 23:39:39 +00:00
|
|
|
{
|
2004-11-16 17:36:02 +00:00
|
|
|
// handle mode indepent mid buttom zoom
|
|
|
|
if ( (e->state() & MidButton) && d->mouseMidStartY > 0 )
|
|
|
|
{
|
|
|
|
d->mouseMidStartY = -1;
|
2005-01-02 11:50:38 +00:00
|
|
|
// while drag-zooming we could have gone over a link
|
|
|
|
updateCursor( e->pos() );
|
2004-11-16 17:36:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-10-06 00:05:49 +00:00
|
|
|
bool leftButton = e->button() & LeftButton,
|
|
|
|
rightButton = e->button() & RightButton;
|
2004-09-26 23:39:39 +00:00
|
|
|
switch ( d->mouseMode )
|
|
|
|
{
|
2004-11-16 17:36:02 +00:00
|
|
|
case MouseNormal:{ // do Follow Link or Display RMB
|
2005-01-02 11:50:38 +00:00
|
|
|
// return the cursor to its normal state after dragging
|
|
|
|
if (cursor().shape() == Qt::SizeAllCursor) updateCursor( e->pos() );
|
|
|
|
|
2005-01-02 17:24:50 +00:00
|
|
|
PageViewItem * pageItem = pickItemOnPoint( e->x(), e->y() );
|
|
|
|
|
2005-01-02 11:50:38 +00:00
|
|
|
// avoid the situation in where you click on a "row" that has a link but you are not over it
|
|
|
|
// drag a bit and move the mouse left to place it over the link while dragging
|
|
|
|
// release the button and BOOM you get the link followed
|
2005-01-02 17:24:50 +00:00
|
|
|
if ( leftButton && pageItem && d->mouseStartPos == e->globalPos())
|
2004-10-02 14:30:30 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
const KPDFPageRect * rect = pageItem->page()->getRect(
|
|
|
|
e->x() - pageItem->geometry().left(),
|
|
|
|
e->y() - pageItem->geometry().top()
|
|
|
|
);
|
|
|
|
if ( rect )
|
2004-10-20 16:41:13 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
// release over a link
|
|
|
|
if ( rect->pointerType() == KPDFPageRect::Link )
|
|
|
|
{
|
|
|
|
const KPDFLink * link = static_cast< const KPDFLink * >( rect->pointer() );
|
|
|
|
d->document->processLink( link );
|
|
|
|
}
|
|
|
|
// release over an image
|
|
|
|
if ( rect->pointerType() == KPDFPageRect::Image )
|
|
|
|
{
|
|
|
|
}
|
2004-10-20 16:41:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// mouse not moved since press, so we have a click. select the page.
|
2005-01-10 13:43:44 +00:00
|
|
|
d->document->setViewportPage( pageItem->pageNumber(), PAGEVIEW_ID );
|
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
|
|
|
{
|
2004-12-04 23:23:18 +00:00
|
|
|
if (pageItem) emit rightClick(pageItem->page(), e->globalPos());
|
|
|
|
else emit rightClick(0, e->globalPos());
|
2004-09-28 13:53:47 +00:00
|
|
|
}
|
2004-10-20 16:41:13 +00:00
|
|
|
// reset start position
|
|
|
|
d->mouseStartPos = QPoint();
|
2004-11-16 17:36:02 +00:00
|
|
|
}break;
|
2004-09-26 23:39:39 +00:00
|
|
|
|
2004-11-16 17:36:02 +00:00
|
|
|
case MouseZoom: // do ZOOM
|
2004-11-03 17:35:48 +00:00
|
|
|
if ( leftButton && !d->mouseSelectionRect.isNull() )
|
|
|
|
{
|
2004-11-05 01:11:50 +00:00
|
|
|
QRect selRect = d->mouseSelectionRect.normalize();
|
2004-11-10 17:08:46 +00:00
|
|
|
if ( selRect.width() < 4 || selRect.height() < 4 )
|
2004-11-05 01:11:50 +00:00
|
|
|
break;
|
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)
|
|
|
|
double zoom = QMIN( (double)visibleWidth() / (double)selRect.width(), (double)visibleHeight() / (double)selRect.height() );
|
2004-11-10 17:08:46 +00:00
|
|
|
double nX = (double)(selRect.left() + selRect.right()) / (2.0 * (double)contentsWidth());
|
|
|
|
double nY = (double)(selRect.top() + selRect.bottom()) / (2.0 * (double)contentsHeight());
|
2004-11-03 17:35:48 +00:00
|
|
|
|
|
|
|
// zoom up to 400%
|
|
|
|
if ( d->zoomFactor <= 4.0 || zoom <= 1.0 )
|
|
|
|
{
|
|
|
|
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
|
2004-11-03 17:35:48 +00:00
|
|
|
center( (int)(nX * contentsWidth()), (int)(nY * contentsHeight()) );
|
2004-11-05 01:11:50 +00:00
|
|
|
updateContents();
|
2004-11-03 17:35:48 +00:00
|
|
|
|
|
|
|
// hide message box and delete overlay window
|
|
|
|
selectionClear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// if in ZoomRect mode, right click zooms out
|
2004-11-05 01:11:50 +00:00
|
|
|
else if ( rightButton )
|
2004-11-03 17:35:48 +00:00
|
|
|
{
|
|
|
|
updateZoom( ZoomOut );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-11-16 17:36:02 +00:00
|
|
|
case MouseSelect:{ // do SELECT
|
|
|
|
if ( !leftButton || d->mouseSelectionRect.isNull() )
|
|
|
|
break;
|
2004-10-20 16:41:13 +00:00
|
|
|
|
2004-11-16 17:36:02 +00:00
|
|
|
QRect selectionRect = d->mouseSelectionRect.normalize();
|
|
|
|
if ( selectionRect.width() < 5 || selectionRect.height() < 5 )
|
2005-01-02 10:46:33 +00:00
|
|
|
{
|
|
|
|
selectionClear();
|
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
|
|
|
|
2004-11-16 17:36:02 +00:00
|
|
|
// grab text in selection by extracting it from all intersected pages
|
|
|
|
QString selectedText;
|
|
|
|
QValueVector< PageViewItem * >::iterator iIt = d->items.begin(), iEnd = d->items.end();
|
|
|
|
for ( ; iIt != iEnd; ++iIt )
|
|
|
|
{
|
|
|
|
PageViewItem * item = *iIt;
|
|
|
|
const QRect & itemRect = item->geometry();
|
|
|
|
if ( selectionRect.intersects( itemRect ) )
|
|
|
|
{
|
|
|
|
// request the textpage if there isn't one
|
|
|
|
const KPDFPage * kpdfPage = item->page();
|
|
|
|
if ( !kpdfPage->hasSearchPage() )
|
|
|
|
d->document->requestTextPage( kpdfPage->number() );
|
|
|
|
// grab text
|
|
|
|
QRect relativeRect = selectionRect.intersect( itemRect );
|
|
|
|
relativeRect.moveBy( -itemRect.left(), -itemRect.top() );
|
|
|
|
selectedText += kpdfPage->getTextInRect( relativeRect, item->zoomFactor() );
|
|
|
|
}
|
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
|
|
|
|
KPopupMenu menu( this );
|
|
|
|
if ( !selectedText.isEmpty() )
|
|
|
|
{
|
|
|
|
menu.insertTitle( i18n( "Text ( %1 characters )" ).arg( selectedText.length() ) );
|
|
|
|
menu.insertItem( SmallIcon("editcopy"), i18n( "Copy to Clipboard" ), 1 );
|
|
|
|
}
|
|
|
|
menu.insertTitle( i18n( "Image ( %1 by %2 pixels )" ).arg( selectionRect.width() ).arg( selectionRect.height() ) );
|
|
|
|
menu.insertItem( SmallIcon("image"), i18n( "Copy to Clipboard" ), 2 );
|
2005-01-02 17:12:35 +00:00
|
|
|
menu.insertItem( SmallIcon("filesave"), i18n( "Save to File..." ), 3 );
|
2004-11-16 17:36:02 +00:00
|
|
|
int choice = menu.exec( e->globalPos() );
|
|
|
|
// IMAGE operation choosen
|
|
|
|
if ( choice > 1 )
|
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( ©Pix );
|
|
|
|
copyPainter.translate( -selectionRect.left(), -selectionRect.top() );
|
|
|
|
paintItems( ©Painter, selectionRect );
|
|
|
|
|
|
|
|
if ( choice == 2 )
|
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 );
|
|
|
|
d->messageWindow->display( i18n( "Image [%1x%2] copied to clipboard." ).arg( copyPix.width() ).arg( copyPix.height() ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// [3] save pixmap to file
|
|
|
|
QString fileName = KFileDialog::getSaveFileName( QString::null, "image/png image/jpeg", this );
|
|
|
|
if ( fileName.isNull() )
|
|
|
|
d->messageWindow->display( i18n( "File not saved." ), PageViewMessage::Warning );
|
|
|
|
else
|
2004-11-03 17:35:48 +00:00
|
|
|
{
|
2004-11-16 17:36:02 +00:00
|
|
|
QString type( KImageIO::type( fileName ) );
|
|
|
|
if ( type.isNull() )
|
|
|
|
type = "PNG";
|
|
|
|
copyPix.save( fileName, type.latin1() );
|
|
|
|
d->messageWindow->display( i18n( "Image [%1x%2] saved to %3 file." ).arg( copyPix.width() ).arg( copyPix.height() ).arg( type ) );
|
2004-11-03 17:35:48 +00:00
|
|
|
}
|
|
|
|
}
|
2004-10-20 16:41:13 +00:00
|
|
|
}
|
2004-11-16 17:36:02 +00:00
|
|
|
// TEXT operation choosen
|
|
|
|
else if ( choice == 1 )
|
|
|
|
{
|
|
|
|
QClipboard *cb = QApplication::clipboard();
|
|
|
|
cb->setText( selectedText, QClipboard::Clipboard );
|
|
|
|
if ( cb->supportsSelection() )
|
|
|
|
cb->setText( selectedText, QClipboard::Selection );
|
|
|
|
}
|
|
|
|
|
|
|
|
// clear widget selection and invalidate rect
|
|
|
|
selectionClear();
|
|
|
|
}break;
|
2004-09-26 23:39:39 +00:00
|
|
|
|
2004-10-20 16:41:13 +00:00
|
|
|
case MouseEdit: // ? apply [tool] ?
|
|
|
|
break;
|
2004-09-26 23:39:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageView::wheelEvent( QWheelEvent *e )
|
|
|
|
{
|
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();
|
|
|
|
if ( (e->state() & ControlButton) == ControlButton ) {
|
2004-10-24 07:06:04 +00:00
|
|
|
if ( e->delta() < 0 )
|
2004-09-26 23:39:39 +00:00
|
|
|
slotZoomOut();
|
|
|
|
else
|
|
|
|
slotZoomIn();
|
|
|
|
}
|
2004-10-29 21:52:06 +00:00
|
|
|
else if ( delta <= -120 && !Settings::viewContinous() && vScroll == verticalScrollBar()->maxValue() )
|
2004-09-30 18:16:12 +00:00
|
|
|
{
|
2004-10-29 21:52:06 +00:00
|
|
|
// go to next page
|
2005-01-09 23:37:07 +00:00
|
|
|
if ( d->document->currentPage() < d->items.count() - 1 )
|
|
|
|
{
|
|
|
|
// more optmized than document->setNextPage and then move view to top
|
|
|
|
DocumentViewport newViewport = d->document->viewport();
|
|
|
|
newViewport.pageNumber += 1;
|
|
|
|
newViewport.reCenter.enabled = true;
|
|
|
|
newViewport.reCenter.normalizedCenterY = 0.0;
|
|
|
|
d->document->setViewport( newViewport );
|
|
|
|
}
|
2004-09-30 18:16:12 +00:00
|
|
|
}
|
2004-10-29 21:52:06 +00:00
|
|
|
else if ( delta >= 120 && !Settings::viewContinous() && vScroll == verticalScrollBar()->minValue() )
|
|
|
|
{
|
|
|
|
// 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-01-09 23:37:07 +00:00
|
|
|
// more optmized than document->setPrevPage and then move view to bottom
|
|
|
|
DocumentViewport newViewport = d->document->viewport();
|
|
|
|
newViewport.pageNumber -= 1;
|
|
|
|
newViewport.reCenter.enabled = true;
|
|
|
|
newViewport.reCenter.normalizedCenterY = 1.0;
|
|
|
|
d->document->setViewport( newViewport );
|
2004-12-12 22:57:54 +00:00
|
|
|
}
|
2004-10-29 21:52:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
QScrollView::wheelEvent( e );
|
2005-01-02 17:12:35 +00:00
|
|
|
|
2004-12-26 21:20:17 +00:00
|
|
|
QPoint cp = viewportToContents(e->pos());
|
|
|
|
updateCursor(cp);
|
2004-09-30 18:16:12 +00:00
|
|
|
}
|
|
|
|
|
2004-09-26 23:39:39 +00:00
|
|
|
void PageView::dragEnterEvent( QDragEnterEvent * ev )
|
|
|
|
{
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageView::dropEvent( QDropEvent * ev )
|
|
|
|
{
|
|
|
|
KURL::List lst;
|
|
|
|
if ( KURLDrag::decode( ev, lst ) )
|
|
|
|
emit urlDropped( lst.first() );
|
|
|
|
}
|
|
|
|
//END widget events
|
|
|
|
|
2004-11-03 17:35:48 +00:00
|
|
|
void PageView::paintItems( QPainter * p, const QRect & contentsRect )
|
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;
|
|
|
|
checkRect.addCoords( -3, -3, 1, 1 );
|
|
|
|
|
2004-11-03 17:35:48 +00:00
|
|
|
// create a region from wich we'll subtract painted rects
|
|
|
|
QRegion remainingArea( contentsRect );
|
|
|
|
|
2004-11-05 00:14:00 +00:00
|
|
|
QValueVector< PageViewItem * >::iterator iIt = d->items.begin(), iEnd = d->items.end();
|
|
|
|
for ( ; iIt != iEnd; ++iIt )
|
2004-10-30 20:54:48 +00:00
|
|
|
{
|
|
|
|
// check if a piece of the page intersects the contents rect
|
2004-11-05 18:14:20 +00:00
|
|
|
if ( !(*iIt)->geometry().intersects( checkRect ) )
|
|
|
|
continue;
|
2004-10-30 20:54:48 +00:00
|
|
|
|
2004-11-05 18:14:20 +00:00
|
|
|
PageViewItem * item = *iIt;
|
|
|
|
QRect pixmapGeometry = item->geometry();
|
2004-10-30 20:54:48 +00:00
|
|
|
|
2004-11-05 18:14:20 +00:00
|
|
|
// translate the painter so we draw top-left pixmap corner in 0,0
|
|
|
|
p->save();
|
|
|
|
p->translate( pixmapGeometry.left(), pixmapGeometry.top() );
|
2004-10-30 20:54:48 +00:00
|
|
|
|
2004-11-05 18:14:20 +00:00
|
|
|
// item pixmap and outline geometry
|
|
|
|
QRect outlineGeometry = pixmapGeometry;
|
|
|
|
outlineGeometry.addCoords( -1, -1, 3, 3 );
|
|
|
|
|
|
|
|
// draw the page outline (little black border and 2px shadow)
|
|
|
|
if ( !pixmapGeometry.contains( contentsRect ) )
|
|
|
|
{
|
|
|
|
int pixmapWidth = pixmapGeometry.width(),
|
|
|
|
pixmapHeight = pixmapGeometry.height();
|
|
|
|
// draw simple outline
|
|
|
|
p->setPen( Qt::black );
|
|
|
|
p->drawRect( -1, -1, pixmapWidth + 2, pixmapHeight + 2 );
|
|
|
|
// draw bottom/right gradient
|
|
|
|
int levels = 2;
|
|
|
|
int r = Qt::gray.red() / (levels + 2),
|
|
|
|
g = Qt::gray.green() / (levels + 2),
|
|
|
|
b = Qt::gray.blue() / (levels + 2);
|
|
|
|
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) ) );
|
|
|
|
p->drawLine( i, i + pixmapHeight + 1, i + pixmapWidth + 1, i + pixmapHeight + 1 );
|
|
|
|
p->drawLine( i + pixmapWidth + 1, i, i + pixmapWidth + 1, i + pixmapHeight );
|
|
|
|
p->setPen( Qt::gray );
|
|
|
|
p->drawLine( -1, i + pixmapHeight + 1, i - 1, i + pixmapHeight + 1 );
|
|
|
|
p->drawLine( i + pixmapWidth + 1, -1, i + pixmapWidth + 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
|
|
|
|
2004-11-05 18:14:20 +00:00
|
|
|
// draw the pixmap (note: this modifies the painter (not saved for performance))
|
|
|
|
if ( contentsRect.intersects( pixmapGeometry ) )
|
|
|
|
{
|
|
|
|
QRect pixmapRect = contentsRect.intersect( pixmapGeometry );
|
|
|
|
pixmapRect.moveBy( -pixmapGeometry.left(), -pixmapGeometry.top() );
|
2004-11-07 14:15:33 +00:00
|
|
|
int flags = PagePainter::Accessibility | PagePainter::EnhanceLinks |
|
2004-12-10 16:04:45 +00:00
|
|
|
PagePainter::EnhanceImages | PagePainter::Highlight;
|
2004-11-07 14:15:33 +00:00
|
|
|
PagePainter::paintPageOnPainter( item->page(), PAGEVIEW_ID, flags, p, pixmapRect,
|
|
|
|
pixmapGeometry.width(), pixmapGeometry.height() );
|
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
|
|
|
|
|
|
|
// paint with background color the unpainted area
|
|
|
|
QMemArray<QRect> backRects = remainingArea.rects();
|
|
|
|
uint backRectsNumber = backRects.count();
|
|
|
|
for ( uint jr = 0; jr < backRectsNumber; jr++ )
|
|
|
|
p->fillRect( backRects[ jr ], Qt::gray );
|
2004-10-30 20:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PageView::updateItemSize( PageViewItem * item, int colWidth, int rowHeight )
|
|
|
|
{
|
|
|
|
const KPDFPage * kpdfPage = item->page();
|
|
|
|
double width = kpdfPage->width(),
|
|
|
|
height = kpdfPage->height(),
|
|
|
|
zoom = d->zoomFactor;
|
|
|
|
|
|
|
|
if ( d->zoomMode == ZoomFixed )
|
|
|
|
{
|
|
|
|
width *= zoom;
|
|
|
|
height *= zoom;
|
|
|
|
item->setWHZ( (int)width, (int)height, d->zoomFactor );
|
|
|
|
}
|
|
|
|
else if ( d->zoomMode == ZoomFitWidth )
|
|
|
|
{
|
|
|
|
height = kpdfPage->ratio() * colWidth;
|
|
|
|
item->setWHZ( colWidth, (int)height, (double)colWidth / width );
|
|
|
|
}
|
|
|
|
else if ( d->zoomMode == ZoomFitPage )
|
|
|
|
{
|
|
|
|
double scaleW = (double)colWidth / (double)width;
|
|
|
|
double scaleH = (double)rowHeight / (double)height;
|
|
|
|
zoom = QMIN( scaleW, scaleH );
|
|
|
|
item->setWHZ( (int)(zoom * width), (int)(zoom * height), zoom );
|
|
|
|
}
|
|
|
|
#ifndef NDEBUG
|
|
|
|
else
|
|
|
|
kdDebug() << "calling updateItemSize with unrecognized d->zoomMode!" << endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
PageViewItem * PageView::pickItemOnPoint( int x, int y )
|
|
|
|
{
|
|
|
|
PageViewItem * item = 0;
|
2005-01-09 23:37:07 +00:00
|
|
|
QValueList< PageViewItem * >::iterator iIt = d->visibleItems.begin(), iEnd = d->visibleItems.end();
|
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;
|
2004-10-30 20:54:48 +00:00
|
|
|
const QRect & r = i->geometry();
|
|
|
|
if ( x < r.right() && x > r.left() && y < r.bottom() )
|
|
|
|
{
|
|
|
|
if ( y > r.top() )
|
|
|
|
item = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2004-11-16 17:36:02 +00:00
|
|
|
void PageView::selectionStart( int x, int y, bool /*aboveAll*/ )
|
2004-09-26 23:39:39 +00:00
|
|
|
{
|
2004-11-03 17:35:48 +00:00
|
|
|
d->mouseSelectionRect.setRect( x, y, 1, 1 );
|
|
|
|
// ensures page doesn't scroll
|
|
|
|
if ( d->scrollTimer )
|
2004-10-29 21:52:06 +00:00
|
|
|
{
|
2004-11-03 17:35:48 +00:00
|
|
|
d->scrollIncrement = 0;
|
|
|
|
d->scrollTimer->stop();
|
2004-10-29 21:52:06 +00:00
|
|
|
}
|
2004-11-03 17:35:48 +00:00
|
|
|
}
|
2004-09-26 23:39:39 +00:00
|
|
|
|
2004-11-03 17:35:48 +00:00
|
|
|
void PageView::selectionEndPoint( int x, int y )
|
|
|
|
{
|
2004-11-16 17:36:02 +00:00
|
|
|
// clip selection to the viewport
|
|
|
|
QRect viewportRect( contentsX(), contentsY(), visibleWidth(), visibleHeight() );
|
2005-01-09 23:37:07 +00:00
|
|
|
x = QMAX( QMIN( x, viewportRect.right() ), viewportRect.left() );
|
2004-11-16 17:36:02 +00:00
|
|
|
y = QMAX( QMIN( y, viewportRect.bottom() ), viewportRect.top() );
|
2004-11-03 17:35:48 +00:00
|
|
|
// if selection changed update rect
|
|
|
|
if ( d->mouseSelectionRect.right() != x || d->mouseSelectionRect.bottom() != y )
|
|
|
|
{
|
|
|
|
// send incremental paint events
|
|
|
|
QRect oldRect = d->mouseSelectionRect.normalize();
|
|
|
|
d->mouseSelectionRect.setRight( x );
|
|
|
|
d->mouseSelectionRect.setBottom( y );
|
|
|
|
QRect newRect = d->mouseSelectionRect.normalize();
|
|
|
|
// generate diff region: [ OLD.unite(NEW) - OLD.intersect(NEW) ]
|
|
|
|
QRegion compoundRegion = QRegion( oldRect ).unite( newRect );
|
|
|
|
if ( oldRect.intersects( newRect ) )
|
|
|
|
{
|
|
|
|
QRect intersection = oldRect.intersect( newRect );
|
|
|
|
intersection.addCoords( 1, 1, -1, -1 );
|
|
|
|
if ( intersection.width() > 20 && intersection.height() > 20 )
|
|
|
|
compoundRegion -= intersection;
|
|
|
|
}
|
|
|
|
// tassellate region with rects and enqueue paint events
|
|
|
|
QMemArray<QRect> rects = compoundRegion.rects();
|
|
|
|
for ( uint i = 0; i < rects.count(); i++ )
|
|
|
|
updateContents( rects[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageView::selectionClear()
|
|
|
|
{
|
|
|
|
updateContents( d->mouseSelectionRect.normalize() );
|
|
|
|
d->mouseSelectionRect.setCoords( 0, 0, -1, -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
KAction * checkedZoomAction = 0;
|
|
|
|
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();
|
|
|
|
newFactor = KGlobal::locale()->readNumber( z.remove( z.find( '%' ), 1 ) ) / 100.0;
|
|
|
|
}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:
|
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 ZoomFitWidth:
|
|
|
|
checkedZoomAction = d->aZoomFitWidth;
|
|
|
|
break;
|
|
|
|
case ZoomFitPage:
|
|
|
|
checkedZoomAction = d->aZoomFitPage;
|
|
|
|
break;
|
|
|
|
case ZoomFitText:
|
|
|
|
checkedZoomAction = d->aZoomFitText;
|
|
|
|
break;
|
|
|
|
case ZoomRefreshCurrent:
|
|
|
|
newZoomMode = ZoomFixed;
|
|
|
|
d->zoomFactor = -1;
|
|
|
|
break;
|
|
|
|
}
|
2004-10-30 23:59:09 +00:00
|
|
|
if ( newFactor > 4.0 )
|
|
|
|
newFactor = 4.0;
|
|
|
|
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
|
|
|
|
d->aZoomFitWidth->setChecked( checkedZoomAction == d->aZoomFitWidth );
|
|
|
|
d->aZoomFitPage->setChecked( checkedZoomAction == d->aZoomFitPage );
|
|
|
|
d->aZoomFitText->setChecked( checkedZoomAction == d->aZoomFitText );
|
|
|
|
}
|
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 )
|
2005-01-09 23:37:07 +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;
|
|
|
|
d->aZoom->clear();
|
2004-09-26 23:39:39 +00:00
|
|
|
|
2004-10-29 21:52:06 +00:00
|
|
|
// add items that describe fit actions
|
|
|
|
QStringList translated;
|
|
|
|
translated << i18n("Fit Width") << i18n("Fit Page"); // << i18n("Fit Text");
|
2004-10-20 16:41:13 +00:00
|
|
|
|
2004-10-29 21:52:06 +00:00
|
|
|
// add percent items
|
|
|
|
QString double_oh( "00" );
|
|
|
|
const float zoomValue[10] = { 0.125, 0.25, 0.333, 0.5, 0.667, 0.75, 1, 1.25, 1.50, 2 };
|
|
|
|
int idx = 0,
|
|
|
|
selIdx = 2; // use 3 if "fit text" present
|
|
|
|
bool inserted = false; //use: "d->zoomMode != ZoomFixed" to hide Fit/* zoom ratio
|
|
|
|
while ( idx < 10 || !inserted )
|
2004-09-28 13:53:47 +00:00
|
|
|
{
|
2004-10-29 21:52:06 +00:00
|
|
|
float value = idx < 10 ? zoomValue[ idx ] : newFactor;
|
|
|
|
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 );
|
|
|
|
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;
|
|
|
|
else if ( d->zoomMode == ZoomFitText )
|
|
|
|
selIdx = 2;
|
|
|
|
d->aZoom->setCurrentItem( selIdx );
|
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() );
|
|
|
|
if ( pageItem )
|
|
|
|
{
|
|
|
|
int pageX = p.x() - pageItem->geometry().left(),
|
|
|
|
pageY = p.y() - pageItem->geometry().top();
|
|
|
|
|
|
|
|
// check if over a KPDFPageRect
|
2005-01-02 11:50:38 +00:00
|
|
|
bool onLink = pageItem->page()->hasLink( pageX, pageY );
|
|
|
|
d->mouseOnRect = onLink;
|
|
|
|
if ( onLink )
|
|
|
|
setCursor( pointingHandCursor );
|
|
|
|
else
|
|
|
|
setCursor( arrowCursor );
|
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;
|
|
|
|
setCursor( arrowCursor );
|
2004-12-26 21:20:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-29 21:52:06 +00:00
|
|
|
//BEGIN private SLOTS
|
2004-09-30 18:04:09 +00:00
|
|
|
void PageView::slotRelayoutPages()
|
2005-01-09 23:37:07 +00:00
|
|
|
// called by: notifySetup, viewportResizeEvent, slotTwoPagesToggled, slotContinousToggled, updateZoom
|
2004-09-27 21:36:25 +00:00
|
|
|
{
|
|
|
|
// set an empty container if we have no pages
|
2004-11-05 00:14:00 +00:00
|
|
|
int pageCount = d->items.count();
|
2004-09-27 21:36:25 +00:00
|
|
|
if ( pageCount < 1 )
|
|
|
|
{
|
2004-10-30 23:59:09 +00:00
|
|
|
resizeContents( 0, 0 );
|
2004-09-27 21:36:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-11-05 00:14:00 +00:00
|
|
|
// common iterator used in this method and viewport parameters
|
|
|
|
QValueVector< PageViewItem * >::iterator iIt, iEnd = d->items.end();
|
2004-10-30 20:54:48 +00:00
|
|
|
int viewportWidth = visibleWidth(),
|
|
|
|
viewportHeight = visibleHeight(),
|
2004-09-30 18:16:12 +00:00
|
|
|
fullWidth = 0,
|
|
|
|
fullHeight = 0;
|
2004-11-05 00:14:00 +00:00
|
|
|
QRect viewportRect( contentsX(), contentsY(), viewportWidth, viewportHeight );
|
|
|
|
|
|
|
|
// set all items geometry and resize contents. handle 'continous' and 'single' modes separately
|
2004-10-29 13:33:51 +00:00
|
|
|
if ( Settings::viewContinous() )
|
2004-09-26 23:39:39 +00:00
|
|
|
{
|
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'.
|
2004-10-29 13:33:51 +00:00
|
|
|
int nCols = Settings::viewColumns(),
|
2004-09-27 21:36:25 +00:00
|
|
|
nRows = (int)ceilf( (float)pageCount / (float)nCols ),
|
|
|
|
* colWidth = new int[ nCols ],
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
// 1) find the maximum columns width and rows height for a grid in
|
|
|
|
// which each page must well-fit inside a cell
|
2004-11-05 00:14:00 +00:00
|
|
|
for ( iIt = d->items.begin(); 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-01-03 15:51:05 +00:00
|
|
|
updateItemSize( item, colWidth[ cIdx ] - 6, viewportHeight - 10 );
|
2004-09-27 21:36:25 +00:00
|
|
|
// find row's maximum height and column's max width
|
2005-01-03 15:51:05 +00:00
|
|
|
if ( item->width() + 6 > colWidth[ cIdx ] )
|
|
|
|
colWidth[ cIdx ] = item->width() + 6;
|
2004-10-30 20:54:48 +00:00
|
|
|
if ( item->height() > rowHeight[ rIdx ] )
|
|
|
|
rowHeight[ rIdx ] = item->height();
|
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
|
|
|
|
|
|
|
// 2) arrange widgets inside cells
|
|
|
|
int insertX = 0,
|
2004-10-30 20:54:48 +00:00
|
|
|
insertY = 10; //TODO take d->zoomFactor into account (2+4*x)
|
|
|
|
cIdx = 0;
|
|
|
|
rIdx = 0;
|
2004-11-05 00:14:00 +00:00
|
|
|
for ( iIt = d->items.begin(); 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 ];
|
2004-10-30 20:54:48 +00:00
|
|
|
// center widget inside 'cells'
|
|
|
|
item->moveTo( insertX + (cWidth - item->width()) / 2,
|
|
|
|
insertY + (rHeight - item->height()) / 2 );
|
2004-09-27 21:36:25 +00:00
|
|
|
// advance col/row index
|
|
|
|
insertX += cWidth;
|
|
|
|
if ( ++cIdx == nCols )
|
|
|
|
{
|
|
|
|
cIdx = 0;
|
|
|
|
rIdx++;
|
|
|
|
insertX = 0;
|
2004-10-30 23:59:09 +00:00
|
|
|
insertY += rHeight + 15; //(int)(5.0 + 15.0 * d->zoomFactor);
|
2004-09-27 21:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-30 18:16:12 +00:00
|
|
|
fullHeight = cIdx ? (insertY + rowHeight[ rIdx ] + 10) : insertY;
|
2004-09-27 21:36:25 +00:00
|
|
|
for ( int i = 0; i < nCols; i++ )
|
|
|
|
fullWidth += colWidth[ i ];
|
|
|
|
|
|
|
|
delete [] colWidth;
|
|
|
|
delete [] rowHeight;
|
|
|
|
}
|
|
|
|
else // viewContinous is FALSE
|
|
|
|
{
|
2005-01-09 23:37:07 +00:00
|
|
|
PageViewItem * currentItem = d->items[ QMAX( 0, (int)d->document->currentPage() ) ];
|
2004-09-30 18:16:12 +00:00
|
|
|
|
|
|
|
// setup varialbles for a 1(row) x N(columns) grid
|
2004-10-29 13:33:51 +00:00
|
|
|
int nCols = Settings::viewColumns(),
|
2004-09-30 18:16:12 +00:00
|
|
|
* colWidth = new int[ nCols ],
|
|
|
|
cIdx = 0;
|
2004-10-30 20:54:48 +00:00
|
|
|
fullHeight = viewportHeight;
|
2004-09-30 18:16:12 +00:00
|
|
|
for ( int i = 0; i < nCols; i++ )
|
|
|
|
colWidth[ i ] = viewportWidth / nCols;
|
|
|
|
|
|
|
|
// 1) find out maximum area extension for the pages
|
2004-11-05 00:14:00 +00:00
|
|
|
for ( iIt = d->items.begin(); iIt != iEnd; ++iIt )
|
2004-09-30 18:16:12 +00:00
|
|
|
{
|
2004-11-05 00:14:00 +00:00
|
|
|
PageViewItem * item = *iIt;
|
2004-10-30 20:54:48 +00:00
|
|
|
if ( item == currentItem || (cIdx > 0 && cIdx < nCols) )
|
2004-09-30 18:16:12 +00:00
|
|
|
{
|
2004-10-30 20:54:48 +00:00
|
|
|
// update internal page size (leaving a little margin in case of Fit* modes)
|
2005-01-03 15:51:05 +00:00
|
|
|
updateItemSize( item, colWidth[ cIdx ] - 4, viewportHeight - 6 );
|
2004-10-30 20:54:48 +00:00
|
|
|
// find row's maximum height and column's max width
|
2005-01-03 15:51:05 +00:00
|
|
|
if ( item->width() + 4 > colWidth[ cIdx ] )
|
|
|
|
colWidth[ cIdx ] = item->width() + 4;
|
|
|
|
if ( item->height() + 6 > fullHeight )
|
|
|
|
fullHeight = item->height() + 6;
|
2004-09-30 18:16:12 +00:00
|
|
|
cIdx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2) hide all widgets except the displayable ones and dispose those
|
2004-10-30 23:59:09 +00:00
|
|
|
int insertX = 0;
|
2004-10-30 20:54:48 +00:00
|
|
|
cIdx = 0;
|
2004-11-05 00:14:00 +00:00
|
|
|
for ( iIt = d->items.begin(); iIt != iEnd; ++iIt )
|
2004-09-30 18:16:12 +00:00
|
|
|
{
|
2004-11-05 00:14:00 +00:00
|
|
|
PageViewItem * item = *iIt;
|
2004-10-30 20:54:48 +00:00
|
|
|
if ( item == currentItem || (cIdx > 0 && cIdx < nCols) )
|
2004-09-30 18:16:12 +00:00
|
|
|
{
|
2004-10-30 20:54:48 +00:00
|
|
|
// center widget inside 'cells'
|
|
|
|
item->moveTo( insertX + (colWidth[ cIdx ] - item->width()) / 2,
|
2004-10-30 23:59:09 +00:00
|
|
|
(fullHeight - item->height()) / 2 );
|
2004-10-30 20:54:48 +00:00
|
|
|
// advance col index
|
2004-09-30 18:16:12 +00:00
|
|
|
insertX += colWidth[ cIdx ];
|
|
|
|
cIdx++;
|
2004-10-30 23:59:09 +00:00
|
|
|
} else
|
|
|
|
item->setGeometry( 0, 0, -1, -1 );
|
2004-09-30 18:16:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for ( int i = 0; i < nCols; i++ )
|
|
|
|
fullWidth += colWidth[ i ];
|
|
|
|
|
|
|
|
delete [] colWidth;
|
2005-01-11 17:35:07 +00:00
|
|
|
slotRequestVisiblePixmaps();
|
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
|
2005-01-10 13:43:44 +00:00
|
|
|
bool wasUpdatesEnabled = viewport()->isUpdatesEnabled();
|
2004-11-05 00:14:00 +00:00
|
|
|
if ( fullWidth != contentsWidth() || fullHeight != contentsHeight() )
|
2004-09-30 18:16:12 +00:00
|
|
|
{
|
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 );
|
2004-09-30 18:16:12 +00:00
|
|
|
resizeContents( 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
|
|
|
const DocumentViewport & vp = d->document->viewport();
|
|
|
|
if ( vp.pageNumber >= 0 )
|
|
|
|
{
|
|
|
|
const QRect & geometry = d->items[ vp.pageNumber ]->geometry();
|
|
|
|
double nX = vp.reCenter.enabled ? vp.reCenter.normalizedCenterX : 0.5,
|
|
|
|
nY = vp.reCenter.enabled ? vp.reCenter.normalizedCenterY : 0.0;
|
|
|
|
center( geometry.left() + ROUND( nX * (double)geometry.width() ),
|
|
|
|
geometry.top() + ROUND( nY * (double)geometry.height() ) );
|
|
|
|
}
|
|
|
|
// 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 )
|
|
|
|
updateContents();
|
2004-09-30 18:04:09 +00:00
|
|
|
}
|
|
|
|
|
2004-09-30 18:16:12 +00:00
|
|
|
void PageView::slotRequestVisiblePixmaps( int newLeft, int newTop )
|
|
|
|
{
|
|
|
|
// precalc view limits for intersecting with page coords inside the lOOp
|
2005-01-09 23:37:07 +00:00
|
|
|
bool isEvent = newLeft != -1 && newTop != -1 && !d->blockViewport;
|
|
|
|
QRect viewportRect( isEvent ? newLeft : contentsX(),
|
|
|
|
isEvent ? newTop : contentsY(),
|
2004-10-30 20:54:48 +00:00
|
|
|
visibleWidth(), visibleHeight() );
|
2004-09-30 18:16:12 +00:00
|
|
|
|
2005-01-09 23:37:07 +00:00
|
|
|
// some variables used to determine the viewport
|
|
|
|
int nearPageNumber = -1,
|
2005-01-10 13:43:44 +00:00
|
|
|
viewportCenterX = (viewportRect.left() + viewportRect.right()) / 2,
|
|
|
|
viewportCenterY = (viewportRect.top() + viewportRect.bottom()) / 2;
|
2005-01-09 23:37:07 +00:00
|
|
|
double focusedX = 0.5,
|
|
|
|
focusedY = 0.0,
|
|
|
|
minDistance = -1.0;
|
|
|
|
|
|
|
|
// iterate over all items
|
2004-12-21 12:38:52 +00:00
|
|
|
d->visibleItems.clear();
|
2004-12-22 18:21:36 +00:00
|
|
|
QValueList< PixmapRequest * > requestedPixmaps;
|
2004-11-05 00:14:00 +00:00
|
|
|
QValueVector< PageViewItem * >::iterator iIt = d->items.begin(), iEnd = d->items.end();
|
|
|
|
for ( ; iIt != iEnd; ++iIt )
|
2004-09-30 18:16:12 +00:00
|
|
|
{
|
2004-12-22 18:21:36 +00:00
|
|
|
PageViewItem * i = *iIt;
|
2005-01-09 23:37:07 +00:00
|
|
|
|
|
|
|
// if the item doesn't intersect the viewport, skip it
|
2004-12-22 18:21:36 +00:00
|
|
|
if ( !viewportRect.intersects( i->geometry() ) )
|
|
|
|
continue;
|
|
|
|
|
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 );
|
2005-01-09 23:37:07 +00:00
|
|
|
|
|
|
|
// if the item has not the right pixmap, add a request for it
|
2004-12-22 18:21:36 +00:00
|
|
|
if ( !i->page()->hasPixmap( PAGEVIEW_ID, i->width(), i->height() ) )
|
|
|
|
requestedPixmaps.push_back( new PixmapRequest( PAGEVIEW_ID, i->pageNumber(), i->width(), i->height() ) );
|
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 )
|
|
|
|
{
|
|
|
|
const QRect & geometry = i->geometry();
|
|
|
|
// compute distance between item center and viewport center
|
2005-01-10 13:43:44 +00:00
|
|
|
double distance = hypot( (geometry.left() + geometry.right()) / 2 - viewportCenterX,
|
|
|
|
(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 )
|
|
|
|
{
|
|
|
|
focusedX = (double)( viewportCenterX - geometry.left() ) / (double)geometry.width();
|
|
|
|
focusedY = (double)( viewportCenterY - geometry.top() ) / (double)geometry.height();
|
|
|
|
}
|
|
|
|
}
|
2004-12-21 12:38:52 +00:00
|
|
|
}
|
|
|
|
|
2005-01-09 23:37:07 +00:00
|
|
|
// request pixmaps in 'requests list'
|
2004-12-22 18:21:36 +00:00
|
|
|
if ( !requestedPixmaps.isEmpty() )
|
2005-01-09 23:37:07 +00:00
|
|
|
d->document->requestPixmaps( requestedPixmaps, true /*ASYNC*/ );
|
|
|
|
|
|
|
|
// if this functions was invoked by viewport events
|
|
|
|
if ( isEvent && nearPageNumber != -1 )
|
|
|
|
{
|
|
|
|
// determine the document viewport
|
|
|
|
DocumentViewport newViewport( nearPageNumber );
|
|
|
|
newViewport.reCenter.enabled = true;
|
|
|
|
newViewport.reCenter.normalizedCenterX = focusedX;
|
|
|
|
newViewport.reCenter.normalizedCenterY = focusedY;
|
|
|
|
// 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
|
|
|
}
|
2004-09-30 18:16:12 +00:00
|
|
|
}
|
2004-10-06 00:05:49 +00:00
|
|
|
|
|
|
|
void PageView::slotAutoScoll()
|
|
|
|
{
|
|
|
|
// the first time create the timer
|
|
|
|
if ( !d->scrollTimer )
|
|
|
|
{
|
|
|
|
d->scrollTimer = new QTimer( this );
|
|
|
|
connect( d->scrollTimer, SIGNAL( timeout() ), this, SLOT( slotAutoScoll() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// if scrollIncrement is zero, stop the timer
|
|
|
|
if ( !d->scrollIncrement )
|
|
|
|
{
|
|
|
|
d->scrollTimer->stop();
|
|
|
|
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 };
|
|
|
|
d->scrollTimer->changeInterval( scrollDelay[ index ] );
|
|
|
|
scrollBy( 0, d->scrollIncrement > 0 ? scrollOffset[ index ] : -scrollOffset[ index ] );
|
|
|
|
}
|
2004-09-30 18:16:12 +00:00
|
|
|
|
2004-10-29 21:52:06 +00:00
|
|
|
void PageView::slotZoom()
|
2004-09-30 18:04:09 +00:00
|
|
|
{
|
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
|
|
|
|
2004-10-29 21:52:06 +00:00
|
|
|
void PageView::slotFitToTextToggled( bool on )
|
|
|
|
{
|
|
|
|
if ( on ) updateZoom( ZoomFitText );
|
|
|
|
}
|
2004-09-30 18:04:09 +00:00
|
|
|
|
2004-10-29 21:52:06 +00:00
|
|
|
void PageView::slotTwoPagesToggled( bool on )
|
|
|
|
{
|
|
|
|
uint newColumns = on ? 2 : 1;
|
|
|
|
if ( Settings::viewColumns() != newColumns )
|
2004-09-30 18:04:09 +00:00
|
|
|
{
|
2004-10-29 21:52:06 +00:00
|
|
|
Settings::setViewColumns( newColumns );
|
|
|
|
if ( d->document->pages() > 0 )
|
|
|
|
slotRelayoutPages();
|
2004-09-30 18:04:09 +00:00
|
|
|
}
|
2004-09-26 23:39:39 +00:00
|
|
|
}
|
|
|
|
|
2004-10-29 21:52:06 +00:00
|
|
|
void PageView::slotContinousToggled( bool on )
|
2004-09-28 13:53:47 +00:00
|
|
|
{
|
2004-10-29 21:52:06 +00:00
|
|
|
if ( Settings::viewContinous() != on )
|
2004-09-28 13:53:47 +00:00
|
|
|
{
|
2004-10-29 21:52:06 +00:00
|
|
|
Settings::setViewContinous( on );
|
|
|
|
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
|
|
|
{
|
2004-10-29 21:52:06 +00:00
|
|
|
d->mouseMode = MouseNormal;
|
2004-11-03 17:35:48 +00:00
|
|
|
d->messageWindow->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageView::slotSetMouseZoom()
|
|
|
|
{
|
|
|
|
d->mouseMode = MouseZoom;
|
2004-11-16 17:36:02 +00:00
|
|
|
d->messageWindow->display( i18n( "Select Zooming Area. Right-Click to zoom out." ), PageViewMessage::Info, -1 );
|
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
|
|
|
{
|
2004-11-16 17:36:02 +00:00
|
|
|
d->mouseMode = MouseSelect;
|
|
|
|
d->messageWindow->display( i18n( "Draw a rectangle around the text/gfx to copy." ), PageViewMessage::Info, -1 );
|
2004-09-26 23:39:39 +00:00
|
|
|
}
|
|
|
|
|
2004-10-29 21:52:06 +00:00
|
|
|
void PageView::slotSetMouseDraw()
|
2004-09-26 23:39:39 +00:00
|
|
|
{
|
2004-10-29 21:52:06 +00:00
|
|
|
d->mouseMode = MouseEdit;
|
|
|
|
d->aMouseEdit->setChecked( true );
|
2004-11-03 17:35:48 +00:00
|
|
|
d->messageWindow->hide();
|
2004-09-26 23:39:39 +00:00
|
|
|
}
|
|
|
|
|
2004-10-29 21:52:06 +00:00
|
|
|
void PageView::slotScrollUp()
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void PageView::slotScrollDown()
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
2004-10-29 21:52:06 +00:00
|
|
|
//END private SLOTS
|
2004-09-26 23:39:39 +00:00
|
|
|
|
|
|
|
#include "pageview.moc"
|