diff --git a/Pdf4QtLib/sources/pdfdocumenttextflow.cpp b/Pdf4QtLib/sources/pdfdocumenttextflow.cpp index fd05c7d..83c221b 100644 --- a/Pdf4QtLib/sources/pdfdocumenttextflow.cpp +++ b/Pdf4QtLib/sources/pdfdocumenttextflow.cpp @@ -936,7 +936,7 @@ void PDFDocumentTextFlowEditor::createEditedFromOriginalTextFlow() { const PDFDocumentTextFlow::Item* originalItem = getOriginalItem(i); - if (originalItem->text.isEmpty()) + if (originalItem->text.trimmed().isEmpty()) { continue; } @@ -944,7 +944,7 @@ void PDFDocumentTextFlowEditor::createEditedFromOriginalTextFlow() EditedItem editedItem; static_cast(editedItem) = *originalItem; editedItem.originalIndex = i; - editedItem.editedItemFlags = None; + editedItem.editedItemFlags = originalItem->isText() ? None : Removed; m_editedTextFlow.emplace_back(std::move(editedItem)); } diff --git a/Pdf4QtViewerPlugins/AudioBookPlugin/audiobookplugin.cpp b/Pdf4QtViewerPlugins/AudioBookPlugin/audiobookplugin.cpp index 3840fc0..7f35c1d 100644 --- a/Pdf4QtViewerPlugins/AudioBookPlugin/audiobookplugin.cpp +++ b/Pdf4QtViewerPlugins/AudioBookPlugin/audiobookplugin.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include namespace pdfplugin @@ -239,6 +240,7 @@ void AudioBookPlugin::onCreateTextStreamTriggered() m_audioTextStreamEditorModel = new pdf::PDFDocumentTextFlowEditorModel(m_audioTextStreamDockWidget); m_audioTextStreamEditorModel->setEditor(&m_textFlowEditor); m_audioTextStreamDockWidget->setModel(m_audioTextStreamEditorModel); + connect(m_audioTextStreamDockWidget->getTextStreamView()->selectionModel(), &QItemSelectionModel::selectionChanged, this, &AudioBookPlugin::onTextStreamTableSelectionChanged); connect(m_audioTextStreamEditorModel, &pdf::PDFDocumentTextFlowEditorModel::modelReset, this, &AudioBookPlugin::onEditedTextFlowChanged); connect(m_audioTextStreamEditorModel, &pdf::PDFDocumentTextFlowEditorModel::dataChanged, this, &AudioBookPlugin::onEditedTextFlowChanged); } @@ -346,7 +348,7 @@ void AudioBookPlugin::onRestoreOriginalText() return; } - if (QMessageBox::question(m_audioTextStreamDockWidget, tr("Question"), tr("Restore original texts in selected items? All changes will be lost."), QMessageBox::No, QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) + if (QMessageBox::question(m_audioTextStreamDockWidget, tr("Question"), tr("Restore original texts in selected items? All changes will be lost."), QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { m_audioTextStreamEditorModel->restoreOriginalTexts(); } @@ -362,6 +364,36 @@ void AudioBookPlugin::onEditedTextFlowChanged() updateActions(); } +void AudioBookPlugin::onTextStreamTableSelectionChanged() +{ + QTableView* tableView = m_audioTextStreamDockWidget->getTextStreamView(); + QModelIndexList indices = tableView->selectionModel()->selectedIndexes(); + + if (m_actionSynchronizeFromTableToGraphics->isChecked() && !indices.empty()) + { + // Jakub Melka: we will find first index, which has valid page number + for (const QModelIndex& index : indices) + { + pdf::PDFInteger pageIndex = m_textFlowEditor.getPageIndex(index.row()); + + if (pageIndex >= 0) + { + m_widget->getDrawWidgetProxy()->goToPage(pageIndex); + break; + } + } + } + + m_textFlowEditor.deselect(); + + for (const QModelIndex& index : indices) + { + m_textFlowEditor.select(index.row(), true); + } + + m_audioTextStreamEditorModel->notifyDataChanged(); +} + void AudioBookPlugin::onClear() { if (m_audioTextStreamEditorModel) @@ -421,7 +453,18 @@ void AudioBookPlugin::shortcutOverrideEvent(QWidget* widget, QKeyEvent* event) void AudioBookPlugin::keyPressEvent(QWidget* widget, QKeyEvent* event) { Q_UNUSED(widget); - Q_UNUSED(event); + + if (m_textFlowEditor.isEmpty()) + { + // Jakub Melka: do nothing, editor is empty + return; + } + + if (event->key() == Qt::Key_Delete) + { + m_audioTextStreamEditorModel->setSelectionActivated(event->modifiers().testFlag(Qt::ShiftModifier)); + event->accept(); + } } void AudioBookPlugin::keyReleaseEvent(QWidget* widget, QKeyEvent* event) diff --git a/Pdf4QtViewerPlugins/AudioBookPlugin/audiobookplugin.h b/Pdf4QtViewerPlugins/AudioBookPlugin/audiobookplugin.h index 1e3939a..de5593c 100644 --- a/Pdf4QtViewerPlugins/AudioBookPlugin/audiobookplugin.h +++ b/Pdf4QtViewerPlugins/AudioBookPlugin/audiobookplugin.h @@ -78,6 +78,7 @@ private: void onSelectByPageList(); void onRestoreOriginalText(); void onEditedTextFlowChanged(); + void onTextStreamTableSelectionChanged(); void onClear(); void onRectanglePicked(pdf::PDFInteger pageIndex, QRectF rectangle); diff --git a/Pdf4QtViewerPlugins/AudioBookPlugin/audiotextstreameditordockwidget.cpp b/Pdf4QtViewerPlugins/AudioBookPlugin/audiotextstreameditordockwidget.cpp index c138fa0..75f2440 100644 --- a/Pdf4QtViewerPlugins/AudioBookPlugin/audiotextstreameditordockwidget.cpp +++ b/Pdf4QtViewerPlugins/AudioBookPlugin/audiotextstreameditordockwidget.cpp @@ -86,6 +86,11 @@ void AudioTextStreamEditorDockWidget::setModel(pdf::PDFDocumentTextFlowEditorMod ui->textStreamTableView->setModel(m_model); } +QTableView* AudioTextStreamEditorDockWidget::getTextStreamView() const +{ + return ui->textStreamTableView; +} + QString AudioTextStreamEditorDockWidget::getSelectionText() const { return m_selectionTextEdit->text(); diff --git a/Pdf4QtViewerPlugins/AudioBookPlugin/audiotextstreameditordockwidget.h b/Pdf4QtViewerPlugins/AudioBookPlugin/audiotextstreameditordockwidget.h index 4c1102a..5356664 100644 --- a/Pdf4QtViewerPlugins/AudioBookPlugin/audiotextstreameditordockwidget.h +++ b/Pdf4QtViewerPlugins/AudioBookPlugin/audiotextstreameditordockwidget.h @@ -24,6 +24,7 @@ class QToolBar; class QLineEdit; +class QTableView; namespace Ui { @@ -63,6 +64,7 @@ public: void setModel(pdf::PDFDocumentTextFlowEditorModel* model); QToolBar* getToolBar() const { return m_toolBar; } + QTableView* getTextStreamView() const; QString getSelectionText() const; void clearSelectionText();