2013-04-24 14:52:04 +00:00
|
|
|
/* This file is (c) 2013 Timon Wong <timon86.wang@gmail.com>
|
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#ifndef __TEXTTOSPEECHSOURCE_HH_INCLUDED__
|
|
|
|
#define __TEXTTOSPEECHSOURCE_HH_INCLUDED__
|
|
|
|
|
|
|
|
#include "ui_texttospeechsource.h"
|
|
|
|
#include "config.hh"
|
|
|
|
#include "speechclient.hh"
|
|
|
|
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QStyledItemDelegate>
|
|
|
|
|
|
|
|
/// A model to be projected into the text to speech view, according to Qt's MVC model
|
|
|
|
class VoiceEnginesModel: public QAbstractItemModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2022-07-31 01:19:50 +00:00
|
|
|
enum {
|
|
|
|
kColumnEnabled = 0,
|
|
|
|
kColumnEngineName,
|
|
|
|
kColumnEngineDName,
|
|
|
|
kColumnIcon,
|
|
|
|
kColumnCount
|
|
|
|
};
|
|
|
|
|
|
|
|
VoiceEnginesModel( QWidget * parent, Config::VoiceEngines const & voiceEngines );
|
|
|
|
|
|
|
|
void removeVoiceEngine( int index );
|
|
|
|
void addNewVoiceEngine( QString const & engine_name, QLocale locale, QString const & name, QString const & voice_name, int volume, int rate );
|
|
|
|
|
|
|
|
Config::VoiceEngines const & getCurrentVoiceEngines() const { return voiceEngines; }
|
|
|
|
void setEngineParams( QModelIndex idx, int volume, int rate );
|
|
|
|
|
|
|
|
QModelIndex index( int row, int column, QModelIndex const & parent ) const override;
|
|
|
|
QModelIndex parent( QModelIndex const & parent ) const override;
|
|
|
|
Qt::ItemFlags flags( QModelIndex const & index ) const override;
|
|
|
|
int rowCount( QModelIndex const & parent ) const override;
|
|
|
|
int columnCount( QModelIndex const & parent ) const override;
|
|
|
|
QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
|
|
|
|
QVariant data( QModelIndex const & index, int role ) const override;
|
|
|
|
bool setData( QModelIndex const & index, const QVariant & value, int role ) override;
|
2013-04-24 14:52:04 +00:00
|
|
|
|
|
|
|
private:
|
2022-07-31 01:19:50 +00:00
|
|
|
Config::VoiceEngines voiceEngines;
|
2013-04-24 14:52:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class VoiceEngineEditor: public QComboBox
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2022-07-31 01:19:50 +00:00
|
|
|
VoiceEngineEditor( SpeechClient::Engines const & engines, QWidget * parent = nullptr );
|
2013-04-24 14:52:04 +00:00
|
|
|
|
2022-07-31 01:19:50 +00:00
|
|
|
|
|
|
|
QString engineName() const;
|
2013-04-24 14:52:04 +00:00
|
|
|
QString engineId() const;
|
|
|
|
void setEngineId( QString const & engineId );
|
|
|
|
};
|
|
|
|
|
|
|
|
class VoiceEngineItemDelegate: public QStyledItemDelegate
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2022-07-31 01:19:50 +00:00
|
|
|
public:
|
|
|
|
VoiceEngineItemDelegate( SpeechClient::Engines const & engines, QObject * parent = nullptr );
|
2013-04-24 14:52:04 +00:00
|
|
|
|
2022-07-31 01:19:50 +00:00
|
|
|
QWidget *
|
|
|
|
createEditor( QWidget * parent, QStyleOptionViewItem const & option, QModelIndex const & index ) const override;
|
|
|
|
virtual void setEditorData( QWidget * uncastedEditor, const QModelIndex & index ) const override;
|
|
|
|
virtual void
|
|
|
|
setModelData( QWidget * uncastedEditor, QAbstractItemModel * model, const QModelIndex & index ) const override;
|
2013-04-24 14:52:04 +00:00
|
|
|
|
2022-07-31 01:19:50 +00:00
|
|
|
private:
|
2013-04-24 14:52:04 +00:00
|
|
|
SpeechClient::Engines engines;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TextToSpeechSource: public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
TextToSpeechSource( QWidget * parent, Config::VoiceEngines voiceEngines );
|
|
|
|
|
|
|
|
const VoiceEnginesModel & getVoiceEnginesModel() const
|
|
|
|
{ return voiceEnginesModel; }
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void on_addVoiceEngine_clicked();
|
|
|
|
void on_removeVoiceEngine_clicked();
|
|
|
|
void on_previewVoice_clicked();
|
2013-04-24 16:01:44 +00:00
|
|
|
void previewVoiceFinished();
|
2013-04-26 13:41:39 +00:00
|
|
|
void slidersChanged();
|
|
|
|
void selectionChanged();
|
2013-04-24 14:52:04 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Ui::TextToSpeechSource ui;
|
|
|
|
VoiceEnginesModel voiceEnginesModel;
|
|
|
|
|
2022-07-31 01:19:50 +00:00
|
|
|
std::unique_ptr< SpeechClient > speechClient;
|
|
|
|
|
2023-03-28 12:23:03 +00:00
|
|
|
QSet<QString> occupiedEngines;
|
|
|
|
|
2013-04-24 14:52:04 +00:00
|
|
|
void fitSelectedVoiceEnginesColumns();
|
2013-04-26 13:41:39 +00:00
|
|
|
void adjustSliders();
|
2013-04-24 14:52:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __TEXTTOSPEECHSOURCE_HH_INCLUDED__
|