-
Notifications
You must be signed in to change notification settings - Fork 1
/
CalendarDelegate.h
78 lines (55 loc) · 2.18 KB
/
CalendarDelegate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef CALENDARDELEGATE_H
#define CALENDARDELEGATE_H
#include <glib.h>
#include <gio/gio.h>
#include <QStyledItemDelegate>
#include <QPainter>
#include <QMaemo5Style>
#include <QFontMetrics>
#include "CWrapper.h"
#include "Roles.h"
#include "Metrics.h"
class CalendarDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
CalendarDelegate(QObject *parent) : QStyledItemDelegate(parent) { }
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
using namespace Metrics::Item;
using namespace Metrics::Pixmap;
QStyledItemDelegate::paint(painter, option, QModelIndex());
QString name = index.data(NameRole).toString();
QString type = CWrapper::calendarType(index.data(TypeRole).toInt());
QIcon icon = QIcon::fromTheme(CWrapper::colorIcon(index.data(ColorRole).toInt()));
bool visibile = index.data(VisibilityRole).toBool();
QFont f = painter->font();
QRect r = option.rect.adjusted(Margin, Margin, -Margin, -Margin);
painter->save();
if (!visibile)
painter->setOpacity(0.25);
// Draw calendar icon
painter->drawPixmap(r.left(), r.top(), IconSize, IconSize, icon.pixmap(IconSize, IconSize));
painter->setOpacity(1.0);
r.adjust(IconSize+Margin, TextMargin, 0, -ValueMargin);
if (!visibile)
painter->setPen(QMaemo5Style::standardColor("DisabledTextColor"));
// Draw calendar name
painter->drawText(r, Qt::AlignTop|Qt::AlignLeft,
QFontMetrics(f).elidedText(name, Qt::ElideRight, r.width()));
if (visibile)
painter->setPen(QMaemo5Style::standardColor("SecondaryTextColor"));
// Draw calendar type
f.setPointSize(13);
painter->setFont(f);
painter->drawText(r, Qt::AlignBottom|Qt::AlignLeft,
QFontMetrics(f).elidedText(type, Qt::ElideRight, r.width()));
painter->restore();
}
QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const
{
using namespace Metrics::Item;
return QSize(Width, Height);
}
};
#endif // CALENDARDELEGATE_H