Changeset View
Changeset View
Standalone View
Standalone View
ui/pageview.cpp
Show First 20 Lines • Show All 96 Lines • ▼ Show 20 Line(s) | |||||
97 | #include "magnifierview.h" | 97 | #include "magnifierview.h" | ||
98 | 98 | | |||
99 | static const int pageflags = PagePainter::Accessibility | PagePainter::EnhanceLinks | | 99 | static const int pageflags = PagePainter::Accessibility | PagePainter::EnhanceLinks | | ||
100 | PagePainter::EnhanceImages | PagePainter::Highlights | | 100 | PagePainter::EnhanceImages | PagePainter::Highlights | | ||
101 | PagePainter::TextSelection | PagePainter::Annotations; | 101 | PagePainter::TextSelection | PagePainter::Annotations; | ||
102 | 102 | | |||
103 | 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 }; | 103 | 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 }; | ||
104 | 104 | | |||
105 | static inline double normClamp( double value, double def ) | 105 | /** | ||
106 | * Returns @p value if in [0, 1], @p defaultValue otherwise. | ||||
107 | */ | ||||
108 | static inline double normClamp( double value, double defaultValue ) | ||||
106 | { | 109 | { | ||
107 | return ( value < 0.0 || value > 1.0 ) ? def : value; | 110 | return ( value < 0.0 || value > 1.0 ) ? defaultValue : value; | ||
108 | } | 111 | } | ||
109 | 112 | | |||
110 | struct TableSelectionPart { | 113 | struct TableSelectionPart { | ||
111 | PageViewItem * item; | 114 | PageViewItem * item; | ||
112 | Okular::NormalizedRect rectInItem; | 115 | Okular::NormalizedRect rectInItem; | ||
113 | Okular::NormalizedRect rectInSelection; | 116 | Okular::NormalizedRect rectInSelection; | ||
114 | 117 | | |||
115 | TableSelectionPart(PageViewItem * item_p, const Okular::NormalizedRect &rectInItem_p, const Okular::NormalizedRect &rectInSelection_p); | 118 | TableSelectionPart(PageViewItem * item_p, const Okular::NormalizedRect &rectInItem_p, const Okular::NormalizedRect &rectInSelection_p); | ||
Show All 9 Lines | |||||
125 | { | 128 | { | ||
126 | public: | 129 | public: | ||
127 | PageViewPrivate( PageView *qq ); | 130 | PageViewPrivate( PageView *qq ); | ||
128 | 131 | | |||
129 | FormWidgetsController* formWidgetsController(); | 132 | FormWidgetsController* formWidgetsController(); | ||
130 | #ifdef HAVE_SPEECH | 133 | #ifdef HAVE_SPEECH | ||
131 | OkularTTS* tts(); | 134 | OkularTTS* tts(); | ||
132 | #endif | 135 | #endif | ||
136 | /** | ||||
137 | * Returns all currently selected text. | ||||
138 | */ | ||||
133 | QString selectedText() const; | 139 | QString selectedText() const; | ||
134 | 140 | | |||
135 | // the document, pageviewItems and the 'visible cache' | 141 | // the document, pageviewItems and the 'visible cache' | ||
136 | PageView *q; | 142 | PageView *q; | ||
137 | Okular::Document * document; | 143 | Okular::Document * document; | ||
138 | QVector< PageViewItem * > items; | 144 | QVector< PageViewItem * > items; | ||
139 | QLinkedList< PageViewItem * > visibleItems; | 145 | QLinkedList< PageViewItem * > visibleItems; | ||
140 | MagnifierView *magnifierView; | 146 | MagnifierView *magnifierView; | ||
▲ Show 20 Lines • Show All 274 Lines • ▼ Show 20 Line(s) | 342 | #endif | |||
415 | horizontalScrollBar()->setSingleStep( 20 ); | 421 | horizontalScrollBar()->setSingleStep( 20 ); | ||
416 | 422 | | |||
417 | // connect the padding of the viewport to pixmaps requests | 423 | // connect the padding of the viewport to pixmaps requests | ||
418 | connect(horizontalScrollBar(), &QAbstractSlider::valueChanged, this, &PageView::slotRequestVisiblePixmaps); | 424 | connect(horizontalScrollBar(), &QAbstractSlider::valueChanged, this, &PageView::slotRequestVisiblePixmaps); | ||
419 | connect(verticalScrollBar(), &QAbstractSlider::valueChanged, this, &PageView::slotRequestVisiblePixmaps); | 425 | connect(verticalScrollBar(), &QAbstractSlider::valueChanged, this, &PageView::slotRequestVisiblePixmaps); | ||
420 | connect( &d->dragScrollTimer, &QTimer::timeout, this, &PageView::slotDragScroll ); | 426 | connect( &d->dragScrollTimer, &QTimer::timeout, this, &PageView::slotDragScroll ); | ||
421 | 427 | | |||
422 | d->leftClickTimer.setSingleShot( true ); | 428 | d->leftClickTimer.setSingleShot( true ); | ||
423 | connect( &d->leftClickTimer, &QTimer::timeout, this, &PageView::slotShowSizeAllCursor ); | 429 | connect( &d->leftClickTimer, &QTimer::timeout, this, &PageView::slotShowSizeAllCursor ); | ||
davidhurka: Wrong cursor? Dragging the page activates a closed hand, not size all. | |||||
424 | 430 | | |||
425 | // set a corner button to resize the view to the page size | 431 | // set a corner button to resize the view to the page size | ||
426 | // QPushButton * resizeButton = new QPushButton( viewport() ); | 432 | // QPushButton * resizeButton = new QPushButton( viewport() ); | ||
427 | // resizeButton->setPixmap( SmallIcon("crop") ); | 433 | // resizeButton->setPixmap( SmallIcon("crop") ); | ||
428 | // setCornerWidget( resizeButton ); | 434 | // setCornerWidget( resizeButton ); | ||
429 | // resizeButton->setEnabled( false ); | 435 | // resizeButton->setEnabled( false ); | ||
430 | // connect(...); | 436 | // connect(...); | ||
431 | setAttribute( Qt::WA_InputMethodEnabled, true ); | 437 | setAttribute( Qt::WA_InputMethodEnabled, true ); | ||
Show All 39 Lines | |||||
471 | void PageView::setupBaseActions( KActionCollection * ac ) | 477 | void PageView::setupBaseActions( KActionCollection * ac ) | ||
472 | { | 478 | { | ||
473 | d->actionCollection = ac; | 479 | d->actionCollection = ac; | ||
474 | 480 | | |||
475 | // Zoom actions ( higher scales takes lots of memory! ) | 481 | // Zoom actions ( higher scales takes lots of memory! ) | ||
476 | d->aZoom = new KSelectAction(QIcon::fromTheme( QStringLiteral("page-zoom") ), i18n("Zoom"), this); | 482 | d->aZoom = new KSelectAction(QIcon::fromTheme( QStringLiteral("page-zoom") ), i18n("Zoom"), this); | ||
477 | ac->addAction(QStringLiteral("zoom_to"), d->aZoom ); | 483 | ac->addAction(QStringLiteral("zoom_to"), d->aZoom ); | ||
478 | d->aZoom->setEditable( true ); | 484 | d->aZoom->setEditable( true ); | ||
479 | d->aZoom->setMaxComboViewCount( 14 ); | 485 | d->aZoom->setMaxComboViewCount( 14 ); | ||
davidhurka: This has usually 17 items. Any reasons to limit to 14 instead? | |||||
480 | connect( d->aZoom, SIGNAL(triggered(QAction*)), this, SLOT(slotZoom()) ); | 486 | connect( d->aZoom, SIGNAL(triggered(QAction*)), this, SLOT(slotZoom()) ); | ||
481 | updateZoomText(); | 487 | updateZoomText(); | ||
482 | 488 | | |||
483 | d->aZoomIn = KStandardAction::zoomIn( this, SLOT(slotZoomIn()), ac ); | 489 | d->aZoomIn = KStandardAction::zoomIn( this, SLOT(slotZoomIn()), ac ); | ||
484 | 490 | | |||
485 | d->aZoomOut = KStandardAction::zoomOut( this, SLOT(slotZoomOut()), ac ); | 491 | d->aZoomOut = KStandardAction::zoomOut( this, SLOT(slotZoomOut()), ac ); | ||
486 | 492 | | |||
487 | d->aZoomActual = KStandardAction::actualSize( this, &PageView::slotZoomActual, ac ); | 493 | d->aZoomActual = KStandardAction::actualSize( this, &PageView::slotZoomActual, ac ); | ||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | 590 | #undef ADD_VIEWMODE_ACTION | |||
607 | mz->setActionGroup( d->mouseModeActionGroup ); | 613 | mz->setActionGroup( d->mouseModeActionGroup ); | ||
608 | mz->setChecked( Okular::Settings::mouseMode() == Okular::Settings::EnumMouseMode::Zoom ); | 614 | mz->setChecked( Okular::Settings::mouseMode() == Okular::Settings::EnumMouseMode::Zoom ); | ||
609 | 615 | | |||
610 | QAction * aToggleChangeColors = new QAction(i18n("&Toggle Change Colors"), this); | 616 | QAction * aToggleChangeColors = new QAction(i18n("&Toggle Change Colors"), this); | ||
611 | ac->addAction(QStringLiteral("toggle_change_colors"), aToggleChangeColors ); | 617 | ac->addAction(QStringLiteral("toggle_change_colors"), aToggleChangeColors ); | ||
612 | connect( aToggleChangeColors, &QAction::triggered, this, &PageView::slotToggleChangeColors ); | 618 | connect( aToggleChangeColors, &QAction::triggered, this, &PageView::slotToggleChangeColors ); | ||
613 | } | 619 | } | ||
614 | 620 | | |||
615 | // WARNING: 'setupViewerActions' must have been called before this method | | |||
616 | void PageView::setupActions( KActionCollection * ac ) | 621 | void PageView::setupActions( KActionCollection * ac ) | ||
617 | { | 622 | { | ||
618 | d->actionCollection = ac; | 623 | d->actionCollection = ac; | ||
619 | 624 | | |||
620 | ac->setDefaultShortcuts(d->aZoomIn, KStandardShortcut::zoomIn()); | 625 | ac->setDefaultShortcuts(d->aZoomIn, KStandardShortcut::zoomIn()); | ||
621 | ac->setDefaultShortcuts(d->aZoomOut, KStandardShortcut::zoomOut()); | 626 | ac->setDefaultShortcuts(d->aZoomOut, KStandardShortcut::zoomOut()); | ||
622 | 627 | | |||
623 | // Mouse-Mode actions | 628 | // Mouse-Mode actions | ||
▲ Show 20 Lines • Show All 726 Lines • ▼ Show 20 Line(s) | 1316 | #endif | |||
1350 | } | 1355 | } | ||
1351 | 1356 | | |||
1352 | // since the page has moved below cursor, update it | 1357 | // since the page has moved below cursor, update it | ||
1353 | updateCursor(); | 1358 | updateCursor(); | ||
1354 | } | 1359 | } | ||
1355 | 1360 | | |||
1356 | void PageView::notifyPageChanged( int pageNumber, int changedFlags ) | 1361 | void PageView::notifyPageChanged( int pageNumber, int changedFlags ) | ||
1357 | { | 1362 | { | ||
1358 | // only handle pixmap / highlight changes notifies | | |||
1359 | if ( changedFlags & DocumentObserver::Bookmark ) | 1363 | if ( changedFlags & DocumentObserver::Bookmark ) | ||
1360 | return; | 1364 | return; | ||
1361 | 1365 | | |||
1362 | if ( changedFlags & DocumentObserver::Annotations ) | 1366 | if ( changedFlags & DocumentObserver::Annotations ) | ||
1363 | { | 1367 | { | ||
1364 | const QLinkedList< Okular::Annotation * > annots = d->document->page( pageNumber )->annotations(); | 1368 | const QLinkedList< Okular::Annotation * > annots = d->document->page( pageNumber )->annotations(); | ||
1365 | const QLinkedList< Okular::Annotation * >::ConstIterator annItEnd = annots.end(); | 1369 | const QLinkedList< Okular::Annotation * >::ConstIterator annItEnd = annots.end(); | ||
1366 | QSet< AnnotWindow * >::Iterator it = d->m_annowindows.begin(); | 1370 | QSet< AnnotWindow * >::Iterator it = d->m_annowindows.begin(); | ||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Line(s) | 1444 | { | |||
1448 | } | 1452 | } | ||
1449 | else | 1453 | else | ||
1450 | { | 1454 | { | ||
1451 | // forbid unloading of the visible items, and of the previous and next | 1455 | // forbid unloading of the visible items, and of the previous and next | ||
1452 | for ( const PageViewItem * visibleItem : qAsConst( d->visibleItems ) ) | 1456 | for ( const PageViewItem * visibleItem : qAsConst( d->visibleItems ) ) | ||
1453 | if ( abs( visibleItem->pageNumber() - pageNumber ) <= 1 ) | 1457 | if ( abs( visibleItem->pageNumber() - pageNumber ) <= 1 ) | ||
1454 | return false; | 1458 | return false; | ||
1455 | } | 1459 | } | ||
1456 | // if hidden premit unloading | 1460 | // if hidden permit unloading | ||
1457 | return true; | 1461 | return true; | ||
1458 | } | 1462 | } | ||
1459 | 1463 | | |||
1460 | void PageView::notifyCurrentPageChanged( int previous, int current ) | 1464 | void PageView::notifyCurrentPageChanged( int previous, int current ) | ||
1461 | { | 1465 | { | ||
1462 | if ( previous != -1 ) | 1466 | if ( previous != -1 ) | ||
1463 | { | 1467 | { | ||
1464 | PageViewItem * item = d->items.at( previous ); | 1468 | PageViewItem * item = d->items.at( previous ); | ||
▲ Show 20 Lines • Show All 2240 Lines • ▼ Show 20 Line(s) | |||||
3705 | #endif | 3709 | #endif | ||
3706 | } | 3710 | } | ||
3707 | 3711 | | |||
3708 | PageViewItem * PageView::pickItemOnPoint( int x, int y ) | 3712 | PageViewItem * PageView::pickItemOnPoint( int x, int y ) | ||
3709 | { | 3713 | { | ||
3710 | PageViewItem * item = nullptr; | 3714 | PageViewItem * item = nullptr; | ||
3711 | for ( PageViewItem * i : qAsConst( d->visibleItems ) ) | 3715 | for ( PageViewItem * i : qAsConst( d->visibleItems ) ) | ||
3712 | { | 3716 | { | ||
3713 | const QRect & r = i->croppedGeometry(); | 3717 | const QRect & r = i->croppedGeometry(); | ||
davidhurka: Suggestion: QRect::contains(x, y, proper = true) | |||||
3714 | if ( x < r.right() && x > r.left() && y < r.bottom() ) | 3718 | if ( x < r.right() && x > r.left() && y < r.bottom() ) | ||
3715 | { | 3719 | { | ||
3716 | if ( y > r.top() ) | 3720 | if ( y > r.top() ) | ||
3717 | item = i; | 3721 | item = i; | ||
3718 | break; | 3722 | break; | ||
3719 | } | 3723 | } | ||
3720 | } | 3724 | } | ||
3721 | return item; | 3725 | return item; | ||
Show All 24 Lines | 3740 | { | |||
3746 | } | 3750 | } | ||
3747 | } | 3751 | } | ||
3748 | 3752 | | |||
3749 | void PageView::scrollPosIntoView( const QPoint & pos ) | 3753 | void PageView::scrollPosIntoView( const QPoint & pos ) | ||
3750 | { | 3754 | { | ||
3751 | // this number slows the speed of the page by its value, chosen not to be too fast or too slow, the actual speed is determined from the mouse position, not critical | 3755 | // this number slows the speed of the page by its value, chosen not to be too fast or too slow, the actual speed is determined from the mouse position, not critical | ||
3752 | const int damping=6; | 3756 | const int damping=6; | ||
3753 | 3757 | | |||
3754 | if (pos.x() < horizontalScrollBar()->value()) d->dragScrollVector.setX((pos.x() - horizontalScrollBar()->value())/damping); | 3758 | if (pos.x() < horizontalScrollBar()->value()) | ||
3755 | else if (horizontalScrollBar()->value() + viewport()->width() < pos.x()) d->dragScrollVector.setX((pos.x() - horizontalScrollBar()->value() - viewport()->width())/damping); | 3759 | d->dragScrollVector.setX((pos.x() - horizontalScrollBar()->value())/damping); | ||
3756 | else d->dragScrollVector.setX(0); | 3760 | else if (horizontalScrollBar()->value() + viewport()->width() < pos.x()) | ||
3757 | 3761 | d->dragScrollVector.setX((pos.x() - horizontalScrollBar()->value() - viewport()->width())/damping); | |||
3758 | if (pos.y() < verticalScrollBar()->value()) d->dragScrollVector.setY((pos.y() - verticalScrollBar()->value())/damping); | 3762 | else | ||
3759 | else if (verticalScrollBar()->value() + viewport()->height() < pos.y()) d->dragScrollVector.setY((pos.y() - verticalScrollBar()->value() - viewport()->height())/damping); | 3763 | d->dragScrollVector.setX(0); | ||
3760 | else d->dragScrollVector.setY(0); | 3764 | | ||
3765 | if (pos.y() < verticalScrollBar()->value()) | ||||
3766 | d->dragScrollVector.setY((pos.y() - verticalScrollBar()->value())/damping); | ||||
3767 | else if (verticalScrollBar()->value() + viewport()->height() < pos.y()) | ||||
3768 | d->dragScrollVector.setY((pos.y() - verticalScrollBar()->value() - viewport()->height())/damping); | ||||
3769 | else | ||||
3770 | d->dragScrollVector.setY(0); | ||||
3761 | 3771 | | |||
3762 | if (d->dragScrollVector != QPoint(0, 0)) | 3772 | if (d->dragScrollVector != QPoint(0, 0)) | ||
3763 | { | 3773 | { | ||
3764 | if (!d->dragScrollTimer.isActive()) d->dragScrollTimer.start(1000/60); //60 fps | 3774 | if (!d->dragScrollTimer.isActive()) d->dragScrollTimer.start(1000/60); //60 fps | ||
3765 | } | 3775 | } | ||
3766 | else d->dragScrollTimer.stop(); | 3776 | else d->dragScrollTimer.stop(); | ||
3767 | } | 3777 | } | ||
3768 | 3778 | | |||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | 3821 | { | |||
3826 | foreach( int p, pagesWithSelectionSet ) | 3836 | foreach( int p, pagesWithSelectionSet ) | ||
3827 | { | 3837 | { | ||
3828 | d->document->setPageTextSelection( p, selections[ p - first ], palette().color( QPalette::Active, QPalette::Highlight ) ); | 3838 | d->document->setPageTextSelection( p, selections[ p - first ], palette().color( QPalette::Active, QPalette::Highlight ) ); | ||
3829 | } | 3839 | } | ||
3830 | d->pagesWithTextSelection = pagesWithSelectionSet; | 3840 | d->pagesWithTextSelection = pagesWithSelectionSet; | ||
3831 | } | 3841 | } | ||
3832 | } | 3842 | } | ||
3833 | 3843 | | |||
3844 | /** | ||||
3845 | * Normalizes a point from a rotated reference area. | ||||
3846 | * | ||||
3847 | * @param rotated The point in absolute coordinates on the rotated reference area. | ||||
3848 | * @param rect The rotated reference area. | ||||
3849 | * @param rotation The rotation of the reference area. This function does the reverse rotation. | ||||
3850 | */ | ||||
3834 | static Okular::NormalizedPoint rotateInNormRect( const QPoint &rotated, const QRect &rect, Okular::Rotation rotation ) | 3851 | static Okular::NormalizedPoint rotateInNormRect( const QPoint &rotated, const QRect &rect, Okular::Rotation rotation ) | ||
3835 | { | 3852 | { | ||
3836 | Okular::NormalizedPoint ret; | 3853 | Okular::NormalizedPoint ret; | ||
3837 | 3854 | | |||
3838 | switch ( rotation ) | 3855 | switch ( rotation ) | ||
3839 | { | 3856 | { | ||
3840 | case Okular::Rotation0: | 3857 | case Okular::Rotation0: | ||
3841 | ret = Okular::NormalizedPoint( rotated.x(), rotated.y(), rect.width(), rect.height() ); | 3858 | ret = Okular::NormalizedPoint( rotated.x(), rotated.y(), rect.width(), rect.height() ); | ||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Line(s) | |||||
3907 | static const int kcolWidthMargin = 6; | 3924 | static const int kcolWidthMargin = 6; | ||
3908 | static const int krowHeightMargin = 12; | 3925 | static const int krowHeightMargin = 12; | ||
3909 | 3926 | | |||
3910 | double PageView::zoomFactorFitMode( ZoomMode mode ) | 3927 | double PageView::zoomFactorFitMode( ZoomMode mode ) | ||
3911 | { | 3928 | { | ||
3912 | const int pageCount = d->items.count(); | 3929 | const int pageCount = d->items.count(); | ||
3913 | if ( pageCount == 0 ) | 3930 | if ( pageCount == 0 ) | ||
3914 | return 0; | 3931 | return 0; | ||
3932 | | ||||
3933 | // Determine how many columns to fit. | ||||
3915 | const bool facingCentered = Okular::Settings::viewMode() == Okular::Settings::EnumViewMode::FacingFirstCentered || (Okular::Settings::viewMode() == Okular::Settings::EnumViewMode::Facing && pageCount == 1); | 3934 | const bool facingCentered = Okular::Settings::viewMode() == Okular::Settings::EnumViewMode::FacingFirstCentered || (Okular::Settings::viewMode() == Okular::Settings::EnumViewMode::Facing && pageCount == 1); | ||
3916 | const bool overrideCentering = facingCentered && pageCount < 3; | 3935 | const bool overrideCentering = facingCentered && pageCount < 3; | ||
3917 | const int nCols = overrideCentering ? 1 : viewColumns(); | 3936 | const int nCols = overrideCentering ? 1 : viewColumns(); | ||
3937 | | ||||
3938 | // Calculate desired page display size. | ||||
3918 | const double colWidth = viewport()->width() / nCols - kcolWidthMargin; | 3939 | const double colWidth = viewport()->width() / nCols - kcolWidthMargin; | ||
3919 | const double rowHeight = viewport()->height() - krowHeightMargin; | 3940 | const double rowHeight = viewport()->height() - krowHeightMargin; | ||
3941 | | ||||
3942 | // Get the size of the current page. | ||||
3920 | const PageViewItem * currentItem = d->items[ qMax( 0, (int)d->document->currentPage()) ]; | 3943 | const PageViewItem * currentItem = d->items[ qMax( 0, (int)d->document->currentPage()) ]; | ||
3921 | // prevent segmentation fault when opening a new document; | 3944 | // prevent segmentation fault when opening a new document; | ||
3922 | if ( !currentItem ) | 3945 | if ( !currentItem ) | ||
3923 | return 0; | 3946 | return 0; | ||
3924 | const Okular::Page * okularPage = currentItem->page(); | 3947 | const Okular::Page * okularPage = currentItem->page(); | ||
3925 | const double width = okularPage->width(), height = okularPage->height(); | 3948 | const double width = okularPage->width(), height = okularPage->height(); | ||
3949 | | ||||
3950 | // Calculate the zoom factor. | ||||
3926 | if ( mode == ZoomFitWidth ) | 3951 | if ( mode == ZoomFitWidth ) | ||
3927 | return (double) colWidth / width; | 3952 | return (double) colWidth / width; | ||
3928 | if ( mode == ZoomFitPage ) | 3953 | if ( mode == ZoomFitPage ) | ||
3929 | { | 3954 | { | ||
3930 | const double scaleW = (double) colWidth / (double)width; | 3955 | const double scaleW = (double) colWidth / (double)width; | ||
3931 | const double scaleH = (double) rowHeight / (double)height; | 3956 | const double scaleH = (double) rowHeight / (double)height; | ||
3932 | return qMin(scaleW, scaleH); | 3957 | return qMin(scaleW, scaleH); | ||
3933 | } | 3958 | } | ||
3934 | return 0; | 3959 | return 0; | ||
3935 | } | 3960 | } | ||
3936 | 3961 | | |||
3937 | void PageView::updateZoom( ZoomMode newZoomMode ) | 3962 | void PageView::updateZoom( ZoomMode newZoomMode ) | ||
3938 | { | 3963 | { | ||
3939 | if ( newZoomMode == ZoomFixed ) | 3964 | if ( newZoomMode == ZoomFixed ) | ||
3940 | { | 3965 | { | ||
3941 | if ( d->aZoom->currentItem() == 0 ) | 3966 | if ( d->aZoom->currentItem() == 0 ) | ||
3942 | newZoomMode = ZoomFitWidth; | 3967 | newZoomMode = ZoomFitWidth; | ||
3943 | else if ( d->aZoom->currentItem() == 1 ) | 3968 | else if ( d->aZoom->currentItem() == 1 ) | ||
3944 | newZoomMode = ZoomFitPage; | 3969 | newZoomMode = ZoomFitPage; | ||
3945 | else if ( d->aZoom->currentItem() == 2 ) | 3970 | else if ( d->aZoom->currentItem() == 2 ) | ||
3946 | newZoomMode = ZoomFitAuto; | 3971 | newZoomMode = ZoomFitAuto; | ||
3947 | } | 3972 | } | ||
3948 | 3973 | | |||
3974 | // Calculate new zoom factor. | ||||
3949 | float newFactor = d->zoomFactor; | 3975 | float newFactor = d->zoomFactor; | ||
3950 | QAction * checkedZoomAction = nullptr; | 3976 | QAction * checkedZoomAction = nullptr; | ||
3951 | switch ( newZoomMode ) | 3977 | switch ( newZoomMode ) | ||
3952 | { | 3978 | { | ||
3953 | case ZoomFixed:{ //ZoomFixed case | 3979 | case ZoomFixed:{ //ZoomFixed case | ||
3954 | QString z = d->aZoom->currentText(); | 3980 | QString z = d->aZoom->currentText(); | ||
3955 | // kdelibs4 sometimes adds accelerators to actions' text directly :( | 3981 | // kdelibs4 sometimes adds accelerators to actions' text directly :( | ||
3956 | z.remove (QLatin1Char('&')); | 3982 | z.remove (QLatin1Char('&')); | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 4039 | case ZoomRefreshCurrent: | |||
4016 | break; | 4042 | break; | ||
4017 | } | 4043 | } | ||
4018 | const float upperZoomLimit = d->document->supportsTiles() ? 16.0 : 4.0; | 4044 | const float upperZoomLimit = d->document->supportsTiles() ? 16.0 : 4.0; | ||
4019 | if ( newFactor > upperZoomLimit ) | 4045 | if ( newFactor > upperZoomLimit ) | ||
4020 | newFactor = upperZoomLimit; | 4046 | newFactor = upperZoomLimit; | ||
4021 | if ( newFactor < 0.1 ) | 4047 | if ( newFactor < 0.1 ) | ||
4022 | newFactor = 0.1; | 4048 | newFactor = 0.1; | ||
4023 | 4049 | | |||
4050 | // Apply new zoom mode and factor. | ||||
4024 | if ( newZoomMode != d->zoomMode || (newZoomMode == ZoomFixed && newFactor != d->zoomFactor ) ) | 4051 | if ( newZoomMode != d->zoomMode || (newZoomMode == ZoomFixed && newFactor != d->zoomFactor ) ) | ||
4025 | { | 4052 | { | ||
4026 | // rebuild layout and update the whole viewport | 4053 | // rebuild layout and update the whole viewport | ||
4027 | d->zoomMode = newZoomMode; | 4054 | d->zoomMode = newZoomMode; | ||
4028 | d->zoomFactor = newFactor; | 4055 | d->zoomFactor = newFactor; | ||
4029 | // be sure to block updates to document's viewport | 4056 | // be sure to block updates to document's viewport | ||
4030 | bool prevState = d->blockViewport; | 4057 | bool prevState = d->blockViewport; | ||
4031 | d->blockViewport = true; | 4058 | d->blockViewport = true; | ||
▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Line(s) | |||||
4206 | 4233 | | |||
4207 | } | 4234 | } | ||
4208 | 4235 | | |||
4209 | void PageView::moveMagnifier( const QPoint& p ) // non scaled point | 4236 | void PageView::moveMagnifier( const QPoint& p ) // non scaled point | ||
4210 | { | 4237 | { | ||
4211 | const int w = d->magnifierView->width() * 0.5; | 4238 | const int w = d->magnifierView->width() * 0.5; | ||
4212 | const int h = d->magnifierView->height() * 0.5; | 4239 | const int h = d->magnifierView->height() * 0.5; | ||
4213 | 4240 | | |||
4241 | // Get top left corner of magnifier. | ||||
4214 | int x = p.x() - w; | 4242 | int x = p.x() - w; | ||
4215 | int y = p.y() - h; | 4243 | int y = p.y() - h; | ||
4216 | 4244 | | |||
4217 | const int max_x = viewport()->width(); | 4245 | const int max_x = viewport()->width(); | ||
4218 | const int max_y = viewport()->height(); | 4246 | const int max_y = viewport()->height(); | ||
4219 | 4247 | | |||
4220 | QPoint scroll(0,0); | 4248 | QPoint scroll(0,0); | ||
4221 | 4249 | | |||
Show All 22 Lines | |||||
4244 | } | 4272 | } | ||
4245 | 4273 | | |||
4246 | if (!scroll.isNull()) | 4274 | if (!scroll.isNull()) | ||
4247 | scrollPosIntoView(contentAreaPoint(p + scroll)); | 4275 | scrollPosIntoView(contentAreaPoint(p + scroll)); | ||
4248 | 4276 | | |||
4249 | d->magnifierView->move(x, y); | 4277 | d->magnifierView->move(x, y); | ||
4250 | } | 4278 | } | ||
4251 | 4279 | | |||
4252 | void PageView::updateMagnifier( const QPoint& p ) // scaled point | 4280 | void PageView::updateMagnifier( const QPoint& p ) | ||
4253 | { | 4281 | { | ||
4254 | /* translate mouse coordinates to page coordinates and inform the magnifier of the situation */ | 4282 | /* translate mouse coordinates to page coordinates and inform the magnifier of the situation */ | ||
4255 | PageViewItem *item = pickItemOnPoint(p.x(), p.y()); | 4283 | PageViewItem *item = pickItemOnPoint(p.x(), p.y()); | ||
4256 | if (item) | 4284 | if (item) | ||
4257 | { | 4285 | { | ||
4258 | Okular::NormalizedPoint np(item->absToPageX(p.x()), item->absToPageY(p.y())); | 4286 | Okular::NormalizedPoint np(item->absToPageX(p.x()), item->absToPageY(p.y())); | ||
4259 | d->magnifierView->updateView( np, item->page() ); | 4287 | d->magnifierView->updateView( np, item->page() ); | ||
4260 | } | 4288 | } | ||
4261 | } | 4289 | } | ||
4262 | 4290 | | |||
4263 | int PageView::viewColumns() const | 4291 | int PageView::viewColumns() const | ||
4264 | { | 4292 | { | ||
4265 | int vm = Okular::Settings::viewMode(); | 4293 | int vm = Okular::Settings::viewMode(); | ||
4266 | if (vm == Okular::Settings::EnumViewMode::Single) return 1; | 4294 | if (vm == Okular::Settings::EnumViewMode::Single) | ||
4295 | return 1; | ||||
4267 | else if (vm == Okular::Settings::EnumViewMode::Facing || | 4296 | else if (vm == Okular::Settings::EnumViewMode::Facing || | ||
4268 | vm == Okular::Settings::EnumViewMode::FacingFirstCentered) return 2; | 4297 | vm == Okular::Settings::EnumViewMode::FacingFirstCentered) | ||
4298 | return 2; | ||||
4269 | else if (vm == Okular::Settings::EnumViewMode::Summary | 4299 | else if (vm == Okular::Settings::EnumViewMode::Summary | ||
4270 | && d->document->pages() < Okular::Settings::viewColumns() ) | 4300 | && d->document->pages() < Okular::Settings::viewColumns() ) | ||
4271 | return d->document->pages(); | 4301 | return d->document->pages(); | ||
4272 | else return Okular::Settings::viewColumns(); | 4302 | else | ||
4303 | return Okular::Settings::viewColumns(); | ||||
4273 | } | 4304 | } | ||
4274 | 4305 | | |||
4275 | void PageView::center(int cx, int cy) | 4306 | void PageView::center(int cx, int cy) | ||
4276 | { | 4307 | { | ||
4277 | scrollTo( cx - viewport()->width() / 2, cy - viewport()->height() / 2 ); | 4308 | scrollTo( cx - viewport()->width() / 2, cy - viewport()->height() / 2 ); | ||
4278 | } | 4309 | } | ||
4279 | 4310 | | |||
4280 | void PageView::scrollTo( int x, int y ) | 4311 | void PageView::scrollTo( int x, int y ) | ||
▲ Show 20 Lines • Show All 266 Lines • ▼ Show 20 Line(s) | 4515 | PageViewItem * currentItem = d->items[ qMax( 0, (int)d->document->currentPage() ) ]; | |||
4547 | for ( PageViewItem * item : qAsConst( d->items ) ) | 4578 | for ( PageViewItem * item : qAsConst( d->items ) ) | ||
4548 | { | 4579 | { | ||
4549 | int cWidth = colWidth[ cIdx ], | 4580 | int cWidth = colWidth[ cIdx ], | ||
4550 | rHeight = rowHeight[ rIdx ]; | 4581 | rHeight = rowHeight[ rIdx ]; | ||
4551 | if ( continuousView || rIdx == pageRowIdx ) | 4582 | if ( continuousView || rIdx == pageRowIdx ) | ||
4552 | { | 4583 | { | ||
4553 | const bool reallyDoCenterFirst = item->pageNumber() == 0 && centerFirstPage; | 4584 | const bool reallyDoCenterFirst = item->pageNumber() == 0 && centerFirstPage; | ||
4554 | const bool reallyDoCenterLast = item->pageNumber() == pageCount - 1 && centerLastPage; | 4585 | const bool reallyDoCenterLast = item->pageNumber() == pageCount - 1 && centerLastPage; | ||
4555 | int actualX = 0; | 4586 | int actualX; | ||
4556 | if ( reallyDoCenterFirst || reallyDoCenterLast ) | 4587 | if ( reallyDoCenterFirst || reallyDoCenterLast ) | ||
4557 | { | 4588 | { | ||
4558 | // page is centered across entire viewport | 4589 | // page is centered across entire viewport | ||
4559 | actualX = (fullWidth - item->croppedWidth()) / 2; | 4590 | actualX = (fullWidth - item->croppedWidth()) / 2; | ||
4560 | } | 4591 | } | ||
4561 | else if ( facingPages ) | 4592 | else if ( facingPages ) | ||
4562 | { | 4593 | { | ||
4563 | if (Okular::Settings::rtlReadingDirection()){ | 4594 | if (Okular::Settings::rtlReadingDirection()){ | ||
▲ Show 20 Lines • Show All 1014 Lines • Show Last 20 Lines |
Wrong cursor? Dragging the page activates a closed hand, not size all.