AudioBook Plugin: Initial commit, document text flow adjustments

This commit is contained in:
Jakub Melka
2021-08-15 17:34:05 +02:00
parent 0559cd7c50
commit 354a93f4d6
12 changed files with 547 additions and 35 deletions

View File

@@ -0,0 +1,7 @@
{
"Name" : "AudioBook",
"Author" : "Jakub Melka",
"Version" : "1.0.0",
"License" : "LGPL v3",
"Description" : "Convert document to an audio book."
}

View File

@@ -0,0 +1,48 @@
# 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/>.
TEMPLATE = lib
DEFINES += AUDIOBOOKPLUGIN_LIBRARY
QT += gui widgets
LIBS += -L$$OUT_PWD/../..
LIBS += -lPdf4QtLib
QMAKE_CXXFLAGS += /std:c++latest /utf-8
INCLUDEPATH += $$PWD/../../Pdf4QtLib/Sources
DESTDIR = $$OUT_PWD/../../pdfplugins
CONFIG += c++11
SOURCES += \
audiobookplugin.cpp
HEADERS += \
audiobookplugin.h
CONFIG += force_debug_info
DISTFILES += \
AudioBookPlugin.json
RESOURCES += \
icons.qrc

View File

@@ -0,0 +1,81 @@
// 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 "audiobookplugin.h"
#include <QAction>
namespace pdfplugin
{
AudioBookPlugin::AudioBookPlugin() :
pdf::PDFPlugin(nullptr),
m_createTextStreamAction(nullptr)
{
}
void AudioBookPlugin::setWidget(pdf::PDFWidget* widget)
{
Q_ASSERT(!m_widget);
BaseClass::setWidget(widget);
m_createTextStreamAction = new QAction(QIcon(":/pdfplugins/audiobook/create-text-stream.svg"), tr("Create Text Stream for Audio Book"), this);
m_createTextStreamAction->setObjectName("actionAudioBook_CreateTextStream");
connect(m_createTextStreamAction, &QAction::triggered, this, &AudioBookPlugin::onCreateTextStreamTriggered);
updateActions();
}
void AudioBookPlugin::setDocument(const pdf::PDFModifiedDocument& document)
{
BaseClass::setDocument(document);
if (document.hasReset())
{
m_textFlowEditor.clear();
updateActions();
}
}
std::vector<QAction*> AudioBookPlugin::getActions() const
{
return { m_createTextStreamAction };
}
void AudioBookPlugin::onCreateTextStreamTriggered()
{
Q_ASSERT(m_document);
if (!m_textFlowEditor.isEmpty())
{
return;
}
pdf::PDFDocumentTextFlowFactory factory;
pdf::PDFDocumentTextFlow textFlow = factory.create(m_document, pdf::PDFDocumentTextFlowFactory::Algorithm::Auto);
m_textFlowEditor.setTextFlow(std::move(textFlow));
}
void AudioBookPlugin::updateActions()
{
m_createTextStreamAction->setEnabled(m_document);
}
} // namespace pdfplugin

View File

@@ -0,0 +1,56 @@
// 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 AUDIOBOOKPLUGIN_H
#define AUDIOBOOKPLUGIN_H
#include "pdfplugin.h"
#include "pdfdocumenttextflow.h"
#include <QObject>
namespace pdfplugin
{
class AudioBookPlugin : public pdf::PDFPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "PDF4QT.AudioBookPlugin" FILE "AudioBookPlugin.json")
private:
using BaseClass = pdf::PDFPlugin;
public:
AudioBookPlugin();
virtual void setWidget(pdf::PDFWidget* widget) override;
virtual void setDocument(const pdf::PDFModifiedDocument& document) override;
virtual std::vector<QAction*> getActions() const override;
private:
void onCreateTextStreamTriggered();
void updateActions();
QAction* m_createTextStreamAction;
pdf::PDFDocumentTextFlowEditor m_textFlowEditor;
};
} // namespace pdfplugin
#endif // AUDIOBOOKPLUGIN_H

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 8.4 KiB

View File

@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/pdfplugins/audiobook">
<file>create-text-stream.svg</file>
</qresource>
</RCC>

View File

@@ -23,6 +23,7 @@ SUBDIRS += \
SoftProofingPlugin \
RedactPlugin \
OutputPreviewPlugin \
ObjectInspectorPlugin
ObjectInspectorPlugin \
AudioBookPlugin