From 3f89246317ecbf2b2c19a4c4416583db72d463bd Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Mon, 21 Sep 2020 01:15:15 +0200 Subject: [PATCH] Show "Follow link" if right clicking over link and annotation Unite handling of right click in mouse release event Before we had handling on press -> show annot menu if annot and in release -> show link menu if link or show the genericmenu if nothing Now we do everything on release and do show link and annot menu if both show link menu if link show annot menu if annot show generic menu if nothing It helps with the fact that you can't click on links if there's an annotation on top, which is a bit of a pain but it makes sense since annotations usually have more interaction than links, you can select, move, etc. them BUGS: 425291 --- ui/pageview.cpp | 55 +++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 01fc5513b..fb8883257 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -2200,32 +2200,6 @@ void PageView::mousePressEvent(QMouseEvent *e) d->scroller->handleInput(QScroller::InputPress, e->pos(), e->timestamp()); d->leftClickTimer.start(QApplication::doubleClickInterval() + 10); } - } else if (rightButton) { - if (pageItem) { - // find out normalized mouse coords inside current item - const QRect &itemRect = pageItem->uncroppedGeometry(); - double nX = pageItem->absToPageX(eventPos.x()); - double nY = pageItem->absToPageY(eventPos.y()); - - const QLinkedList orects = pageItem->page()->objectRects(Okular::ObjectRect::OAnnotation, nX, nY, itemRect.width(), itemRect.height()); - - if (!orects.isEmpty()) { - AnnotationPopup popup(d->document, AnnotationPopup::MultiAnnotationMode, this); - - for (const Okular::ObjectRect *orect : orects) { - Okular::Annotation *ann = ((Okular::AnnotationObjectRect *)orect)->annotation(); - if (ann && (ann->subType() != Okular::Annotation::AWidget)) - popup.addAnnotation(ann, pageItem->pageNumber()); - } - - connect(&popup, &AnnotationPopup::openAnnotationWindow, this, &PageView::openAnnotationWindow); - - popup.exec(e->globalPos()); - // Since ↑ spins its own event loop we won't get the mouse release event - // so reset mousePressPos here - d->mousePressPos = QPoint(); - } - } } } break; @@ -2446,15 +2420,38 @@ void PageView::mouseReleaseEvent(QMouseEvent *e) } else if (rightButton && !d->mouseAnnotation->isModified()) { if (pageItem && pageItem == pageItemPressPos && ((d->mousePressPos - e->globalPos()).manhattanLength() < QApplication::startDragDistance())) { QMenu *menu = createProcessLinkMenu(pageItem, eventPos); + + const QRect &itemRect = pageItem->uncroppedGeometry(); + const double nX = pageItem->absToPageX(eventPos.x()); + const double nY = pageItem->absToPageY(eventPos.y()); + + const QLinkedList annotRects = pageItem->page()->objectRects(Okular::ObjectRect::OAnnotation, nX, nY, itemRect.width(), itemRect.height()); + + AnnotationPopup annotPopup(d->document, AnnotationPopup::MultiAnnotationMode, this); + // Do not move annotPopup inside the if, it needs to live until menu->exec() + if (!annotRects.isEmpty()) { + for (const Okular::ObjectRect *annotRect : annotRects) { + Okular::Annotation *ann = ((Okular::AnnotationObjectRect *)annotRect)->annotation(); + if (ann && (ann->subType() != Okular::Annotation::AWidget)) { + annotPopup.addAnnotation(ann, pageItem->pageNumber()); + } + } + + connect(&annotPopup, &AnnotationPopup::openAnnotationWindow, this, &PageView::openAnnotationWindow); + + if (!menu) { + menu = new QMenu(this); + } + annotPopup.addActionsToMenu(menu); + } + if (menu) { menu->exec(e->globalPos()); menu->deleteLater(); } else { - const double nX = pageItem->absToPageX(eventPos.x()); - const double nY = pageItem->absToPageY(eventPos.y()); // a link can move us to another page or even to another document, there's no point in trying to // process the click on the image once we have processes the click on the link - const Okular::ObjectRect *rect = pageItem->page()->objectRect(Okular::ObjectRect::Image, nX, nY, pageItem->uncroppedWidth(), pageItem->uncroppedHeight()); + const Okular::ObjectRect *rect = pageItem->page()->objectRect(Okular::ObjectRect::Image, nX, nY, itemRect.width(), itemRect.height()); if (rect) { // handle right click over a image } else {