1 /* This file is (c) 2013 Timon Wong <timon86.wang@gmail.com> 2 * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ 3 4 #ifndef __TEXTTOSPEECHSOURCE_HH_INCLUDED__ 5 #define __TEXTTOSPEECHSOURCE_HH_INCLUDED__ 6 7 #include "ui_texttospeechsource.h" 8 #include "config.hh" 9 #include "speechclient.hh" 10 11 #include <QComboBox> 12 #include <QStyledItemDelegate> 13 14 /// A model to be projected into the text to speech view, according to Qt's MVC model 15 class VoiceEnginesModel: public QAbstractItemModel 16 { 17 Q_OBJECT 18 19 public: 20 21 enum { 22 kColumnEnabled = 0, 23 kColumnEngineId, 24 kColumnEngineName, 25 kColumnIcon, 26 kColumnCount 27 }; 28 29 VoiceEnginesModel( QWidget * parent, Config::VoiceEngines const & voiceEngines ); 30 31 void removeVoiceEngine( int index ); 32 void addNewVoiceEngine( QString const & id, QString const & name, 33 int volume, int rate ); 34 getCurrentVoiceEngines() const35 Config::VoiceEngines const & getCurrentVoiceEngines() const 36 { return voiceEngines; } 37 void setEngineParams( QModelIndex idx, int volume, int rate ); 38 39 QModelIndex index( int row, int column, QModelIndex const & parent ) const; 40 QModelIndex parent( QModelIndex const & parent ) const; 41 Qt::ItemFlags flags( QModelIndex const & index ) const; 42 int rowCount( QModelIndex const & parent ) const; 43 int columnCount( QModelIndex const & parent ) const; 44 QVariant headerData( int section, Qt::Orientation orientation, int role ) const; 45 QVariant data( QModelIndex const & index, int role ) const; 46 bool setData( QModelIndex const & index, const QVariant & value, int role ); 47 48 private: 49 50 Config::VoiceEngines voiceEngines; 51 }; 52 53 class VoiceEngineEditor: public QComboBox 54 { 55 Q_OBJECT 56 57 public: 58 VoiceEngineEditor( SpeechClient::Engines const & engines, QWidget * parent = 0 ); 59 60 public: 61 QString engineName() const; 62 QString engineId() const; 63 void setEngineId( QString const & engineId ); 64 }; 65 66 class VoiceEngineItemDelegate: public QStyledItemDelegate 67 { 68 Q_OBJECT 69 70 public: 71 VoiceEngineItemDelegate( SpeechClient::Engines const & engines, QObject * parent = 0 ); 72 73 virtual QWidget * createEditor( QWidget *parent, 74 QStyleOptionViewItem const & option, 75 QModelIndex const & index ) const; 76 virtual void setEditorData( QWidget *uncastedEditor, const QModelIndex & index ) const; 77 virtual void setModelData( QWidget *uncastedEditor, QAbstractItemModel * model, 78 const QModelIndex & index ) const; 79 80 private: 81 SpeechClient::Engines engines; 82 }; 83 84 class TextToSpeechSource: public QWidget 85 { 86 Q_OBJECT 87 88 public: 89 TextToSpeechSource( QWidget * parent, Config::VoiceEngines voiceEngines ); 90 getVoiceEnginesModel() const91 const VoiceEnginesModel & getVoiceEnginesModel() const 92 { return voiceEnginesModel; } 93 94 private slots: 95 void on_addVoiceEngine_clicked(); 96 void on_removeVoiceEngine_clicked(); 97 void on_previewVoice_clicked(); 98 void previewVoiceFinished(); 99 void slidersChanged(); 100 void selectionChanged(); 101 102 private: 103 Ui::TextToSpeechSource ui; 104 VoiceEnginesModel voiceEnginesModel; 105 106 void fitSelectedVoiceEnginesColumns(); 107 void adjustSliders(); 108 }; 109 110 #endif // __TEXTTOSPEECHSOURCE_HH_INCLUDED__ 111