-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworklogdialoglistvievitemdelegate.cpp
More file actions
56 lines (48 loc) · 1.85 KB
/
worklogdialoglistvievitemdelegate.cpp
File metadata and controls
56 lines (48 loc) · 1.85 KB
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
#include "worklogdialoglistvievitemdelegate.h"
#include "jira/jiraissue.h"
#include "utils/colors.h"
#include <QPainterPath>
WorklogDialogListVievItemDelegate::WorklogDialogListVievItemDelegate()
{
}
void WorklogDialogListVievItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QVariantMap v = index.model()->data(index, Qt::UserRole).toMap();
QVariantMap issueMap = v.value("issue").toMap();
int issueType = v.value("type").toInt();
Q_UNUSED(issueType);
JiraIssue j(issueMap);
QRect boundingRect = option.rect;
bool selected = option.state.testFlag(QStyle::State_Selected);
if (selected) {
// Draw background selected color
painter->fillRect(boundingRect, Colors::khakiWeb());
}
QRect typeBoundingRect(boundingRect);
typeBoundingRect.setRight(50);
typeBoundingRect.adjust(5, 5, -5, -5);
QPainterPath path;
path.addRoundedRect(typeBoundingRect, 3, 3);
painter->save();
auto currentFont = painter->font();
currentFont.setPixelSize(typeBoundingRect.height());
painter->setFont(currentFont);
QPen pen;
if (issueType == 0) {
painter->fillPath(path, Colors::radicalRed());
painter->drawText(typeBoundingRect, "Recent", QTextOption(Qt::AlignHCenter|Qt::AlignVCenter));
} else {
painter->fillPath(path, Colors::turquise());
painter->drawText(typeBoundingRect, "Search", QTextOption(Qt::AlignHCenter|Qt::AlignVCenter));
}
painter->restore();
QRect textBoundingRect(boundingRect);
textBoundingRect.setLeft(50);
painter->drawText(textBoundingRect, QString("%1 %2").arg(j.key(), j.summary()));
}
QSize WorklogDialogListVievItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
Q_UNUSED(index);
Q_UNUSED(option);
return QSize(300, 20);
}