-
Notifications
You must be signed in to change notification settings - Fork 2
/
console.h
81 lines (62 loc) · 1.83 KB
/
console.h
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
73
74
75
76
77
78
79
80
81
/****************************************************************************
**
** Copyright (C) 2015 Benjamin Vernoux
**
****************************************************************************/
#ifndef CONSOLE_H
#define CONSOLE_H
#include <QPlainTextEdit>
#include <QObject>
#include <QElapsedTimer>
QT_BEGIN_NAMESPACE
class QPaintEvent;
class QResizeEvent;
class QSize;
class QWidget;
QT_END_NAMESPACE
class LineNumberArea;
class Console : public QPlainTextEdit
{
Q_OBJECT
signals:
void getData(const QByteArray &data);
public:
Console(QWidget *parent = 0);
void putData(const QByteArray &data);
void setLocalEchoEnabled(bool set);
void setLocalVerticalScrollBarMaxEnabled(bool set);
void lineNumberAreaPaintEvent(QPaintEvent *event);
int lineNumberAreaWidth();
protected:
virtual void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
virtual void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
virtual void mouseDoubleClickEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
virtual void contextMenuEvent(QContextMenuEvent *e) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
private slots:
void updateLineNumberAreaWidth(int newBlockCount);
void highlightCurrentLine();
void updateLineNumberArea(const QRect &, int);
private:
bool localEchoEnabled;
bool localVerticalAutoScrollEnabled;
QWidget *lineNumberArea;
QElapsedTimer t;
};
class LineNumberArea : public QWidget
{
public:
LineNumberArea(Console *editor) : QWidget(editor) {
console = editor;
}
QSize sizeHint() const Q_DECL_OVERRIDE {
return QSize(console->lineNumberAreaWidth(), 0);
}
protected:
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE {
console->lineNumberAreaPaintEvent(event);
}
private:
Console *console;
};
#endif // CONSOLE_H