Updated the Tools menu to reflect current build.
[kdepim.git] / kalarm / resourcemodelview.h
blob57ba819ffea42afa4c6cdbf619aee230e5c8339b
1 /*
2 * resourcemodelview.h - model/view classes for alarm resource lists
3 * Program: kalarm
4 * Copyright © 2007,2008,2011 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 "resources/alarmresource.h"
27 #include "resources/alarmresources.h"
29 #include <QAbstractListModel>
30 #include <QSortFilterProxyModel>
31 #include <QItemDelegate>
32 #include <QListView>
33 #include <QList>
34 #include <QFont>
35 #include <QColor>
37 using namespace KAlarmCal;
39 class ResourceModel : public QAbstractListModel
41 Q_OBJECT
42 public:
43 static ResourceModel* instance(QObject* parent = 0);
44 virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
45 virtual QModelIndex index(int row, int column, const QModelIndex& parent) const;
46 virtual QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const;
47 virtual bool setData(const QModelIndex&, const QVariant& value, int role = Qt::EditRole);
48 virtual Qt::ItemFlags flags(const QModelIndex&) const;
49 AlarmResource* resource(const QModelIndex&) const;
50 void removeResource(AlarmResource*);
51 void notifyChange(const QModelIndex&);
53 private slots:
54 void refresh();
55 void addResource(AlarmResource*);
56 void updateResource(AlarmResource*);
57 void slotStandardChanged(CalEvent::Type);
58 void slotLoaded(AlarmResource*, bool active);
59 void slotStatusChanged(AlarmResource*, AlarmResources::Change);
61 private:
62 explicit ResourceModel(QObject* parent = 0);
64 static ResourceModel* mInstance;
65 QList<AlarmResource*> mResources;
66 QString mErrorPrompt;
67 QFont mFont;
71 class ResourceFilterModel : public QSortFilterProxyModel
73 Q_OBJECT
74 public:
75 ResourceFilterModel(QAbstractItemModel* baseModel, QObject* parent);
76 void setFilter(CalEvent::Type);
77 AlarmResource* resource(int row) const;
78 AlarmResource* resource(const QModelIndex&) const;
79 void notifyChange(int row);
80 void notifyChange(const QModelIndex&);
82 protected:
83 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const;
85 private:
86 CalEvent::Type mResourceType;
90 class ResourceView : public QListView
92 Q_OBJECT
93 public:
94 explicit ResourceView(QWidget* parent = 0) : QListView(parent) {}
95 virtual void setModel(QAbstractItemModel*);
96 AlarmResource* resource(int row) const;
97 AlarmResource* resource(const QModelIndex&) const;
98 void notifyChange(int row) const;
99 void notifyChange(const QModelIndex&) const;
101 protected:
102 virtual void mouseReleaseEvent(QMouseEvent*);
103 virtual bool viewportEvent(QEvent*);
107 class ResourceDelegate : public QItemDelegate
109 Q_OBJECT
110 public:
111 explicit ResourceDelegate(ResourceView* parent = 0) : QItemDelegate(parent) {}
112 virtual bool editorEvent(QEvent*, QAbstractItemModel*, const QStyleOptionViewItem&, const QModelIndex&);
115 #endif // RESOURCEMODELVIEW_H
117 // vim: et sw=4: