~ubuntu-branches/ubuntu/lucid/ktorrent/lucid

« back to all changes in this revision

Viewing changes to libktcore/gui/activitylistmodel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-12-08 19:17:41 UTC
  • mfrom: (1.2.1 upstream) (0.7.12 sid)
  • Revision ID: james.westby@ubuntu.com-20091208191741-lqlq0xvnlv8ki19u
Tags: 3.3.1+dfsg.1-1ubuntu1
* Merge with Debian Testing remaining changes:
  - Build-depend directly on libboost-serialization1.40-dev since
    libboost-serialization-dev from boost-defaults is not in Main
  - Add in rules: include /usr/lib/kubuntu-desktop-i18n/debhelper/kubuntu.mk
  - Don't use dpkg-source 3.0 format
  - Add quilt to build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2009 by Joris Guisson                                   *
 
3
 *   joris.guisson@gmail.com                                               *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 *   This program is distributed in the hope that it will be useful,       *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
13
 *   GNU General Public License for more details.                          *
 
14
 *                                                                         *
 
15
 *   You should have received a copy of the GNU General Public License     *
 
16
 *   along with this program; if not, write to the                         *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
 
19
 ***************************************************************************/
 
20
#include <kicon.h>
 
21
#include "activitylistmodel.h"
 
22
#include "activitylistwidget.h"
 
23
#include <interfaces/activity.h>
 
24
 
 
25
namespace kt
 
26
{
 
27
        ActivityListModel::ActivityListModel(ActivityListWidget* widget) : QStringListModel(widget),widget(widget)
 
28
        {
 
29
        }
 
30
        
 
31
        ActivityListModel::~ActivityListModel()
 
32
        {
 
33
        }
 
34
 
 
35
        int ActivityListModel::rowCount(const QModelIndex & parent) const 
 
36
        {
 
37
                if (!parent.isValid())
 
38
                        return activities.count();
 
39
                else
 
40
                        return 0;
 
41
        }
 
42
 
 
43
        QVariant ActivityListModel::data(const QModelIndex& index, int role) const 
 
44
        {
 
45
                if (!index.isValid())
 
46
                        return QVariant();
 
47
                
 
48
                Activity* act = (Activity*)index.internalPointer();
 
49
                if (!act)
 
50
                        return QVariant();
 
51
                
 
52
                switch (role)
 
53
                {
 
54
                        case Qt::DisplayRole:
 
55
                                if (widget->displayMode() == ICONS_ONLY)
 
56
                                        return QVariant();
 
57
                                else
 
58
                                        return act->name();
 
59
                        case Qt::DecorationRole:
 
60
                                if (widget->displayMode() == TEXT_ONLY)
 
61
                                        return QVariant();
 
62
                                else
 
63
                                        return KIcon(act->icon());
 
64
                        case Qt::ToolTipRole:
 
65
                                return act->toolTip();
 
66
                        case Qt::TextAlignmentRole:
 
67
                                return Qt::AlignCenter;
 
68
                        default:
 
69
                                return QVariant();
 
70
                }
 
71
        }
 
72
        
 
73
        void ActivityListModel::addActivity(kt::Activity* act) 
 
74
        {
 
75
                activities.append(act);
 
76
                insertRow(activities.count() - 1);
 
77
        }
 
78
 
 
79
        void ActivityListModel::removeActivity(kt::Activity* act) 
 
80
        {
 
81
                int idx = activities.indexOf(act);
 
82
                if (idx < 0)
 
83
                        return;
 
84
                
 
85
                activities.removeAll(act);
 
86
                removeRow(idx);
 
87
        }
 
88
 
 
89
        QModelIndex ActivityListModel::index(int row, int column, const QModelIndex& parent) const 
 
90
        {
 
91
                if (parent.isValid() || row < 0 || row >= activities.count())
 
92
                        return QModelIndex();
 
93
                
 
94
                return createIndex(row,column,activities[row]);
 
95
        }
 
96
 
 
97
        QModelIndex ActivityListModel::indexOf(Activity* act) const
 
98
        {
 
99
                int r = activities.indexOf(act);
 
100
                if (r < 0)
 
101
                        return QModelIndex();
 
102
                else
 
103
                        return index(r,0,QModelIndex());
 
104
        }
 
105
        
 
106
        void ActivityListModel::emitLayoutChanged()
 
107
        {
 
108
                emit layoutChanged();
 
109
        }
 
110
        
 
111
        void ActivityListModel::sort(int column, Qt::SortOrder order) 
 
112
        {
 
113
                qSort(activities.begin(),activities.end(),Activity::lessThan);
 
114
                emitLayoutChanged();
 
115
        }
 
116
 
 
117
}
 
 
b'\\ No newline at end of file'