2 * Copyright Johannes Sixt
3 * This file is licensed under the GNU General Public License Version 2.
4 * See the file COPYING in the toplevel directory of the source directory.
7 #include "threadlist.h"
9 #include <klocalizedstring.h>
10 #include <kiconloader.h>
12 #include <QHeaderView>
16 class ThreadEntry
: public QTreeWidgetItem
, public ThreadInfo
19 ThreadEntry(QTreeWidget
* parent
, const ThreadInfo
& thread
);
20 void setFunction(const QString
& func
);
22 bool m_delete
; /* used for updating the list */
25 ThreadEntry::ThreadEntry(QTreeWidget
* parent
, const ThreadInfo
& thread
) :
26 QTreeWidgetItem(parent
, QStringList() << thread
.threadName
<< thread
.function
),
32 void ThreadEntry::setFunction(const QString
& func
)
39 ThreadList::ThreadList(QWidget
* parent
) :
42 setHeaderLabels(QStringList() << i18n("Thread ID") << i18n("Location"));
43 header()->setSectionResizeMode(1, QHeaderView::Interactive
);
44 setRootIsDecorated(false);
47 m_focusIcon
= UserIcon("pcinner");
50 connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem
*, QTreeWidgetItem
*)),
51 this, SLOT(slotCurrentChanged(QTreeWidgetItem
*)));
54 ThreadList::~ThreadList()
58 void ThreadList::updateThreads(const std::list
<ThreadInfo
>& threads
)
60 // reset flag in all items
61 for (QTreeWidgetItemIterator
i(this); *i
; ++i
)
62 static_cast<ThreadEntry
*>(*i
)->m_delete
= true;
64 for (std::list
<ThreadInfo
>::const_iterator i
= threads
.begin(); i
!= threads
.end(); ++i
)
66 // look up this thread by id
67 ThreadEntry
* te
= threadById(i
->id
);
69 te
= new ThreadEntry(this, *i
);
72 te
->setFunction(i
->function
);
75 te
->hasFocus
= i
->hasFocus
;
76 te
->setIcon(0, i
->hasFocus
? QIcon(m_focusIcon
) : QIcon(m_noFocusIcon
));
79 // delete all entries that have not been seen
80 for (QTreeWidgetItemIterator
i(this); *i
;)
82 ThreadEntry
* te
= static_cast<ThreadEntry
*>(*i
);
83 ++i
; // step ahead before deleting it ;-)
90 ThreadEntry
* ThreadList::threadById(int id
)
92 for (QTreeWidgetItemIterator
i(this); *i
; ++i
)
94 ThreadEntry
* te
= static_cast<ThreadEntry
*>(*i
);
103 * Creates an icon of the same size as the m_focusIcon, but which is
104 * totally transparent.
106 void ThreadList::makeNoFocusIcon()
108 m_noFocusIcon
= m_focusIcon
;
110 QPainter
p(&m_noFocusIcon
);
111 p
.fillRect(0,0, m_noFocusIcon
.width(),m_noFocusIcon
.height(), QColor(Qt::white
));
113 m_noFocusIcon
.setMask(m_noFocusIcon
.createHeuristicMask());
116 void ThreadList::slotCurrentChanged(QTreeWidgetItem
* newItem
)
121 ThreadEntry
* te
= static_cast<ThreadEntry
*>(newItem
);
123 // change the focused thread
127 emit
setThread(te
->id
);
131 #include "threadlist.moc"