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

parley

  • sources
  • kde-4.12
  • 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 #include "summarywordwidget.h"
16 
17 #include "languagesettings.h"
18 #include "vocabulary/lessonmodel.h"
19 #include "vocabulary/vocabularymodel.h"
20 #include "vocabulary/vocabularyfilter.h"
21 #include "vocabulary/wordtypemodel.h"
22 
23 // Qt headers
24 #include <QAbstractItemModel>
25 #include <QDataWidgetMapper>
26 #include <QHeaderView>
27 #include <QItemSelection>
28 #include <QLabel>
29 #include <QTreeView>
30 
31 // KDE imports
32 #include <keduvoccontainer.h>
33 #include <keduvocdocument.h>
34 #include <keduvocexpression.h>
35 #include <keduvocwordtype.h>
36 #include <KIcon>
37 #include <KLocale>
38 
39 using namespace Editor;
40 
41 SummaryWordWidget::SummaryWordWidget(VocabularyFilter *model, KEduVocDocument *doc, QWidget *parent)
42 :QWidget(parent)
43 ,m_doc(doc)
44 ,m_wordTypeModel(0)
45 ,m_wordTypeView(0)
46 ,m_entry(0)
47 ,m_translationId(0)
48 {
49  Q_ASSERT(model);
50  Q_ASSERT(m_doc);
51  m_model = model;
52 
53  setupUi(this);
54  slotDocumentChanged(m_doc);
55 
56  m_mapper = new QDataWidgetMapper(this);
57  m_mapper->setModel(model);
58  m_mapper->setItemDelegate(new SummaryWordDelegate(this));
59 
60  connect(wordTypeComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(wordTypeSelected(QString)));
61 }
62 
63 void SummaryWordWidget::setTranslation(KEduVocExpression *entry, int translation)
64 {
65  if (entry) {
66  // we need to map the widgets relative to the translation (each translation has 9 columns)
67  m_mapper->clearMapping();
68 
69  m_mapper->addMapping(wordEntry,
70  VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::Translation);
71  //m_mapper->addMapping(wordTypeComboBox,
72  // VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::WordType);
73  m_mapper->addMapping(pronunciationEntry,
74  VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::Pronunciation);
75  m_mapper->addMapping(exampleEntry,
76  VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::Example);
77  m_mapper->addMapping(paraphraseEntry,
78  VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::Paraphrase);
79  m_mapper->addMapping(commentEntry,
80  VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::Comment);
81 
82  languageLabel->setText("<b>" + m_doc->identifier(translation).name() + "</b>");
83  lessonLabel->setText(entry->lesson()->name());
84 
85  setCurrentWordType(entry, translation);
86  } else {
87  clear();
88  }
89 
90  m_entry = entry;
91  m_translationId = translation;
92 }
93 
94 void SummaryWordWidget::slotDocumentChanged(KEduVocDocument *doc)
95 {
96  m_doc = doc;
97  if (!m_doc) {
98  kDebug() << "Set invalid document";
99  delete m_wordTypeModel;
100  m_wordTypeModel = 0;
101  } else {
102  delete m_wordTypeView;
103  if (!m_wordTypeModel) {
104  kDebug() << "Create word type model for summary view";
105  m_wordTypeModel = new WordTypeModel(this);
106  }
107  m_wordTypeModel->setDocument(m_doc);
108  m_wordTypeView = new QTreeView(this);
109  m_wordTypeView->setModel(m_wordTypeModel);
110  wordTypeComboBox->setModel(m_wordTypeModel);
111  wordTypeComboBox->setView(m_wordTypeView);
112 
113  m_wordTypeView->setColumnHidden(1, true);
114  m_wordTypeView->header()->setVisible(false);
115  m_wordTypeView->setRootIsDecorated(true);
116  m_wordTypeView->expandAll();
117  }
118 }
119 
120 
121 void SummaryWordWidget::slotSelectionChanged(const QItemSelection &itemSelected,
122  const QItemSelection &itemDeselected)
123 {
124  Q_UNUSED(itemDeselected)
125 
126  if (itemSelected.indexes().size() >= 1) {
127  // the selected index belongs to VocabularyFilter, when we need it from the vocabulary model
128  QModelIndex index = m_model->index(itemSelected.indexes().at(0).row(),
129  itemSelected.indexes().at(0).column());
130  m_mapper->setCurrentModelIndex(index);
131  }
132 }
133 
134 /*
135 void SummaryWordWidget::populateLessonList(KEduVocExpression *entry)
136 {
137  lessonComboBox->clear();
138 
139  LessonModel *basicLessonModel = new LessonModel(this);
140  lessonComboBox->setModel(basicLessonModel);
141  QTreeView *view = new QTreeView(this);
142 
143  view->setModel(basicLessonModel);
144  lessonComboBox->setView(view);
145 
146  basicLessonModel->setDocument(m_doc);
147 
148  view->header()->setVisible(false);
149  view->setRootIsDecorated(true);
150  view->expandAll();
151 
152  view->setCurrentIndex(basicLessonModel->index(entry->lesson()));
153 }
154 */
155 
156 void SummaryWordWidget::setCurrentWordType(KEduVocExpression *entry, int translation)
157 {
158  if (entry && entry->translation(translation)->wordType()) {
159  kDebug() << "Set current word type: " << entry->translation(translation)->wordType()->name();
160  // select the right word type
161  m_wordTypeView->setCurrentIndex(m_wordTypeModel->index(entry->translation(translation)->wordType()));
162  } else {
163  wordTypeComboBox->setCurrentIndex(-1);
164  }
165 }
166 
167 void SummaryWordWidget::clear()
168 {
169  kDebug() << "Clear summary widget";
170 
171  languageLabel->setText(QString());
172  wordEntry->setText(QString());
173 
174  // lessonComboBox->clear();
175  lessonLabel->setText(QString());
176 
177  pronunciationEntry->setText(QString());
178  exampleEntry->setText(QString());
179  paraphraseEntry->setText(QString());
180  commentEntry->setText(QString());
181 }
182 
183 SummaryWordDelegate::SummaryWordDelegate(QObject *parent) : QItemDelegate(parent)
184 {
185 }
186 
187 void SummaryWordDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
188 {
189  if (!index.isValid()) {
190  return;
191  }
192 
193  if (editor) {
194  switch (VocabularyModel::columnType(index.column())) {
195  case VocabularyModel::WordType:
196  break;
197 
198  case VocabularyModel::Comment:
199  case VocabularyModel::Pronunciation:
200  case VocabularyModel::Translation:
201  case VocabularyModel::Example:
202  case VocabularyModel::Paraphrase:
203 
204  KLineEdit *entry = static_cast <KLineEdit *> (editor);
205  if (entry) {
206  entry->setText(index.model()->data(index).toString());
207  }
208  break;
209  }
210  }
211 }
212 
213 void SummaryWordWidget::wordTypeSelected(const QString& wordTypeName)
214 {
215  if (!m_doc || !m_entry) {
216  return;
217  }
218 
219  KEduVocContainer* container = m_doc->wordTypeContainer()->childContainer(wordTypeName);
220  if (container) {
221  KEduVocWordType *wordType = static_cast<KEduVocWordType*>(container);
222  if (wordType) {
223  m_entry->translation(m_translationId)->setWordType(wordType);
224  }
225  }
226 }
227 
228 
229 #include "summarywordwidget.moc"
230 
languagesettings.h
QWidget
Editor::SummaryWordWidget::wordTypeSelected
void wordTypeSelected(const QString &wordTypeName)
Definition: summarywordwidget.cpp:213
QObject
Editor::VocabularyModel::Example
Definition: vocabularymodel.h:40
Editor::SummaryWordWidget::SummaryWordWidget
SummaryWordWidget(VocabularyFilter *model, KEduVocDocument *doc, QWidget *parent=0)
Definition: summarywordwidget.cpp:41
Editor::VocabularyFilter
Definition: vocabularyfilter.h:27
QTreeView
Editor::VocabularyModel::Pronunciation
Definition: vocabularymodel.h:36
Editor::VocabularyModel::columnType
static int columnType(int column)
Returns the type of the column specified.
Definition: vocabularymodel.cpp:318
Editor::VocabularyModel::EntryColumnsMAX
Definition: vocabularymodel.h:45
summarywordwidget.h
Editor::VocabularyModel::WordType
Definition: vocabularymodel.h:37
Editor::SummaryWordWidget::setTranslation
void setTranslation(KEduVocExpression *entry, int translation)
Sets the selected word (KEduVocExpression) from the vocabularyView.
Definition: summarywordwidget.cpp:63
Editor::SummaryWordDelegate
Definition: summarywordwidget.h:96
lessonmodel.h
Editor::SummaryWordDelegate::SummaryWordDelegate
SummaryWordDelegate(QObject *parent=0)
Definition: summarywordwidget.cpp:183
QItemDelegate
wordtypemodel.h
Editor::BasicContainerModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: basiccontainermodel.cpp:55
Editor::VocabularyModel::Translation
Definition: vocabularymodel.h:35
Editor::SummaryWordDelegate::setEditorData
void setEditorData(QWidget *editor, const QModelIndex &index) const
Definition: summarywordwidget.cpp:187
Editor::VocabularyModel::Paraphrase
Definition: vocabularymodel.h:42
Editor::SummaryWordWidget::slotDocumentChanged
void slotDocumentChanged(KEduVocDocument *doc)
Called when a KEduVocDocument change happened.
Definition: summarywordwidget.cpp:94
Editor::BasicContainerModel::setDocument
void setDocument(KEduVocDocument *doc)
Set the new source kvtml file.
Definition: basiccontainermodel.cpp:44
Editor::SummaryWordWidget::slotSelectionChanged
void slotSelectionChanged(const QItemSelection &, const QItemSelection &)
Called when the selection changed in the vocabulary view.
Definition: summarywordwidget.cpp:121
vocabularyfilter.h
Editor::WordTypeModel
Model for the tree of word types.
Definition: wordtypemodel.h:25
Editor::VocabularyModel::Comment
Definition: vocabularymodel.h:41
vocabularymodel.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:06 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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