diff --git a/src/platform/qt/LogView.cpp b/src/platform/qt/LogView.cpp index 1f2d0702b..deb999ec4 100644 --- a/src/platform/qt/LogView.cpp +++ b/src/platform/qt/LogView.cpp @@ -1,5 +1,8 @@ #include "LogView.h" +#include +#include + using namespace QGBA; LogView::LogView(QWidget* parent) @@ -13,7 +16,9 @@ LogView::LogView(QWidget* parent) connect(m_ui.levelError, SIGNAL(toggled(bool)), this, SLOT(setLevelError(bool))); connect(m_ui.levelFatal, SIGNAL(toggled(bool)), this, SLOT(setLevelFatal(bool))); connect(m_ui.levelGameError, SIGNAL(toggled(bool)), this, SLOT(setLevelGameError(bool))); - m_logLevel = -1; + connect(m_ui.clear, SIGNAL(clicked()), this, SLOT(clear())); + m_logLevel = GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL; + m_lines = 0; } void LogView::postLog(int level, const QString& log) { @@ -21,6 +26,10 @@ void LogView::postLog(int level, const QString& log) { return; } m_ui.view->appendPlainText(QString("%1:\t%2").arg(toString(level)).arg(log)); + ++m_lines; + if (m_lines > LINE_LIMIT) { + clearLine(); + } } void LogView::clear() { @@ -96,3 +105,12 @@ QString LogView::toString(int level) { } return QString(); } + +void LogView::clearLine() { + QTextCursor cursor(m_ui.view->document()); + cursor.setPosition(0); + cursor.select(QTextCursor::BlockUnderCursor); + cursor.removeSelectedText(); + cursor.deleteChar(); + --m_lines; +} diff --git a/src/platform/qt/LogView.h b/src/platform/qt/LogView.h index 6bbf24d23..2d366396c 100644 --- a/src/platform/qt/LogView.h +++ b/src/platform/qt/LogView.h @@ -31,12 +31,17 @@ private slots: void setLevelGameError(bool); private: + static const int LINE_LIMIT = 1000; + Ui::LogView m_ui; int m_logLevel; + int m_lines; static QString toString(int level); void setLevel(int level) { m_logLevel |= level; } void clearLevel(int level) { m_logLevel &= ~level; } + + void clearLine(); }; } diff --git a/src/platform/qt/LogView.ui b/src/platform/qt/LogView.ui index ee3d31875..703bb75fd 100644 --- a/src/platform/qt/LogView.ui +++ b/src/platform/qt/LogView.ui @@ -28,7 +28,7 @@ Debug - true + false @@ -38,7 +38,7 @@ Stub - true + false @@ -48,7 +48,7 @@ Info - true + false @@ -104,7 +104,7 @@ Game Error - true + false @@ -143,22 +143,5 @@ - - - clear - clicked() - view - clear() - - - 98 - 376 - - - 299 - 311 - - - - +