parley
containerview.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "containerview.h"
00017
00018 #include "prefs.h"
00019 #include "containermodel.h"
00020
00021 #include <KAction>
00022 #include <KMessageBox>
00023 #include <KInputDialog>
00024 #include <kdebug.h>
00025 #include <klocale.h>
00026 #include <kiconloader.h>
00027 #include <kicon.h>
00028 #include <kconfig.h>
00029 #include <keduvocdocument.h>
00030 #include <keduvoclesson.h>
00031 #include <keduvocwordtype.h>
00032 #include <keduvocexpression.h>
00033 #include <QTreeView>
00034 #include <QHeaderView>
00035 #include <QMenu>
00036 #include <QContextMenuEvent>
00037
00038 ContainerView::ContainerView(QWidget *parent) : QTreeView(parent)
00039 {
00040 header()->setStretchLastSection(false);
00041 header()->setVisible(false);
00042
00043 setAlternatingRowColors(true);
00044
00045
00046 setContextMenuPolicy(Qt::ActionsContextMenu);
00047 setSelectionMode(QAbstractItemView::SingleSelection);
00048
00049
00050 setDragEnabled(true);
00051 setAcceptDrops(true);
00052 setDropIndicatorShown(true);
00053 setDragDropMode(QAbstractItemView::DragDrop);
00054 }
00055
00056 void ContainerView::setModel(ContainerModel *model)
00057 {
00058 QTreeView::setModel(model);
00059 m_model = model;
00060
00061 header()->setResizeMode(0, QHeaderView::Stretch);
00062 header()->setResizeMode(1, QHeaderView::ResizeToContents);
00063 }
00064
00065 void ContainerView::setTranslation(KEduVocExpression * entry, int translation)
00066 {
00068 if (entry == 0) {
00069 return;
00070 }
00071
00072
00073 if(m_model->containerType() == KEduVocContainer::Lesson) {
00074 QModelIndex current = m_model->index(entry->lesson());
00075 selectionModel()->select(current, QItemSelectionModel::ClearAndSelect);
00076 scrollTo(current);
00077 return;
00078 }
00079
00080 if(m_model->containerType() == KEduVocContainer::WordType) {
00081
00082 QModelIndex modelIndex;
00083 modelIndex = m_model->index(entry->translation(translation)->wordType());
00084 scrollTo(modelIndex);
00085 selectionModel()->select(modelIndex, QItemSelectionModel::ClearAndSelect);
00086 return;
00087 }
00088
00089
00090 selectionModel()->clearSelection();
00091 return;
00092 }
00093
00094 void ContainerView::slotRename()
00095 {
00096 edit(selectionModel()->currentIndex());
00097 }
00098
00099 #include "containerview.moc"
00100
00101