Convert from Qt 3 to Qt 4 using qt3to4.
[kdbg.git] / kdbg / threadlist.cpp
blobdc58ce6f5397648e5484d5e853fa5c020ea6fa29
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 Q3ListViewItem, public ThreadInfo
17 public:
18 ThreadEntry(Q3ListView* parent, const ThreadInfo& thread);
19 void setFunction(const QString& func);
21 bool m_delete; /* used for updating the list */
24 ThreadEntry::ThreadEntry(Q3ListView* parent, const ThreadInfo& thread) :
25 Q3ListViewItem(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) :
39 Q3ListView(parent)
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(Q3ListViewItem*)),
49 this, SLOT(slotCurrentChanged(Q3ListViewItem*)));
52 ThreadList::~ThreadList()
56 void ThreadList::updateThreads(const std::list<ThreadInfo>& threads)
58 // reset flag in all items
59 for (Q3ListViewItem* e = firstChild(); e != 0; e = e->nextSibling()) {
60 static_cast<ThreadEntry*>(e)->m_delete = true;
63 for (std::list<ThreadInfo>::const_iterator i = threads.begin(); i != threads.end(); ++i)
65 // look up this thread by id
66 ThreadEntry* te = threadById(i->id);
67 if (te == 0) {
68 te = new ThreadEntry(this, *i);
69 } else {
70 te->m_delete = false;
71 te->setFunction(i->function);
73 // set focus icon
74 te->hasFocus = i->hasFocus;
75 te->setPixmap(0, i->hasFocus ? m_focusIcon : m_noFocusIcon);
78 // delete all entries that have not been seen
79 for (Q3ListViewItem* e = firstChild(); e != 0;) {
80 ThreadEntry* te = static_cast<ThreadEntry*>(e);
81 e = e->nextSibling(); /* step ahead before deleting it ;-) */
82 if (te->m_delete) {
83 delete te;
88 ThreadEntry* ThreadList::threadById(int id)
90 for (Q3ListViewItem* e = firstChild(); e != 0; e = e->nextSibling()) {
91 ThreadEntry* te = static_cast<ThreadEntry*>(e);
92 if (te->id == id) {
93 return te;
96 return 0;
100 * Creates an icon of the same size as the m_focusIcon, but which is
101 * totally transparent.
103 void ThreadList::makeNoFocusIcon()
105 m_noFocusIcon = m_focusIcon;
107 QPainter p(&m_noFocusIcon);
108 p.fillRect(0,0, m_noFocusIcon.width(),m_noFocusIcon.height(), QColor(Qt::white));
110 m_noFocusIcon.setMask(m_noFocusIcon.createHeuristicMask());
113 void ThreadList::slotCurrentChanged(Q3ListViewItem* newItem)
115 if (newItem == 0)
116 return;
118 ThreadEntry* te = static_cast<ThreadEntry*>(newItem);
120 // change the focused thread
121 if (te->hasFocus)
122 return;
124 emit setThread(te->id);
128 #include "threadlist.moc"