File: threadlist.cpp

package info (click to toggle)
kdbg 1.2.4-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,504 kB
  • ctags: 1,945
  • sloc: cpp: 15,961; sh: 8,183; makefile: 481; perl: 71; ansic: 16
file content (135 lines) | stat: -rw-r--r-- 3,110 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// $Id: threadlist.cpp,v 1.1.2.1 2001/12/29 20:12:16 jsixt Exp $

// Copyright by Johannes Sixt
// This file is under GPL, the GNU General Public Licence

#include "threadlist.h"
#include "dbgdriver.h"
#if QT_VERSION < 200
#include <kapp.h>
#else
#include <klocale.h>
#endif
#include <kiconloader.h>
#include <qbitmap.h>
#include <qpainter.h>


class ThreadEntry : public QListViewItem, public ThreadInfo
{
public:
    ThreadEntry(QListView* parent, ThreadInfo* thread);
    void setFunction(const QString& func);

    bool m_delete;			/* used for updating the list */
};

ThreadEntry::ThreadEntry(QListView* parent, ThreadInfo* thread) :
	QListViewItem(parent, thread->threadName, thread->function),
	ThreadInfo(*thread),
	m_delete(false)
{
}

void ThreadEntry::setFunction(const QString& func)
{
    function = func;
    setText(1, function);
}


ThreadList::ThreadList(QWidget* parent, const char* name) :
	QListView(parent, name)
{
    addColumn(i18n("Thread ID"), 150);
    addColumn(i18n("Location"));

    // load pixmaps
#if QT_VERSION < 200
    KIconLoader* loader = kapp->getIconLoader();
    m_focusIcon = loader->loadIcon("pcinner.xpm");
#else
    m_focusIcon = BarIcon("pcinner");
#endif
    makeNoFocusIcon();

    connect(this, SIGNAL(currentChanged(QListViewItem*)),
	    this, SLOT(slotCurrentChanged(QListViewItem*)));
}

ThreadList::~ThreadList()
{
}

void ThreadList::updateThreads(QList<ThreadInfo>& threads)
{
    // reset flag in all items
    for (QListViewItem* e = firstChild(); e != 0; e = e->nextSibling()) {
	static_cast<ThreadEntry*>(e)->m_delete = true;
    }

    for (ThreadInfo* i = threads.first(); i != 0; i = threads.next()) {
	// look up this thread by id
	ThreadEntry* te = threadById(i->id);
	if (te == 0) {
	    te = new ThreadEntry(this, i);
	} else {
	    te->m_delete = false;
	    te->setFunction(i->function);
	}
	// set focus icon
	te->hasFocus = i->hasFocus;
	te->setPixmap(0, i->hasFocus  ?  m_focusIcon  :  m_noFocusIcon);
    }

    // delete all entries that have not been seen
    for (QListViewItem* e = firstChild(); e != 0;) {
	ThreadEntry* te = static_cast<ThreadEntry*>(e);
	e = e->nextSibling();		/* step ahead before deleting it ;-) */
	if (te->m_delete) {
	    delete te;
	}
    }
}

ThreadEntry* ThreadList::threadById(int id)
{
    for (QListViewItem* e = firstChild(); e != 0; e = e->nextSibling()) {
	ThreadEntry* te = static_cast<ThreadEntry*>(e);
	if (te->id == id) {
	    return te;
	}
    }
    return 0;
}

/*
 * Creates an icon of the same size as the m_focusIcon, but which is
 * totally transparent.
 */
void ThreadList::makeNoFocusIcon()
{
    m_noFocusIcon = m_focusIcon;
    {
	QPainter p(&m_noFocusIcon);
	p.fillRect(0,0, m_noFocusIcon.width(),m_noFocusIcon.height(), QColor(white));
    }
    m_noFocusIcon.setMask(m_noFocusIcon.createHeuristicMask());
}

void ThreadList::slotCurrentChanged(QListViewItem* newItem)
{
    if (newItem == 0)
	return;

    ThreadEntry* te = static_cast<ThreadEntry*>(newItem);

    // change the focused thread
    if (te->hasFocus)
	return;

    emit setThread(te->id);
}


#include "threadlist.moc"