AudioBook Plugin: Text Stream Editor

This commit is contained in:
Jakub Melka
2021-08-19 17:51:35 +02:00
parent 78aca34b57
commit 9daaa92e90
13 changed files with 482 additions and 3 deletions

View File

@@ -33,10 +33,12 @@ DESTDIR = $$OUT_PWD/../../pdfplugins
CONFIG += c++11
SOURCES += \
audiobookplugin.cpp
audiobookplugin.cpp \
audiotextstreameditordockwidget.cpp
HEADERS += \
audiobookplugin.h
audiobookplugin.h \
audiotextstreameditordockwidget.h
CONFIG += force_debug_info
@@ -46,3 +48,6 @@ DISTFILES += \
RESOURCES += \
icons.qrc
FORMS += \
audiotextstreameditordockwidget.ui

View File

@@ -18,13 +18,16 @@
#include "audiobookplugin.h"
#include <QAction>
#include <QMainWindow>
namespace pdfplugin
{
AudioBookPlugin::AudioBookPlugin() :
pdf::PDFPlugin(nullptr),
m_createTextStreamAction(nullptr)
m_createTextStreamAction(nullptr),
m_audioTextStreamDockWidget(nullptr),
m_audioTextStreamEditorModel(nullptr)
{
}
@@ -63,6 +66,21 @@ void AudioBookPlugin::onCreateTextStreamTriggered()
{
Q_ASSERT(m_document);
if (!m_audioTextStreamDockWidget)
{
m_audioTextStreamDockWidget = new AudioTextStreamEditorDockWidget(m_dataExchangeInterface->getMainWindow());
m_audioTextStreamDockWidget->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
m_dataExchangeInterface->getMainWindow()->addDockWidget(Qt::BottomDockWidgetArea, m_audioTextStreamDockWidget, Qt::Horizontal);
m_audioTextStreamDockWidget->setFloating(false);
Q_ASSERT(!m_audioTextStreamEditorModel);
m_audioTextStreamEditorModel = new pdf::PDFDocumentTextFlowEditorModel(m_audioTextStreamDockWidget);
m_audioTextStreamEditorModel->setEditor(&m_textFlowEditor);
m_audioTextStreamDockWidget->setModel(m_audioTextStreamEditorModel);
}
m_audioTextStreamDockWidget->show();
if (!m_textFlowEditor.isEmpty())
{
return;
@@ -71,7 +89,10 @@ void AudioBookPlugin::onCreateTextStreamTriggered()
pdf::PDFDocumentTextFlowFactory factory;
factory.setCalculateBoundingBoxes(true);
pdf::PDFDocumentTextFlow textFlow = factory.create(m_document, pdf::PDFDocumentTextFlowFactory::Algorithm::Auto);
m_audioTextStreamEditorModel->beginFlowChange();
m_textFlowEditor.setTextFlow(std::move(textFlow));
m_audioTextStreamEditorModel->endFlowChange();
}
void AudioBookPlugin::updateActions()

View File

@@ -20,6 +20,8 @@
#include "pdfplugin.h"
#include "pdfdocumenttextflow.h"
#include "pdfdocumenttextfloweditormodel.h"
#include "audiotextstreameditordockwidget.h"
#include <QObject>
@@ -49,6 +51,8 @@ private:
QAction* m_createTextStreamAction;
pdf::PDFDocumentTextFlowEditor m_textFlowEditor;
AudioTextStreamEditorDockWidget* m_audioTextStreamDockWidget;
pdf::PDFDocumentTextFlowEditorModel* m_audioTextStreamEditorModel;
};
} // namespace pdfplugin

View File

@@ -0,0 +1,54 @@
// Copyright (C) 2021 Jakub Melka
//
// This file is part of PDF4QT.
//
// PDF4QT is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// with the written consent of the copyright owner, any later version.
//
// PDF4QT is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
#include "audiotextstreameditordockwidget.h"
#include "ui_audiotextstreameditordockwidget.h"
#include "pdfwidgetutils.h"
namespace pdfplugin
{
AudioTextStreamEditorDockWidget::AudioTextStreamEditorDockWidget(QWidget *parent) :
QDockWidget(parent),
ui(new Ui::AudioTextStreamEditorDockWidget),
m_model(nullptr)
{
ui->setupUi(this);
ui->textStreamTableView->horizontalHeader()->setStretchLastSection(true);
ui->textStreamTableView->horizontalHeader()->setMinimumSectionSize(pdf::PDFWidgetUtils::scaleDPI_x(this, 85));
setMinimumSize(pdf::PDFWidgetUtils::scaleDPI(this, QSize(300, 150)));
}
AudioTextStreamEditorDockWidget::~AudioTextStreamEditorDockWidget()
{
delete ui;
}
pdf::PDFDocumentTextFlowEditorModel* AudioTextStreamEditorDockWidget::getModel() const
{
return m_model;
}
void AudioTextStreamEditorDockWidget::setModel(pdf::PDFDocumentTextFlowEditorModel* model)
{
m_model = model;
ui->textStreamTableView->setModel(m_model);
}
} // namespace pdfplugin

View File

@@ -0,0 +1,51 @@
// Copyright (C) 2021 Jakub Melka
//
// This file is part of PDF4QT.
//
// PDF4QT is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// with the written consent of the copyright owner, any later version.
//
// PDF4QT is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
#ifndef AUDIOTEXTSTREAMEDITORDOCKWIDGET_H
#define AUDIOTEXTSTREAMEDITORDOCKWIDGET_H
#include "pdfdocumenttextfloweditormodel.h"
#include <QDockWidget>
namespace Ui
{
class AudioTextStreamEditorDockWidget;
}
namespace pdfplugin
{
class AudioTextStreamEditorDockWidget : public QDockWidget
{
Q_OBJECT
public:
explicit AudioTextStreamEditorDockWidget(QWidget* parent);
virtual ~AudioTextStreamEditorDockWidget() override;
pdf::PDFDocumentTextFlowEditorModel* getModel() const;
void setModel(pdf::PDFDocumentTextFlowEditorModel* model);
private:
Ui::AudioTextStreamEditorDockWidget* ui;
pdf::PDFDocumentTextFlowEditorModel* m_model;
};
} // namespace pdfplugin
#endif // AUDIOTEXTSTREAMEDITORDOCKWIDGET_H

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AudioTextStreamEditorDockWidget</class>
<widget class="QDockWidget" name="AudioTextStreamEditorDockWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>723</width>
<height>552</height>
</rect>
</property>
<property name="windowTitle">
<string>Text Stream for Audio Book</string>
</property>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableView" name="textStreamTableView"/>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>