-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfiledelegate.cpp
203 lines (177 loc) · 6.48 KB
/
filedelegate.cpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include <QItemDelegate>
#include <QStandardItemModel>
#include <QPainter>
#include <QDirModel>
#include <QSettings>
#include <QDebug>
#include "osso-intl.h"
#include "filedelegate.h"
#include <QDateTime>
#include <QMaemo5Style>
FileDelegate::FileDelegate(QObject *parent)
: QStyledItemDelegate(parent)
{
}
void FileDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
painter->save();
QRect r = option.rect;
if(option.state & QStyle::State_Selected){
QPixmap is1 = QPixmap("/etc/hildon/theme/images/TouchListBackgroundPressed.png");
painter->drawTiledPixmap(r,is1);
} else {
QPixmap is1 = QPixmap("/etc/hildon/theme/images/TouchListBackgroundNormal.png" );
painter->drawTiledPixmap(r,is1);
}
QPixmap pict;
if ( index.data(Qt::DisplayRole) == "active" )
pict = QIcon::fromTheme("clock_alarm_on").pixmap(48, 48);
else if ( index.data(Qt::DisplayRole) == "inactive" )
pict = QIcon::fromTheme("clock_alarm_off").pixmap(48, 48);
painter->drawPixmap(r.left(), r.top()+12, pict);
painter->setPen(QPen(QMaemo5Style::standardColor("DefaultTextColor")));
QFont f = painter->font();
QString name = index.data(Qt::DisplayRole).toString();
QString help = index.data(Qt::WhatsThisRole).toString();
QString localPMtxt = QLocale::system().pmText();
QString localAMtxt = QLocale::system().amText();
if ( help == "time" )
{
QString name2 = "";
if ( name.contains(localAMtxt) )
{
name2 = localAMtxt;
name.remove(localAMtxt);
}
if ( name.contains(localPMtxt) )
{
name2 = localPMtxt;
name.remove(localPMtxt);
}
if ( index.data(Qt::StatusTipRole).toString() == "inactive" )
painter->setPen(QPen(QMaemo5Style::standardColor("SecondaryTextColor")));
f.setPointSize( f.pointSize() + 8 );
painter->setFont(f);
r = option.rect;
painter->drawText(r.left()+6, r.top(), 92, r.height(), Qt::AlignVCenter|Qt::AlignRight, name, &r);
f.setPointSize( f.pointSize() - 12 );
painter->setFont(f);
r = option.rect;
painter->drawText(r.left()+96, r.top(), r.width(), r.height(), Qt::AlignVCenter|Qt::AlignLeft, name2, &r);
}
if ( help == "name" )
{
painter->setFont(f);
r = option.rect;
if ( index.data(Qt::StatusTipRole).toString() == "inactive" )
painter->setPen(QPen(QMaemo5Style::standardColor("SecondaryTextColor")));
painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignVCenter|Qt::AlignLeft, name, &r);
}
if ( help == "days" )
{
painter->setPen(QPen(QMaemo5Style::standardColor("SecondaryTextColor")));
f.setPointSize( f.pointSize()-4 );
painter->setFont(f);
r = option.rect;
int i = name.count(",");
if ( i > 2 )
{
//short daynames
QString l1;
i = name.indexOf(",");
l1 = name.left(i+1);
name.remove(0, i+1);
i = name.indexOf(",");
l1 = l1 + name.left(i+1);
name.remove(0, i+1);
i = name.indexOf(",");
l1 = l1 + name.left(i);
name.remove(0,i+2);
name = l1 + "\n" + name;
QLocale loc;
name.replace("1", loc.dayName(1, QLocale::ShortFormat) );
name.replace("2", loc.dayName(2, QLocale::ShortFormat) );
name.replace("3", loc.dayName(3, QLocale::ShortFormat) );
name.replace("4", loc.dayName(4, QLocale::ShortFormat) );
name.replace("5", loc.dayName(5, QLocale::ShortFormat) );
name.replace("6", loc.dayName(6, QLocale::ShortFormat) );
name.replace("7", loc.dayName(7, QLocale::ShortFormat) );
}
else
{
QLocale loc;
QString dateSep = QDate::currentDate().toString(Qt::SystemLocaleShortDate).remove(QRegExp("\\d+|\\s+")).at(0);
if ( ! name.contains(dateSep))
{
// no exact time/date specified
name.replace("1", loc.dayName(1) );
name.replace("2", loc.dayName(2) );
name.replace("3", loc.dayName(3) );
name.replace("4", loc.dayName(4) );
name.replace("5", loc.dayName(5) );
name.replace("6", loc.dayName(6) );
name.replace("7", loc.dayName(7) );
name.replace("0", _("cloc_va_never") );
name.replace("8", _("cloc_va_everyday") );
}
}
painter->setPen(QPen(QMaemo5Style::standardColor("SecondaryTextColor")));
painter->drawText(r.left(), r.top(), r.width()-12, r.height(), Qt::AlignVCenter|Qt::AlignRight|Qt::TextWordWrap, name, &r);
}
if ( help == "world-name" )
{
QString tmp = name;
int j = tmp.indexOf("startdesc");
tmp.remove(0, j+9);
name.remove(tmp);
name.remove("startdesc");
painter->setFont(f);
r = option.rect;
if ( r.width() < 400 )
name = name + "\n";
painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignVCenter|Qt::AlignLeft, name, &r);
QFontMetrics fm(f);
int len = fm.width(name);
painter->setPen(QPen(QMaemo5Style::standardColor("DefaultTextColor")));
painter->setFont(f);
r = option.rect;
int h1 = 0;
if ( r.width() < 400 )
{
len = 0;
h1 = 30;
f.setPointSize(14);
painter->setFont(f);
}
painter->setPen(QPen(QMaemo5Style::standardColor("SecondaryTextColor")));
painter->drawText(r.left()+len, r.top()+h1, r.width()-len, r.height()-h1, Qt::AlignVCenter|Qt::AlignLeft, tmp, &r);
}
if ( help == "world-date" )
{
painter->setPen(QPen(QMaemo5Style::standardColor("SecondaryTextColor")));
f.setPointSize(14);
painter->setFont(f);
QString tmp = name;
int j = tmp.indexOf(" startdesc");
tmp.remove(0, j+11);
name.remove(tmp);
name.remove(" startdesc");
r = option.rect;
if ( r.width() < 200 )
name = name + "\n";
else
name = name + " (" + tmp + ")";
painter->drawText(r.left(), r.top(), r.width()-6, r.height(), Qt::AlignVCenter|Qt::AlignRight, name, &r);
painter->setFont(f);
r = option.rect;
if ( r.width() < 200 )
painter->drawText(r.left(), r.top()+30, r.width()-6, r.height()-30, Qt::AlignVCenter|Qt::AlignRight, "("+tmp+")", &r);
}
painter->restore();
}
QSize FileDelegate::sizeHint(const QStyleOptionViewItem &,
const QModelIndex &) const
{
return QSize( 0, 70);
}