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
|
#include "Swift/QtUI/Roster/QtTreeWidgetItem.h"
#include "Swift/QtUI/Roster/QtTreeWidget.h"
#include <qdebug.h>
namespace Swift {
QtTreeWidgetItem::QtTreeWidgetItem(QtTreeWidgetItem* parentItem) : QObject(), textColor_(0,0,0), backgroundColor_(255,255,255) {
parent_ = parentItem;
shown_ = true;
}
void QtTreeWidgetItem::setText(const String& text) {
displayName_ = P2QSTRING(text);
}
void QtTreeWidgetItem::setStatusText(const String& text) {
statusText_ = P2QSTRING(text);
}
void QtTreeWidgetItem::setAvatarPath(const String& path) {
qDebug() << "Setting avatar to " << P2QSTRING(path);
avatar_ = QIcon(P2QSTRING(path));
}
void QtTreeWidgetItem::setTextColor(unsigned long color) {
textColor_ = QColor(
((color & 0xFF0000)>>16),
((color & 0xFF00)>>8),
(color & 0xFF));
}
void QtTreeWidgetItem::setBackgroundColor(unsigned long color) {
backgroundColor_ = QColor(
((color & 0xFF0000)>>16),
((color & 0xFF00)>>8),
(color & 0xFF));
}
void QtTreeWidgetItem::setExpanded(bool b) {
//treeWidget()->setItemExpanded(this, b);
}
void QtTreeWidgetItem::hide() {
shown_ = false;
emit changed();
}
void QtTreeWidgetItem::show() {
shown_ = true;
emit changed();
}
bool QtTreeWidgetItem::isShown() {
return isContact() ? shown_ : shownChildren_.size() > 0;
}
QWidget* QtTreeWidgetItem::getCollapsedRosterWidget() {
QWidget* widget = new QWidget();
return widget;
}
QWidget* QtTreeWidgetItem::getExpandedRosterWidget() {
QWidget* widget = new QWidget();
return widget;
}
QtTreeWidgetItem::~QtTreeWidgetItem() {
qDeleteAll(children_);
}
QtTreeWidgetItem* QtTreeWidgetItem::getParentItem() {
return parent_;
}
void QtTreeWidgetItem::addChild(QtTreeWidgetItem* child) {
children_.append(child);
connect(child, SIGNAL(changed()), this, SLOT(handleChanged()));
handleChanged();
}
void QtTreeWidgetItem::handleChanged() {
shownChildren_.clear();
for (int i = 0; i < children_.size(); i++) {
if (children_[i]->isShown()) {
shownChildren_.append(children_[i]);
}
}
emit changed();
}
int QtTreeWidgetItem::rowCount() {
//qDebug() << "Returning size of " << children_.size() << " for item " << displayName_;
return shownChildren_.size();
}
int QtTreeWidgetItem::rowOf(QtTreeWidgetItem* item) {
return shownChildren_.indexOf(item);
}
int QtTreeWidgetItem::row() {
return parent_ ? parent_->rowOf(this) : 0;
}
QtTreeWidgetItem* QtTreeWidgetItem::getItem(int row) {
//qDebug() << "Returning row " << row << " from item " << displayName_;
return shownChildren_[row];
}
QVariant QtTreeWidgetItem::data(int role) {
switch (role) {
case Qt::DisplayRole: return displayName_;
case Qt::TextColorRole: return textColor_;
case Qt::BackgroundColorRole: return backgroundColor_;
case StatusTextRole: return statusText_;
case AvatarRole: return avatar_;
default: return QVariant();
}
}
bool QtTreeWidgetItem::isContact() {
return children_.size() == 0;
}
}
|