mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2024-12-28 17:20:02 +01:00
Pin/unpin functionality
This commit is contained in:
parent
47baae321e
commit
7264a45e30
@ -103,6 +103,8 @@ ObjectInspectorDialog::ObjectInspectorDialog(const pdf::PDFCMS* cms, const pdf::
|
||||
ui->splitter->setSizes(QList<int>() << 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<ObjectViewerWidget*>(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<ObjectViewerWidget*>(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);
|
||||
|
@ -43,6 +43,8 @@ public:
|
||||
|
||||
private:
|
||||
void onModeChanged();
|
||||
void onPinRequest();
|
||||
void onUnpinRequest();
|
||||
void onCurrentIndexChanged(const QModelIndex& current, const QModelIndex& previous);
|
||||
|
||||
Ui::ObjectInspectorDialog* ui;
|
||||
|
@ -40,6 +40,9 @@
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="movable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="currentObjectTab">
|
||||
<attribute name="title">
|
||||
<string>Current Object</string>
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user