From 93496339d4e37a8c52861273ea4279d1e4c5588d Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Sat, 7 Oct 2023 16:43:12 +0200 Subject: [PATCH] Issue #76: Finished --- Pdf4QtViewer/pdfsidebarwidget.cpp | 60 ++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/Pdf4QtViewer/pdfsidebarwidget.cpp b/Pdf4QtViewer/pdfsidebarwidget.cpp index 4d2f0ba..2cc8063 100644 --- a/Pdf4QtViewer/pdfsidebarwidget.cpp +++ b/Pdf4QtViewer/pdfsidebarwidget.cpp @@ -32,6 +32,7 @@ #include "pdfsignaturehandler.h" #include "pdfdrawspacecontroller.h" #include "pdfdocumentbuilder.h" +#include "pdfwidgetutils.h" #include #include @@ -40,6 +41,10 @@ #include #include #include +#include +#include +#include +#include namespace pdfviewer { @@ -854,7 +859,60 @@ void PDFSidebarWidget::onBookmarksTreeViewContextMenuRequested(const QPoint& pos return onSetTarget; }; - submenu->addAction(tr("Named Destination")); + auto onNamedDestinationTriggered = [this, index]() + { + class SelectNamedDestinationDialog : public QDialog + { + public: + explicit SelectNamedDestinationDialog(const QStringList& items, QWidget* parent) + : QDialog(parent) + { + setWindowTitle(tr("Select Named Destination")); + setMinimumWidth(pdf::PDFWidgetUtils::scaleDPI_x(this, 150)); + + QVBoxLayout* layout = new QVBoxLayout(this); + + m_comboBox = new QComboBox(this); + m_comboBox->addItems(items); + m_comboBox->setEditable(false); + layout->addWidget(m_comboBox); + + QHBoxLayout* buttonsLayout = new QHBoxLayout(); + QPushButton* okButton = new QPushButton(tr("OK"), this); + QPushButton* cancelButton = new QPushButton(tr("Cancel"), this); + + buttonsLayout->addWidget(okButton); + buttonsLayout->addWidget(cancelButton); + + layout->addLayout(buttonsLayout); + + connect(okButton, &QPushButton::clicked, this, &QDialog::accept); + connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject); + } + + QString selectedText() const + { + return m_comboBox->currentText(); + } + + private: + QComboBox* m_comboBox; + }; + + QStringList items; + for (const auto& namedDestination : m_document->getCatalog()->getNamedDestinations()) + { + items << QString::fromLatin1(namedDestination.first); + } + + SelectNamedDestinationDialog dialog(items, m_proxy->getWidget()); + if (dialog.exec() == QDialog::Accepted) + { + m_outlineTreeModel->setDestination(index, pdf::PDFDestination::createNamed(dialog.selectedText().toLatin1())); + } + }; + + submenu->addAction(tr("Named Destination"), onNamedDestinationTriggered); submenu->addAction(tr("Fit Page"), createOnSetTarget(pdf::DestinationType::Fit)); submenu->addAction(tr("Fit Page Horizontally"), createOnSetTarget(pdf::DestinationType::FitH)); submenu->addAction(tr("Fit Page Vertically"), createOnSetTarget(pdf::DestinationType::FitV));