~ubuntu-branches/ubuntu/wily/zanshin/wily-proposed

« back to all changes in this revision

Viewing changes to src/actionlistview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2009-08-13 23:19:32 UTC
  • Revision ID: james.westby@ubuntu.com-20090813231932-lewqphiry1qs7w80
Tags: upstream-0.1+svn1006410
ImportĀ upstreamĀ versionĀ 0.1+svn1006410

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of Zanshin Todo.
 
2
 
 
3
   Copyright 2008 Kevin Ottens <ervin@kde.org>
 
4
   Copyright 2008, 2009 Mario Bensi <nef@ipsquad.net>
 
5
 
 
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.
 
13
 
 
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.
 
18
 
 
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,
 
22
   USA.
 
23
*/
 
24
 
 
25
#include "actionlistview.h"
 
26
 
 
27
#include <QtGui/QHeaderView>
 
28
 
 
29
#include "actionlistdelegate.h"
 
30
#include "actionduedatedelegate.h"
 
31
 
 
32
ActionListView::ActionListView(QWidget *parent)
 
33
    : Akonadi::ItemView(parent)
 
34
{
 
35
    setRootIsDecorated(false);
 
36
    setItemDelegate(new ActionListDelegate(this));
 
37
    setItemDelegateForColumn(2, new ActionDueDateDelegate(this));
 
38
    setAnimated(true);
 
39
    setSelectionMode(QAbstractItemView::ExtendedSelection);
 
40
    setDragEnabled(true);
 
41
    viewport()->setAcceptDrops(true);
 
42
    setDropIndicatorShown(true);
 
43
    setIndentation(0);
 
44
    setStyleSheet("QTreeView::branch { background: palette(base) }");
 
45
}
 
46
 
 
47
ActionListView::~ActionListView()
 
48
{
 
49
 
 
50
}
 
51
 
 
52
void ActionListView::setModel(QAbstractItemModel *model)
 
53
{
 
54
    QByteArray headerState = header()->saveState();
 
55
 
 
56
    Akonadi::ItemView::setModel(model);
 
57
    expandAll();
 
58
    connectModel(model);
 
59
 
 
60
    header()->restoreState(headerState);
 
61
}
 
62
 
 
63
void ActionListView::setRootIndex(const QModelIndex &index)
 
64
{
 
65
    Akonadi::ItemView::setRootIndex(index);
 
66
    expandAll();
 
67
}
 
68
 
 
69
void ActionListView::expandBranch(const QModelIndex& parent)
 
70
{
 
71
    QModelIndex index = parent;
 
72
 
 
73
    while (index.isValid()) {
 
74
        expand(index);
 
75
        index = index.parent();
 
76
    }
 
77
}
 
78
 
 
79
void ActionListView::connectModel(QAbstractItemModel *model) const
 
80
{
 
81
    connect(model, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
 
82
            this, SLOT(expandBranch(const QModelIndex&)));
 
83
}
 
84
 
 
85
void ActionListView::startDrag(Qt::DropActions supportedActions)
 
86
{
 
87
    ActionListDelegate *delegate = qobject_cast<ActionListDelegate*>(itemDelegate());
 
88
    if (delegate) {
 
89
        delegate->setDragModeCount(selectedIndexes().size());
 
90
    }
 
91
 
 
92
    Akonadi::ItemView::startDrag(supportedActions);
 
93
}
 
94
 
 
95
QModelIndex ActionListView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
 
96
{
 
97
    QModelIndex index = currentIndex();
 
98
    QModelIndex newIndex;
 
99
 
 
100
    if (!index.isValid()) {
 
101
        index = model()->index(0, 0);
 
102
 
 
103
        while (index.isValid() && (model()->flags(index) & Qt::ItemIsEnabled) == 0) {
 
104
            index = indexBelow(index);
 
105
        }
 
106
 
 
107
        return index;
 
108
    }
 
109
 
 
110
    switch (cursorAction) {
 
111
    case MoveLeft:
 
112
        if (index.column()==0) {
 
113
            return index;
 
114
        }
 
115
 
 
116
        return index.sibling(index.row(), index.column()-1);
 
117
 
 
118
    case MoveRight:
 
119
        if (index.column()==model()->columnCount(index)-1) {
 
120
            return index;
 
121
        }
 
122
 
 
123
        return index.sibling(index.row(), index.column()+1);
 
124
 
 
125
    case MoveUp:
 
126
    case MoveDown:
 
127
        newIndex = Akonadi::ItemView::moveCursor(cursorAction, modifiers);
 
128
        return newIndex.sibling(newIndex.row(), index.column());
 
129
 
 
130
    default:
 
131
        return Akonadi::ItemView::moveCursor(cursorAction, modifiers);
 
132
    }
 
133
}