-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.cpp
41 lines (37 loc) · 1.38 KB
/
console.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "console.h"
#include <QFont>
#include <QKeyEvent>
#include <QPalette>
#include <QTextCursor>
#include <QTextLine>
Console::Console(QWidget *parent) : QTextEdit(parent) {
this->setStyleSheet(QString("background-color:black"));
this->setTextBackgroundColor(QColor(QString("black")));
this->setTextColor(QColor(QString("lightgreen")));
QFont font("Consolas", 10, 70);
this->setFont(QFont(font));
}
void Console::keyPressEvent(QKeyEvent *event) {
this->setTextColor(QColor(QString("white")));
if (event->key() == Qt::Key_Backspace) this->textCursor().clearSelection();
if (event->key() == Qt::Key_Delete) {
QTextCursor cursor = this->textCursor();
cursor.movePosition(QTextCursor::End);
cursor.select(QTextCursor::LineUnderCursor);
cursor.removeSelectedText();
}
if (this->textCursor().hasSelection()) return;
if (event->key() == Qt::Key_Return) {
QTextCursor cursor = this->textCursor();
cursor.movePosition(QTextCursor::End);
cursor.select(QTextCursor::LineUnderCursor);
QString lastLine = cursor.selectedText();
emit newLineWritten(lastLine);
}
QTextEdit::keyPressEvent(event);
}
void Console::write(QString msg) {
this->setTextColor(QColor(QString("lightgreen")));
this->append(msg);
}
void Console::inputWaitFunction(QString msg) { this->write("input " + msg); }