16 #include "leitnerview.h"
19 #include "leitnermodel.h"
20 #include "keduvocleitnerbox.h"
22 #include <KLocalizedString>
23 #include <KMessageBox>
24 #include <KInputDialog>
26 #include <KActionCollection>
28 LeitnerView::LeitnerView(Editor *parent) :QListView(parent)
70 void LeitnerView::currentChanged(
const QModelIndex & current,
const QModelIndex & previous)
72 QListView::currentChanged(current, previous);
74 if (current.isValid()) {
75 KEduVocLeitnerBox *container =
static_cast<KEduVocLeitnerBox*
>(current.internalPointer());
77 emit selectedLeitnerBoxChanged(container);
78 emit signalShowContainer(container);
83 void LeitnerView::selectionChanged(
const QItemSelection & selected,
const QItemSelection & deselected)
85 QListView::selectionChanged(selected, deselected);
87 if(selected.count() == 0) {
91 KEduVocLeitnerBox *container =
static_cast<KEduVocLeitnerBox*
>(selected.indexes().value(0).internalPointer());
93 emit selectedLeitnerBoxChanged(container);
97 void LeitnerView::slotCreateLeitnerBox()
99 QModelIndex selectedIndex = selectionModel()->currentIndex();
101 if (!selectedIndex.isValid()) {
102 selectedIndex = m_model->index(0, 0, QModelIndex());
105 QModelIndex modelIndex = m_model->appendContainer(selectedIndex);
107 scrollTo(modelIndex);
108 selectionModel()->setCurrentIndex(modelIndex, QItemSelectionModel::ClearAndSelect);
112 void LeitnerView::slotDeleteLeitnerBox()
114 QModelIndex selectedIndex = selectionModel()->currentIndex();
116 if (selectedIndex.parent() == QModelIndex()) {
117 KMessageBox::information(
this, i18n(
"The root lesson cannot be deleted."));
121 KEduVocLesson* lesson =
static_cast<KEduVocLesson*
>(selectedIndex.internalPointer());
123 int count = lesson->entryCount(KEduVocLesson::Recursive);
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);
131 void LeitnerView::setModel(LeitnerModel * model)
133 QListView::setModel(model);
135 setRootIndex(model->index(0,0, model->index(0,0, QModelIndex())));
138 #include "leitnerview.moc"