1
/* This file is part of Zanshin Todo.
3
Copyright 2008 Kevin Ottens <ervin@kde.org>
4
Copyright 2008, 2009 Mario Bensi <nef@ipsquad.net>
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License as
8
published by the Free Software Foundation; either version 2 of
9
the License or (at your option) version 3 or any later version
10
accepted by the membership of KDE e.V. (or its successor approved
11
by the membership of KDE e.V.), which shall act as a proxy
12
defined in Section 14 of version 3 of the license.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25
#include "actionlistview.h"
27
#include <QtGui/QHeaderView>
29
#include "actionlistdelegate.h"
30
#include "actionduedatedelegate.h"
32
ActionListView::ActionListView(QWidget *parent)
33
: Akonadi::ItemView(parent)
35
setRootIsDecorated(false);
36
setItemDelegate(new ActionListDelegate(this));
37
setItemDelegateForColumn(2, new ActionDueDateDelegate(this));
39
setSelectionMode(QAbstractItemView::ExtendedSelection);
41
viewport()->setAcceptDrops(true);
42
setDropIndicatorShown(true);
44
setStyleSheet("QTreeView::branch { background: palette(base) }");
47
ActionListView::~ActionListView()
52
void ActionListView::setModel(QAbstractItemModel *model)
54
QByteArray headerState = header()->saveState();
56
Akonadi::ItemView::setModel(model);
60
header()->restoreState(headerState);
63
void ActionListView::setRootIndex(const QModelIndex &index)
65
Akonadi::ItemView::setRootIndex(index);
69
void ActionListView::expandBranch(const QModelIndex& parent)
71
QModelIndex index = parent;
73
while (index.isValid()) {
75
index = index.parent();
79
void ActionListView::connectModel(QAbstractItemModel *model) const
81
connect(model, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
82
this, SLOT(expandBranch(const QModelIndex&)));
85
void ActionListView::startDrag(Qt::DropActions supportedActions)
87
ActionListDelegate *delegate = qobject_cast<ActionListDelegate*>(itemDelegate());
89
delegate->setDragModeCount(selectedIndexes().size());
92
Akonadi::ItemView::startDrag(supportedActions);
95
QModelIndex ActionListView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
97
QModelIndex index = currentIndex();
100
if (!index.isValid()) {
101
index = model()->index(0, 0);
103
while (index.isValid() && (model()->flags(index) & Qt::ItemIsEnabled) == 0) {
104
index = indexBelow(index);
110
switch (cursorAction) {
112
if (index.column()==0) {
116
return index.sibling(index.row(), index.column()-1);
119
if (index.column()==model()->columnCount(index)-1) {
123
return index.sibling(index.row(), index.column()+1);
127
newIndex = Akonadi::ItemView::moveCursor(cursorAction, modifiers);
128
return newIndex.sibling(newIndex.row(), index.column());
131
return Akonadi::ItemView::moveCursor(cursorAction, modifiers);