-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansiwidget.h
120 lines (107 loc) · 3.1 KB
/
ansiwidget.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef ANSIWIDGET_H
#define ANSIWIDGET_H
#include "common.h"
#include <QObject>
#include <QWidget>
#include <QTimer>
#include <QRubberBand>
class AnsiWidget : public QWidget
{
Q_OBJECT
public:
explicit AnsiWidget(QWidget *parent = nullptr);
~AnsiWidget();
void parseTxt(char *str);
void clear();
uint getRows() const;
uint getCols() const;
uint getHa() const;
uint getPadding() const;
uint getFontsize() const;
uint getInterline() const;
bool saveFile(QString filename);
bool applicateUnDo();
QString getSelection(bool cut=false);
void ansiPaste();
bool getShw2J() const;
void setShw2J(bool newShw2J);
bool removeLine();
int getCsrow() const;
int getCscol() const;
protected:
void paintEvent(QPaintEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
private:
int rows = 80;
int cols = 80;
int ha = 9;
int padding = 4;
QString fontname = "Hack";
int fontsize = 12;
int interline = (fontsize/3) < 4 ? 4 : fontsize/3;
char *buf=nullptr;
char *attrs=nullptr;
QColor colors[17] = {
// 8 normal Colors
QColor(0, 0, 0), // Black
QColor(170, 0, 0), // Red
QColor(0, 170, 0), // Green
QColor(170, 85, 0), // Yellow
QColor(0, 0, 170), // Blue
QColor(170, 0, 170), // Magenta
QColor(0, 170, 170), // Cyan
QColor(178, 178, 178), // light gray
// 8 bright colors
QColor(85, 85, 85), // Dark Gray
QColor(255, 85, 85), // Bright Red
QColor(85, 255, 85), // Bright Green
QColor(255, 255, 85), // Bright Yellow
QColor(85, 85, 255), // Bright Blue
QColor(255, 85, 255), // Bright Magenta
QColor(85, 255, 255), // Bright Cyan
QColor(255, 255, 255), // white
QColor(255, 255, 255,150) // cursor
};
QString lastclip="";
QString esc = QChar(27);
QString csi = esc + "[";
QStringList cmds={"H", "A", "B", "C", "D", "E", "F", "G", "J", "K", "f", "m", "s", "u"};
int riga=0, sriga=0;
int colo=0, scolo=0;
uint fg=7, bg=0;
bool bright=false, blink=false, blinkst=false, blinkwrt=false;
QTimer *timer1=nullptr;
QByteArray StoQ(QString txt);
int csrow=0, cscol=0;
bool eventFilter(QObject *obj, QEvent *event) override;
struct _unDo{
int offs;
uint8_t txtval;
uint8_t attrsval;
uint16_t op;
};
QList<_unDo> unDo;
int unDoPtr = 0;
QRubberBand *rubber=nullptr;
int cfin=0, rfin=0;
struct _paste {
QByteArray pastetxt;
QByteArray pasteattrs;
};
struct _paste paste;
bool shw2J=true;
public slots:
void charClick(int val);
private slots:
void timer1timeout();
void cbBlinkChanged(int state);
void applyAttrs();
signals:
void csrRowChanged(int csrow);
void documentModified();
void attrsPicked(int at);
void repaintDone();
};
#endif // ANSIWIDGET_H