From 7264a45e30ceaafbff06d6a97672e9b42c9eea3f Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Wed, 16 Jun 2021 18:45:47 +0200 Subject: [PATCH] Pin/unpin functionality --- .../objectinspectordialog.cpp | 30 +++++++++++++++++ .../objectinspectordialog.h | 2 ++ .../objectinspectordialog.ui | 3 ++ .../objectviewerwidget.cpp | 33 ++++++++++++++++++- .../objectviewerwidget.h | 4 +++ 5 files changed, 71 insertions(+), 1 deletion(-) diff --git a/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectinspectordialog.cpp b/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectinspectordialog.cpp index 0493e65..5fa5eb1 100644 --- a/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectinspectordialog.cpp +++ b/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectinspectordialog.cpp @@ -103,6 +103,8 @@ ObjectInspectorDialog::ObjectInspectorDialog(const pdf::PDFCMS* cms, const pdf:: ui->splitter->setSizes(QList() << pdf::PDFWidgetUtils::scaleDPI_x(this, 300) << pdf::PDFWidgetUtils::scaleDPI_x(this, 200)); connect(ui->objectTreeView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ObjectInspectorDialog::onCurrentIndexChanged); + connect(ui->currentObjectWidget, &ObjectViewerWidget::pinRequest, this, &ObjectInspectorDialog::onPinRequest); + connect(ui->currentObjectWidget, &ObjectViewerWidget::unpinRequest, this, &ObjectInspectorDialog::onUnpinRequest); ui->objectTreeView->setMinimumWidth(pdf::PDFWidgetUtils::scaleDPI_x(this, 200)); setMinimumSize(pdf::PDFWidgetUtils::scaleDPI(this, QSize(800, 600))); @@ -119,6 +121,34 @@ void ObjectInspectorDialog::onModeChanged() m_model->setMode(mode); } +void ObjectInspectorDialog::onPinRequest() +{ + ObjectViewerWidget* source = qobject_cast(sender()); + + if (!source || source != ui->currentObjectWidget) + { + return; + } + + ObjectViewerWidget* cloned = ui->currentObjectWidget->clone(true, this); + connect(cloned, &ObjectViewerWidget::pinRequest, this, &ObjectInspectorDialog::onPinRequest); + connect(cloned, &ObjectViewerWidget::unpinRequest, this, &ObjectInspectorDialog::onUnpinRequest); + ui->tabWidget->addTab(cloned, cloned->getTitleText()); +} + +void ObjectInspectorDialog::onUnpinRequest() +{ + ObjectViewerWidget* source = qobject_cast(sender()); + + if (!source || source == ui->currentObjectWidget) + { + return; + } + + ui->tabWidget->removeTab(ui->tabWidget->indexOf(source)); + source->deleteLater(); +} + void ObjectInspectorDialog::onCurrentIndexChanged(const QModelIndex& current, const QModelIndex& previous) { Q_UNUSED(previous); diff --git a/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectinspectordialog.h b/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectinspectordialog.h index 47c60c3..f5d1bac 100644 --- a/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectinspectordialog.h +++ b/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectinspectordialog.h @@ -43,6 +43,8 @@ public: private: void onModeChanged(); + void onPinRequest(); + void onUnpinRequest(); void onCurrentIndexChanged(const QModelIndex& current, const QModelIndex& previous); Ui::ObjectInspectorDialog* ui; diff --git a/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectinspectordialog.ui b/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectinspectordialog.ui index dc9f560..d740606 100644 --- a/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectinspectordialog.ui +++ b/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectinspectordialog.ui @@ -40,6 +40,9 @@ 0 + + true + Current Object diff --git a/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectviewerwidget.cpp b/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectviewerwidget.cpp index a551aa0..06797c7 100644 --- a/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectviewerwidget.cpp +++ b/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectviewerwidget.cpp @@ -46,7 +46,7 @@ ObjectViewerWidget::ObjectViewerWidget(bool isPinned, QWidget* parent) : m_printableCharacters.push_back('\n'); connect(ui->pinButton, &QPushButton::clicked, this, &ObjectViewerWidget::pinRequest); - connect(ui->unpinButton, &QPushButton::clicked, this, &ObjectViewerWidget::pinRequest); + connect(ui->unpinButton, &QPushButton::clicked, this, &ObjectViewerWidget::unpinRequest); updateUi(); updatePinnedUi(); @@ -57,6 +57,18 @@ ObjectViewerWidget::~ObjectViewerWidget() delete ui; } +ObjectViewerWidget* ObjectViewerWidget::clone(bool isPinned, QWidget* parent) +{ + ObjectViewerWidget* cloned = new ObjectViewerWidget(isPinned, parent); + + cloned->setDocument(m_document); + cloned->setCms(m_cms); + cloned->setData(m_currentReference, m_currentObject, m_isRootObject); + + + return cloned; +} + void ObjectViewerWidget::setPinned(bool isPinned) { if (m_isPinned != isPinned) @@ -271,6 +283,25 @@ void ObjectViewerWidget::setCms(const pdf::PDFCMS* cms) m_cms = cms; } +QString ObjectViewerWidget::getTitleText() const +{ + if (!m_currentReference.isValid()) + { + return tr("[Unknown]"); + } + + QString referenceString = tr("%1 %2 R").arg(m_currentReference.objectNumber).arg(m_currentReference.generation); + + if (m_isRootObject) + { + return referenceString; + } + else + { + return tr("%1 (part)").arg(referenceString); + } +} + const pdf::PDFDocument* ObjectViewerWidget::getDocument() const { return m_document; diff --git a/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectviewerwidget.h b/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectviewerwidget.h index d166ce8..ff82d40 100644 --- a/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectviewerwidget.h +++ b/Pdf4QtViewerPlugins/ObjectInspectorPlugin/objectviewerwidget.h @@ -40,6 +40,8 @@ public: explicit ObjectViewerWidget(bool isPinned, QWidget* parent); virtual ~ObjectViewerWidget() override; + ObjectViewerWidget* clone(bool isPinned, QWidget* parent); + void setPinned(bool isPinned); void setData(pdf::PDFObjectReference currentReference, pdf::PDFObject currentObject, bool isRootObject); @@ -49,6 +51,8 @@ public: const pdf::PDFCMS* getCms() const; void setCms(const pdf::PDFCMS* cms); + QString getTitleText() const; + signals: void pinRequest(); void unpinRequest();