• 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
  • vocabulary
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 Lesson"));
38  actionNewLesson->setIcon(KIcon("lesson-add"));
39  actionNewLesson->setWhatsThis(i18n("Add a new lesson 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 Lesson"));
46  actionRenameLesson->setIcon(KIcon("edit-rename"));
47 // actionRenameLesson->setWhatsThis(i18n("Rename the selected lesson"));
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 Lesson"));
54  actionDeleteLesson->setIcon(KIcon("lesson-remove"));
55  actionDeleteLesson->setWhatsThis(i18n("Delete the selected lesson."));
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 Lesson into Smaller Lessons"));
62  actionSplitLesson->setIcon(KIcon("edit-copy"));
63  actionSplitLesson->setWhatsThis(i18n("Make multiple smaller lessons out of one big lesson."));
64  actionSplitLesson->setToolTip(actionSplitLesson->whatsThis());
65  actionSplitLesson->setStatusTip(actionSplitLesson->whatsThis());
66 
67  connect(actionNewLesson, SIGNAL(triggered()),
68  SLOT(slotCreateNewLesson()));
69  connect(actionRenameLesson, SIGNAL(triggered()),
70  SLOT(slotRename()));
71  connect(actionDeleteLesson, SIGNAL(triggered()),
72  SLOT(slotDeleteLesson()));
73  connect(actionSplitLesson, SIGNAL(triggered()),
74  SLOT(slotSplitLesson()));
75 
76  // right cick menu for the lesson view:
77  addAction(actionNewLesson);
78  addAction(actionRenameLesson);
79  addAction(actionDeleteLesson);
80  QAction* separator = new QAction(this);
81  separator->setSeparator(true);
82  addAction(separator);
83  separator = new QAction(this);
84  separator->setSeparator(true);
85  addAction(separator);
86  addAction(actionSplitLesson);
87 }
88 
89 void LessonView::currentChanged(const QModelIndex & current, const QModelIndex & previous)
90 {
91  QTreeView::currentChanged(current, previous);
92 
93  if (current.isValid()) {
94  KEduVocLesson *container = static_cast<KEduVocLesson*>(current.internalPointer());
95  if (container) {
96  emit selectedLessonChanged(container);
97  emit signalShowContainer(container);
98  }
99  }
100 }
101 
102 void LessonView::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
103 {
104  QTreeView::selectionChanged(selected, deselected);
105 
106  if(selected.count() == 0) {
107  return;
108  }
109 
110  KEduVocLesson *container = static_cast<KEduVocLesson*>(selected.indexes().value(0).internalPointer());
111  if (container) {
112  emit selectedLessonChanged(container);
113  }
114 }
115 
116 void LessonView::setTranslation(KEduVocExpression * entry, int translation)
117 {
118  Q_UNUSED(translation)
119 
120  if (entry == 0) {
121  selectionModel()->clearSelection();
122  return;
123  }
124 
125  QModelIndex index(m_model->index(entry->lesson()));
126  selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
127  scrollTo(index);
128 }
129 
130 void LessonView::slotCreateNewLesson()
131 {
132  QModelIndex selectedIndex = selectionModel()->currentIndex();
133 
134  if (!selectedIndex.isValid()) {
135  selectedIndex = m_model->index(0, 0, QModelIndex());
136  }
137 
138  QModelIndex modelIndex = m_model->appendContainer(selectedIndex);
139 
140  scrollTo(modelIndex);
141  selectionModel()->setCurrentIndex(modelIndex, QItemSelectionModel::ClearAndSelect);
142  edit(modelIndex); // let the user type a new name for the lesson
143 }
144 
145 void LessonView::slotDeleteLesson()
146 {
147  QModelIndex selectedIndex = selectionModel()->currentIndex();
148 
149  if (selectedIndex.parent() == QModelIndex()) {
150  KMessageBox::information(this, i18n("The root lesson cannot be deleted."));
151  return;
152  }
153 
154  KEduVocLesson* lesson = static_cast<KEduVocLesson*>(selectedIndex.internalPointer());
155 
156  int count = lesson->entryCount(KEduVocLesson::Recursive);
157 
158  if ( count == 0 ||
159  KMessageBox::warningYesNo(this, i18np("There is %1 word left in this lesson. Do you want to delete it?", "There are %1 words left in this lesson. Do you want to delete them?", count)) == KMessageBox::Yes) {
160  m_model->deleteContainer(selectedIndex);
161  }
162 }
163 
164 void LessonView::slotSplitLesson()
165 {
166  if (!selectionModel()->currentIndex().isValid()) {
167  return;
168  }
169 
172  bool ok = false;
173  int numEntries = KInputDialog::getInteger(i18n("Entries per Lesson"), i18n("The lesson will be split into smaller lessons. How many entries in each lesson do you want?"), Prefs::entriesPerLesson(), 1, 1000, 1, &ok, this);
174  if (!ok) {
175  return;
176  }
177  Prefs::setEntriesPerLesson(numEntries);
178  m_model->splitLesson(selectionModel()->currentIndex(), numEntries, LessonModel::Random);
179  setExpanded(selectionModel()->currentIndex(), true);
180 }
181 
182 void LessonView::setModel(LessonModel * model)
183 {
184  m_model = model;
185  ContainerView::setModel(model);
186  connect(model, SIGNAL(columnsInserted ( const QModelIndex &, int, int )), this, SLOT(columnsInserted()));
187  for (int i = 2; i< model->columnCount(QModelIndex()); i++) {
188  setColumnHidden(i, true);
189  }
190 }
191 
192 void LessonView::columnsInserted()
193 {
194  for (int i = 2; i< m_model->columnCount(QModelIndex()); i++) {
195  setColumnHidden(i, true);
196  }
197 }
198 
199 
200 
201 #include "lessonview.moc"
202 
203 
Editor::LessonView::setTranslation
void setTranslation(KEduVocExpression *entry, int translationId)
Definition: lessonview.cpp:116
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:192
Editor::ContainerView::slotRename
void slotRename()
let the user type a new name for the container
Definition: containerview.cpp:49
lessonview.h
Prefs::setEntriesPerLesson
static void setEntriesPerLesson(int v)
Set The number of entries per lesson.
Definition: prefs.h:112
Editor::ContainerModel::deleteContainer
void deleteContainer(const QModelIndex &containerIndex)
Definition: containermodel.cpp:199
prefs.h
Editor::LessonView::selectedLessonChanged
void selectedLessonChanged(KEduVocLesson *lesson)
A lesson was selected.
Editor::LessonView::slotCreateNewLesson
void slotCreateNewLesson()
Append a lesson to the model and automatically set an edit up so the user can change "New lesson" int...
Definition: lessonview.cpp:130
Editor::LessonView::slotDeleteLesson
void slotDeleteLesson()
Remove a lesson.
Definition: lessonview.cpp:145
editor.h
Editor::LessonView::setModel
virtual void setModel(LessonModel *model)
Set the model for the view.
Definition: lessonview.cpp:182
Editor::ContainerView::setModel
virtual void setModel(ContainerModel *model)
Set the model for the view.
Definition: containerview.cpp:40
Editor::ContainerModel::columnCount
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: containermodel.cpp:187
Editor::ContainerView
View for containers (KEduVocContainer).
Definition: containerview.h:31
Prefs::entriesPerLesson
static int entriesPerLesson()
Get The number of entries per lesson.
Definition: prefs.h:122
lessonmodel.h
Editor::LessonModel::splitLesson
void splitLesson(const QModelIndex &containerIndex, int entriesPerLesson, SplitLessonOrder order)
Divide a lesson into smaller ones.
Definition: lessonmodel.cpp:83
Editor::ContainerModel::appendContainer
QModelIndex appendContainer(const QModelIndex &parent, const QString &containerName=QString())
Definition: containermodel.cpp:43
Editor::LessonModel::Random
Randomized.
Definition: lessonmodel.h:33
Editor::BasicContainerModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: basiccontainermodel.cpp:55
Editor::EditorWindow
Definition: editor.h:46
Editor::LessonView::selectionChanged
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
Definition: lessonview.cpp:102
Editor::LessonModel
Model for the tree of lessons.
Definition: lessonmodel.h:25
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:89
Editor::LessonView::slotSplitLesson
void slotSplitLesson()
Creates many small lessons with the contents of the original lesson.
Definition: lessonview.cpp:164
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