-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.cpp
More file actions
72 lines (63 loc) · 1.5 KB
/
console.cpp
File metadata and controls
72 lines (63 loc) · 1.5 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/****************************************************************************
**
** Copyright (C) 2018 Ivan Fesyuk
** Contact: https://eneus.github.io/
** https://github.com/eneus/
**
**
** $QT_BEGIN_LICENSE:BSD$
** MIT License Usage
**
****************************************************************************/
#include "console.h"
#include <QScrollBar>
#include <QDebug>
Console::Console(QWidget *parent) :
QPlainTextEdit(parent)
{
document()->setMaximumBlockCount(100);
QPalette p = palette();
p.setColor(QPalette::Base, Qt::black);
p.setColor(QPalette::Text, Qt::green);
setPalette(p);
}
void Console::putData(const QByteArray &data)
{
// insertPlainText("data:" + data + "\n");
insertPlainText(QString(data.toHex()) + "\n");
qDebug() << "Value: " << data;
QScrollBar *bar = verticalScrollBar();
bar->setValue(bar->maximum());
}
void Console::setLocalEchoEnabled(bool set)
{
m_localEchoEnabled = set;
}
void Console::keyPressEvent(QKeyEvent *e)
{
switch (e->key()) {
case Qt::Key_Backspace:
case Qt::Key_Left:
case Qt::Key_Right:
case Qt::Key_Up:
case Qt::Key_Down:
break;
default:
if (m_localEchoEnabled)
QPlainTextEdit::keyPressEvent(e);
emit getData(e->text().toLocal8Bit());
}
}
void Console::mousePressEvent(QMouseEvent *e)
{
Q_UNUSED(e)
setFocus();
}
void Console::mouseDoubleClickEvent(QMouseEvent *e)
{
Q_UNUSED(e)
}
void Console::contextMenuEvent(QContextMenuEvent *e)
{
Q_UNUSED(e)
}