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

parley

  • sources
  • kde-4.14
  • kdeedu
  • parley
  • src
  • editor
summarywordwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  Copyright 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
4  Copyright 2008 Javier Goday <jgoday@gmail.com>
5  ***************************************************************************/
6 
7 /***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "summarywordwidget.h"
17 
18 #include "languagesettings.h"
19 
20 #include "lessonmodel.h"
21 #include "vocabularymodel.h"
22 #include "vocabularyfilter.h"
23 #include "wordclassmodel.h"
24 
25 // Qt headers
26 #include <QAbstractItemModel>
27 #include <QDataWidgetMapper>
28 #include <QHeaderView>
29 #include <QItemSelection>
30 #include <QLabel>
31 #include <QTreeView>
32 
33 // KDE imports
34 #include <KIcon>
35 #include <KLocale>
36 
37 // KEduVocDocument
38 #include <keduvoccontainer.h>
39 #include <keduvocdocument.h>
40 #include <keduvocexpression.h>
41 #include <keduvocwordtype.h>
42 
43 using namespace Editor;
44 
45 
46 SummaryWordWidget::SummaryWordWidget(VocabularyFilter *model, KEduVocDocument *doc, QWidget *parent)
47  : QWidget(parent)
48  , m_doc(doc)
49  , m_wordTypeModel(0)
50  , m_wordTypeView(0)
51  , m_entry(0)
52  , m_translationId(0)
53 {
54  Q_ASSERT(model);
55  Q_ASSERT(m_doc);
56  m_model = model;
57 
58  setupUi(this);
59  slotDocumentChanged(m_doc);
60 
61  m_mapper = new QDataWidgetMapper(this);
62  m_mapper->setModel(model);
63  m_mapper->setItemDelegate(new SummaryWordDelegate(this));
64 
65  connect(wordTypeComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(wordTypeSelected(QString)));
66 }
67 
68 void SummaryWordWidget::setTranslation(KEduVocExpression *entry, int translation)
69 {
70  if (entry) {
71  // we need to map the widgets relative to the translation (each translation has 9 columns)
72  m_mapper->clearMapping();
73 
74  m_mapper->addMapping(wordEntry,
75  VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::Translation);
76  //m_mapper->addMapping(wordTypeComboBox,
77  // VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::WordType);
78  m_mapper->addMapping(pronunciationEntry,
79  VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::Pronunciation);
80  m_mapper->addMapping(exampleEntry,
81  VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::Example);
82  m_mapper->addMapping(paraphraseEntry,
83  VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::Paraphrase);
84  m_mapper->addMapping(commentEntry,
85  VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::Comment);
86 
87  languageLabel->setText("<b>" + m_doc->identifier(translation).name() + "</b>");
88  lessonLabel->setText(entry->lesson()->name());
89 
90  setCurrentWordType(entry, translation);
91  } else {
92  clear();
93  }
94 
95  m_entry = entry;
96  m_translationId = translation;
97 }
98 
99 void SummaryWordWidget::slotDocumentChanged(KEduVocDocument *doc)
100 {
101  m_doc = doc;
102  if (!m_doc) {
103  kDebug() << "Set invalid document";
104  delete m_wordTypeModel;
105  m_wordTypeModel = 0;
106  } else {
107  delete m_wordTypeView;
108  if (!m_wordTypeModel) {
109  kDebug() << "Create word type model for summary view";
110  m_wordTypeModel = new WordClassModel(this);
111  }
112  m_wordTypeModel->setDocument(m_doc);
113  m_wordTypeView = new QTreeView(this);
114  m_wordTypeView->setModel(m_wordTypeModel);
115  wordTypeComboBox->setModel(m_wordTypeModel);
116  wordTypeComboBox->setView(m_wordTypeView);
117 
118  m_wordTypeView->setColumnHidden(1, true);
119  m_wordTypeView->header()->setVisible(false);
120  m_wordTypeView->setRootIsDecorated(true);
121  m_wordTypeView->expandAll();
122  }
123 }
124 
125 
126 void SummaryWordWidget::slotSelectionChanged(const QItemSelection &itemSelected,
127  const QItemSelection &itemDeselected)
128 {
129  Q_UNUSED(itemDeselected)
130 
131  if (itemSelected.indexes().size() >= 1) {
132  // the selected index belongs to VocabularyFilter, when we need it from the vocabulary model
133  QModelIndex index = m_model->index(itemSelected.indexes().at(0).row(),
134  itemSelected.indexes().at(0).column());
135  m_mapper->setCurrentModelIndex(index);
136  }
137 }
138 
139 /*
140 void SummaryWordWidget::populateLessonList(KEduVocExpression *entry)
141 {
142  lessonComboBox->clear();
143 
144  LessonModel *basicLessonModel = new LessonModel(this);
145  lessonComboBox->setModel(basicLessonModel);
146  QTreeView *view = new QTreeView(this);
147 
148  view->setModel(basicLessonModel);
149  lessonComboBox->setView(view);
150 
151  basicLessonModel->setDocument(m_doc);
152 
153  view->header()->setVisible(false);
154  view->setRootIsDecorated(true);
155  view->expandAll();
156 
157  view->setCurrentIndex(basicLessonModel->index(entry->lesson()));
158 }
159 */
160 
161 void SummaryWordWidget::setCurrentWordType(KEduVocExpression *entry, int translation)
162 {
163  if (entry && entry->translation(translation)->wordType()) {
164  kDebug() << "Set current word type: " << entry->translation(translation)->wordType()->name();
165  // select the right word type
166  m_wordTypeView->setCurrentIndex(m_wordTypeModel->index(entry->translation(translation)->wordType()));
167  } else {
168  wordTypeComboBox->setCurrentIndex(-1);
169  }
170 }
171 
172 void SummaryWordWidget::clear()
173 {
174  kDebug() << "Clear summary widget";
175 
176  languageLabel->setText(QString());
177  wordEntry->setText(QString());
178 
179  // lessonComboBox->clear();
180  lessonLabel->setText(QString());
181 
182  pronunciationEntry->setText(QString());
183  exampleEntry->setText(QString());
184  paraphraseEntry->setText(QString());
185  commentEntry->setText(QString());
186 }
187 
188 SummaryWordDelegate::SummaryWordDelegate(QObject *parent) : QItemDelegate(parent)
189 {
190 }
191 
192 void SummaryWordDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
193 {
194  if (!index.isValid()) {
195  return;
196  }
197 
198  if (editor) {
199  switch (VocabularyModel::columnType(index.column())) {
200  case VocabularyModel::WordClass:
201  break;
202 
203  case VocabularyModel::Comment:
204  case VocabularyModel::Pronunciation:
205  case VocabularyModel::Translation:
206  case VocabularyModel::Example:
207  case VocabularyModel::Paraphrase:
208 
209  KLineEdit *entry = static_cast <KLineEdit *>(editor);
210  if (entry) {
211  entry->setText(index.model()->data(index).toString());
212  }
213  break;
214  }
215  }
216 }
217 
218 void SummaryWordWidget::wordTypeSelected(const QString& wordTypeName)
219 {
220  if (!m_doc || !m_entry) {
221  return;
222  }
223 
224  KEduVocContainer* container = m_doc->wordTypeContainer()->childContainer(wordTypeName);
225  if (container) {
226  KEduVocWordType *wordType = static_cast<KEduVocWordType*>(container);
227  if (wordType) {
228  m_entry->translation(m_translationId)->setWordType(wordType);
229  }
230  }
231 }
232 
233 
234 #include "summarywordwidget.moc"
235 
QSortFilterProxyModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
QItemSelection::indexes
QModelIndexList indexes() const
QModelIndex
QWidget
QWidget::setupUi
void setupUi(QWidget *widget)
QAbstractItemView::setCurrentIndex
void setCurrentIndex(const QModelIndex &index)
languagesettings.h
WordClassModel
Model for the tree of word types.
Definition: wordclassmodel.h:24
VocabularyFilter
Definition: vocabularyfilter.h:26
VocabularyModel::WordClass
Definition: vocabularymodel.h:36
VocabularyModel::Translation
Definition: vocabularymodel.h:34
Editor::SummaryWordWidget::wordTypeSelected
void wordTypeSelected(const QString &wordTypeName)
Definition: summarywordwidget.cpp:218
ReadonlyContainerModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: readonlycontainermodel.cpp:49
QWidget::setVisible
virtual void setVisible(bool visible)
Editor::SummaryWordWidget::SummaryWordWidget
SummaryWordWidget(VocabularyFilter *model, KEduVocDocument *doc, QWidget *parent=0)
Definition: summarywordwidget.cpp:46
VocabularyModel::Comment
Definition: vocabularymodel.h:40
QModelIndex::isValid
bool isValid() const
VocabularyModel::Pronunciation
Definition: vocabularymodel.h:35
VocabularyModel::columnType
static int columnType(int column)
Returns the type of the column specified.
Definition: vocabularymodel.cpp:315
QObject
QDataWidgetMapper
QItemDelegate
QAbstractItemModel::data
virtual QVariant data(const QModelIndex &index, int role) const =0
QDataWidgetMapper::clearMapping
void clearMapping()
QString
summarywordwidget.h
QDataWidgetMapper::setItemDelegate
void setItemDelegate(QAbstractItemDelegate *delegate)
VocabularyModel::Example
Definition: vocabularymodel.h:39
wordclassmodel.h
VocabularyModel::Paraphrase
Definition: vocabularymodel.h:41
QTreeView::setColumnHidden
void setColumnHidden(int column, bool hide)
Editor::SummaryWordWidget::setTranslation
void setTranslation(KEduVocExpression *entry, int translation)
Sets the selected word (KEduVocExpression) from the vocabularyView.
Definition: summarywordwidget.cpp:68
Editor::SummaryWordDelegate
Definition: summarywordwidget.h:98
QTreeView::expandAll
void expandAll()
lessonmodel.h
QItemSelection
Editor::SummaryWordDelegate::SummaryWordDelegate
SummaryWordDelegate(QObject *parent=0)
Definition: summarywordwidget.cpp:188
QDataWidgetMapper::addMapping
void addMapping(QWidget *widget, int section)
QModelIndex::model
const QAbstractItemModel * model() const
QDataWidgetMapper::setModel
void setModel(QAbstractItemModel *model)
QTreeView
QDataWidgetMapper::setCurrentModelIndex
void setCurrentModelIndex(const QModelIndex &index)
QTreeView::setModel
virtual void setModel(QAbstractItemModel *model)
ReadonlyContainerModel::setDocument
void setDocument(KEduVocDocument *doc)
Set the new source kvtml file.
Definition: readonlycontainermodel.cpp:43
QModelIndex::column
int column() const
Editor::SummaryWordDelegate::setEditorData
void setEditorData(QWidget *editor, const QModelIndex &index) const
Definition: summarywordwidget.cpp:192
QTreeView::header
QHeaderView * header() const
VocabularyModel::EntryColumnsMAX
Definition: vocabularymodel.h:44
Editor::SummaryWordWidget::slotDocumentChanged
void slotDocumentChanged(KEduVocDocument *doc)
Called when a KEduVocDocument change happened.
Definition: summarywordwidget.cpp:99
QTreeView::setRootIsDecorated
void setRootIsDecorated(bool show)
Editor::SummaryWordWidget::slotSelectionChanged
void slotSelectionChanged(const QItemSelection &, const QItemSelection &)
Called when the selection changed in the vocabulary view.
Definition: summarywordwidget.cpp:126
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
vocabularyfilter.h
QVariant::toString
QString toString() const
vocabularymodel.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:15:56 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

parley

Skip menu "parley"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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