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"
10 #include <kiconloader.h>
15 class ThreadEntry
: public QListViewItem
, public ThreadInfo
18 ThreadEntry(QListView
* parent
, ThreadInfo
* thread
);
19 void setFunction(const QString
& func
);
21 bool m_delete
; /* used for updating the list */
24 ThreadEntry::ThreadEntry(QListView
* parent
, ThreadInfo
* thread
) :
25 QListViewItem(parent
, thread
->threadName
, thread
->function
),
31 void ThreadEntry::setFunction(const QString
& func
)
38 ThreadList::ThreadList(QWidget
* parent
, const char* name
) :
39 QListView(parent
, name
)
41 addColumn(i18n("Thread ID"), 150);
42 addColumn(i18n("Location"));
45 m_focusIcon
= UserIcon("pcinner");
48 connect(this, SIGNAL(currentChanged(QListViewItem
*)),
49 this, SLOT(slotCurrentChanged(QListViewItem
*)));
52 ThreadList::~ThreadList()
56 void ThreadList::updateThreads(QList
<ThreadInfo
>& threads
)
58 // reset flag in all items
59 for (QListViewItem
* e
= firstChild(); e
!= 0; e
= e
->nextSibling()) {
60 static_cast<ThreadEntry
*>(e
)->m_delete
= true;
63 for (ThreadInfo
* i
= threads
.first(); i
!= 0; i
= threads
.next()) {
64 // look up this thread by id
65 ThreadEntry
* te
= threadById(i
->id
);
67 te
= new ThreadEntry(this, i
);
70 te
->setFunction(i
->function
);
73 te
->hasFocus
= i
->hasFocus
;
74 te
->setPixmap(0, i
->hasFocus
? m_focusIcon
: m_noFocusIcon
);
77 // delete all entries that have not been seen
78 for (QListViewItem
* e
= firstChild(); e
!= 0;) {
79 ThreadEntry
* te
= static_cast<ThreadEntry
*>(e
);
80 e
= e
->nextSibling(); /* step ahead before deleting it ;-) */
87 ThreadEntry
* ThreadList::threadById(int id
)
89 for (QListViewItem
* e
= firstChild(); e
!= 0; e
= e
->nextSibling()) {
90 ThreadEntry
* te
= static_cast<ThreadEntry
*>(e
);
99 * Creates an icon of the same size as the m_focusIcon, but which is
100 * totally transparent.
102 void ThreadList::makeNoFocusIcon()
104 m_noFocusIcon
= m_focusIcon
;
106 QPainter
p(&m_noFocusIcon
);
107 p
.fillRect(0,0, m_noFocusIcon
.width(),m_noFocusIcon
.height(), QColor(white
));
109 m_noFocusIcon
.setMask(m_noFocusIcon
.createHeuristicMask());
112 void ThreadList::slotCurrentChanged(QListViewItem
* newItem
)
117 ThreadEntry
* te
= static_cast<ThreadEntry
*>(newItem
);
119 // change the focused thread
123 emit
setThread(te
->id
);
127 #include "threadlist.moc"