Merge with version 2.0.
[kdbg.git] / kdbg / threadlist.cpp
blobfaf3f9f2d26fed9704656fc3436d034024adcadc
1 // $Id$
3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
6 #include "threadlist.h"
7 #include "dbgdriver.h"
8 #include <klocale.h>
9 #include <kiconloader.h>
10 #include <qbitmap.h>
11 #include <qpainter.h>
14 class ThreadEntry : public QListViewItem, public ThreadInfo
16 public:
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),
25 ThreadInfo(*thread),
26 m_delete(false)
30 void ThreadEntry::setFunction(const QString& func)
32 function = func;
33 setText(1, function);
37 ThreadList::ThreadList(QWidget* parent, const char* name) :
38 QListView(parent, name)
40 addColumn(i18n("Thread ID"), 150);
41 addColumn(i18n("Location"));
43 // load pixmaps
44 m_focusIcon = UserIcon("pcinner");
45 makeNoFocusIcon();
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);
65 if (te == 0) {
66 te = new ThreadEntry(this, i);
67 } else {
68 te->m_delete = false;
69 te->setFunction(i->function);
71 // set focus icon
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 ;-) */
80 if (te->m_delete) {
81 delete te;
86 ThreadEntry* ThreadList::threadById(int id)
88 for (QListViewItem* e = firstChild(); e != 0; e = e->nextSibling()) {
89 ThreadEntry* te = static_cast<ThreadEntry*>(e);
90 if (te->id == id) {
91 return te;
94 return 0;
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)
113 if (newItem == 0)
114 return;
116 ThreadEntry* te = static_cast<ThreadEntry*>(newItem);
118 // change the focused thread
119 if (te->hasFocus)
120 return;
122 emit setThread(te->id);
126 #include "threadlist.moc"