libosmscout  1.1.1
InstalledVoicesModel.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_CLIENT_QT_INSTALLEDVOICESMODEL_H
2 #define OSMSCOUT_CLIENT_QT_INSTALLEDVOICESMODEL_H
3 
4 /*
5  OSMScout - a Qt backend for libosmscout and libosmscout-map
6  Copyright (C) 2020 Lukas Karas
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22 #include <osmscout/VoiceManager.h>
23 #include <osmscout/Voice.h>
24 #include <osmscout/Settings.h>
26 
27 #include <QAbstractListModel>
28 #include <QList>
29 #include <QMediaPlayer>
30 #include <QMediaPlaylist>
31 
32 namespace osmscout {
33 
42 class OSMSCOUT_CLIENT_QT_API InstalledVoicesModel : public QAbstractListModel {
43  Q_OBJECT
44 
45 signals:
46  void voiceChanged(const QString);
47 
48 public slots:
49  void update();
50  void onVoiceChanged(const QString&);
51 
52 public:
54 
55  virtual ~InstalledVoicesModel();
56 
57  enum Roles {
58  NameRole = Qt::UserRole, // name
59  LangRole = Qt::UserRole + 1, //
60  GenderRole = Qt::UserRole + 2, // male or female (for now :-))
61  ValidRole = Qt::UserRole + 3, // true if it real voice, false when placeholder for no-voice configuration
62  LicenseRole = Qt::UserRole + 4,
63  AuthorRole = Qt::UserRole + 5,
64  DescriptionRole = Qt::UserRole + 6,
65  SelectedRole = Qt::UserRole + 7 // true when this voice is selected
66  };
67  Q_ENUM(Roles)
68 
69  Q_INVOKABLE virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
70  Q_INVOKABLE virtual QVariant data(const QModelIndex &index, int role) const;
71  virtual QHash<int, QByteArray> roleNames() const;
72  Q_INVOKABLE virtual Qt::ItemFlags flags(const QModelIndex &index) const;
73 
74  Q_INVOKABLE void select(const QModelIndex &index);
75  Q_INVOKABLE void playSample(const QModelIndex &index, const QStringList &sample);
76 private:
77  QString voiceDir;
78  QList<Voice> voices;
79  VoiceManagerRef voiceManager;
80  SettingsRef settings;
81 
82  // we setup QObject parents, objects are cleaned after Module destruction
83  QMediaPlaylist *currentPlaylist{nullptr};
84  QMediaPlayer *mediaPlayer{nullptr};
85 };
86 }
87 #endif //OSMSCOUT_CLIENT_QT_INSTALLEDVOICESMODEL_H
std::shared_ptr< Settings > SettingsRef
Definition: Settings.h:171
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
std::shared_ptr< VoiceManager > VoiceManagerRef
Definition: VoiceManager.h:125
Definition: Area.h:38
Roles
Definition: InstalledVoicesModel.h:57
Definition: InstalledVoicesModel.h:42