Changeset View
Changeset View
Standalone View
Standalone View
ui/pageview.cpp
Show First 20 Lines • Show All 239 Lines • ▼ Show 20 Line(s) | 191 | #endif | |||
---|---|---|---|---|---|
240 | 240 | | |||
241 | int setting_viewCols; | 241 | int setting_viewCols; | ||
242 | bool rtl_Mode; | 242 | bool rtl_Mode; | ||
243 | // Keep track of whether tablet pen is currently pressed down | 243 | // Keep track of whether tablet pen is currently pressed down | ||
244 | bool penDown; | 244 | bool penDown; | ||
245 | 245 | | |||
246 | // Keep track of mouse over link object | 246 | // Keep track of mouse over link object | ||
247 | const Okular::ObjectRect * mouseOverLinkObject; | 247 | const Okular::ObjectRect * mouseOverLinkObject; | ||
248 | bool pinchActive; | ||||
248 | }; | 249 | }; | ||
249 | 250 | | |||
250 | PageViewPrivate::PageViewPrivate( PageView *qq ) | 251 | PageViewPrivate::PageViewPrivate( PageView *qq ) | ||
251 | : q( qq ) | 252 | : q( qq ) | ||
252 | #ifdef HAVE_SPEECH | 253 | #ifdef HAVE_SPEECH | ||
253 | , m_tts( nullptr ) | 254 | , m_tts( nullptr ) | ||
254 | #endif | 255 | #endif | ||
255 | { | 256 | { | ||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Line(s) | 337 | #endif | |||
360 | d->aPageSizes=nullptr; | 361 | d->aPageSizes=nullptr; | ||
361 | d->setting_viewCols = Okular::Settings::viewColumns(); | 362 | d->setting_viewCols = Okular::Settings::viewColumns(); | ||
362 | d->rtl_Mode = Okular::Settings::rtlReadingDirection(); | 363 | d->rtl_Mode = Okular::Settings::rtlReadingDirection(); | ||
363 | d->mouseModeActionGroup = nullptr; | 364 | d->mouseModeActionGroup = nullptr; | ||
364 | d->penDown = false; | 365 | d->penDown = false; | ||
365 | d->aMouseMagnifier = nullptr; | 366 | d->aMouseMagnifier = nullptr; | ||
366 | d->aFitWindowToPage = nullptr; | 367 | d->aFitWindowToPage = nullptr; | ||
367 | d->trimBoundingBox = Okular::NormalizedRect(); // Null box | 368 | d->trimBoundingBox = Okular::NormalizedRect(); // Null box | ||
369 | d->pinchActive = false; | ||||
368 | 370 | | |||
369 | switch( Okular::Settings::zoomMode() ) | 371 | switch( Okular::Settings::zoomMode() ) | ||
370 | { | 372 | { | ||
371 | case 0: | 373 | case 0: | ||
372 | { | 374 | { | ||
373 | d->zoomFactor = 1; | 375 | d->zoomFactor = 1; | ||
374 | d->zoomMode = PageView::ZoomFixed; | 376 | d->zoomMode = PageView::ZoomFixed; | ||
375 | break; | 377 | break; | ||
▲ Show 20 Lines • Show All 1198 Lines • ▼ Show 20 Line(s) | 1575 | { | |||
1574 | // Viewport zoom level at the moment where the pinch gesture starts. | 1576 | // Viewport zoom level at the moment where the pinch gesture starts. | ||
1575 | // The viewport zoom level _during_ the gesture will be this value | 1577 | // The viewport zoom level _during_ the gesture will be this value | ||
1576 | // times the relative zoom reported by QGestureEvent. | 1578 | // times the relative zoom reported by QGestureEvent. | ||
1577 | static qreal vanillaZoom = d->zoomFactor; | 1579 | static qreal vanillaZoom = d->zoomFactor; | ||
1578 | 1580 | | |||
1579 | if (pinch->state() == Qt::GestureStarted) | 1581 | if (pinch->state() == Qt::GestureStarted) | ||
1580 | { | 1582 | { | ||
1581 | vanillaZoom = d->zoomFactor; | 1583 | vanillaZoom = d->zoomFactor; | ||
1584 | d->pinchActive = true; | ||||
1582 | } | 1585 | } | ||
1583 | 1586 | | |||
1584 | const QPinchGesture::ChangeFlags changeFlags = pinch->changeFlags(); | 1587 | const QPinchGesture::ChangeFlags changeFlags = pinch->changeFlags(); | ||
1585 | 1588 | | |||
1586 | // Zoom | 1589 | // Zoom | ||
1587 | if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged) | 1590 | if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged) | ||
1588 | { | 1591 | { | ||
1589 | d->zoomFactor = vanillaZoom * pinch->totalScaleFactor(); | 1592 | holdZoomCenter( ZoomRefreshCurrent, mapFromGlobal( pinch->centerPoint().toPoint()), vanillaZoom * pinch->totalScaleFactor() ); | ||
1590 | | ||||
1591 | d->blockPixmapsRequest = true; | | |||
1592 | updateZoom( ZoomRefreshCurrent ); | | |||
1593 | d->blockPixmapsRequest = false; | | |||
1594 | viewport()->repaint(); | | |||
1595 | } | 1593 | } | ||
1596 | 1594 | | |||
1597 | // Count the number of 90-degree rotations we did since the start of the pinch gesture. | 1595 | // Count the number of 90-degree rotations we did since the start of the pinch gesture. | ||
1598 | // Otherwise a pinch turned to 90 degrees and held there will rotate the page again and again. | 1596 | // Otherwise a pinch turned to 90 degrees and held there will rotate the page again and again. | ||
1599 | static int rotations = 0; | 1597 | static int rotations = 0; | ||
1600 | 1598 | | |||
1601 | if (changeFlags & QPinchGesture::RotationAngleChanged) | 1599 | if (changeFlags & QPinchGesture::RotationAngleChanged) | ||
1602 | { | 1600 | { | ||
Show All 10 Lines | 1610 | { | |||
1613 | slotRotateCounterClockwise(); | 1611 | slotRotateCounterClockwise(); | ||
1614 | rotations--; | 1612 | rotations--; | ||
1615 | } | 1613 | } | ||
1616 | } | 1614 | } | ||
1617 | 1615 | | |||
1618 | if (pinch->state() == Qt::GestureFinished) | 1616 | if (pinch->state() == Qt::GestureFinished) | ||
1619 | { | 1617 | { | ||
1620 | rotations = 0; | 1618 | rotations = 0; | ||
1619 | d->pinchActive = false; | ||||
1621 | } | 1620 | } | ||
1622 | 1621 | | |||
1623 | return true; | 1622 | return true; | ||
1624 | } | 1623 | } | ||
1625 | 1624 | | |||
1626 | return false; | 1625 | return false; | ||
1627 | } | 1626 | } | ||
1628 | 1627 | | |||
▲ Show 20 Lines • Show All 417 Lines • ▼ Show 20 Line(s) | 2039 | { | |||
2046 | d->annotator->routeTabletEvent( e, pageItem, localOriginInGlobal ); | 2045 | d->annotator->routeTabletEvent( e, pageItem, localOriginInGlobal ); | ||
2047 | } else { | 2046 | } else { | ||
2048 | e->ignore(); | 2047 | e->ignore(); | ||
2049 | } | 2048 | } | ||
2050 | } | 2049 | } | ||
2051 | 2050 | | |||
2052 | void PageView::mouseMoveEvent( QMouseEvent * e ) | 2051 | void PageView::mouseMoveEvent( QMouseEvent * e ) | ||
2053 | { | 2052 | { | ||
2053 | if ( e->source() == Qt::MouseEventSynthesizedByQt && d->pinchActive ) | ||||
2054 | return; | ||||
2055 | | ||||
2054 | // For some reason in Qt 5.11.2 (no idea when this started) all wheel | 2056 | // For some reason in Qt 5.11.2 (no idea when this started) all wheel | ||
2055 | // events are followed by mouse move events (without changing position), | 2057 | // events are followed by mouse move events (without changing position), | ||
2056 | // so we only actually reset the controlWheelAccumulatedDelta if there is a mouse movement | 2058 | // so we only actually reset the controlWheelAccumulatedDelta if there is a mouse movement | ||
2057 | if ( e->globalPos() != d->previousMouseMovePos ) | 2059 | if ( e->globalPos() != d->previousMouseMovePos ) | ||
2058 | { | 2060 | { | ||
2059 | d->controlWheelAccumulatedDelta = 0; | 2061 | d->controlWheelAccumulatedDelta = 0; | ||
2060 | } | 2062 | } | ||
2061 | d->previousMouseMovePos = e->globalPos(); | 2063 | d->previousMouseMovePos = e->globalPos(); | ||
Show All 35 Lines | 2097 | { | |||
2097 | QCursor::setPos( e->globalPos().x(), mouseY ); | 2099 | QCursor::setPos( e->globalPos().x(), mouseY ); | ||
2098 | } | 2100 | } | ||
2099 | // remember last position | 2101 | // remember last position | ||
2100 | d->mouseMidLastY = mouseY; | 2102 | d->mouseMidLastY = mouseY; | ||
2101 | 2103 | | |||
2102 | // update zoom level, perform zoom and redraw | 2104 | // update zoom level, perform zoom and redraw | ||
2103 | if ( deltaY ) | 2105 | if ( deltaY ) | ||
2104 | { | 2106 | { | ||
2105 | d->zoomFactor *= ( 1.0 + ( (double)deltaY / 500.0 ) ); | 2107 | holdZoomCenter( ZoomRefreshCurrent , mapFromGlobal(d->mousePressPos), d->zoomFactor * ( 1.0 + ( (double)deltaY / 500.0 ) )); | ||
2106 | d->blockPixmapsRequest = true; | | |||
2107 | updateZoom( ZoomRefreshCurrent ); | | |||
2108 | d->blockPixmapsRequest = false; | | |||
2109 | viewport()->repaint(); | | |||
2110 | } | 2108 | } | ||
2111 | return; | 2109 | return; | ||
2112 | } | 2110 | } | ||
2113 | 2111 | | |||
2114 | const QPoint eventPos = contentAreaPoint( e->pos() ); | 2112 | const QPoint eventPos = contentAreaPoint( e->pos() ); | ||
2115 | 2113 | | |||
2116 | // if we're editing an annotation, dispatch event to it | 2114 | // if we're editing an annotation, dispatch event to it | ||
2117 | if ( d->annotator && d->annotator->active() ) | 2115 | if ( d->annotator && d->annotator->active() ) | ||
▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Line(s) | 2236 | { | |||
2248 | 2246 | | |||
2249 | // if the page is scrolling, stop it | 2247 | // if the page is scrolling, stop it | ||
2250 | if ( d->autoScrollTimer ) | 2248 | if ( d->autoScrollTimer ) | ||
2251 | { | 2249 | { | ||
2252 | d->scrollIncrement = 0; | 2250 | d->scrollIncrement = 0; | ||
2253 | d->autoScrollTimer->stop(); | 2251 | d->autoScrollTimer->stop(); | ||
2254 | } | 2252 | } | ||
2255 | 2253 | | |||
2254 | // update press / 'start drag' mouse position | ||||
2255 | d->mousePressPos = e->globalPos(); | ||||
2256 | | ||||
2256 | // if pressing mid mouse button while not doing other things, begin 'continuous zoom' mode | 2257 | // if pressing mid mouse button while not doing other things, begin 'continuous zoom' mode | ||
2257 | if ( e->button() == Qt::MidButton ) | 2258 | if ( e->button() == Qt::MidButton ) | ||
2258 | { | 2259 | { | ||
2259 | d->mouseMidLastY = e->globalPos().y(); | 2260 | d->mouseMidLastY = e->globalPos().y(); | ||
2260 | setCursor( Qt::SizeVerCursor ); | 2261 | setCursor( Qt::SizeVerCursor ); | ||
2261 | return; | 2262 | return; | ||
2262 | } | 2263 | } | ||
2263 | 2264 | | |||
Show All 14 Lines | 2277 | { | |||
2278 | return; | 2279 | return; | ||
2279 | } | 2280 | } | ||
2280 | if ( e->button() == Qt::XButton2 ) | 2281 | if ( e->button() == Qt::XButton2 ) | ||
2281 | { | 2282 | { | ||
2282 | emit mouseForwardButtonClick(); | 2283 | emit mouseForwardButtonClick(); | ||
2283 | return; | 2284 | return; | ||
2284 | } | 2285 | } | ||
2285 | 2286 | | |||
2286 | // update press / 'start drag' mouse position | | |||
2287 | d->mousePressPos = e->globalPos(); | | |||
2288 | | ||||
2289 | // handle mode dependent mouse press actions | 2287 | // handle mode dependent mouse press actions | ||
2290 | bool leftButton = e->button() == Qt::LeftButton, | 2288 | bool leftButton = e->button() == Qt::LeftButton, | ||
2291 | rightButton = e->button() == Qt::RightButton; | 2289 | rightButton = e->button() == Qt::RightButton; | ||
2292 | 2290 | | |||
2293 | // Not sure we should erase the selection when clicking with left. | 2291 | // Not sure we should erase the selection when clicking with left. | ||
2294 | if ( d->mouseMode != Okular::Settings::EnumMouseMode::TextSelect ) | 2292 | if ( d->mouseMode != Okular::Settings::EnumMouseMode::TextSelect ) | ||
2295 | textSelectionClear(); | 2293 | textSelectionClear(); | ||
2296 | 2294 | | |||
▲ Show 20 Lines • Show All 1000 Lines • ▼ Show 20 Line(s) | 3285 | { | |||
3297 | 3295 | | |||
3298 | int delta = e->delta(), | 3296 | int delta = e->delta(), | ||
3299 | vScroll = verticalScrollBar()->value(); | 3297 | vScroll = verticalScrollBar()->value(); | ||
3300 | e->accept(); | 3298 | e->accept(); | ||
3301 | if ( (e->modifiers() & Qt::ControlModifier) == Qt::ControlModifier ) { | 3299 | if ( (e->modifiers() & Qt::ControlModifier) == Qt::ControlModifier ) { | ||
3302 | d->controlWheelAccumulatedDelta += delta; | 3300 | d->controlWheelAccumulatedDelta += delta; | ||
3303 | if ( d->controlWheelAccumulatedDelta <= -QWheelEvent::DefaultDeltasPerStep ) | 3301 | if ( d->controlWheelAccumulatedDelta <= -QWheelEvent::DefaultDeltasPerStep ) | ||
3304 | { | 3302 | { | ||
3305 | slotZoomOut(); | 3303 | holdZoomCenter( ZoomOut, e->pos() ); | ||
3306 | d->controlWheelAccumulatedDelta = 0; | 3304 | d->controlWheelAccumulatedDelta = 0; | ||
3307 | } | 3305 | } | ||
3308 | else if ( d->controlWheelAccumulatedDelta >= QWheelEvent::DefaultDeltasPerStep ) | 3306 | else if ( d->controlWheelAccumulatedDelta >= QWheelEvent::DefaultDeltasPerStep ) | ||
3309 | { | 3307 | { | ||
3310 | slotZoomIn(); | 3308 | holdZoomCenter( ZoomIn, e->pos() ); | ||
3311 | d->controlWheelAccumulatedDelta = 0; | 3309 | d->controlWheelAccumulatedDelta = 0; | ||
3312 | } | 3310 | } | ||
3313 | } | 3311 | } | ||
3314 | else | 3312 | else | ||
3315 | { | 3313 | { | ||
3316 | d->controlWheelAccumulatedDelta = 0; | 3314 | d->controlWheelAccumulatedDelta = 0; | ||
3317 | 3315 | | |||
3318 | if ( delta <= -QWheelEvent::DefaultDeltasPerStep && !Okular::Settings::viewContinuous() && vScroll == verticalScrollBar()->maximum() ) | 3316 | if ( delta <= -QWheelEvent::DefaultDeltasPerStep && !Okular::Settings::viewContinuous() && vScroll == verticalScrollBar()->maximum() ) | ||
▲ Show 20 Lines • Show All 1114 Lines • ▼ Show 20 Line(s) | 4401 | { | |||
4433 | connect( processLink, &QAction::triggered, [this, link]() { | 4431 | connect( processLink, &QAction::triggered, [this, link]() { | ||
4434 | d->document->processAction( link ); | 4432 | d->document->processAction( link ); | ||
4435 | }); | 4433 | }); | ||
4436 | return menu; | 4434 | return menu; | ||
4437 | } | 4435 | } | ||
4438 | return nullptr; | 4436 | return nullptr; | ||
4439 | } | 4437 | } | ||
4440 | 4438 | | |||
4439 | void PageView::holdZoomCenter(PageView::ZoomMode newZm, QPointF zoomCenter, float newZoom) | ||||
4440 | { | ||||
4441 | const QPointF centerBegin = viewportToContentArea( d->document->viewport() ); | ||||
4442 | const QPointF oldScroll = contentAreaPosition(); | ||||
4443 | | ||||
4444 | d->blockPixmapsRequest = true; | ||||
4445 | | ||||
4446 | if ( newZoom ) | ||||
4447 | d->zoomFactor = newZoom; | ||||
4448 | | ||||
4449 | updateZoom( newZm ); | ||||
4450 | | ||||
4451 | const QPointF centerEnd = viewportToContentArea( d->document->viewport() ); | ||||
4452 | //The calculation for newScroll is taken from Gwenview class Abstractimageview::setZoom | ||||
4453 | const double zoomFactor = centerEnd.y() / centerBegin.y(); | ||||
4454 | const QPointF newScroll = zoomFactor * ( oldScroll + zoomCenter ) - zoomCenter; | ||||
4455 | | ||||
4456 | d->blockPixmapsRequest = false; | ||||
4457 | scrollTo( newScroll.x(), newScroll.y() ); | ||||
4458 | } | ||||
4459 | | ||||
4441 | //BEGIN private SLOTS | 4460 | //BEGIN private SLOTS | ||
4442 | void PageView::slotRelayoutPages() | 4461 | void PageView::slotRelayoutPages() | ||
4443 | // called by: notifySetup, viewportResizeEvent, slotViewMode, slotContinuousToggled, updateZoom | 4462 | // called by: notifySetup, viewportResizeEvent, slotViewMode, slotContinuousToggled, updateZoom | ||
4444 | { | 4463 | { | ||
4445 | // set an empty container if we have no pages | 4464 | // set an empty container if we have no pages | ||
4446 | const int pageCount = d->items.count(); | 4465 | const int pageCount = d->items.count(); | ||
4447 | if ( pageCount < 1 ) | 4466 | if ( pageCount < 1 ) | ||
4448 | { | 4467 | { | ||
▲ Show 20 Lines • Show All 1129 Lines • Show Last 20 Lines |