forked from GLDsuh-a/qt-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kjstyleditemdelegate.cpp
53 lines (46 loc) · 1.44 KB
/
kjstyleditemdelegate.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
#include "kjstyleditemdelegate.h"
#include <QDebug>
#include <QPainter>
#include <QApplication>
#include <QStyledItemDelegate>
#include <QStyleOptionViewItem>
KJStyledItemDelegate::KJStyledItemDelegate(QObject *parent)
: QStyledItemDelegate(parent)
{
for (int i = 0; i < 30; i )
{
KJConversationWidget *widget = new KJConversationWidget();
widget->widgetIndex = i;
widget->setHidden(true);
widgets.append(widget);
}
}
void KJStyledItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
// re-layout widget
Q_UNUSED(painter);
KJConversationWidget *widget = this->widgets.at(index.row() % widgets.count());
widget->init(QString("Conversation %1").arg(index.row()), QString("Detail %1").arg(index.row()%widgets.count()), index.row());
widget->setGeometry(option.rect);
// hide unneccessaray widget
for (int i = 0; i < widgets.count(); i )
{
KJConversationWidget *widget = this->widgets.at(i);
if (widget->geometry().x() != 0)
{
widget->setGeometry(QRect(10000,10000,0,0));
}
}
}
QSize KJStyledItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
Q_UNUSED(index);
return option.rect.size();
}
void KJStyledItemDelegate::refreshWidgets(bool hide)
{
for (int i = 0; i < 30; i )
{
widgets.at(i)->setHidden(hide);
}
}