Keep track of the current page by overloading the widget paint event.
| 1386 | |
| 1387 | // Keep track of the current page by overloading the widget paint event. |
| 1388 | void PDFDocumentView::paintEvent(QPaintEvent *event) |
| 1389 | { |
| 1390 | Super::paintEvent(event); |
| 1391 | |
| 1392 | // After `QGraphicsView` has taken care of updates to this widget, find the |
| 1393 | // currently displayed page. We do this by grabbing all items that are |
| 1394 | // currently within the bounds of the viewport's top half. We take the |
| 1395 | // first item found to be the "current page". |
| 1396 | if (_pdf_scene) { |
| 1397 | QRect pageBbox = viewport()->rect(); |
| 1398 | pageBbox.setHeight(pageBbox.height() / 2); |
| 1399 | size_type nextCurrentPage = _pdf_scene->pageNumAt(mapToScene(pageBbox)); |
| 1400 | |
| 1401 | if ( nextCurrentPage != _currentPage && nextCurrentPage >= 0 && nextCurrentPage < _lastPage ) |
| 1402 | { |
| 1403 | _currentPage = nextCurrentPage; |
| 1404 | emit changedPage(_currentPage); |
| 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | if (_armedTool) |
| 1409 | _armedTool->paintEvent(event); |
| 1410 | |
| 1411 | emit updated(); |
| 1412 | } |
| 1413 | |
| 1414 | void PDFDocumentView::keyPressEvent(QKeyEvent *event) |
| 1415 | { |