You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.4 KiB
C++
52 lines
1.4 KiB
C++
#include "gsterminal.h"
|
|
#include <QTextStream>
|
|
#include <QDir>
|
|
|
|
|
|
GSTerminal::GSTerminal(QWidget *parent) : QPlainTextEdit(parent)
|
|
{
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
|
|
setMinimumHeight(50);
|
|
setMaximumHeight(200);
|
|
|
|
QPalette p = palette();
|
|
p.setColor(QPalette::Base, Qt::black);
|
|
p.setColor(QPalette::Text, Qt::white);
|
|
setPalette(p);
|
|
QFont newFont("Consolas", 10, QFont::Normal, true);
|
|
newFont.setItalic(false);
|
|
setFont(newFont);
|
|
setReadOnly(true);
|
|
int x = 0;
|
|
//QDir::rootPath for open logger <-----------PROBABLY. not tested
|
|
while(QFile::exists(QDir::currentPath() + QString(tr("/log_%1.csv").arg(x))))
|
|
{
|
|
x++;
|
|
}
|
|
logPath = new QFile(QString(QDir::currentPath() + QString(tr("/log_%1.csv").arg(x))), this);
|
|
|
|
|
|
}
|
|
|
|
GSTerminal::~GSTerminal()
|
|
{
|
|
|
|
}
|
|
|
|
void GSTerminal::putData(const QByteArray &data)
|
|
{
|
|
QTextCursor cursor = textCursor();
|
|
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
|
|
setTextCursor(cursor);
|
|
insertPlainText(QString(data));
|
|
QScrollBar* bar = verticalScrollBar();
|
|
//bar->setValue(bar->maximumHeight());
|
|
bar->setSliderDown(true);
|
|
if(logPath->open(QFile::WriteOnly | QFile::Truncate))
|
|
{
|
|
QTextStream stream(logPath);
|
|
stream << toPlainText();
|
|
logPath->close();
|
|
}
|
|
}
|