diff --git a/Pdf4QtLibWidgets/sources/pdfwidgetannotation.cpp b/Pdf4QtLibWidgets/sources/pdfwidgetannotation.cpp index 3a65e58..4d797ef 100644 --- a/Pdf4QtLibWidgets/sources/pdfwidgetannotation.cpp +++ b/Pdf4QtLibWidgets/sources/pdfwidgetannotation.cpp @@ -126,21 +126,34 @@ void PDFWidgetAnnotationManager::mousePressEvent(QWidget* widget, QMouseEvent* e } } - if (m_editableAnnotation.isValid()) - { - QMenu menu(tr("Annotation"), pdfWidget); - QAction* showPopupAction = menu.addAction(tr("Show Popup Window")); - QAction* copyAction = menu.addAction(tr("Copy to Multiple Pages")); - QAction* editAction = menu.addAction(tr("Edit")); - QAction* deleteAction = menu.addAction(tr("Delete")); - connect(showPopupAction, &QAction::triggered, this, &PDFWidgetAnnotationManager::onShowPopupAnnotation); - connect(copyAction, &QAction::triggered, this, &PDFWidgetAnnotationManager::onCopyAnnotation); - connect(editAction, &QAction::triggered, this, &PDFWidgetAnnotationManager::onEditAnnotation); - connect(deleteAction, &QAction::triggered, this, &PDFWidgetAnnotationManager::onDeleteAnnotation); + QPoint menuPosition = pdfWidget->mapToGlobal(event->pos()); + showAnnotationMenu(m_editableAnnotation, m_editableAnnotationPage, menuPosition); + } +} - m_editableAnnotationGlobalPosition = pdfWidget->mapToGlobal(event->pos()); - menu.exec(m_editableAnnotationGlobalPosition); - } +void PDFWidgetAnnotationManager::showAnnotationMenu(PDFObjectReference annotationReference, + PDFObjectReference pageReference, + QPoint globalMenuPosition) +{ + m_editableAnnotation = annotationReference; + m_editableAnnotationPage = pageReference; + + if (m_editableAnnotation.isValid()) + { + PDFWidget* pdfWidget = m_proxy->getWidget(); + + QMenu menu(tr("Annotation"), pdfWidget); + QAction* showPopupAction = menu.addAction(tr("Show Popup Window")); + QAction* copyAction = menu.addAction(tr("Copy to Multiple Pages")); + QAction* editAction = menu.addAction(tr("Edit")); + QAction* deleteAction = menu.addAction(tr("Delete")); + connect(showPopupAction, &QAction::triggered, this, &PDFWidgetAnnotationManager::onShowPopupAnnotation); + connect(copyAction, &QAction::triggered, this, &PDFWidgetAnnotationManager::onCopyAnnotation); + connect(editAction, &QAction::triggered, this, &PDFWidgetAnnotationManager::onEditAnnotation); + connect(deleteAction, &QAction::triggered, this, &PDFWidgetAnnotationManager::onDeleteAnnotation); + + m_editableAnnotationGlobalPosition = globalMenuPosition; + menu.exec(m_editableAnnotationGlobalPosition); } } diff --git a/Pdf4QtLibWidgets/sources/pdfwidgetannotation.h b/Pdf4QtLibWidgets/sources/pdfwidgetannotation.h index aa0ef98..4ad1865 100644 --- a/Pdf4QtLibWidgets/sources/pdfwidgetannotation.h +++ b/Pdf4QtLibWidgets/sources/pdfwidgetannotation.h @@ -65,6 +65,10 @@ public: virtual int getInputPriority() const override { return AnnotationPriority; } + void showAnnotationMenu(pdf::PDFObjectReference annotationReference, + pdf::PDFObjectReference pageReference, + QPoint globalMenuPosition); + signals: void actionTriggered(const PDFAction* action); void documentModified(PDFModifiedDocument document); diff --git a/Pdf4QtViewer/pdfsidebarwidget.cpp b/Pdf4QtViewer/pdfsidebarwidget.cpp index e3f181b..522e7d0 100644 --- a/Pdf4QtViewer/pdfsidebarwidget.cpp +++ b/Pdf4QtViewer/pdfsidebarwidget.cpp @@ -158,6 +158,7 @@ PDFSidebarWidget::PDFSidebarWidget(pdf::PDFDrawWidgetProxy* proxy, connect(ui->notesSearchLineEdit, &QLineEdit::editingFinished, this, &PDFSidebarWidget::onNotesSearchText); connect(ui->notesSearchLineEdit, &QLineEdit::textChanged, this, &PDFSidebarWidget::onNotesSearchText); connect(ui->notesTreeView, &QTreeView::clicked, this, &PDFSidebarWidget::onNotesItemClicked); + connect(ui->notesTreeView, &QTreeView::customContextMenuRequested, this, &PDFSidebarWidget::onNotesTreeViewContextMenuRequested); m_pageInfo[Invalid] = { nullptr, ui->emptyPage }; m_pageInfo[OptionalContent] = { ui->optionalContentButton, ui->optionalContentPage }; @@ -1092,6 +1093,32 @@ void PDFSidebarWidget::onOutlineTreeViewContextMenuRequested(const QPoint& pos) contextMenu.exec(ui->outlineTreeView->mapToGlobal(pos)); } +void PDFSidebarWidget::onNotesTreeViewContextMenuRequested(const QPoint& pos) +{ + QModelIndex index = ui->notesTreeView->indexAt(pos); + + if (index.isValid()) + { + QVariant userData = index.data(Qt::UserRole); + if (userData.isValid()) + { + const int annotationIndex = userData.toInt(); + + if (annotationIndex >= 0 && annotationIndex < m_markupAnnotations.size()) + { + const auto& annotationItem = m_markupAnnotations[annotationIndex]; + QPoint globalPos = ui->notesTreeView->viewport()->mapToGlobal(pos); + + pdf::PDFObjectReference annotationReference = annotationItem.first; + pdf::PDFObjectReference pageReference = m_document->getCatalog()->getPage(annotationItem.second)->getPageReference(); + + m_proxy->goToPage(annotationItem.second); + m_proxy->getAnnotationManager()->showAnnotationMenu(annotationReference, pageReference, globalPos); + } + } + } +} + void PDFSidebarWidget::onOutlineItemsChanged() { if (m_document) diff --git a/Pdf4QtViewer/pdfsidebarwidget.h b/Pdf4QtViewer/pdfsidebarwidget.h index 756dbf7..778ee12 100644 --- a/Pdf4QtViewer/pdfsidebarwidget.h +++ b/Pdf4QtViewer/pdfsidebarwidget.h @@ -120,8 +120,9 @@ private: void onThumbnailsSizeChanged(int size); void onAttachmentCustomContextMenuRequested(const QPoint& pos); void onThumbnailClicked(const QModelIndex& index); - void onSignatureCustomContextMenuRequested(const QPoint &pos); - void onOutlineTreeViewContextMenuRequested(const QPoint &pos); + void onSignatureCustomContextMenuRequested(const QPoint& pos); + void onOutlineTreeViewContextMenuRequested(const QPoint& pos); + void onNotesTreeViewContextMenuRequested(const QPoint& pos); void onOutlineItemsChanged(); void onBookmarkActivated(int index, PDFBookmarkManager::Bookmark bookmark); void onBookmarsCurrentIndexChanged(const QModelIndex& current, const QModelIndex& previous); diff --git a/Pdf4QtViewer/pdfsidebarwidget.ui b/Pdf4QtViewer/pdfsidebarwidget.ui index 081fa90..2765718 100644 --- a/Pdf4QtViewer/pdfsidebarwidget.ui +++ b/Pdf4QtViewer/pdfsidebarwidget.ui @@ -539,7 +539,14 @@ - + + + Qt::CustomContextMenu + + + true + +