• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeaccessibility API Reference
  • KDE Home
  • Contact Us
 

jovie

  • sources
  • kde-4.12
  • kdeaccessibility
  • jovie
  • libkttsd
talkerlistmodel.cpp
Go to the documentation of this file.
1 /***************************************************** vim:set ts=4 sw=4 sts=4:
2  Widget for listing Talkers. Based on QTreeView.
3  -------------------
4  Copyright : (C) 2005 by Gary Cramblitt <garycramblitt@comcast.net>
5  Copyright : (C) 2009 by Jeremy Whiting <jpwhiting@kde.org>
6  -------------------
7  Original author: Gary Cramblitt <garycramblitt@comcast.net>
8  Current Maintainer: Jeremy Whiting <jpwhiting@kde.org>
9  ******************************************************************************/
10 
11 /******************************************************************************
12  This program is free software; you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 2 of the License, or
15  (at your option) any later version.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 *******************************************************************************/
26 
27 // TalkerListWidget includes.
28 #include "talkerlistmodel.h"
29 #include "talkerlistmodel.moc"
30 
31 // Qt includes.
32 
33 // KDE includes.
34 #include "klocale.h"
35 #include "kconfig.h"
36 #include "kdebug.h"
37 #include "kconfiggroup.h"
38 
39 // ----------------------------------------------------------------------------
40 
41 enum Columns {
42  kNameColumn = 0,
43  kLanguageColumn,
44  kModuleColumn,
45  kVoiceTypeColumn,
46  kVolumeColumn,
47  kRateColumn,
48  kPitchColumn,
49  kColumnCount
50 };
51 
52 TalkerListModel::TalkerListModel(TalkerCode::TalkerCodeList talkers, QObject *parent) :
53  QAbstractListModel(parent),
54  m_talkerCodes(talkers)
55 {
56 }
57 
58 int TalkerListModel::rowCount(const QModelIndex &parent) const
59 {
60  if (!parent.isValid())
61  return m_talkerCodes.count();
62  else
63  return 0;
64 }
65 
66 int TalkerListModel::columnCount(const QModelIndex &parent) const
67 {
68  Q_UNUSED(parent);
69  return kColumnCount;
70 }
71 
72 QModelIndex TalkerListModel::index(int row, int column, const QModelIndex &parent) const
73 {
74  if (!parent.isValid())
75  return createIndex(row, column, 0);
76  else
77  return QModelIndex();
78 }
79 
80 QModelIndex TalkerListModel::parent(const QModelIndex & index ) const
81 {
82  Q_UNUSED(index);
83  return QModelIndex();
84 }
85 
86 QVariant TalkerListModel::data(const QModelIndex &index, int role) const
87 {
88  if (!index.isValid())
89  return QVariant();
90 
91  if (index.row() < 0 || index.row() >= m_talkerCodes.count())
92  return QVariant();
93 
94  if (index.column() < 0 || index.column() >= kColumnCount)
95  return QVariant();
96 
97  if (role == Qt::DisplayRole)
98  return dataColumn(m_talkerCodes.at(index.row()), index.column());
99  else
100  return QVariant();
101 }
102 
103 QVariant TalkerListModel::dataColumn(const TalkerCode& talkerCode, int column) const
104 {
105  switch (column)
106  {
107  case kNameColumn: return talkerCode.name(); break;
108  case kLanguageColumn: return TalkerCode::languageCodeToLanguage(talkerCode.language()); break;
109  case kModuleColumn: return talkerCode.outputModule(); break;
110  case kVoiceTypeColumn: return TalkerCode::translatedVoiceType(talkerCode.voiceType()); break;
111  case kVolumeColumn: return talkerCode.volume(); break;
112  case kRateColumn: return talkerCode.rate(); break;
113  case kPitchColumn: return talkerCode.pitch(); break;
114  }
115  return QVariant();
116 }
117 
118 Qt::ItemFlags TalkerListModel::flags(const QModelIndex &index) const
119 {
120  if (!index.isValid())
121  return Qt::ItemIsEnabled;
122 
123  return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
124 }
125 
126 QVariant TalkerListModel::headerData(int section, Qt::Orientation orientation, int role) const
127 {
128  if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
129  switch (section)
130  {
131  case kNameColumn: return i18n("Name"); break;
132  case kLanguageColumn: return i18n("Language"); break;
133  case kModuleColumn: return i18n("Synthesizer"); break;
134  case kVoiceTypeColumn: return i18n("Voice Type"); break;
135  case kVolumeColumn: return i18nc("Volume of noise", "Volume"); break;
136  case kRateColumn: return i18n("Speed"); break;
137  case kPitchColumn: return i18n("Pitch"); break;
138  };
139 
140  return QVariant();
141 }
142 
143 bool TalkerListModel::removeRow(int row, const QModelIndex & parent)
144 {
145  beginRemoveRows(parent, row, row);
146  m_talkerCodes.removeAt(row);
147  endRemoveRows();
148  return true;
149 }
150 
151 void TalkerListModel::setDatastore(TalkerCode::TalkerCodeList talkers)
152 {
153  m_talkerCodes = talkers;
154  emit reset();
155 }
156 
157 TalkerCode TalkerListModel::getRow(int row) const
158 {
159  TalkerCode code;
160  if (row < 0 || row >= rowCount())
161  return code;
162  return m_talkerCodes.at(row);
163 }
164 
165 bool TalkerListModel::appendRow(TalkerCode& talker)
166 {
167  beginInsertRows(QModelIndex(), m_talkerCodes.count(), m_talkerCodes.count());
168  m_talkerCodes.append(talker);
169  endInsertRows();
170  return true;
171 }
172 
173 bool TalkerListModel::updateRow(int row, TalkerCode& talker)
174 {
175  m_talkerCodes.replace(row, talker);
176  emit dataChanged(index(row, 0, QModelIndex()), index(row, columnCount()-1, QModelIndex()));
177  return true;
178 }
179 
180 bool TalkerListModel::swap(int i, int j)
181 {
182  m_talkerCodes.swap(i, j);
183  emit dataChanged(index(i, 0, QModelIndex()), index(j, columnCount()-1, QModelIndex()));
184  return true;
185 }
186 
187 void TalkerListModel::clear()
188 {
189  m_talkerCodes.clear();
190  emit reset();
191 }
192 
193 void TalkerListModel::loadTalkerCodesFromConfig(KConfig* c)
194 {
195  // Clear the model and view.
196  clear();
197  // Iterate through list of the TalkerCode IDs.
198  KConfigGroup config(c, "General");
199  QStringList talkerIDsList = config.readEntry("TalkerIDs", QStringList());
200  // kDebug() << "TalkerListModel::loadTalkerCodesFromConfig: talkerIDsList = " << talkerIDsList;
201  if (!talkerIDsList.isEmpty())
202  {
203  QStringList::ConstIterator itEnd = talkerIDsList.constEnd();
204  for (QStringList::ConstIterator it = talkerIDsList.constBegin(); it != itEnd; ++it)
205  {
206  QString talkerID = *it;
207  kDebug() << "TalkerListWidget::loadTalkerCodes: talkerID = " << talkerID;
208  KConfigGroup talkGroup(c, "Talkers");
209  QString talkerCode = talkGroup.readEntry(talkerID);
210  TalkerCode tc(talkerCode, true);
211  kDebug() << "TalkerCodeWidget::loadTalkerCodes: talkerCode = " << talkerCode;
212  //tc.setId(talkerID);
213  appendRow(tc);
214  }
215  }
216 }
TalkerListModel::updateRow
bool updateRow(int row, TalkerCode &talker)
Updates a row of the model/view with information from specified TalkerCode.
Definition: talkerlistmodel.cpp:173
kVoiceTypeColumn
Definition: talkerlistmodel.cpp:45
TalkerCode::language
QString language() const
Definition: talkercode.cpp:119
kNameColumn
Definition: talkerlistmodel.cpp:42
TalkerListModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: talkerlistmodel.cpp:72
TalkerListModel::TalkerListModel
TalkerListModel(TalkerCode::TalkerCodeList talkers=TalkerCode::TalkerCodeList(), QObject *parent=0)
Definition: talkerlistmodel.cpp:52
TalkerCode::TalkerCodeList
QList< TalkerCode > TalkerCodeList
Definition: talkercode.h:61
TalkerListModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: talkerlistmodel.cpp:66
TalkerListModel::swap
bool swap(int i, int j)
Swaps two rows of the model/view.
Definition: talkerlistmodel.cpp:180
QAbstractListModel
TalkerListModel::clear
void clear()
Clears the model/view.
Definition: talkerlistmodel.cpp:187
QObject
TalkerCode::translatedVoiceType
static QString translatedVoiceType(int voiceType)
These functions return translated Talker Code attributes.
Definition: talkercode.cpp:247
TalkerListModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: talkerlistmodel.cpp:58
TalkerCode::volume
int volume() const
Definition: talkercode.cpp:129
TalkerListModel::parent
QModelIndex parent(const QModelIndex &index) const
Definition: talkerlistmodel.cpp:80
TalkerCode::name
QString name() const
Properties.
Definition: talkercode.cpp:114
kColumnCount
Definition: talkerlistmodel.cpp:49
kLanguageColumn
Definition: talkerlistmodel.cpp:43
talkerlistmodel.h
TalkerCode::rate
int rate() const
Definition: talkercode.cpp:134
TalkerCode::languageCodeToLanguage
static QString languageCodeToLanguage(const QString &languageCode)
Converts a language code plus optional country code to language description.
Definition: talkercode.cpp:282
TalkerListModel::appendRow
bool appendRow(TalkerCode &talker)
Adds a new row to the model/view containing the specified TalkerCode.
Definition: talkerlistmodel.cpp:165
TalkerCode
Definition: talkercode.h:38
TalkerListModel::setDatastore
void setDatastore(TalkerCode::TalkerCodeList talkers=TalkerCode::TalkerCodeList())
Definition: talkerlistmodel.cpp:151
TalkerListModel::data
QVariant data(const QModelIndex &index, int role) const
Definition: talkerlistmodel.cpp:86
kVolumeColumn
Definition: talkerlistmodel.cpp:46
Columns
Columns
Definition: talkerlistmodel.cpp:41
TalkerListModel::removeRow
bool removeRow(int row, const QModelIndex &parent=QModelIndex())
Definition: talkerlistmodel.cpp:143
TalkerListModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: talkerlistmodel.cpp:126
kPitchColumn
Definition: talkerlistmodel.cpp:48
TalkerCode::voiceType
int voiceType() const
Definition: talkercode.cpp:124
TalkerCode::outputModule
QString outputModule() const
Definition: talkercode.cpp:149
TalkerListModel::getRow
TalkerCode getRow(int row) const
Returns the TalkerCode for a specified row of the model/view.
Definition: talkerlistmodel.cpp:157
kModuleColumn
Definition: talkerlistmodel.cpp:44
TalkerListModel::loadTalkerCodesFromConfig
void loadTalkerCodesFromConfig(KConfig *config)
Loads the TalkerCodes into the model/view from the config file.
Definition: talkerlistmodel.cpp:193
TalkerCode::pitch
int pitch() const
Definition: talkercode.cpp:139
TalkerListModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const
Definition: talkerlistmodel.cpp:118
kRateColumn
Definition: talkerlistmodel.cpp:47
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:32:25 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

jovie

Skip menu "jovie"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeaccessibility API Reference

Skip menu "kdeaccessibility API Reference"
  • jovie

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal