mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
AudioBook plugin: Selection synchronization; minor bugfixes
This commit is contained in:
@ -936,7 +936,7 @@ void PDFDocumentTextFlowEditor::createEditedFromOriginalTextFlow()
|
|||||||
{
|
{
|
||||||
const PDFDocumentTextFlow::Item* originalItem = getOriginalItem(i);
|
const PDFDocumentTextFlow::Item* originalItem = getOriginalItem(i);
|
||||||
|
|
||||||
if (originalItem->text.isEmpty())
|
if (originalItem->text.trimmed().isEmpty())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -944,7 +944,7 @@ void PDFDocumentTextFlowEditor::createEditedFromOriginalTextFlow()
|
|||||||
EditedItem editedItem;
|
EditedItem editedItem;
|
||||||
static_cast<PDFDocumentTextFlow::Item&>(editedItem) = *originalItem;
|
static_cast<PDFDocumentTextFlow::Item&>(editedItem) = *originalItem;
|
||||||
editedItem.originalIndex = i;
|
editedItem.originalIndex = i;
|
||||||
editedItem.editedItemFlags = None;
|
editedItem.editedItemFlags = originalItem->isText() ? None : Removed;
|
||||||
m_editedTextFlow.emplace_back(std::move(editedItem));
|
m_editedTextFlow.emplace_back(std::move(editedItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QTableView>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
namespace pdfplugin
|
namespace pdfplugin
|
||||||
@ -239,6 +240,7 @@ void AudioBookPlugin::onCreateTextStreamTriggered()
|
|||||||
m_audioTextStreamEditorModel = new pdf::PDFDocumentTextFlowEditorModel(m_audioTextStreamDockWidget);
|
m_audioTextStreamEditorModel = new pdf::PDFDocumentTextFlowEditorModel(m_audioTextStreamDockWidget);
|
||||||
m_audioTextStreamEditorModel->setEditor(&m_textFlowEditor);
|
m_audioTextStreamEditorModel->setEditor(&m_textFlowEditor);
|
||||||
m_audioTextStreamDockWidget->setModel(m_audioTextStreamEditorModel);
|
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::modelReset, this, &AudioBookPlugin::onEditedTextFlowChanged);
|
||||||
connect(m_audioTextStreamEditorModel, &pdf::PDFDocumentTextFlowEditorModel::dataChanged, this, &AudioBookPlugin::onEditedTextFlowChanged);
|
connect(m_audioTextStreamEditorModel, &pdf::PDFDocumentTextFlowEditorModel::dataChanged, this, &AudioBookPlugin::onEditedTextFlowChanged);
|
||||||
}
|
}
|
||||||
@ -346,7 +348,7 @@ void AudioBookPlugin::onRestoreOriginalText()
|
|||||||
return;
|
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();
|
m_audioTextStreamEditorModel->restoreOriginalTexts();
|
||||||
}
|
}
|
||||||
@ -362,6 +364,36 @@ void AudioBookPlugin::onEditedTextFlowChanged()
|
|||||||
updateActions();
|
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()
|
void AudioBookPlugin::onClear()
|
||||||
{
|
{
|
||||||
if (m_audioTextStreamEditorModel)
|
if (m_audioTextStreamEditorModel)
|
||||||
@ -421,7 +453,18 @@ void AudioBookPlugin::shortcutOverrideEvent(QWidget* widget, QKeyEvent* event)
|
|||||||
void AudioBookPlugin::keyPressEvent(QWidget* widget, QKeyEvent* event)
|
void AudioBookPlugin::keyPressEvent(QWidget* widget, QKeyEvent* event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(widget);
|
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)
|
void AudioBookPlugin::keyReleaseEvent(QWidget* widget, QKeyEvent* event)
|
||||||
|
@ -78,6 +78,7 @@ private:
|
|||||||
void onSelectByPageList();
|
void onSelectByPageList();
|
||||||
void onRestoreOriginalText();
|
void onRestoreOriginalText();
|
||||||
void onEditedTextFlowChanged();
|
void onEditedTextFlowChanged();
|
||||||
|
void onTextStreamTableSelectionChanged();
|
||||||
void onClear();
|
void onClear();
|
||||||
|
|
||||||
void onRectanglePicked(pdf::PDFInteger pageIndex, QRectF rectangle);
|
void onRectanglePicked(pdf::PDFInteger pageIndex, QRectF rectangle);
|
||||||
|
@ -86,6 +86,11 @@ void AudioTextStreamEditorDockWidget::setModel(pdf::PDFDocumentTextFlowEditorMod
|
|||||||
ui->textStreamTableView->setModel(m_model);
|
ui->textStreamTableView->setModel(m_model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTableView* AudioTextStreamEditorDockWidget::getTextStreamView() const
|
||||||
|
{
|
||||||
|
return ui->textStreamTableView;
|
||||||
|
}
|
||||||
|
|
||||||
QString AudioTextStreamEditorDockWidget::getSelectionText() const
|
QString AudioTextStreamEditorDockWidget::getSelectionText() const
|
||||||
{
|
{
|
||||||
return m_selectionTextEdit->text();
|
return m_selectionTextEdit->text();
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
class QToolBar;
|
class QToolBar;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
|
class QTableView;
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
@ -63,6 +64,7 @@ public:
|
|||||||
void setModel(pdf::PDFDocumentTextFlowEditorModel* model);
|
void setModel(pdf::PDFDocumentTextFlowEditorModel* model);
|
||||||
|
|
||||||
QToolBar* getToolBar() const { return m_toolBar; }
|
QToolBar* getToolBar() const { return m_toolBar; }
|
||||||
|
QTableView* getTextStreamView() const;
|
||||||
|
|
||||||
QString getSelectionText() const;
|
QString getSelectionText() const;
|
||||||
void clearSelectionText();
|
void clearSelectionText();
|
||||||
|
Reference in New Issue
Block a user