mirror of https://github.com/mgba-emu/mgba.git
Qt: Refactor out log widget
This commit is contained in:
parent
86f7acbbb9
commit
ab3cd84ed4
|
@ -109,6 +109,7 @@ set(SOURCE_FILES
|
|||
LogController.cpp
|
||||
LogConfigModel.cpp
|
||||
LogView.cpp
|
||||
LogWidget.cpp
|
||||
MapView.cpp
|
||||
MemoryDump.cpp
|
||||
MemoryModel.cpp
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "DebuggerConsoleController.h"
|
||||
#include "GBAApp.h"
|
||||
|
||||
#include <QScrollBar>
|
||||
#include <QKeyEvent>
|
||||
|
||||
using namespace QGBA;
|
||||
|
||||
|
@ -19,23 +19,16 @@ DebuggerConsole::DebuggerConsole(DebuggerConsoleController* controller, QWidget*
|
|||
m_ui.setupUi(this);
|
||||
|
||||
m_ui.prompt->installEventFilter(this);
|
||||
m_ui.log->setFont(GBAApp::app()->monospaceFont());
|
||||
m_ui.prompt->setFont(GBAApp::app()->monospaceFont());
|
||||
|
||||
connect(m_ui.prompt, &QLineEdit::returnPressed, this, &DebuggerConsole::postLine);
|
||||
connect(controller, &DebuggerConsoleController::log, this, &DebuggerConsole::log);
|
||||
connect(controller, &DebuggerConsoleController::log, m_ui.log, &LogWidget::log);
|
||||
connect(m_ui.breakpoint, &QAbstractButton::clicked, controller, &DebuggerController::attach);
|
||||
connect(m_ui.breakpoint, &QAbstractButton::clicked, controller, &DebuggerController::breakInto);
|
||||
|
||||
controller->historyLoad();
|
||||
}
|
||||
|
||||
void DebuggerConsole::log(const QString& line) {
|
||||
m_ui.log->moveCursor(QTextCursor::End);
|
||||
m_ui.log->insertPlainText(line);
|
||||
m_ui.log->verticalScrollBar()->setValue(m_ui.log->verticalScrollBar()->maximum());
|
||||
}
|
||||
|
||||
void DebuggerConsole::postLine() {
|
||||
m_consoleController->attach();
|
||||
QString line = m_ui.prompt->text();
|
||||
|
@ -44,7 +37,7 @@ void DebuggerConsole::postLine() {
|
|||
m_consoleController->enterLine(QString("\n"));
|
||||
} else {
|
||||
m_historyOffset = 0;
|
||||
log(QString("> %1\n").arg(line));
|
||||
m_ui.log->log(QString("> %1\n").arg(line));
|
||||
m_consoleController->enterLine(line);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ public:
|
|||
DebuggerConsole(DebuggerConsoleController* controller, QWidget* parent = nullptr);
|
||||
|
||||
private slots:
|
||||
void log(const QString&);
|
||||
void postLine();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QPlainTextEdit" name="log">
|
||||
<widget class="QGBA::LogWidget" name="log">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
|
@ -37,6 +37,13 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QGBA::LogWidget</class>
|
||||
<extends>QPlainTextEdit</extends>
|
||||
<header>LogWidget.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/* Copyright (c) 2013-2022 Jeffrey Pfau
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
#include "LogWidget.h"
|
||||
|
||||
#include "GBAApp.h"
|
||||
|
||||
#include <QScrollBar>
|
||||
|
||||
using namespace QGBA;
|
||||
|
||||
LogWidget::LogWidget(QWidget* parent)
|
||||
: QTextEdit(parent)
|
||||
{
|
||||
setFont(GBAApp::app()->monospaceFont());
|
||||
}
|
||||
|
||||
void LogWidget::log(const QString& line) {
|
||||
moveCursor(QTextCursor::End);
|
||||
insertPlainText(line);
|
||||
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/* Copyright (c) 2013-2022 Jeffrey Pfau
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
#pragma once
|
||||
|
||||
#include <QTextEdit>
|
||||
|
||||
namespace QGBA {
|
||||
|
||||
class LogWidget : public QTextEdit {
|
||||
public:
|
||||
LogWidget(QWidget* parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void log(const QString&);
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue