Source

pynoto / src / Main / Consoles / ApplicationOutput.cpp

Full commit
#include <QDebug>
#include <QScrollBar>
#include "ApplicationOutput.h"
#include "IApplicationOutput.h"

namespace Main {

ApplicationOutput::ApplicationOutput(QWidget *parent) :
    QPlainTextEdit(parent)
{
    _errFmt.setForeground(Qt::red);
    _normFmt.setForeground(Qt::black);

}

void ApplicationOutput::addOutput(const QString& line)
{
    qDebug() << "out" << line;
    _mut.lock();
    //_queue.append(Line(line, 0));
    QTextCursor cursor = textCursor();
    moveCursor(QTextCursor::End);
    cursor.beginEditBlock();
    cursor.insertText(line.endsWith("\n") ? line : line+"\n", _normFmt);
    cursor.endEditBlock();
    //setTextCursor(cursor);
    scrollToBottom();
    _mut.unlock();
}

void ApplicationOutput::addError(const QString& line)
{
    qDebug() << "err" << line;
    _mut.lock();
    //_queue.append(Line(line, 1));
    QTextCursor cursor = textCursor();
    moveCursor(QTextCursor::End);
    cursor.beginEditBlock();
    cursor.insertText(line.endsWith("\n") ? line : line+"\n", _errFmt);
    cursor.endEditBlock();
    //setTextCursor(cursor);
    scrollToBottom();
    _mut.unlock();
}

void ApplicationOutput::scrollToBottom()
{
    verticalScrollBar()->setValue(verticalScrollBar()->maximum());
    verticalScrollBar()->setValue(verticalScrollBar()->maximum());
}

}