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

parley

kvtlessonview.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002 
00003                              kvtlessonview
00004 
00005     -----------------------------------------------------------------------
00006 
00007     copyright     : (C) 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
00008 
00009     -----------------------------------------------------------------------
00010 
00011  ***************************************************************************/
00012 
00013 /***************************************************************************
00014  *                                                                         *
00015  *   This program is free software; you can redistribute it and/or modify  *
00016  *   it under the terms of the GNU General Public License as published by  *
00017  *   the Free Software Foundation; either version 2 of the License, or     *
00018  *   (at your option) any later version.                                   *
00019  *                                                                         *
00020  ***************************************************************************/
00021 
00022 #include "kvtlessonview.h"
00023 
00024 #include <QTreeView>
00025 #include <QMenu>
00026 #include <QContextMenuEvent>
00027 #include <KAction>
00028 #include <KMessageBox>
00029 #include <KInputDialog>
00030 #include <kdebug.h>
00031 #include <klocale.h>
00032 #include <kiconloader.h>
00033 #include <kicon.h>
00034 #include <kconfig.h>
00035 #include <keduvocdocument.h>
00036 
00037 #include "prefs.h"
00038 #include "kvtlessonmodel.h"
00039 
00040 KVTLessonView::KVTLessonView(QWidget *parent) : QTreeView(parent)
00041 {
00042     // drag and drop
00043     setDragEnabled(true);
00044     //setMovement(QListView::Snap);
00045     setAcceptDrops(true);
00046     setDropIndicatorShown(true);
00047     // only allow internal moves - so far no interaction with the outside world.
00048     setDragDropMode(QAbstractItemView::InternalMove);
00049     // show the actions added by addAction() as right click menu.
00050     setContextMenuPolicy(Qt::ActionsContextMenu);
00051 }
00052 
00053 void KVTLessonView::setModel(KVTLessonModel *model)
00054 {
00055     QTreeView::setModel(model);
00056     m_model = model;
00057 }
00058 
00059 void KVTLessonView::slotModelReset()
00060 {
00061     initializeSelection();
00062 }
00063 
00064 void KVTLessonView::initializeSelection()
00065 {
00066     slotSelectLesson(m_model->currentLesson());
00067 }
00068 
00069 void KVTLessonView::slotCheckAllLessons()
00070 {
00071     m_model->setAllLessonsInPractice();
00072 }
00073 
00074 void KVTLessonView::slotCheckNoLessons()
00075 {
00076     m_model->setNoLessonsInPractice();
00077 }
00078 
00079 void KVTLessonView::slotCreateNewLesson()
00080 {
00081     int newLessonIndex = m_model->addLesson();
00082     slotSelectLesson(newLessonIndex);
00083 
00084     QModelIndex modelIndex = m_model->index(newLessonIndex, 0, QModelIndex());
00085     edit(modelIndex);    // let the user type a new name for the lesson
00086 }
00087 
00088 void KVTLessonView::slotRenameLesson()
00089 {
00090     QModelIndexList indexes = selectionModel()->selectedIndexes();
00091     edit(indexes.at(0));
00092 }
00093 
00094 void KVTLessonView::slotDeleteLesson()
00095 {
00096     int currentIndex = indexOfCurrentLesson();
00097     // Delete right away, if the lesson is empty, otherwise ask
00098     if (m_model->deleteLesson(currentIndex, KEduVocDocument::DeleteEmptyLesson))
00099         return; // lesson was empty - done.
00100     int exit = KMessageBox::warningYesNo(this, i18n("There are vocabularies left in this lesson. Do you want to delete them? You will lose your entries! You have been warned!")); 
00101     if (exit == KMessageBox::Yes) {
00102         m_model->deleteLesson(currentIndex, KEduVocDocument::DeleteEntriesAndLesson);
00103     }
00104 }
00105 
00106 void KVTLessonView::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
00107 {
00108     QTreeView::selectionChanged(selected, deselected);
00109     slotSelectLesson(selected.indexes().at(0).row());
00110 }
00111 
00112 
00113 void KVTLessonView::slotSelectLesson(int lesson)
00114 {
00115     // if current lesson is not set in the document default to the first one. Because we do -1 this is 1.
00116     if ( (lesson < 0) || (lesson > m_model->document()->lessonCount()) ) {
00117         lesson = 0;
00118     }
00119 
00120     QModelIndex indexOfCurrent = m_model->index(lesson, 0, QModelIndex());
00121     setCurrentIndex(indexOfCurrent);
00122 
00123     m_model->document()->setCurrentLesson(lesson);
00124     emit signalCurrentLessonChanged(lesson);
00125 }
00126 
00127 void KVTLessonView::slotSplitLesson()
00128 {
00131     bool ok = false;
00132     int numEntries = KInputDialog::getInteger(i18n("Entries per Lesson"), i18n("The lesson will be split into smaller lessons. The order will be randomized.\nHow many entries in each lesson do you want?"), Prefs::entriesPerLesson(), 1, 1000, 1, &ok, this);
00133     if (!ok)
00134         return;
00135     Prefs::setEntriesPerLesson(numEntries);
00136     m_model->splitLesson(indexOfCurrentLesson(), numEntries, KVTLessonModel::random);
00137 }
00138 
00139 void KVTLessonView::dropEvent(QDropEvent * event)
00140 {
00141     Q_UNUSED(event);
00142     kDebug() << "dropEvent()";
00143 }
00144 
00145 int KVTLessonView::indexOfCurrentLesson()
00146 {
00147     QModelIndexList indexes = selectionModel()->selectedIndexes();
00148     if (indexes.empty()) {
00149         kDebug() << "WARNING - NO SELECTION FOR ACTIVE LESSON! THIS SHOULD NOT HAPPEN!";
00150         return 0;
00151     }
00152     return indexes.at(0).row();
00153 }
00154 
00155 #include "kvtlessonview.moc"

parley

Skip menu "parley"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
Generated for kdeedu by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal