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.
7 #include "watchwindow.h"
8 #include <klocale.h> /* i18n */
9 #include <QDragEnterEvent>
14 WatchWindow::WatchWindow(QWidget
* parent
) :
17 m_watchAdd(i18n(" Add "), this),
18 m_watchDelete(i18n(" Del "), this),
19 m_watchVariables(this, i18n("Expression")),
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);
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
) {
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');
78 text
= text
.trimmed();
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"