src/platform/qt/DebuggerConsole.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 "DebuggerConsole.h"
7
8#include "DebuggerConsoleController.h"
9
10#include <QScrollBar>
11
12using namespace QGBA;
13
14DebuggerConsole::DebuggerConsole(DebuggerConsoleController* controller, QWidget* parent)
15 : QWidget(parent)
16 , m_consoleController(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(attach()));
23 connect(m_ui.breakpoint, SIGNAL(clicked()), controller, SLOT(breakInto()));
24}
25
26void DebuggerConsole::log(const QString& line) {
27 m_ui.log->moveCursor(QTextCursor::End);
28 m_ui.log->insertPlainText(line);
29 m_ui.log->verticalScrollBar()->setValue(m_ui.log->verticalScrollBar()->maximum());
30}
31
32void DebuggerConsole::postLine() {
33 m_consoleController->attach();
34 QString line = m_ui.prompt->text();
35 m_ui.prompt->clear();
36 if (line.isEmpty()) {
37 m_consoleController->enterLine(QString("\n"));
38 } else {
39 log(QString("> %1\n").arg(line));
40 m_consoleController->enterLine(line);
41 }
42}