AudioBook plugin: Selection synchronization; minor bugfixes

This commit is contained in:
Jakub Melka 2021-08-25 20:28:37 +02:00
parent 4cb077f75e
commit 7525265233
5 changed files with 55 additions and 4 deletions

View File

@ -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<PDFDocumentTextFlow::Item&>(editedItem) = *originalItem;
editedItem.originalIndex = i;
editedItem.editedItemFlags = None;
editedItem.editedItemFlags = originalItem->isText() ? None : Removed;
m_editedTextFlow.emplace_back(std::move(editedItem));
}

View File

@ -26,6 +26,7 @@
#include <QMainWindow>
#include <QMessageBox>
#include <QMouseEvent>
#include <QTableView>
#include <QRegularExpression>
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)

View File

@ -78,6 +78,7 @@ private:
void onSelectByPageList();
void onRestoreOriginalText();
void onEditedTextFlowChanged();
void onTextStreamTableSelectionChanged();
void onClear();
void onRectanglePicked(pdf::PDFInteger pageIndex, QRectF rectangle);

View File

@ -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();

View File

@ -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();