Fixed wrong implicit cast causing invocation of wrong overload of
[kdbg.git] / kdbg / threadlist.cpp
blob234cfbc41c1c26bb62cc788afc7393a370b96ca5
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 #if QT_VERSION < 200
9 #include <kapp.h>
10 #else
11 #include <klocale.h>
12 #endif
13 #include <kiconloader.h>
14 #include <qbitmap.h>
17 class ThreadEntry : public QListViewItem, public ThreadInfo
19 public:
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),
28 ThreadInfo(*thread),
29 m_delete(false)
33 void ThreadEntry::setFunction(const QString& func)
35 function = func;
36 setText(1, function);
40 ThreadList::ThreadList(QWidget* parent, const char* name) :
41 QListView(parent, name)
43 addColumn(i18n("Thread ID"), 150);
44 addColumn(i18n("Location"));
46 // load pixmaps
47 #if QT_VERSION < 200
48 KIconLoader* loader = kapp->getIconLoader();
49 m_focusIcon = loader->loadIcon("pcinner.xpm");
50 #else
51 m_focusIcon = BarIcon("pcinner");
52 #endif
53 makeNoFocusIcon();
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);
73 if (te == 0) {
74 te = new ThreadEntry(this, i);
75 } else {
76 te->m_delete = false;
77 te->setFunction(i->function);
79 // set focus icon
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 ;-) */
88 if (te->m_delete) {
89 delete te;
94 ThreadEntry* ThreadList::threadById(int id)
96 for (QListViewItem* e = firstChild(); e != 0; e = e->nextSibling()) {
97 ThreadEntry* te = static_cast<ThreadEntry*>(e);
98 if (te->id == id) {
99 return te;
102 return 0;
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)
121 if (newItem == 0)
122 return;
124 ThreadEntry* te = static_cast<ThreadEntry*>(newItem);
126 // change the focused thread
127 if (te->hasFocus)
128 return;
130 emit setThread(te->id);
134 #include "threadlist.moc"