Fix presentation of floating point registers.
[kdbg.git] / kdbg / watchwindow.cpp
blob014bda5f514500382d854af832fa4acaa084cdd3
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 "watchwindow.h"
8 #include <klocale.h> /* i18n */
9 #include <QDragEnterEvent>
10 #include <QDropEvent>
11 #include <QKeyEvent>
12 #include <QMimeData>
14 WatchWindow::WatchWindow(QWidget* parent) :
15 QWidget(parent),
16 m_watchEdit(this),
17 m_watchAdd(i18n(" Add "), this),
18 m_watchDelete(i18n(" Del "), this),
19 m_watchVariables(this, i18n("Expression")),
20 m_watchV(this),
21 m_watchH()
23 // setup the layout
24 m_watchAdd.setMinimumSize(m_watchAdd.sizeHint());
25 m_watchDelete.setMinimumSize(m_watchDelete.sizeHint());
26 m_watchV.setMargin(0);
27 m_watchV.setSpacing(0);
28 m_watchH.setMargin(0);
29 m_watchH.setSpacing(0);
30 m_watchV.addLayout(&m_watchH);
31 m_watchV.addWidget(&m_watchVariables);
32 m_watchH.addWidget(&m_watchEdit);
33 m_watchH.addWidget(&m_watchAdd);
34 m_watchH.addWidget(&m_watchDelete);
36 connect(&m_watchEdit, SIGNAL(returnPressed()), SIGNAL(addWatch()));
37 connect(&m_watchAdd, SIGNAL(clicked()), SIGNAL(addWatch()));
38 connect(&m_watchDelete, SIGNAL(clicked()), SIGNAL(deleteWatch()));
39 connect(&m_watchVariables, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
40 SLOT(slotWatchHighlighted()));
42 m_watchVariables.installEventFilter(this);
43 setAcceptDrops(true);
46 WatchWindow::~WatchWindow()
50 bool WatchWindow::eventFilter(QObject*, QEvent* ev)
52 if (ev->type() == QEvent::KeyPress)
54 QKeyEvent* kev = static_cast<QKeyEvent*>(ev);
55 if (kev->key() == Qt::Key_Delete) {
56 emit deleteWatch();
57 return true;
60 return false;
63 void WatchWindow::dragEnterEvent(QDragEnterEvent* event)
65 if (event->mimeData()->hasText())
66 event->acceptProposedAction();
69 void WatchWindow::dropEvent(QDropEvent* event)
71 if (event->mimeData()->hasText()) {
72 QString text = event->mimeData()->text();
73 // pick only the first line
74 text = text.trimmed();
75 int pos = text.indexOf('\n');
76 if (pos > 0)
77 text.truncate(pos);
78 text = text.trimmed();
79 if (!text.isEmpty())
80 emit textDropped(text);
82 event->acceptProposedAction();
86 // place the text of the hightlighted watch expr in the edit field
87 void WatchWindow::slotWatchHighlighted()
89 VarTree* expr = m_watchVariables.selectedItem();
90 QString text = expr ? expr->computeExpr() : QString();
91 m_watchEdit.setText(text);
94 #include "watchwindow.moc"