📄 pageview.cpp.svn-base
字号:
/*************************************************************************** * Copyright (C) 2004-2005 by Enrico Ros <eros.kde@email.it> * * Copyright (C) 2004-2006 by Albert Astals Cid <tsdgeos@terra.es> * * * * With portions of code from kpdf/kpdf_pagewidget.cc by: * * 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> * * * * 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. * ***************************************************************************/#include <X11/Xlib.h>#include <X11/extensions/Xrender.h>#include <fixx11h.h>// qt/kde includes#include <qcursor.h>#include <qevent.h>#include <qpainter.h>#include <qtimer.h>#include <qdatetime.h>#include <qpushbutton.h>#include <qapplication.h>#include <qclipboard.h>#include <QX11Info>#include <kiconloader.h>#include <kaction.h>#include <kstdaccel.h>#include <kstdaction.h>#include <kactioncollection.h>#include <kmenu.h>#include <klocale.h>#include <kfiledialog.h>#include <kimageeffect.h>#include <kselectaction.h>#include <ktoggleaction.h>#include <ktoolinvocation.h>#include <kdebug.h>#include <kmessagebox.h>#include <kicon.h>#include <QtDBus/QtDBus>// system includes#include <math.h>#include <stdlib.h>// local includes#include "pageview.h"#include "pageviewutils.h"#include "pagepainter.h"#include "core/annotations.h"#include "annotwindow.h" //"embeddedannotationdialog.h"#include "annotationpropertiesdialog.h"#include "pageviewannotator.h"#include "core/document.h"#include "core/page.h"#include "core/misc.h"#include "core/link.h"#include "core/generator.h"#include "settings.h"#define ROUND(x) (int(x + 0.5))static int pageflags = PagePainter::Accessibility | PagePainter::EnhanceLinks | PagePainter::EnhanceImages | PagePainter::Highlights | PagePainter::Annotations;// structure used internally by PageView for data storageclass PageViewPrivate{public: // the document, pageviewItems and the 'visible cache' KPDFDocument * document; QVector< PageViewItem * > items; QLinkedList< PageViewItem * > visibleItems; // view layout (columns and continuous in Settings), zoom and mouse PageView::ZoomMode zoomMode; float zoomFactor; PageView::MouseMode mouseMode; QPoint mouseGrabPos; QPoint mousePressPos; QPoint mouseSelectPos; bool mouseMidZooming; int mouseMidLastY; bool mouseSelecting; QRect mouseSelectionRect; QColor mouseSelectionColor; bool mouseTextSelecting; bool mouseTextSelectionPainted; QList<QRect>* mouseTextSelectionRect; QColor mouseTextSelectionColor; TextSelection * mouseTextSelectionInfo; bool mouseOnRect; // type ahead find bool typeAheadActive; QString typeAheadString; QTimer * findTimeoutTimer; // viewport move bool viewportMoveActive; QTime viewportMoveTime; QPoint viewportMoveDest; QTimer * viewportMoveTimer; // auto scroll int scrollIncrement; QTimer * autoScrollTimer; // annotations PageViewAnnotator * annotator; //text annotation dialogs list QList<AnnotWindow *> m_annowindows; // other stuff QTimer * delayResizeTimer; bool dirtyLayout; bool blockViewport; // prevents changes to viewport bool blockPixmapsRequest; // prevent pixmap requests PageViewMessage * messageWindow; // in pageviewutils.h // actions KSelectAction * aOrientation; KSelectAction * aPaperSizes; KAction * aMouseNormal; KAction * aMouseSelect; KToggleAction * aToggleAnnotator; KSelectAction * aZoom; KToggleAction * aZoomFitWidth; KToggleAction * aZoomFitPage; KToggleAction * aZoomFitText; KSelectAction * aRenderMode; KToggleAction * aViewContinuous; KAction * aPrevAction; KActionCollection * actionCollection;};/* 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) * 550 - events: mouse, keyboard, drag/drop * 170 - slotRelayoutPages: set contents of the scrollview on continuous/single modes * 100 - zoom: zooming pages in different ways, keeping update the toolbar actions, etc.. * other misc functions: only slotRequestVisiblePixmaps and pickItemOnPoint noticeable, * and many insignificant stuff like this comment :-) */PageView::PageView( QWidget *parent, KPDFDocument *document ) : Q3ScrollView( parent ){ // create and initialize private storage structure d = new PageViewPrivate(); d->document = document; d->aOrientation = 0; d->aRenderMode = 0; d->zoomMode = (PageView::ZoomMode) KpdfSettings::zoomMode(); d->zoomFactor = KpdfSettings::zoomFactor(); d->mouseMode = MouseNormal; d->mouseMidZooming = false; d->mouseSelecting = false; d->mouseTextSelecting = false; d->mouseOnRect = false; d->typeAheadActive = false; d->findTimeoutTimer = 0; d->viewportMoveActive = false; d->viewportMoveTimer = 0; d->scrollIncrement = 0; d->autoScrollTimer = 0; d->annotator = 0; d->delayResizeTimer = 0; d->dirtyLayout = false; d->blockViewport = false; d->blockPixmapsRequest = false; d->messageWindow = new PageViewMessage(this); d->aPrevAction = 0; d->mouseTextSelectionRect=0; d->mouseTextSelectionInfo=0; d->mouseTextSelectionPainted=0; d->aPaperSizes=0; setAttribute( Qt::WA_StaticContents ); setObjectName( QLatin1String( "okular::pageView" ) ); // widget setup: setup focus, accept drops and track mouse viewport()->setFocusProxy( this ); viewport()->setFocusPolicy( Qt::StrongFocus ); //viewport()->setPaletteBackgroundColor( Qt::white ); viewport()->setAttribute( Qt::WA_OpaquePaintEvent ); setResizePolicy( Manual ); setAcceptDrops( true ); setDragAutoScroll( false ); viewport()->setMouseTracking( true ); // conntect the padding of the viewport to pixmaps requests connect( this, SIGNAL(contentsMoving(int, int)), this, SLOT(slotRequestVisiblePixmaps(int, int)) ); // show initial welcome text d->messageWindow->display( i18n( "Welcome" ), PageViewMessage::Info, 2000 ); // set a corner button to resize the view to the page size// QPushButton * resizeButton = new QPushButton( viewport() );// resizeButton->setPixmap( SmallIcon("crop") );// setCornerWidget( resizeButton );// resizeButton->setEnabled( false ); // connect(...); setInputMethodEnabled( true );}PageView::~PageView(){ // delete the local storage structure foreach(AnnotWindow* tempwnd, d->m_annowindows) { if(tempwnd) delete tempwnd; } d->document->removeObserver( this ); delete d;}void PageView::setupActions( KActionCollection * ac ){ d->actionCollection = ac; d->aOrientation=new KSelectAction( i18n( "&Orientation" ), ac, "view_orientation" ); d->aPaperSizes=new KSelectAction( i18n( "&Paper sizes" ), ac, "view_papersizes" ); QStringList rotations; rotations.append( i18n( "Default" ) ); rotations.append( i18n( "Rotated 90 Degrees" ) ); rotations.append( i18n( "Rotated 180 Degrees" ) ); rotations.append( i18n( "Rotated 270 Degrees" ) ); d->aOrientation->setItems( rotations ); connect( d->aOrientation , SIGNAL( triggered( int ) ), d->document , SLOT( slotRotation( int ) ) ); connect( d->aPaperSizes , SIGNAL( triggered( int ) ), d->document , SLOT( slotPaperSizes( int ) ) ); d->aOrientation->setEnabled(d->document->supportsRotation()); bool paperSizes=d->document->supportsPaperSizes(); d->aPaperSizes->setEnabled(paperSizes); if (paperSizes) d->aPaperSizes->setItems(d->document->paperSizes()); // Zoom actions ( higher scales takes lots of memory! ) d->aZoom = new KSelectAction( KIcon( "viewmag" ), i18n( "Zoom" ), ac, "zoom_to" ); d->aZoom->setEditable( true ); d->aZoom->setMaxComboViewCount( 13 ); connect( d->aZoom, SIGNAL( triggered(QAction *) ), this, SLOT( slotZoom() ) ); updateZoomText(); KStdAction::zoomIn( this, SLOT( slotZoomIn() ), ac, "zoom_in" ); KStdAction::zoomOut( this, SLOT( slotZoomOut() ), ac, "zoom_out" ); d->aZoomFitWidth = new KToggleAction( KIcon( "view_fit_width" ), i18n("Fit to Page &Width"), ac, "zoom_fit_width" ); connect( d->aZoomFitWidth, SIGNAL( toggled( bool ) ), SLOT( slotFitToWidthToggled( bool ) ) ); d->aZoomFitPage = new KToggleAction( KIcon( "view_fit_window" ), i18n("Fit to &Page"), ac, "zoom_fit_page" ); connect( d->aZoomFitPage, SIGNAL( toggled( bool ) ), SLOT( slotFitToPageToggled( bool ) ) ); d->aZoomFitText = new KToggleAction( KIcon( "viewmagfit" ), i18n("Fit to &Text"), ac, "zoom_fit_text" ); connect( d->aZoomFitText, SIGNAL( toggled( bool ) ), SLOT( slotFitToTextToggled( bool ) ) ); // View-Layout actions QStringList renderModes; renderModes.append( i18n( "Single" ) ); renderModes.append( i18n( "Facing" ) ); renderModes.append( i18n( "Overview" ) ); d->aRenderMode = new KSelectAction( KIcon( "view_left_right" ), i18n("&Render Mode"), ac, "view_render_mode" ); connect( d->aRenderMode, SIGNAL( triggered( int ) ), SLOT( slotRenderMode( int ) ) ); d->aRenderMode->setItems( renderModes ); d->aRenderMode->setCurrentItem( KpdfSettings::renderMode() ); d->aViewContinuous = new KToggleAction( KIcon( "view_text" ), i18n("&Continuous"), ac, "view_continuous" ); connect( d->aViewContinuous, SIGNAL( toggled( bool ) ), SLOT( slotContinuousToggled( bool ) ) ); d->aViewContinuous->setChecked( KpdfSettings::viewContinuous() ); // Mouse-Mode actions QActionGroup * actGroup = new QActionGroup( this ); actGroup->setExclusive( true ); d->aMouseNormal = new KAction( KIcon( "mouse" ), i18n("&Browse Tool"), ac, "mouse_drag" ); connect( d->aMouseNormal, SIGNAL( triggered() ), this, SLOT( slotSetMouseNormal() ) ); d->aMouseNormal->setCheckable( true ); d->aMouseNormal->setActionGroup( actGroup ); d->aMouseNormal->setChecked( true ); KAction * mz = new KAction( KIcon( "viewmag" ), i18n("&Zoom Tool"), ac, "mouse_zoom" ); connect( mz, SIGNAL( triggered() ), this, SLOT( slotSetMouseZoom() ) ); mz->setCheckable( true ); mz->setActionGroup( actGroup ); d->aMouseSelect = new KAction( KIcon( "frame_edit" ), i18n("&Select Tool"), ac, "mouse_select" ); connect( d->aMouseSelect, SIGNAL( triggered() ), this, SLOT( slotSetMouseSelect() ) ); d->aMouseSelect->setCheckable( true ); d->aMouseSelect->setActionGroup( actGroup ); d->aToggleAnnotator = new KToggleAction( KIcon( "pencil" ), i18n("&Review"), ac, "mouse_toggle_annotate" ); d->aToggleAnnotator->setCheckable( true ); connect( d->aToggleAnnotator, SIGNAL( toggled( bool ) ), SLOT( slotToggleAnnotator( bool ) ) ); d->aToggleAnnotator->setShortcut( Qt::Key_F6 ); // Other actions KAction * su = new KAction( i18n("Scroll Up"), ac, "view_scroll_up" ); connect( su, SIGNAL( triggered() ), this, SLOT( slotScrollUp() ) ); su->setShortcut( QKeySequence(Qt::SHIFT + Qt::Key_Up) ); KAction * sd = new KAction( i18n("Scroll Down"), ac, "view_scroll_down" ); connect( sd, SIGNAL( triggered() ), this, SLOT( slotScrollDown() ) ); sd->setShortcut( QKeySequence(Qt::SHIFT + Qt::Key_Down) );}bool PageView::canFitPageWidth(){ return KpdfSettings::renderMode() != 0 || d->zoomMode != ZoomFitWidth;}void PageView::fitPageWidth( int page ){ // zoom: Fit Width, columns: 1. setActions + relayout + setPage + update d->zoomMode = ZoomFitWidth; KpdfSettings::setRenderMode( 0 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -