Add QTL classes to qt3.kdbgtt.
[kdbg.git] / kdbg / threadlist.cpp
blobd164f5a42df354e6095e4c527afc60767ae7034f
1 /*
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.
5 */
7 #include "threadlist.h"
8 #include "dbgdriver.h"
9 #include <klocale.h>
10 #include <kiconloader.h>
11 #include <qbitmap.h>
12 #include <qpainter.h>
15 class ThreadEntry : public QListViewItem, public ThreadInfo
17 public:
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),
26 ThreadInfo(*thread),
27 m_delete(false)
31 void ThreadEntry::setFunction(const QString& func)
33 function = func;
34 setText(1, function);
38 ThreadList::ThreadList(QWidget* parent, const char* name) :
39 QListView(parent, name)
41 addColumn(i18n("Thread ID"), 150);
42 addColumn(i18n("Location"));
44 // load pixmaps
45 m_focusIcon = UserIcon("pcinner");
46 makeNoFocusIcon();
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);
66 if (te == 0) {
67 te = new ThreadEntry(this, i);
68 } else {
69 te->m_delete = false;
70 te->setFunction(i->function);
72 // set focus icon
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 ;-) */
81 if (te->m_delete) {
82 delete te;
87 ThreadEntry* ThreadList::threadById(int id)
89 for (QListViewItem* e = firstChild(); e != 0; e = e->nextSibling()) {
90 ThreadEntry* te = static_cast<ThreadEntry*>(e);
91 if (te->id == id) {
92 return te;
95 return 0;
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)
114 if (newItem == 0)
115 return;
117 ThreadEntry* te = static_cast<ThreadEntry*>(newItem);
119 // change the focused thread
120 if (te->hasFocus)
121 return;
123 emit setThread(te->id);
127 #include "threadlist.moc"