• 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
lessonview.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  Copyright 2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
4 
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 "lessonview.h"
17 
18 #include <KAction>
19 #include <KActionCollection>
20 #include <KInputDialog>
21 #include <KLocalizedString>
22 #include <KMessageBox>
23 
24 #include <keduvocexpression.h>
25 #include <keduvoclesson.h>
26 
27 #include "editor/editor.h"
28 #include "lessonmodel.h"
29 #include "prefs.h"
30 
31 using namespace Editor;
32 
33 LessonView::LessonView(EditorWindow * parent) : ContainerView(parent)
34 {
35  KAction *actionNewLesson = new KAction(this);
36  parent->actionCollection()->addAction("new_lesson", actionNewLesson);
37  actionNewLesson->setText(i18n("New Unit"));
38  actionNewLesson->setIcon(KIcon("lesson-add"));
39  actionNewLesson->setWhatsThis(i18n("Add a new unit to your document"));
40  actionNewLesson->setToolTip(actionNewLesson->whatsThis());
41  actionNewLesson->setStatusTip(actionNewLesson->whatsThis());
42 
43  KAction *actionRenameLesson = new KAction(this);
44  parent->actionCollection()->addAction("rename_lesson", actionRenameLesson);
45  actionRenameLesson->setText(i18n("Rename Unit"));
46  actionRenameLesson->setIcon(KIcon("edit-rename"));
47 // actionRenameLesson->setWhatsThis(i18n("Rename the selected unit"));
48  actionRenameLesson->setToolTip(actionRenameLesson->whatsThis());
49  actionRenameLesson->setStatusTip(actionRenameLesson->whatsThis());
50 
51  KAction *actionDeleteLesson = new KAction(this);
52  parent->actionCollection()->addAction("delete_lesson", actionDeleteLesson);
53  actionDeleteLesson->setText(i18n("Delete Unit"));
54  actionDeleteLesson->setIcon(KIcon("lesson-remove"));
55  actionDeleteLesson->setWhatsThis(i18n("Delete the selected unit."));
56  actionDeleteLesson->setToolTip(actionDeleteLesson->whatsThis());
57  actionDeleteLesson->setStatusTip(actionDeleteLesson->whatsThis());
58 
59  KAction *actionSplitLesson = new KAction(this);
60  parent->actionCollection()->addAction("split_lesson", actionSplitLesson);
61  actionSplitLesson->setText(i18n("Split Unit into Smaller Units"));
62  actionSplitLesson->setIcon(KIcon("edit-copy"));
63  actionSplitLesson->setWhatsThis(i18n("Make multiple smaller units out of one big unit."));
64  actionSplitLesson->setToolTip(actionSplitLesson->whatsThis());
65  actionSplitLesson->setStatusTip(actionSplitLesson->whatsThis());
66 
67  KAction *actionRemoveGradesLesson = new KAction(this);
68  parent->actionCollection()->addAction("remove_grades_lesson", actionRemoveGradesLesson);
69  actionRemoveGradesLesson->setText(i18n("Remove Confidence Levels"));
70  actionRemoveGradesLesson->setIcon(KIcon("edit-clear"));
71  actionRemoveGradesLesson->setWhatsThis(i18n("Remove confidence levels from this unit."));
72  actionRemoveGradesLesson->setToolTip(actionRemoveGradesLesson->whatsThis());
73  actionRemoveGradesLesson->setStatusTip(actionRemoveGradesLesson->whatsThis());
74 
75  KAction *actionRemoveGradesLessonChildren = new KAction(this);
76  parent->actionCollection()->addAction("remove_grades_lesson_children", actionRemoveGradesLessonChildren);
77  actionRemoveGradesLessonChildren->setText(i18n("Remove Confidence Levels From This Unit And All Subunits"));
78  actionRemoveGradesLessonChildren->setIcon(KIcon("edit-clear"));
79  actionRemoveGradesLessonChildren->setWhatsThis(i18n("Remove confidence levels from this unit and all subunits."));
80  actionRemoveGradesLessonChildren->setToolTip(actionRemoveGradesLessonChildren->whatsThis());
81  actionRemoveGradesLessonChildren->setStatusTip(actionRemoveGradesLessonChildren->whatsThis());
82 
83  KAction *actionExpandAll = new KAction(this);
84  parent->actionCollection()->addAction("expand_all_lesson_children", actionExpandAll);
85  actionExpandAll->setText(i18n("Expand Units and Subunits"));
86  actionExpandAll->setIcon(KIcon("go-down-search"));
87  actionExpandAll->setWhatsThis(i18n("Expand all units and subunits."));
88  actionExpandAll->setToolTip(actionExpandAll->whatsThis());
89  actionExpandAll->setStatusTip(actionExpandAll->whatsThis());
90 
91  KAction *actionCollapseAll = new KAction(this);
92  parent->actionCollection()->addAction("collapse_all_lesson_children", actionExpandAll);
93  actionCollapseAll->setText(i18n("Collapse All Units And Subunits"));
94  actionCollapseAll->setIcon(KIcon("go-up-search"));
95  actionCollapseAll->setWhatsThis(i18n("Collapse all units and subunits."));
96  actionCollapseAll->setToolTip(actionCollapseAll->whatsThis());
97  actionCollapseAll->setStatusTip(actionCollapseAll->whatsThis());
98 
99  connect(actionNewLesson, SIGNAL(triggered()),
100  SLOT(slotCreateNewLesson()));
101  connect(actionRenameLesson, SIGNAL(triggered()),
102  SLOT(slotRename()));
103  connect(actionDeleteLesson, SIGNAL(triggered()),
104  SLOT(slotDeleteLesson()));
105  connect(actionSplitLesson, SIGNAL(triggered()),
106  SLOT(slotSplitLesson()));
107  connect(actionRemoveGradesLesson, SIGNAL(triggered()),
108  SLOT(slotRemoveGradesLesson()));
109  connect(actionRemoveGradesLessonChildren, SIGNAL(triggered()),
110  SLOT(slotRemoveGradesLessonChildren()));
111  connect(actionExpandAll, SIGNAL(triggered()),
112  SLOT(expandAllLesson()));
113  connect(actionCollapseAll, SIGNAL(triggered()),
114  SLOT(collapseAllLesson()));
115 
116  // right cick menu for the lesson view:
117  addAction(actionNewLesson);
118  addAction(actionRenameLesson);
119  addAction(actionDeleteLesson);
120  QAction* separator = new QAction(this);
121  separator->setSeparator(true);
122  addAction(separator);
123  addAction(actionRemoveGradesLesson);
124  addAction(actionRemoveGradesLessonChildren);
125  separator = new QAction(this);
126  separator->setSeparator(true);
127  addAction(separator);
128  addAction(actionSplitLesson);
129  addAction(actionExpandAll);
130  addAction(actionCollapseAll);
131 }
132 
133 void LessonView::currentChanged(const QModelIndex & current, const QModelIndex & previous)
134 {
135  QTreeView::currentChanged(current, previous);
136 
137  if (current.isValid()) {
138  KEduVocLesson *container = static_cast<KEduVocLesson*>(current.internalPointer());
139  if (container) {
140  emit selectedLessonChanged(container);
141  emit signalShowContainer(container);
142  }
143  }
144 }
145 
146 void LessonView::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
147 {
148  QTreeView::selectionChanged(selected, deselected);
149 
150  if (selected.count() == 0) {
151  return;
152  }
153 
154  KEduVocLesson *container = static_cast<KEduVocLesson*>(selected.indexes().value(0).internalPointer());
155  if (container) {
156  emit selectedLessonChanged(container);
157  }
158 }
159 
160 void LessonView::setTranslation(KEduVocExpression * entry, int translation)
161 {
162  Q_UNUSED(translation)
163 
164  if (entry == 0) {
165  selectionModel()->clearSelection();
166  return;
167  }
168 
169  QModelIndex index(m_model->index(entry->lesson()));
170  selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
171  scrollTo(index);
172 }
173 
174 void LessonView::slotCreateNewLesson()
175 {
176  QModelIndex selectedIndex = selectionModel()->currentIndex();
177 
178  if (!selectedIndex.isValid()) {
179  selectedIndex = m_model->index(0, 0, QModelIndex());
180  }
181 
182  QModelIndex modelIndex = m_model->appendContainer(selectedIndex);
183 
184  scrollTo(modelIndex);
185  selectionModel()->setCurrentIndex(modelIndex, QItemSelectionModel::ClearAndSelect);
186  edit(modelIndex); // let the user type a new name for the lesson
187 }
188 
189 void LessonView::slotDeleteLesson()
190 {
191  QModelIndex selectedIndex = selectionModel()->currentIndex();
192 
193  if (selectedIndex.parent() == QModelIndex()) {
194  KMessageBox::information(this, i18n("The root lesson cannot be deleted."));
195  return;
196  }
197 
198  KEduVocLesson* lesson = static_cast<KEduVocLesson*>(selectedIndex.internalPointer());
199 
200  int count = lesson->entryCount(KEduVocLesson::Recursive);
201 
202  if (count == 0 ||
203  KMessageBox::warningYesNo(this, i18np("There is %1 word left in this unit. Do you want to delete it?", "There are %1 words left in this unit. Do you want to delete them?", count)) == KMessageBox::Yes) {
204  m_model->deleteContainer(selectedIndex);
205  }
206 }
207 
208 void LessonView::slotSplitLesson()
209 {
210  if (!selectionModel()->currentIndex().isValid()) {
211  return;
212  }
213 
216  bool ok = false;
217  int numEntries = KInputDialog::getInteger(i18n("Entries per Unit"), i18n("The unit will be split into smaller unit. How many entries in each unit do you want?"), Prefs::entriesPerLesson(), 1, 1000, 1, &ok, this);
218  if (!ok) {
219  return;
220  }
221  Prefs::setEntriesPerLesson(numEntries);
222  m_model->splitLesson(selectionModel()->currentIndex(), numEntries, LessonModel::Random);
223  setExpanded(selectionModel()->currentIndex(), true);
224 }
225 
226 void LessonView::slotRemoveGradesLesson()
227 {
228  QModelIndex selectedIndex = selectionModel()->currentIndex();
229  KEduVocLesson* lesson = static_cast<KEduVocLesson*>(selectedIndex.internalPointer());
230  lesson->resetGrades(-1, KEduVocContainer::NotRecursive);
231  emit signalShowContainer(lesson);
232 }
233 
234 void LessonView::slotRemoveGradesLessonChildren()
235 {
236  QModelIndex selectedIndex = selectionModel()->currentIndex();
237  KEduVocLesson* lesson = static_cast<KEduVocLesson*>(selectedIndex.internalPointer());
238  lesson->resetGrades(-1, KEduVocContainer::Recursive);
239  emit signalShowContainer(lesson);
240 }
241 
242 void LessonView::setModel(LessonModel * model)
243 {
244  m_model = model;
245  ContainerView::setModel(model);
246  connect(model, SIGNAL(columnsInserted(const QModelIndex &, int, int)), this, SLOT(columnsInserted()));
247  for (int i = 2; i < model->columnCount(QModelIndex()); i++) {
248  setColumnHidden(i, true);
249  }
250 }
251 
252 void LessonView::columnsInserted()
253 {
254  for (int i = 2; i < m_model->columnCount(QModelIndex()); i++) {
255  setColumnHidden(i, true);
256  }
257 }
258 
259 void LessonView::expandAllLesson()
260 {
261  expandAll();
262 }
263 
264 void LessonView::collapseAllLesson()
265 {
266  collapseAll();
267 }
268 
269 #include "lessonview.moc"
270 
271 
QItemSelection::indexes
QModelIndexList indexes() const
Editor::LessonView::setTranslation
void setTranslation(KEduVocExpression *entry, int translationId)
Definition: lessonview.cpp:160
Editor::LessonView::slotRemoveGradesLessonChildren
void slotRemoveGradesLessonChildren()
Remove the grades for the selected lesson and its children.
Definition: lessonview.cpp:234
QModelIndex
Editor::LessonView::LessonView
LessonView(EditorWindow *parent)
Definition: lessonview.cpp:33
Editor::LessonView::columnsInserted
void columnsInserted()
get notified of new columns only to hide them (grades not shown by default).
Definition: lessonview.cpp:252
lessonview.h
QAction::setSeparator
void setSeparator(bool b)
QItemSelectionModel::currentIndex
QModelIndex currentIndex() const
QAbstractItemView::selectionModel
QItemSelectionModel * selectionModel() const
QWidget::addAction
void addAction(QAction *action)
QTreeView::currentChanged
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous)
Prefs::setEntriesPerLesson
static void setEntriesPerLesson(int v)
Set The number of entries per unit.
Definition: prefs.h:117
QTreeView::collapseAll
void collapseAll()
ReadonlyContainerModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: readonlycontainermodel.cpp:49
ContainerView
View for containers (KEduVocContainer).
Definition: containerview.h:31
prefs.h
Editor::LessonView::expandAllLesson
void expandAllLesson()
Expand all the lessons and its corresponding sub-lessons.
Definition: lessonview.cpp:259
Editor::LessonView::selectedLessonChanged
void selectedLessonChanged(KEduVocLesson *lesson)
A lesson was selected.
ContainerView::slotRename
void slotRename()
let the user type a new name for the container
Definition: containerview.cpp:51
ContainerView::setModel
virtual void setModel(ContainerModel *model)
Set the model for the view.
Definition: containerview.cpp:42
LessonModel
Model for the tree of lessons.
Definition: lessonmodel.h:24
Editor::LessonView::slotCreateNewLesson
void slotCreateNewLesson()
Append a lesson to the model and automatically set an edit up so the user can change "New unit" into ...
Definition: lessonview.cpp:174
Editor::LessonView::slotDeleteLesson
void slotDeleteLesson()
Remove a lesson.
Definition: lessonview.cpp:189
editor.h
QTreeView::setExpanded
void setExpanded(const QModelIndex &index, bool expanded)
Editor::LessonView::setModel
virtual void setModel(LessonModel *model)
Set the model for the view.
Definition: lessonview.cpp:242
QModelIndex::isValid
bool isValid() const
QList::count
int count(const T &value) const
Editor::LessonView::collapseAllLesson
void collapseAllLesson()
Collapse all the lessons and its corresponding sub-lessons.
Definition: lessonview.cpp:264
QItemSelectionModel::select
virtual void select(const QModelIndex &index, QFlags< QItemSelectionModel::SelectionFlag > command)
LessonModel::splitLesson
void splitLesson(const QModelIndex &containerIndex, int entriesPerLesson, SplitLessonOrder order)
Divide a lesson into smaller ones.
Definition: lessonmodel.cpp:83
QModelIndex::internalPointer
void * internalPointer() const
QItemSelectionModel::clearSelection
void clearSelection()
QModelIndex::parent
QModelIndex parent() const
QTreeView::setColumnHidden
void setColumnHidden(int column, bool hide)
ContainerModel::appendContainer
QModelIndex appendContainer(const QModelIndex &parent, const QString &containerName=QString())
Definition: containermodel.cpp:43
Prefs::entriesPerLesson
static int entriesPerLesson()
Get The number of entries per unit.
Definition: prefs.h:127
QTreeView::scrollTo
virtual void scrollTo(const QModelIndex &index, ScrollHint hint)
QTreeView::expandAll
void expandAll()
LessonModel::Random
Randomized.
Definition: lessonmodel.h:32
lessonmodel.h
QItemSelection
QTreeView::selectionChanged
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
QAction
ContainerModel::columnCount
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: containermodel.cpp:187
Editor::EditorWindow
Definition: editor.h:50
Editor::LessonView::selectionChanged
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
Definition: lessonview.cpp:146
Editor::LessonView::slotRemoveGradesLesson
void slotRemoveGradesLesson()
Remove the grades for the selected lesson.
Definition: lessonview.cpp:226
ContainerModel::deleteContainer
void deleteContainer(const QModelIndex &containerIndex)
Definition: containermodel.cpp:199
QAbstractItemView::edit
void edit(const QModelIndex &index)
QItemSelectionModel::setCurrentIndex
void setCurrentIndex(const QModelIndex &index, QFlags< QItemSelectionModel::SelectionFlag > command)
QAbstractItemView::model
QAbstractItemModel * model() const
QAbstractItemView::currentIndex
QModelIndex currentIndex() const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Editor::LessonView::signalShowContainer
void signalShowContainer(KEduVocContainer *selected)
Emitted when a new container is selected.
Editor::LessonView::currentChanged
void currentChanged(const QModelIndex &current, const QModelIndex &previous)
Definition: lessonview.cpp:133
Editor::LessonView::slotSplitLesson
void slotSplitLesson()
Creates many small lessons with the contents of the original lesson.
Definition: lessonview.cpp:208
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