2020-02-18 20:21:18 +01:00
|
|
|
|
// Copyright (C) 2020 Jakub Melka
|
|
|
|
|
//
|
|
|
|
|
// This file is part of PdfForQt.
|
|
|
|
|
//
|
|
|
|
|
// PdfForQt 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
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// PdfForQt 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 PDFForQt. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef PDFTEXTTOSPEECH_H
|
|
|
|
|
#define PDFTEXTTOSPEECH_H
|
|
|
|
|
|
|
|
|
|
#include "pdftextlayout.h"
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
|
2020-02-20 19:25:32 +01:00
|
|
|
|
class QLabel;
|
2020-02-18 20:21:18 +01:00
|
|
|
|
class QSlider;
|
|
|
|
|
class QComboBox;
|
|
|
|
|
class QToolButton;
|
2020-02-20 19:25:32 +01:00
|
|
|
|
class QTextBrowser;
|
2020-02-18 20:21:18 +01:00
|
|
|
|
class QTextToSpeech;
|
|
|
|
|
|
|
|
|
|
namespace pdf
|
|
|
|
|
{
|
|
|
|
|
class PDFDocument;
|
|
|
|
|
class PDFDrawWidgetProxy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace pdfviewer
|
|
|
|
|
{
|
|
|
|
|
class PDFViewerSettings;
|
|
|
|
|
|
|
|
|
|
/// Text to speech engine used to reading the document
|
|
|
|
|
class PDFTextToSpeech : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
using BaseClass = QObject;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit PDFTextToSpeech(QObject* parent);
|
|
|
|
|
|
|
|
|
|
enum State
|
|
|
|
|
{
|
|
|
|
|
Invalid, ///< Text to speech engine is invalid (maybe bad engine)
|
|
|
|
|
NoDocument, ///< No document to read
|
|
|
|
|
Ready, ///< Ready to read the document contents
|
|
|
|
|
Playing, ///< Document is being read
|
|
|
|
|
Paused, ///< User paused the reading
|
|
|
|
|
Error ///< Error occured in text to speech engine
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// Returns true, if text to speech engine is valid and can be used
|
|
|
|
|
/// to synthetise text.
|
|
|
|
|
bool isValid() const;
|
|
|
|
|
|
|
|
|
|
/// Sets active document to text to speech engine
|
|
|
|
|
void setDocument(const pdf::PDFDocument* document);
|
|
|
|
|
|
|
|
|
|
/// Apply settings to the reader
|
|
|
|
|
void setSettings(const PDFViewerSettings* viewerSettings);
|
|
|
|
|
|
|
|
|
|
/// Set draw proxy
|
2020-02-20 19:25:32 +01:00
|
|
|
|
void setProxy(pdf::PDFDrawWidgetProxy* proxy);
|
2020-02-18 20:21:18 +01:00
|
|
|
|
|
|
|
|
|
/// Initialize the ui, which is used
|
|
|
|
|
void initializeUI(QComboBox* speechLocaleComboBox,
|
|
|
|
|
QComboBox* speechVoiceComboBox,
|
|
|
|
|
QSlider* speechRateEdit,
|
|
|
|
|
QSlider* speechPitchEdit,
|
2020-02-19 19:26:11 +01:00
|
|
|
|
QSlider* speechVolumeEdit,
|
2020-02-18 20:21:18 +01:00
|
|
|
|
QToolButton* speechPlayButton,
|
|
|
|
|
QToolButton* speechPauseButton,
|
|
|
|
|
QToolButton* speechStopButton,
|
2020-02-20 19:25:32 +01:00
|
|
|
|
QToolButton* speechSynchronizeButton,
|
|
|
|
|
QLabel* speechRateValueLabel,
|
|
|
|
|
QLabel* speechPitchValueLabel,
|
|
|
|
|
QLabel* speechVolumeValueLabel,
|
|
|
|
|
QTextBrowser* speechActualTextBrowser);
|
2020-02-18 20:21:18 +01:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
/// Updates UI controls depending on the state
|
|
|
|
|
void updateUI();
|
|
|
|
|
|
|
|
|
|
/// Stop the engine, if it is reading
|
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
|
|
void setLocale(const QString& locale);
|
|
|
|
|
void setVoice(const QString& voice);
|
|
|
|
|
void setRate(const double rate);
|
|
|
|
|
void setPitch(const double pitch);
|
|
|
|
|
void setVolume(const double volume);
|
|
|
|
|
|
|
|
|
|
void onLocaleChanged();
|
|
|
|
|
void onVoiceChanged();
|
|
|
|
|
void onRateChanged(int rate);
|
|
|
|
|
void onPitchChanged(int pitch);
|
|
|
|
|
void onVolumeChanged(int volume);
|
|
|
|
|
|
|
|
|
|
void onPlayClicked();
|
|
|
|
|
void onPauseClicked();
|
|
|
|
|
void onStopClicked();
|
|
|
|
|
|
|
|
|
|
void updatePlay();
|
|
|
|
|
void updateToNextPage(pdf::PDFInteger pageIndex);
|
|
|
|
|
|
|
|
|
|
QTextToSpeech* m_textToSpeech;
|
|
|
|
|
const pdf::PDFDocument* m_document;
|
2020-02-20 19:25:32 +01:00
|
|
|
|
pdf::PDFDrawWidgetProxy* m_proxy;
|
2020-02-18 20:21:18 +01:00
|
|
|
|
State m_state;
|
|
|
|
|
bool m_initialized;
|
|
|
|
|
|
|
|
|
|
QComboBox* m_speechLocaleComboBox;
|
|
|
|
|
QComboBox* m_speechVoiceComboBox;
|
|
|
|
|
QSlider* m_speechRateEdit;
|
|
|
|
|
QSlider* m_speechVolumeEdit;
|
|
|
|
|
QSlider* m_speechPitchEdit;
|
|
|
|
|
QToolButton* m_speechPlayButton;
|
|
|
|
|
QToolButton* m_speechPauseButton;
|
|
|
|
|
QToolButton* m_speechStopButton;
|
|
|
|
|
QToolButton* m_speechSynchronizeButton;
|
2020-02-20 19:25:32 +01:00
|
|
|
|
QLabel* m_speechRateValueLabel;
|
|
|
|
|
QLabel* m_speechPitchValueLabel;
|
|
|
|
|
QLabel* m_speechVolumeValueLabel;
|
|
|
|
|
QTextBrowser* m_speechActualTextBrowser;
|
2020-02-18 20:21:18 +01:00
|
|
|
|
|
|
|
|
|
pdf::PDFTextLayout m_currentTextLayout; ///< Text layout for actual page
|
|
|
|
|
pdf::PDFTextFlows m_textFlows; ///< Text flows for actual page
|
|
|
|
|
size_t m_currentTextFlowIndex = 0; ///< Index of current text flow
|
|
|
|
|
pdf::PDFInteger m_currentPage = 0; ///< Current page
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace pdfviewer
|
|
|
|
|
|
|
|
|
|
#endif // PDFTEXTTOSPEECH_H
|