• 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
leitnerview.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 "leitnerview.h"
17 
18 #include "editor/editor.h"
19 #include "leitnermodel.h"
20 #include "keduvocleitnerbox.h"
21 #include "prefs.h"
22 #include <KLocalizedString>
23 #include <KMessageBox>
24 #include <KInputDialog>
25 #include <KAction>
26 #include <KActionCollection>
27 
28 LeitnerView::LeitnerView(Editor *parent) :QListView(parent)
29 {
30 /*
31  KAction *actionNewLesson = new KAction(this);
32  parent->actionCollection()->addAction("new_lesson", actionNewLesson);
33  actionNewLesson->setText(i18n("New Lesson"));
34  actionNewLesson->setIcon(KIcon("lesson-add"));
35  actionNewLesson->setWhatsThis(i18n("Add a new lesson to your document"));
36  actionNewLesson->setToolTip(actionNewLesson->whatsThis());
37  actionNewLesson->setStatusTip(actionNewLesson->whatsThis());
38 
39  KAction *actionRenameLesson = new KAction(this);
40  parent->actionCollection()->addAction("rename_lesson", actionRenameLesson);
41  actionRenameLesson->setText(i18n("Rename Lesson"));
42  actionRenameLesson->setIcon(KIcon("edit-rename"));
43  actionRenameLesson->setWhatsThis(i18n("Rename the selected lesson"));
44  actionRenameLesson->setToolTip(actionRenameLesson->whatsThis());
45  actionRenameLesson->setStatusTip(actionRenameLesson->whatsThis());
46 
47  KAction *actionDeleteLesson = new KAction(this);
48  parent->actionCollection()->addAction("delete_lesson", actionDeleteLesson);
49  actionDeleteLesson->setText(i18n("Delete Lesson"));
50  actionDeleteLesson->setIcon(KIcon("lesson-remove"));
51  actionDeleteLesson->setWhatsThis(i18n("Delete the selected lesson."));
52  actionDeleteLesson->setToolTip(actionDeleteLesson->whatsThis());
53  actionDeleteLesson->setStatusTip(actionDeleteLesson->whatsThis());
54 
55 
56  connect(actionNewLesson, SIGNAL(triggered()),
57  SLOT(slotCreateNewLesson()));
58  connect(actionRenameLesson, SIGNAL(triggered()),
59  SLOT(slotRename()));
60  connect(actionDeleteLesson, SIGNAL(triggered()),
61  SLOT(slotDeleteLesson()));
62 
63  // right cick menu for the lesson view:
64  addAction(actionNewLesson);
65  addAction(actionRenameLesson);
66  addAction(actionDeleteLesson);
67 */
68 }
69 
70 void LeitnerView::currentChanged(const QModelIndex & current, const QModelIndex & previous)
71 {
72  QListView::currentChanged(current, previous);
73 
74  if (current.isValid()) {
75  KEduVocLeitnerBox *container = static_cast<KEduVocLeitnerBox*>(current.internalPointer());
76  if (container) {
77  emit selectedLeitnerBoxChanged(container);
78  emit signalShowContainer(container);
79  }
80  }
81 }
82 
83 void LeitnerView::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
84 {
85  QListView::selectionChanged(selected, deselected);
86 
87  if(selected.count() == 0) {
88  return;
89  }
90 
91  KEduVocLeitnerBox *container = static_cast<KEduVocLeitnerBox*>(selected.indexes().value(0).internalPointer());
92  if (container) {
93  emit selectedLeitnerBoxChanged(container);
94  }
95 }
96 
97 void LeitnerView::slotCreateLeitnerBox()
98 {
99  QModelIndex selectedIndex = selectionModel()->currentIndex();
100 
101  if (!selectedIndex.isValid()) {
102  selectedIndex = m_model->index(0, 0, QModelIndex());
103  }
104 
105  QModelIndex modelIndex = m_model->appendContainer(selectedIndex);
106 
107  scrollTo(modelIndex);
108  selectionModel()->setCurrentIndex(modelIndex, QItemSelectionModel::ClearAndSelect);
109  edit(modelIndex); // let the user type a new name for the lesson
110 }
111 
112 void LeitnerView::slotDeleteLeitnerBox()
113 {
114  QModelIndex selectedIndex = selectionModel()->currentIndex();
115 
116  if (selectedIndex.parent() == QModelIndex()) {
117  KMessageBox::information(this, i18n("The root lesson cannot be deleted."));
118  return;
119  }
120 
121  KEduVocLesson* lesson = static_cast<KEduVocLesson*>(selectedIndex.internalPointer());
122 
123  int count = lesson->entryCount(KEduVocLesson::Recursive);
124 
125  if ( count == 0 ||
126  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) {
127  m_model->deleteContainer(selectedIndex);
128  }
129 }
130 
131 void LeitnerView::setModel(LeitnerModel * model)
132 {
133  QListView::setModel(model);
134  m_model = model;
135  setRootIndex(model->index(0,0, model->index(0,0, QModelIndex())));
136 }
137 
138 #include "leitnerview.moc"
139 
140 
prefs.h
editor.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