3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
6 #include "threadlist.h"
13 #include <kiconloader.h>
17 class ThreadEntry
: public QListViewItem
, public ThreadInfo
20 ThreadEntry(QListView
* parent
, ThreadInfo
* thread
);
21 void setFunction(const QString
& func
);
23 bool m_delete
; /* used for updating the list */
26 ThreadEntry::ThreadEntry(QListView
* parent
, ThreadInfo
* thread
) :
27 QListViewItem(parent
, thread
->threadName
, thread
->function
),
33 void ThreadEntry::setFunction(const QString
& func
)
40 ThreadList::ThreadList(QWidget
* parent
, const char* name
) :
41 QListView(parent
, name
)
43 addColumn(i18n("Thread ID"), 150);
44 addColumn(i18n("Location"));
48 KIconLoader
* loader
= kapp
->getIconLoader();
49 m_focusIcon
= loader
->loadIcon("pcinner.xpm");
51 m_focusIcon
= BarIcon("pcinner");
55 connect(this, SIGNAL(currentChanged(QListViewItem
*)),
56 this, SLOT(slotCurrentChanged(QListViewItem
*)));
59 ThreadList::~ThreadList()
63 void ThreadList::updateThreads(QList
<ThreadInfo
>& threads
)
65 // reset flag in all items
66 for (QListViewItem
* e
= firstChild(); e
!= 0; e
= e
->nextSibling()) {
67 static_cast<ThreadEntry
*>(e
)->m_delete
= true;
70 for (ThreadInfo
* i
= threads
.first(); i
!= 0; i
= threads
.next()) {
71 // look up this thread by id
72 ThreadEntry
* te
= threadById(i
->id
);
74 te
= new ThreadEntry(this, i
);
77 te
->setFunction(i
->function
);
80 te
->hasFocus
= i
->hasFocus
;
81 te
->setPixmap(0, i
->hasFocus
? m_focusIcon
: m_noFocusIcon
);
84 // delete all entries that have not been seen
85 for (QListViewItem
* e
= firstChild(); e
!= 0;) {
86 ThreadEntry
* te
= static_cast<ThreadEntry
*>(e
);
87 e
= e
->nextSibling(); /* step ahead before deleting it ;-) */
94 ThreadEntry
* ThreadList::threadById(int id
)
96 for (QListViewItem
* e
= firstChild(); e
!= 0; e
= e
->nextSibling()) {
97 ThreadEntry
* te
= static_cast<ThreadEntry
*>(e
);
106 * Creates an icon of the same size as the m_focusIcon, but which is
107 * totally transparent.
109 void ThreadList::makeNoFocusIcon()
111 m_noFocusIcon
= m_focusIcon
;
113 QPainter
p(&m_noFocusIcon
);
114 p
.fillRect(0,0, m_noFocusIcon
.width(),m_noFocusIcon
.height(), QColor(white
));
116 m_noFocusIcon
.setMask(m_noFocusIcon
.createHeuristicMask());
119 void ThreadList::slotCurrentChanged(QListViewItem
* newItem
)
124 ThreadEntry
* te
= static_cast<ThreadEntry
*>(newItem
);
126 // change the focused thread
130 emit
setThread(te
->id
);
134 #include "threadlist.moc"