58 Class implementing a specialized PDF view. |
58 Class implementing a specialized PDF view. |
59 """ |
59 """ |
60 |
60 |
61 MarkerColors = { |
61 MarkerColors = { |
62 # merker type: (pen color, brush color) |
62 # merker type: (pen color, brush color) |
63 PdfMarkerType.SearchResult: (QColor(255, 200, 0, 255), QColor(255, 200, 0, 64)), |
63 PdfMarkerType.SEARCHRESULT: (QColor(255, 200, 0, 255), QColor(255, 200, 0, 64)), |
64 PdfMarkerType.Selection: (QColor(0, 0, 255, 255), QColor(0, 0, 255, 64)), |
64 PdfMarkerType.SELECTION: (QColor(0, 0, 255, 255), QColor(0, 0, 255, 64)), |
65 } |
65 } |
66 |
66 |
67 selectionAvailable = pyqtSignal(bool) |
67 selectionAvailable = pyqtSignal(bool) |
68 |
68 |
69 def __init__(self, parent): |
69 def __init__(self, parent): |
249 |
249 |
250 @param evt reference to the mouse event |
250 @param evt reference to the mouse event |
251 @type QMouseEvent |
251 @type QMouseEvent |
252 """ |
252 """ |
253 if evt.button() == Qt.MouseButton.LeftButton: |
253 if evt.button() == Qt.MouseButton.LeftButton: |
254 self.clearMarkers(PdfMarkerType.Selection) |
254 self.clearMarkers(PdfMarkerType.SELECTION) |
255 self.selectionAvailable.emit(False) |
255 self.selectionAvailable.emit(False) |
256 |
256 |
257 self.__rubberBandOrigin = evt.pos() |
257 self.__rubberBandOrigin = evt.pos() |
258 if self.__rubberBand is None: |
258 if self.__rubberBand is None: |
259 self.__rubberBand = QRubberBand( |
259 self.__rubberBand = QRubberBand( |
309 page, selectionRect.topLeft(), selectionRect.bottomRight() |
309 page, selectionRect.topLeft(), selectionRect.bottomRight() |
310 ) |
310 ) |
311 if selection.isValid(): |
311 if selection.isValid(): |
312 for bound in selection.bounds(): |
312 for bound in selection.bounds(): |
313 self.addMarker( |
313 self.addMarker( |
314 page, bound.boundingRect(), PdfMarkerType.Selection |
314 page, bound.boundingRect(), PdfMarkerType.SELECTION |
315 ) |
315 ) |
316 self.selectionAvailable.emit(True) |
316 self.selectionAvailable.emit(True) |
317 |
317 |
318 super().mousePressEvent(evt) |
318 super().mousePressEvent(evt) |
319 |
319 |
436 |
436 |
437 totalWidth = 0 |
437 totalWidth = 0 |
438 |
438 |
439 startPage = ( |
439 startPage = ( |
440 self.pageNavigator().currentPage() |
440 self.pageNavigator().currentPage() |
441 if self.pageMode == QPdfView.PageMode.SinglePage |
441 if self.pageMode() == QPdfView.PageMode.SinglePage |
442 else 0 |
442 else 0 |
443 ) |
443 ) |
444 endPage = ( |
444 endPage = ( |
445 self.pageNavigator().currentPage() + 1 |
445 self.pageNavigator().currentPage() + 1 |
446 if self.pageMode == QPdfView.PageMode.SinglePage |
446 if self.pageMode() == QPdfView.PageMode.SinglePage |
447 else pageCount |
447 else pageCount |
448 ) |
448 ) |
449 |
449 |
450 # calculate pageSizes |
450 # calculate pageSizes |
451 for page in range(startPage, endPage): |
451 for page in range(startPage, endPage): |
610 |
610 |
611 @param link reference to the PDF link object |
611 @param link reference to the PDF link object |
612 @type QPdfLink |
612 @type QPdfLink |
613 """ |
613 """ |
614 for rect in link.rectangles(): |
614 for rect in link.rectangles(): |
615 self.addMarker(link.page(), rect, PdfMarkerType.SearchResult) |
615 self.addMarker(link.page(), rect, PdfMarkerType.SEARCHRESULT) |
616 |
616 |
617 @pyqtSlot() |
617 @pyqtSlot() |
618 def clearSearchMarkers(self): |
618 def clearSearchMarkers(self): |
619 """ |
619 """ |
620 Public slot to clear the search markers. |
620 Public slot to clear the search markers. |
621 """ |
621 """ |
622 self.clearMarkers(PdfMarkerType.SearchResult) |
622 self.clearMarkers(PdfMarkerType.SEARCHRESULT) |
623 |
623 |
624 def hasSelection(self): |
624 def hasSelection(self): |
625 """ |
625 """ |
626 Public method to check the presence of a selection. |
626 Public method to check the presence of a selection. |
627 |
627 |
628 @return flag indicating the presence of a selection |
628 @return flag indicating the presence of a selection |
629 @rtype bool |
629 @rtype bool |
630 """ |
630 """ |
631 return any( |
631 return any( |
632 m.markerType == PdfMarkerType.Selection |
632 m.markerType == PdfMarkerType.SELECTION |
633 for p in self.__markers |
633 for p in self.__markers |
634 for m in self.__markers[p] |
634 for m in self.__markers[p] |
635 ) |
635 ) |
636 |
636 |
637 def getSelection(self): |
637 def getSelection(self): |
642 @rtype QPdfSelection |
642 @rtype QPdfSelection |
643 """ |
643 """ |
644 for page in self.__markers: |
644 for page in self.__markers: |
645 markersList = [ |
645 markersList = [ |
646 m for m in self.__markers[page] |
646 m for m in self.__markers[page] |
647 if m.markerType == PdfMarkerType.Selection |
647 if m.markerType == PdfMarkerType.SELECTION |
648 ] |
648 ] |
649 if markersList: |
649 if markersList: |
650 selection = self.document().getSelection( |
650 selection = self.document().getSelection( |
651 page, |
651 page, |
652 markersList[0].rectangle.topLeft(), |
652 markersList[0].rectangle.topLeft(), |