Make it possible to use a distinct selection model in the foldertreewidget.
[kdepim.git] / kalarm / resourcemodelview.h
blob2ada9a33f19c7ff0b2a42ee239d13385d8177c94
1 /*
2 * resourcemodelview.h - model/view classes for alarm resource lists
3 * Program: kalarm
4 * Copyright © 2007,2008 by David Jarvie <djarvie@kde.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef RESOURCEMODELVIEW_H
22 #define RESOURCEMODELVIEW_H
24 #include "kalarm.h"
26 #include <QAbstractListModel>
27 #include <QSortFilterProxyModel>
28 #include <QItemDelegate>
29 #include <QListView>
30 #include <QList>
31 #include <QFont>
32 #include <QColor>
34 #include "resources/alarmresource.h"
35 #include "resources/alarmresources.h"
38 class ResourceModel : public QAbstractListModel
40 Q_OBJECT
41 public:
42 static ResourceModel* instance(QObject* parent = 0);
43 virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
44 virtual QModelIndex index(int row, int column, const QModelIndex& parent) const;
45 virtual QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const;
46 virtual bool setData(const QModelIndex&, const QVariant& value, int role = Qt::EditRole);
47 virtual Qt::ItemFlags flags(const QModelIndex&) const;
48 AlarmResource* resource(const QModelIndex&) const;
49 void removeResource(AlarmResource*);
50 void notifyChange(const QModelIndex&);
52 private slots:
53 void refresh();
54 void addResource(AlarmResource*);
55 void updateResource(AlarmResource*);
56 void slotStandardChanged(AlarmResource::Type);
57 void slotLoaded(AlarmResource*, bool active);
58 void slotStatusChanged(AlarmResource*, AlarmResources::Change);
60 private:
61 explicit ResourceModel(QObject* parent = 0);
63 static ResourceModel* mInstance;
64 QList<AlarmResource*> mResources;
65 QString mErrorPrompt;
66 QFont mFont;
70 class ResourceFilterModel : public QSortFilterProxyModel
72 public:
73 ResourceFilterModel(QAbstractItemModel* baseModel, QObject* parent);
74 void setFilter(AlarmResource::Type);
75 AlarmResource* resource(int row) const;
76 AlarmResource* resource(const QModelIndex&) const;
77 void notifyChange(int row);
78 void notifyChange(const QModelIndex&);
80 protected:
81 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const;
83 private:
84 AlarmResource::Type mResourceType;
88 class ResourceView : public QListView
90 public:
91 ResourceView(QWidget* parent = 0) : QListView(parent) {}
92 virtual void setModel(QAbstractItemModel*);
93 AlarmResource* resource(int row) const;
94 AlarmResource* resource(const QModelIndex&) const;
95 void notifyChange(int row) const;
96 void notifyChange(const QModelIndex&) const;
98 protected:
99 virtual void mouseReleaseEvent(QMouseEvent*);
100 virtual bool viewportEvent(QEvent*);
104 class ResourceDelegate : public QItemDelegate
106 public:
107 ResourceDelegate(ResourceView* parent = 0) : QItemDelegate(parent) {}
108 virtual bool editorEvent(QEvent*, QAbstractItemModel*, const QStyleOptionViewItem&, const QModelIndex&);
111 #endif // RESOURCEMODELVIEW_H