-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommandWidget.h
63 lines (46 loc) · 1.18 KB
/
CommandWidget.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
#ifndef OSMA_BACOMMANDWIDGET_H
#define OSMA_BACOMMANDWIDGET_H
#include <QTextEdit>
#include <QKeyEvent>
#include <QFont>
#include <QProcess>
#include <QByteArray>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QTextLayout>
#include <QTextCursor>
#include <QTextBlock>
namespace BACommand {
enum Types {
STANDARDMSG,
ERRORMSG,
};
}
class CommandWidget : public QTextEdit {
Q_OBJECT
public:
explicit CommandWidget(QWidget *parent = nullptr);
void setPrefix(const QString &pre);
void initView();
protected:
void keyPressEvent(QKeyEvent *e) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseDoubleClickEvent(QMouseEvent *event) override;
private:
// 字体
QFont font;
// 光标位置
qint64 lastPosition = 0;
// 上一次的输入内容
QByteArray lastInput;
//输出前缀
QString prefix;
void writeToTextEdit(const QString &str, Qt::GlobalColor c);
public slots:
void readMessage(const QString& str, BACommand::Types type);
signals:
void message(QString msg);
};
#endif//OSMA_BACOMMANDWIDGET_H