src/platform/qt/DebuggerREPL.cpp (view raw)
1/* Copyright (c) 2013-2016 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#include "DebuggerREPL.h"
7
8#include "DebuggerREPLController.h"
9
10#include <QScrollBar>
11
12using namespace QGBA;
13
14DebuggerREPL::DebuggerREPL(DebuggerREPLController* controller, QWidget* parent)
15 : QWidget(parent)
16 , m_replController(controller)
17{
18 m_ui.setupUi(this);
19
20 connect(m_ui.prompt, SIGNAL(returnPressed()), this, SLOT(postLine()));
21 connect(controller, SIGNAL(log(const QString&)), this, SLOT(log(const QString&)));
22 connect(m_ui.breakpoint, SIGNAL(clicked()), controller, SLOT(breakInto()));
23
24 controller->attach();
25}
26
27void DebuggerREPL::log(const QString& line) {
28 m_ui.log->moveCursor(QTextCursor::End);
29 m_ui.log->insertPlainText(line);
30 m_ui.log->verticalScrollBar()->setValue(m_ui.log->verticalScrollBar()->maximum());
31}
32
33void DebuggerREPL::postLine() {
34 QString line = m_ui.prompt->text();
35 m_ui.prompt->clear();
36 if (line.isEmpty()) {
37 m_replController->enterLine(QString("\n"));
38 } else {
39 log(QString("> %1\n").arg(line));
40 m_replController->enterLine(line);
41 }
42}