forked from GLDsuh-a/qt-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstalledappdelegate.cpp
96 lines (80 loc) · 2.67 KB
/
installedappdelegate.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
#include "installedappdelegate.h"
#include <QDebug>
#include <QPainter>
#include <QStyleOptionButton>
#include <QApplication>
#include <QCheckBox>
#include "downloadingitem.h"
InstalledAppDelegate::InstalledAppDelegate(QObject *parent)
: QItemDelegate(parent)
{
}
void InstalledAppDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
bool checked = index.model()->data(index, Qt::CheckStateRole).toBool();
if (checked)
{
painter->save();
painter->drawImage(option.rect, QImage("select.png"));
painter->restore();
}
if (index.column() == 1)
{
QString name = index.model()->data(index, Qt::UserRole+1).toString();
QString icon = index.model()->data(index, Qt::UserRole+2).toString();
painter->save();
painter->drawImage(option.rect.x() + 8, option.rect.y() + 7, QImage(icon));
painter->drawText(option.rect.x()+68, option.rect.y()+35, name);
painter->restore();
}
else if (index.column() == 0)
{
painter->save();
painter->drawImage(option.rect.x() + 5, option.rect.y() + 25, QImage("checkbox.png"));
if (checked)
{
painter->drawImage(option.rect.x() + 5, option.rect.y() + 25, QImage("checked.png"));
}
painter->restore();
}
}
QSize InstalledAppDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
return QSize(100, 150);
}
QWidget *InstalledAppDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const
{
if (index.column() == 2)
{
downloadingitem *item = new downloadingitem(parent);
item->setItemIndex(index);
connect(item, SIGNAL(pauseButtonClicked()),
this, SLOT(handlePauseButtonClicked()));
connect(item, SIGNAL(removeButtonClicked()),
this, SLOT(handleRemoveButtonClicked()));
connect(item, SIGNAL(startButtonClicked()),
this, SLOT(handleStartButtonClicked()));
return item;
}
return NULL;
}
void InstalledAppDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
}
void InstalledAppDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
}
void InstalledAppDelegate::handleStartButtonClicked()
{
qDebug() << "start button clicked" << endl;
}
void InstalledAppDelegate::handleRemoveButtonClicked()
{
qDebug() << "remove button clicked" << endl;
}
void InstalledAppDelegate::handlePauseButtonClicked()
{
qDebug() << "pause button clicked" << endl;
}