3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
6 #include "threadlist.h"
9 #include <kiconloader.h>
14 class ThreadEntry
: public QListViewItem
, public ThreadInfo
17 ThreadEntry(QListView
* parent
, ThreadInfo
* thread
);
18 void setFunction(const QString
& func
);
20 bool m_delete
; /* used for updating the list */
23 ThreadEntry::ThreadEntry(QListView
* parent
, ThreadInfo
* thread
) :
24 QListViewItem(parent
, thread
->threadName
, thread
->function
),
30 void ThreadEntry::setFunction(const QString
& func
)
37 ThreadList::ThreadList(QWidget
* parent
, const char* name
) :
38 QListView(parent
, name
)
40 addColumn(i18n("Thread ID"), 150);
41 addColumn(i18n("Location"));
44 m_focusIcon
= UserIcon("pcinner");
47 connect(this, SIGNAL(currentChanged(QListViewItem
*)),
48 this, SLOT(slotCurrentChanged(QListViewItem
*)));
51 ThreadList::~ThreadList()
55 void ThreadList::updateThreads(QList
<ThreadInfo
>& threads
)
57 // reset flag in all items
58 for (QListViewItem
* e
= firstChild(); e
!= 0; e
= e
->nextSibling()) {
59 static_cast<ThreadEntry
*>(e
)->m_delete
= true;
62 for (ThreadInfo
* i
= threads
.first(); i
!= 0; i
= threads
.next()) {
63 // look up this thread by id
64 ThreadEntry
* te
= threadById(i
->id
);
66 te
= new ThreadEntry(this, i
);
69 te
->setFunction(i
->function
);
72 te
->hasFocus
= i
->hasFocus
;
73 te
->setPixmap(0, i
->hasFocus
? m_focusIcon
: m_noFocusIcon
);
76 // delete all entries that have not been seen
77 for (QListViewItem
* e
= firstChild(); e
!= 0;) {
78 ThreadEntry
* te
= static_cast<ThreadEntry
*>(e
);
79 e
= e
->nextSibling(); /* step ahead before deleting it ;-) */
86 ThreadEntry
* ThreadList::threadById(int id
)
88 for (QListViewItem
* e
= firstChild(); e
!= 0; e
= e
->nextSibling()) {
89 ThreadEntry
* te
= static_cast<ThreadEntry
*>(e
);
98 * Creates an icon of the same size as the m_focusIcon, but which is
99 * totally transparent.
101 void ThreadList::makeNoFocusIcon()
103 m_noFocusIcon
= m_focusIcon
;
105 QPainter
p(&m_noFocusIcon
);
106 p
.fillRect(0,0, m_noFocusIcon
.width(),m_noFocusIcon
.height(), QColor(white
));
108 m_noFocusIcon
.setMask(m_noFocusIcon
.createHeuristicMask());
111 void ThreadList::slotCurrentChanged(QListViewItem
* newItem
)
116 ThreadEntry
* te
= static_cast<ThreadEntry
*>(newItem
);
118 // change the focused thread
122 emit
setThread(te
->id
);
126 #include "threadlist.moc"