pageview.cpp 215 KB
Newer Older
1
/***************************************************************************
2
 *   Copyright (C) 2004-2005 by Enrico Ros <eros.kde@email.it>             *
Albert Astals Cid's avatar
Albert Astals Cid committed
3
 *   Copyright (C) 2004-2006 by Albert Astals Cid <aacid@kde.org>          *
4
 *                                                                         *
5
 *   With portions of code from kpdf/kpdf_pagewidget.cc by:                *
6 7 8 9 10 11
 *     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>                  *
Jiri Baum's avatar
Jiri Baum committed
12
 *     Copyright (C) 2011 by Jiri Baum - NICTA <jiri@baum.com.au>          *
13 14 15 16 17 18 19
 *                                                                         *
 *   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.                                   *
 ***************************************************************************/

Albert Astals Cid's avatar
Albert Astals Cid committed
20 21
#include "pageview.h"

22
// qt/kde includes
23
#include <QtCore/qloggingcategory.h>
24
#include <qcursor.h>
25
#include <qevent.h>
26
#include <qimage.h>
27 28
#include <qpainter.h>
#include <qtimer.h>
29
#include <qset.h>
30
#include <qscrollbar.h>
31
#include <qtooltip.h>
Enrico Ros's avatar
Enrico Ros committed
32 33
#include <qapplication.h>
#include <qclipboard.h>
Vishesh Handa's avatar
Vishesh Handa committed
34
#include <qmenu.h>
35
#include <QInputDialog>
36
#include <qdesktopwidget.h>
37
#include <QDesktopServices>
Laurent Montel's avatar
Laurent Montel committed
38
#include <QMimeDatabase>
Olivier Churlaud's avatar
Olivier Churlaud committed
39
#include <QMimeData>
40
#include <QGestureEvent>
41

Laurent Montel's avatar
Laurent Montel committed
42
#include <qaction.h>
43
#include <kactionmenu.h>
Laurent Montel's avatar
Laurent Montel committed
44
#include <kstandardaction.h>
45
#include <kactioncollection.h>
Lukáš Tinkl's avatar
Lukáš Tinkl committed
46
#include <KLocalizedString>
Albert Astals Cid's avatar
compile  
Albert Astals Cid committed
47 48
#include <kselectaction.h>
#include <ktoggleaction.h>
49
#include <QtCore/QDebug>
50
#include <kmessagebox.h>
Laurent Montel's avatar
Laurent Montel committed
51
#include <QIcon>
52 53 54
#include <kurifilter.h>
#include <kstringhandler.h>
#include <ktoolinvocation.h>
55
#include <krun.h>
Albert Astals Cid's avatar
compile  
Albert Astals Cid committed
56

57
// system includes
58
#include <math.h>
59
#include <stdlib.h>
60

61
// local includes
62
#include "debug_ui.h"
63
#include "formwidgets.h"
64
#include "pageviewutils.h"
65
#include "pagepainter.h"
66
#include "core/annotations.h"
67
#include "annotwindow.h"
Pino Toscano's avatar
Pino Toscano committed
68
#include "guiutils.h"
69
#include "annotationpopup.h"
70
#include "pageviewannotator.h"
71
#include "priorities.h"
72
#include "toolaction.h"
73
#include "okmenutitle.h"
74 75 76
#ifdef HAVE_SPEECH
#include "tts.h"
#endif
77
#include "videowidget.h"
Pino Toscano's avatar
Pino Toscano committed
78
#include "core/action.h"
79
#include "core/area.h"
80
#include "core/document_p.h"
81
#include "core/form.h"
82
#include "core/page.h"
83
#include "core/misc.h"
84
#include "core/generator.h"
85
#include "core/movie.h"
Jaydeep Solanki's avatar
Jaydeep Solanki committed
86
#include "core/audioplayer.h"
87
#include "core/sourcereference.h"
88
#include "core/tile.h"
89
#include "settings.h"
90
#include "settings_core.h"
91
#include "url_utils.h"
Michal Humpula's avatar
Michal Humpula committed
92
#include "magnifierview.h"
93

94
static const int pageflags = PagePainter::Accessibility | PagePainter::EnhanceLinks |
95
                       PagePainter::EnhanceImages | PagePainter::Highlights |
96
                       PagePainter::TextSelection | PagePainter::Annotations;
97

Tingnan Zhang's avatar
Tingnan Zhang committed
98 99
static const float kZoomValues[] = { 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 };

100 101 102 103 104
static inline double normClamp( double value, double def )
{
    return ( value < 0.0 || value > 1.0 ) ? def : value;
}

Jiri Baum's avatar
Jiri Baum committed
105 106 107 108 109
struct TableSelectionPart {
    PageViewItem * item;
    Okular::NormalizedRect rectInItem;
    Okular::NormalizedRect rectInSelection;

110
    TableSelectionPart(PageViewItem * item_p, const Okular::NormalizedRect &rectInItem_p, const Okular::NormalizedRect &rectInSelection_p);
Jiri Baum's avatar
Jiri Baum committed
111 112
};

113
TableSelectionPart::TableSelectionPart(  PageViewItem * item_p, const Okular::NormalizedRect &rectInItem_p, const Okular::NormalizedRect &rectInSelection_p)
Jiri Baum's avatar
Jiri Baum committed
114 115 116 117
    : item ( item_p ), rectInItem (rectInItem_p), rectInSelection (rectInSelection_p)
{
}

118 119 120 121
// structure used internally by PageView for data storage
class PageViewPrivate
{
public:
122 123 124
    PageViewPrivate( PageView *qq );

    FormWidgetsController* formWidgetsController();
125 126 127
#ifdef HAVE_SPEECH
    OkularTTS* tts();
#endif
128
    QString selectedText() const;
129

130
    // the document, pageviewItems and the 'visible cache'
131
    PageView *q;
132
    Okular::Document * document;
133 134
    QVector< PageViewItem * > items;
    QLinkedList< PageViewItem * > visibleItems;
Michal Humpula's avatar
Michal Humpula committed
135
    MagnifierView *magnifierView;
136

137
    // view layout (columns and continuous in Settings), zoom and mouse
138 139 140
    PageView::ZoomMode zoomMode;
    float zoomFactor;
    QPoint mouseGrabPos;
141
    QPoint mousePressPos;
142
    QPoint mouseSelectPos;
143
    int mouseMidLastY;
144
    bool mouseSelecting;
145
    QRect mouseSelectionRect;
146
    QColor mouseSelectionColor;
147
    bool mouseTextSelecting;
148
    QSet< int > pagesWithTextSelection;
149
    bool mouseOnRect;
150 151
    Okular::Annotation * mouseAnn;
    QPoint mouseAnnPos;
152
    int mouseAnnPageNum;
153
    int mouseMode;
154

Jiri Baum's avatar
Jiri Baum committed
155 156 157 158
    // table selection
    QList<double> tableSelectionCols;
    QList<double> tableSelectionRows;
    QList<TableSelectionPart> tableSelectionParts;
159
    bool tableDividersGuessed;
Jiri Baum's avatar
Jiri Baum committed
160

Enrico Ros's avatar
Enrico Ros committed
161 162 163 164
    // viewport move
    bool viewportMoveActive;
    QTime viewportMoveTime;
    QPoint viewportMoveDest;
165 166 167
    int lastSourceLocationViewportPageNumber;
    double lastSourceLocationViewportNormalizedX;
    double lastSourceLocationViewportNormalizedY;
Enrico Ros's avatar
Enrico Ros committed
168
    QTimer * viewportMoveTimer;
169
    int controlWheelAccumulatedDelta;
Enrico Ros's avatar
Enrico Ros committed
170
    // auto scroll
171
    int scrollIncrement;
Enrico Ros's avatar
Enrico Ros committed
172
    QTimer * autoScrollTimer;
173
    // annotations
174
    PageViewAnnotator * annotator;
175
    //text annotation dialogs list
176
    QHash< Okular::Annotation *, AnnotWindow * > m_annowindows;
Enrico Ros's avatar
Enrico Ros committed
177
    // other stuff
178
    QTimer * delayResizeEventTimer;
179
    bool dirtyLayout;
Enrico Ros's avatar
Enrico Ros committed
180
    bool blockViewport;                 // prevents changes to viewport
181 182
    bool blockPixmapsRequest;           // prevent pixmap requests
    PageViewMessage * messageWindow;    // in pageviewutils.h
183
    bool m_formsVisible;
184
    FormWidgetsController *formsWidgetController;
185 186 187
#ifdef HAVE_SPEECH
    OkularTTS * m_tts;
#endif
188
    QTimer * refreshTimer;
189
    QSet<int> refreshPages;
190

Jake Linder's avatar
Jake Linder committed
191 192 193
    // bbox state for Trim to Selection mode
    Okular::NormalizedRect trimBoundingBox;

194
    // infinite resizing loop prevention
195
    bool verticalScrollBarVisible;
Thomas Fischer's avatar
Thomas Fischer committed
196
    bool horizontalScrollBarVisible;
197

198 199 200 201
    // drag scroll
    QPoint dragScrollVector;
    QTimer dragScrollTimer;

202 203 204
    // left click depress
    QTimer leftClickTimer;

205
    // actions
Vishesh Handa's avatar
Vishesh Handa committed
206 207 208
    QAction * aRotateClockwise;
    QAction * aRotateCounterClockwise;
    QAction * aRotateOriginal;
209
    KSelectAction * aPageSizes;
Jake Linder's avatar
Jake Linder committed
210
    KActionMenu * aTrimMode;
211
    KToggleAction * aTrimMargins;
Vishesh Handa's avatar
Vishesh Handa committed
212 213 214 215 216
    QAction * aMouseNormal;
    QAction * aMouseSelect;
    QAction * aMouseTextSelect;
    QAction * aMouseTableSelect;
    QAction * aMouseMagnifier;
Jake Linder's avatar
Jake Linder committed
217
    KToggleAction * aTrimToSelection;
218
    KToggleAction * aToggleAnnotator;
219
    KSelectAction * aZoom;
220 221
    QAction * aZoomIn;
    QAction * aZoomOut;
222 223
    KToggleAction * aZoomFitWidth;
    KToggleAction * aZoomFitPage;
Thomas Fischer's avatar
Thomas Fischer committed
224
    KToggleAction * aZoomAutoFit;
225
    KActionMenu * aViewMode;
226
    KToggleAction * aViewContinuous;
Laurent Montel's avatar
Laurent Montel committed
227
    QAction * aPrevAction;
Vishesh Handa's avatar
Vishesh Handa committed
228 229 230 231
    QAction * aToggleForms;
    QAction * aSpeakDoc;
    QAction * aSpeakPage;
    QAction * aSpeakStop;
232
    KActionCollection * actionCollection;
233
    QActionGroup * mouseModeActionGroup;
234
    QAction * aFitWindowToPage;
235

236
    int setting_viewCols;
237
    bool rtl_Mode;
238 239
    // Keep track of whether tablet pen is currently pressed down
    bool penDown;
240 241
};

242 243
PageViewPrivate::PageViewPrivate( PageView *qq )
    : q( qq )
244 245 246
#ifdef HAVE_SPEECH
    , m_tts( 0 )
#endif
247 248 249 250 251 252 253
{
}

FormWidgetsController* PageViewPrivate::formWidgetsController()
{
    if ( !formsWidgetController )
    {
Jon Mease's avatar
Jon Mease committed
254 255 256 257 258
        formsWidgetController = new FormWidgetsController( document );
        QObject::connect( formsWidgetController, SIGNAL( changed( int ) ),
                          q, SLOT( slotFormChanged( int ) ) );
        QObject::connect( formsWidgetController, SIGNAL( action( Okular::Action* ) ),
                          q, SLOT( slotAction( Okular::Action* ) ) );
259 260 261 262 263
    }

    return formsWidgetController;
}

264 265 266 267 268 269 270 271
#ifdef HAVE_SPEECH
OkularTTS* PageViewPrivate::tts()
{
    if ( !m_tts )
    {
        m_tts = new OkularTTS( q );
        if ( aSpeakStop )
        {
Laurent Montel's avatar
Laurent Montel committed
272 273
            QObject::connect( m_tts, &OkularTTS::isSpeaking,
                              aSpeakStop, &QAction::setEnabled );
274 275
        }
    }
276

277 278 279
    return m_tts;
}
#endif
280

281

282 283 284 285
/* 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)
286
 *  550 - events: mouse, keyboard, drag
287
 *  170 - slotRelayoutPages: set contents of the scrollview on continuous/single modes
288
 *  100 - zoom: zooming pages in different ways, keeping update the toolbar actions, etc..
289
 *  other misc functions: only slotRequestVisiblePixmaps and pickItemOnPoint noticeable,
290
 * and many insignificant stuff like this comment :-)
291
 */
292
PageView::PageView( QWidget *parent, Okular::Document *document )
293
    : QAbstractScrollArea( parent )
Laurent Montel's avatar
Laurent Montel committed
294
    , Okular::View( QLatin1String( "PageView" ) )
295 296
{
    // create and initialize private storage structure
297
    d = new PageViewPrivate( this );
298
    d->document = document;
299 300 301
    d->aRotateClockwise = 0;
    d->aRotateCounterClockwise = 0;
    d->aRotateOriginal = 0;
302
    d->aViewMode = 0;
303
    d->zoomMode = PageView::ZoomFitWidth;
304
    d->zoomFactor = 1.0;
305
    d->mouseSelecting = false;
306
    d->mouseTextSelecting = false;
307
    d->mouseOnRect = false;
308
    d->mouseAnn = 0;
309
    d->mouseMode = Okular::Settings::mouseMode();
310
    d->tableDividersGuessed = false;
Enrico Ros's avatar
Enrico Ros committed
311
    d->viewportMoveActive = false;
312 313 314
    d->lastSourceLocationViewportPageNumber = -1;
    d->lastSourceLocationViewportNormalizedX = 0.0;
    d->lastSourceLocationViewportNormalizedY = 0.0;
Enrico Ros's avatar
Enrico Ros committed
315
    d->viewportMoveTimer = 0;
316
    d->controlWheelAccumulatedDelta = 0;
317
    d->scrollIncrement = 0;
Enrico Ros's avatar
Enrico Ros committed
318
    d->autoScrollTimer = 0;
319
    d->annotator = 0;
320
    d->dirtyLayout = false;
321
    d->blockViewport = false;
322
    d->blockPixmapsRequest = false;
323
    d->messageWindow = new PageViewMessage(this);
324
    d->m_formsVisible = false;
325
    d->formsWidgetController = 0;
326 327 328
#ifdef HAVE_SPEECH
    d->m_tts = 0;
#endif
329
    d->refreshTimer = 0;
330 331 332 333
    d->aRotateClockwise = 0;
    d->aRotateCounterClockwise = 0;
    d->aRotateOriginal = 0;
    d->aPageSizes = 0;
Jake Linder's avatar
Jake Linder committed
334
    d->aTrimMode = 0;
335
    d->aTrimMargins = 0;
Jake Linder's avatar
Jake Linder committed
336
    d->aTrimToSelection = 0;
337 338 339 340 341 342
    d->aMouseNormal = 0;
    d->aMouseSelect = 0;
    d->aMouseTextSelect = 0;
    d->aToggleAnnotator = 0;
    d->aZoomFitWidth = 0;
    d->aZoomFitPage = 0;
Thomas Fischer's avatar
Thomas Fischer committed
343
    d->aZoomAutoFit = 0;
344 345
    d->aViewMode = 0;
    d->aViewContinuous = 0;
346
    d->aPrevAction = 0;
347
    d->aToggleForms = 0;
348 349
    d->aSpeakDoc = 0;
    d->aSpeakPage = 0;
350
    d->aSpeakStop = 0;
351
    d->actionCollection = 0;
352
    d->aPageSizes=0;
353
    d->setting_viewCols = Okular::Settings::viewColumns();
354
    d->rtl_Mode = Okular::Settings::rtlReadingDirection();
355
    d->mouseModeActionGroup = 0;
356
    d->penDown = false;
357
    d->aMouseMagnifier = 0;
358
    d->aFitWindowToPage = 0;
Jake Linder's avatar
Jake Linder committed
359
    d->trimBoundingBox = Okular::NormalizedRect(); // Null box
360

Albert Astals Cid's avatar
Albert Astals Cid committed
361
    switch( Okular::Settings::zoomMode() )
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
    {
        case 0:
        {
            d->zoomFactor = 1;
            d->zoomMode = PageView::ZoomFixed;
            break;
        }
        case 1:
        {
            d->zoomMode = PageView::ZoomFitWidth;
            break;
        }
        case 2:
        {
            d->zoomMode = PageView::ZoomFitPage;
            break;
        }
Thomas Fischer's avatar
Thomas Fischer committed
379 380 381 382 383
        case 3:
        {
            d->zoomMode = PageView::ZoomFitAuto;
            break;
        }
384 385
    }

386 387
    d->delayResizeEventTimer = new QTimer( this );
    d->delayResizeEventTimer->setSingleShot( true );
Laurent Montel's avatar
Laurent Montel committed
388
    connect( d->delayResizeEventTimer, &QTimer::timeout, this, &PageView::delayedResizeEvent );
389

390 391
    setFrameStyle(QFrame::NoFrame);

Pino Toscano's avatar
Pino Toscano committed
392 393
    setAttribute( Qt::WA_StaticContents );

Laurent Montel's avatar
Laurent Montel committed
394
    setObjectName( QStringLiteral( "okular::pageView" ) );
Pino Toscano's avatar
Pino Toscano committed
395

396
    // viewport setup: setup focus, and track mouse
397
    viewport()->setFocusProxy( this );
398
    viewport()->setFocusPolicy( Qt::StrongFocus );
399 400 401
    viewport()->setAttribute( Qt::WA_OpaquePaintEvent );
    viewport()->setAttribute( Qt::WA_NoSystemBackground );
    viewport()->setMouseTracking( true );
402
    viewport()->setAutoFillBackground( false );
403 404 405
    // the apparently "magic" value of 20 is the same used internally in QScrollArea
    verticalScrollBar()->setSingleStep( 20 );
    horizontalScrollBar()->setSingleStep( 20 );
406 407

    // conntect the padding of the viewport to pixmaps requests
Laurent Montel's avatar
Laurent Montel committed
408 409 410
    connect(horizontalScrollBar(), &QAbstractSlider::valueChanged, this, &PageView::slotRequestVisiblePixmaps);
    connect(verticalScrollBar(), &QAbstractSlider::valueChanged, this, &PageView::slotRequestVisiblePixmaps);
    connect( &d->dragScrollTimer, &QTimer::timeout, this, &PageView::slotDragScroll );
411

412
    d->leftClickTimer.setSingleShot( true );
Laurent Montel's avatar
Laurent Montel committed
413
    connect( &d->leftClickTimer, &QTimer::timeout, this, &PageView::slotShowSizeAllCursor );
414

415
    // set a corner button to resize the view to the page size
416 417 418 419
//    QPushButton * resizeButton = new QPushButton( viewport() );
//    resizeButton->setPixmap( SmallIcon("crop") );
//    setCornerWidget( resizeButton );
//    resizeButton->setEnabled( false );
420
    // connect(...);
Tobias Koenig's avatar
Tobias Koenig committed
421
    setAttribute( Qt::WA_InputMethodEnabled, true );
422

423
    // Grab pinch gestures to zoom and rotate the view
424 425
    grabGesture(Qt::PinchGesture);

Michal Humpula's avatar
Michal Humpula committed
426 427
    d->magnifierView = new MagnifierView(document, this);
    d->magnifierView->hide();
428
    d->magnifierView->setGeometry(0, 0, 351, 201); // TODO: more dynamic?
Michal Humpula's avatar
Michal Humpula committed
429

Laurent Montel's avatar
Laurent Montel committed
430 431
    connect(document, &Okular::Document::processMovieAction, this, &PageView::slotProcessMovieAction);
    connect(document, &Okular::Document::processRenditionAction, this, &PageView::slotProcessRenditionAction);
432

433
    // schedule the welcome message
434
    QMetaObject::invokeMethod(this, "slotShowWelcome", Qt::QueuedConnection);
435 436 437 438
}

PageView::~PageView()
{
439 440 441 442
#ifdef HAVE_SPEECH
    if ( d->m_tts )
        d->m_tts->stopAllSpeechs();
#endif
Pino Toscano's avatar
Pino Toscano committed
443

444
    // delete the local storage structure
445

446 447 448 449 450 451
    // 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 );

452
    // delete all widgets
Laurent Montel's avatar
Laurent Montel committed
453
    QVector< PageViewItem * >::const_iterator dIt = d->items.constBegin(), dEnd = d->items.constEnd();
454 455
    for ( ; dIt != dEnd; ++dIt )
        delete *dIt;
456
    delete d->formsWidgetController;
Albert Astals Cid's avatar
Albert Astals Cid committed
457
    d->document->removeObserver( this );
458 459 460
    delete d;
}

461 462 463 464 465
void PageView::setupBaseActions( KActionCollection * ac )
{
    d->actionCollection = ac;

    // Zoom actions ( higher scales takes lots of memory! )
Laurent Montel's avatar
Laurent Montel committed
466 467
    d->aZoom  = new KSelectAction(QIcon::fromTheme( QStringLiteral("page-zoom") ), i18n("Zoom"), this);
    ac->addAction(QStringLiteral("zoom_to"), d->aZoom );
468
    d->aZoom->setEditable( true );
469
    d->aZoom->setMaxComboViewCount( 14 );
Laurent Montel's avatar
Laurent Montel committed
470
    connect( d->aZoom, SIGNAL(triggered(QAction*)), this, SLOT(slotZoom()) );
471 472
    updateZoomText();

Laurent Montel's avatar
Laurent Montel committed
473
    d->aZoomIn = KStandardAction::zoomIn( this, SLOT(slotZoomIn()), ac );
474

Laurent Montel's avatar
Laurent Montel committed
475
    d->aZoomOut = KStandardAction::zoomOut( this, SLOT(slotZoomOut()), ac );
476 477
}

478
void PageView::setupViewerActions( KActionCollection * ac )
479
{
480 481
    d->actionCollection = ac;

482 483
    ac->setDefaultShortcut(d->aZoomIn, QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Plus));
    ac->setDefaultShortcut(d->aZoomOut, QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Minus));
484

485
    // orientation menu actions
Laurent Montel's avatar
Laurent Montel committed
486
    d->aRotateClockwise = new QAction( QIcon::fromTheme( QStringLiteral("object-rotate-right") ), i18n( "Rotate &Right" ), this );
487
    d->aRotateClockwise->setIconText( i18nc( "Rotate right", "Right" ) );
Laurent Montel's avatar
Laurent Montel committed
488
    ac->addAction( QStringLiteral("view_orientation_rotate_cw"), d->aRotateClockwise );
489
    d->aRotateClockwise->setEnabled( false );
Laurent Montel's avatar
Laurent Montel committed
490 491
    connect( d->aRotateClockwise, &QAction::triggered, this, &PageView::slotRotateClockwise );
    d->aRotateCounterClockwise = new QAction( QIcon::fromTheme( QStringLiteral("object-rotate-left") ), i18n( "Rotate &Left" ), this );
492
    d->aRotateCounterClockwise->setIconText( i18nc( "Rotate left", "Left" ) );
Laurent Montel's avatar
Laurent Montel committed
493
    ac->addAction( QStringLiteral("view_orientation_rotate_ccw"), d->aRotateCounterClockwise );
494
    d->aRotateCounterClockwise->setEnabled( false );
Laurent Montel's avatar
Laurent Montel committed
495
    connect( d->aRotateCounterClockwise, &QAction::triggered, this, &PageView::slotRotateCounterClockwise );
Vishesh Handa's avatar
Vishesh Handa committed
496
    d->aRotateOriginal = new QAction( i18n( "Original Orientation" ), this );
Laurent Montel's avatar
Laurent Montel committed
497
    ac->addAction( QStringLiteral("view_orientation_original"), d->aRotateOriginal );
498
    d->aRotateOriginal->setEnabled( false );
Laurent Montel's avatar
Laurent Montel committed
499
    connect( d->aRotateOriginal, &QAction::triggered, this, &PageView::slotRotateOriginal );
500

Laurent Montel's avatar
Laurent Montel committed
501
    d->aPageSizes = new KSelectAction(i18n("&Page Size"), this);
Laurent Montel's avatar
Laurent Montel committed
502
    ac->addAction(QStringLiteral("view_pagesizes"), d->aPageSizes);
503
    d->aPageSizes->setEnabled( false );
504

Laurent Montel's avatar
Laurent Montel committed
505 506
    connect( d->aPageSizes , SIGNAL(triggered(int)),
         this, SLOT(slotPageSizes(int)) );
507

Jake Linder's avatar
Jake Linder committed
508 509 510
    // Trim View actions
    d->aTrimMode = new KActionMenu(i18n( "&Trim View" ), this );
    d->aTrimMode->setDelayed( false );
Laurent Montel's avatar
Laurent Montel committed
511
    ac->addAction(QStringLiteral("view_trim_mode"), d->aTrimMode );
Jake Linder's avatar
Jake Linder committed
512 513 514

    d->aTrimMargins  = new KToggleAction( i18n( "&Trim Margins" ), d->aTrimMode->menu() );
    d->aTrimMode->addAction( d->aTrimMargins  );
Laurent Montel's avatar
Laurent Montel committed
515
    ac->addAction( QStringLiteral("view_trim_margins"), d->aTrimMargins  );
Jake Linder's avatar
Jake Linder committed
516
    d->aTrimMargins->setData( qVariantFromValue( (int)Okular::Settings::EnumTrimMode::Margins ) );
Laurent Montel's avatar
Laurent Montel committed
517
    connect( d->aTrimMargins, &QAction::toggled, this, &PageView::slotTrimMarginsToggled );
518
    d->aTrimMargins->setChecked( Okular::Settings::trimMargins() );
519

Jake Linder's avatar
Jake Linder committed
520 521
    d->aTrimToSelection  = new KToggleAction( i18n( "Trim To &Selection" ), d->aTrimMode->menu() );
    d->aTrimMode->addAction( d->aTrimToSelection);
Laurent Montel's avatar
Laurent Montel committed
522
    ac->addAction( QStringLiteral("view_trim_selection"), d->aTrimToSelection);
Jake Linder's avatar
Jake Linder committed
523
    d->aTrimToSelection->setData( qVariantFromValue( (int)Okular::Settings::EnumTrimMode::Selection ) );
Laurent Montel's avatar
Laurent Montel committed
524
    connect( d->aTrimToSelection, &QAction::toggled, this, &PageView::slotTrimToSelectionToggled );
Jake Linder's avatar
Jake Linder committed
525

Laurent Montel's avatar
Laurent Montel committed
526 527 528
    d->aZoomFitWidth  = new KToggleAction(QIcon::fromTheme( QStringLiteral("zoom-fit-width") ), i18n("Fit &Width"), this);
    ac->addAction(QStringLiteral("view_fit_to_width"), d->aZoomFitWidth );
    connect( d->aZoomFitWidth, &QAction::toggled, this, &PageView::slotFitToWidthToggled );
529

Laurent Montel's avatar
Laurent Montel committed
530 531 532
    d->aZoomFitPage  = new KToggleAction(QIcon::fromTheme( QStringLiteral("zoom-fit-best") ), i18n("Fit &Page"), this);
    ac->addAction(QStringLiteral("view_fit_to_page"), d->aZoomFitPage );
    connect( d->aZoomFitPage, &QAction::toggled, this, &PageView::slotFitToPageToggled );
533

Laurent Montel's avatar
Laurent Montel committed
534 535 536
    d->aZoomAutoFit  = new KToggleAction(QIcon::fromTheme( QStringLiteral("zoom-fit-best") ), i18n("&Auto Fit"), this);
    ac->addAction(QStringLiteral("view_auto_fit"), d->aZoomAutoFit );
    connect( d->aZoomAutoFit, &QAction::toggled, this, &PageView::slotAutoFitToggled );
Thomas Fischer's avatar
Thomas Fischer committed
537

Laurent Montel's avatar
Laurent Montel committed
538
    d->aFitWindowToPage = new QAction(QIcon::fromTheme( QStringLiteral("zoom-fit-width") ), i18n("Fit Wi&ndow to Page"), this);
539
    d->aFitWindowToPage->setEnabled( Okular::Settings::viewMode() == (int)Okular::Settings::EnumViewMode::Single );
Laurent Montel's avatar
Laurent Montel committed
540
    ac->setDefaultShortcut(d->aFitWindowToPage, QKeySequence(Qt::CTRL + Qt::Key_J) );
Laurent Montel's avatar
Laurent Montel committed
541 542
    ac->addAction( QStringLiteral("fit_window_to_page"), d->aFitWindowToPage );
    connect( d->aFitWindowToPage, &QAction::triggered, this, &PageView::slotFitWindowToPage );
543

544
    // View-Layout actions
Laurent Montel's avatar
Laurent Montel committed
545
    d->aViewMode = new KActionMenu( QIcon::fromTheme( QStringLiteral("view-split-left-right") ), i18n( "&View Mode" ), this );
546 547 548
    d->aViewMode->setDelayed( false );
#define ADD_VIEWMODE_ACTION( text, name, id ) \
do { \
Vishesh Handa's avatar
Vishesh Handa committed
549
    QAction *vm = new QAction( text, this ); \
550 551 552
    vm->setCheckable( true ); \
    vm->setData( qVariantFromValue( id ) ); \
    d->aViewMode->addAction( vm ); \
553
    ac->addAction( QStringLiteral(name), vm ); \
554 555
    vmGroup->addAction( vm ); \
} while( 0 )
Laurent Montel's avatar
Laurent Montel committed
556
    ac->addAction(QStringLiteral("view_render_mode"), d->aViewMode );
Vishesh Handa's avatar
Vishesh Handa committed
557
    QActionGroup *vmGroup = new QActionGroup( this ); //d->aViewMode->menu() );
558 559
    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 );
560
    ADD_VIEWMODE_ACTION( i18n( "Facing Pages (Center First Page)" ), "view_render_mode_facing_center_first", (int)Okular::Settings::EnumViewMode::FacingFirstCentered );
561 562 563 564 565 566 567 568 569
    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 );
        }
    }
Laurent Montel's avatar
Laurent Montel committed
570
    connect( vmGroup, &QActionGroup::triggered, this, &PageView::slotViewMode );
571
#undef ADD_VIEWMODE_ACTION
572

Laurent Montel's avatar
Laurent Montel committed
573 574 575
    d->aViewContinuous  = new KToggleAction(QIcon::fromTheme( QStringLiteral("view-list-text") ), i18n("&Continuous"), this);
    ac->addAction(QStringLiteral("view_continuous"), d->aViewContinuous );
    connect( d->aViewContinuous, &QAction::toggled, this, &PageView::slotContinuousToggled );
576
    d->aViewContinuous->setChecked( Okular::Settings::viewContinuous() );
577

578 579 580
    // Mouse mode actions for viewer mode
    d->mouseModeActionGroup = new QActionGroup( this );
    d->mouseModeActionGroup->setExclusive( true );
Laurent Montel's avatar
Laurent Montel committed
581 582 583
    d->aMouseNormal  = new QAction( QIcon::fromTheme( QStringLiteral("input-mouse") ), i18n( "&Browse Tool" ), this );
    ac->addAction(QStringLiteral("mouse_drag"), d->aMouseNormal );
    connect( d->aMouseNormal, &QAction::triggered, this, &PageView::slotSetMouseNormal );
Pino Toscano's avatar
Pino Toscano committed
584
    d->aMouseNormal->setIconText( i18nc( "Browse Tool", "Browse" ) );
Pino Toscano's avatar
Pino Toscano committed
585
    d->aMouseNormal->setCheckable( true );
586
    ac->setDefaultShortcut(d->aMouseNormal, QKeySequence(Qt::CTRL + Qt::Key_1));
587
    d->aMouseNormal->setActionGroup( d->mouseModeActionGroup );
588
    d->aMouseNormal->setChecked( Okular::Settings::mouseMode() == Okular::Settings::EnumMouseMode::Browse );
589

Laurent Montel's avatar
Laurent Montel committed
590 591 592
    QAction * mz  = new QAction(QIcon::fromTheme( QStringLiteral("page-zoom") ), i18n("&Zoom Tool"), this);
    ac->addAction(QStringLiteral("mouse_zoom"), mz );
    connect( mz, &QAction::triggered, this, &PageView::slotSetMouseZoom );
Pino Toscano's avatar
Pino Toscano committed
593
    mz->setIconText( i18nc( "Zoom Tool", "Zoom" ) );
Pino Toscano's avatar
Pino Toscano committed
594
    mz->setCheckable( true );
595
    ac->setDefaultShortcut(mz, QKeySequence(Qt::CTRL + Qt::Key_2));
596
    mz->setActionGroup( d->mouseModeActionGroup );
597
    mz->setChecked( Okular::Settings::mouseMode() == Okular::Settings::EnumMouseMode::Zoom );
598

Vishesh Handa's avatar
Vishesh Handa committed
599
    QAction * aToggleChangeColors  = new QAction(i18n("&Toggle Change Colors"), this);
Laurent Montel's avatar
Laurent Montel committed
600 601
    ac->addAction(QStringLiteral("toggle_change_colors"), aToggleChangeColors );
    connect( aToggleChangeColors, &QAction::triggered, this, &PageView::slotToggleChangeColors );
602 603 604 605 606 607 608
}

// WARNING: 'setupViewerActions' must have been called before this method
void PageView::setupActions( KActionCollection * ac )
{
    d->actionCollection = ac;

609 610
    ac->setDefaultShortcuts(d->aZoomIn, KStandardShortcut::zoomIn());
    ac->setDefaultShortcuts(d->aZoomOut, KStandardShortcut::zoomOut());
611 612

    // Mouse-Mode actions
Laurent Montel's avatar
Laurent Montel committed
613 614 615
    d->aMouseSelect  = new QAction(QIcon::fromTheme( QStringLiteral("select-rectangular") ), i18n("&Selection Tool"), this);
    ac->addAction(QStringLiteral("mouse_select"), d->aMouseSelect );
    connect( d->aMouseSelect, &QAction::triggered, this, &PageView::slotSetMouseSelect );
Pino Toscano's avatar
Pino Toscano committed
616
    d->aMouseSelect->setIconText( i18nc( "Select Tool", "Selection" ) );
Pino Toscano's avatar
Pino Toscano committed
617
    d->aMouseSelect->setCheckable( true );
618 619
    ac->setDefaultShortcut(d->aMouseSelect, Qt::CTRL + Qt::Key_3);

620
    d->aMouseSelect->setActionGroup( d->mouseModeActionGroup );
621
    d->aMouseSelect->setChecked( Okular::Settings::mouseMode() == Okular::Settings::EnumMouseMode::RectSelect );
622

Laurent Montel's avatar
Laurent Montel committed
623 624 625
    d->aMouseTextSelect  = new QAction(QIcon::fromTheme( QStringLiteral("draw-text") ), i18n("&Text Selection Tool"), this);
    ac->addAction(QStringLiteral("mouse_textselect"), d->aMouseTextSelect );
    connect( d->aMouseTextSelect, &QAction::triggered, this, &PageView::slotSetMouseTextSelect );
Pino Toscano's avatar
Pino Toscano committed
626
    d->aMouseTextSelect->setIconText( i18nc( "Text Selection Tool", "Text Selection" ) );
627
    d->aMouseTextSelect->setCheckable( true );
628
    ac->setDefaultShortcut(d->aMouseTextSelect, Qt::CTRL + Qt::Key_4);
629
    d->aMouseTextSelect->setActionGroup( d->mouseModeActionGroup );
630
    d->aMouseTextSelect->setChecked( Okular::Settings::mouseMode() == Okular::Settings::EnumMouseMode::TextSelect );
631

Laurent Montel's avatar
Laurent Montel committed
632 633 634
    d->aMouseTableSelect  = new QAction(QIcon::fromTheme( QStringLiteral("table") ), i18n("T&able Selection Tool"), this);
    ac->addAction(QStringLiteral("mouse_tableselect"), d->aMouseTableSelect );
    connect( d->aMouseTableSelect, &QAction::triggered, this, &PageView::slotSetMouseTableSelect );
Jiri Baum's avatar
Jiri Baum committed
635 636
    d->aMouseTableSelect->setIconText( i18nc( "Table Selection Tool", "Table Selection" ) );
    d->aMouseTableSelect->setCheckable( true );
637
    ac->setDefaultShortcut(d->aMouseTableSelect, Qt::CTRL + Qt::Key_5);
638
    d->aMouseTableSelect->setActionGroup( d->mouseModeActionGroup );
639
    d->aMouseTableSelect->setChecked( Okular::Settings::mouseMode() == Okular::Settings::EnumMouseMode::TableSelect );
Jiri Baum's avatar
Jiri Baum committed
640

Laurent Montel's avatar
Laurent Montel committed
641 642 643
    d->aMouseMagnifier = new QAction(QIcon::fromTheme( QStringLiteral("document-preview") ), i18n("&Magnifier"), this);
    ac->addAction(QStringLiteral("mouse_magnifier"), d->aMouseMagnifier );
    connect( d->aMouseMagnifier, &QAction::triggered, this, &PageView::slotSetMouseMagnifier );
Michal Humpula's avatar
Michal Humpula committed
644 645
    d->aMouseMagnifier->setIconText( i18nc( "Magnifier Tool", "Magnifier" ) );
    d->aMouseMagnifier->setCheckable( true );
646
    ac->setDefaultShortcut(d->aMouseMagnifier, Qt::CTRL + Qt::Key_6);
Michal Humpula's avatar
Michal Humpula committed
647 648 649
    d->aMouseMagnifier->setActionGroup( d->mouseModeActionGroup );
    d->aMouseMagnifier->setChecked( Okular::Settings::mouseMode() == Okular::Settings::EnumMouseMode::Magnifier );

Laurent Montel's avatar
Laurent Montel committed
650 651
    d->aToggleAnnotator  = new KToggleAction(QIcon::fromTheme( QStringLiteral("draw-freehand") ), i18n("&Review"), this);
    ac->addAction(QStringLiteral("mouse_toggle_annotate"), d->aToggleAnnotator );
Pino Toscano's avatar
Pino Toscano committed
652
    d->aToggleAnnotator->setCheckable( true );
Laurent Montel's avatar
Laurent Montel committed
653
    connect( d->aToggleAnnotator, &QAction::toggled, this, &PageView::slotToggleAnnotator );
654
    ac->setDefaultShortcut(d->aToggleAnnotator, Qt::Key_F6);
655

656
    ToolAction *ta = new ToolAction( this );
Laurent Montel's avatar
Laurent Montel committed
657
    ac->addAction( QStringLiteral("mouse_selecttools"), ta );
658 659
    ta->addAction( d->aMouseSelect );
    ta->addAction( d->aMouseTextSelect );
660
    ta->addAction( d->aMouseTableSelect );
661

662
    // speak actions