Repository navigation
Expand file tree
/
Copy pathterminal.cpp
More file actions
146 lines (127 loc) · 3.5 KB
/
Copy pathterminal.cpp
File metadata and controls
146 lines (127 loc) · 3.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "terminal.h"
#include "properties.h"
#include "qextserialport.h"
Terminal::Terminal(QWidget *parent) : QDialog(parent)
{
QSettings settings(publisherKey, PropellerIdeGuiKey);
QVariant echov = settings.value(terminalEchoOn,true);
QVBoxLayout *termLayout = new QVBoxLayout(this);
termLayout->setContentsMargins(4,4,4,4);
termEditor = new Console(parent);
termEditor->setReadOnly(false);
//connect(this, SIGNAL(accepted()), this, SLOT(keyPressEvent(QKeyEvent *)));
termLayout->addWidget(termEditor);
QPushButton *cls = new QPushButton(tr("Clear"),this);
connect(cls,SIGNAL(clicked()), this, SLOT(clearScreen()));
echoOnBox.setText("Echo On");
echoOnBox.setCheckable(true);
echoOnBox.setChecked(echov.toBool());
connect(&echoOnBox, SIGNAL(clicked()), this, SLOT(echoClicked()));
portLabel.setMargin(2);
portLabel.setStyleSheet("QLabel { background-color: white; }");
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
QHBoxLayout *butLayout = new QHBoxLayout();
termLayout->addLayout(butLayout);
butLayout->addWidget(cls);
butLayout->addWidget(&echoOnBox);
butLayout->addWidget(&portLabel);
butLayout->addWidget(buttonBox);
setLayout(termLayout);
this->setWindowFlags(Qt::Tool);
portListener = NULL;
resize(700,500);
}
Console *Terminal::getEditor()
{
return termEditor;
}
void Terminal::setPortListener(PortListener *listener)
{
portListener = listener;
QextSerialPort *port = listener->getPort();
if(port) {
if(port->portName().isEmpty() == false)
portLabel.setText(port->portName());
}
else {
portLabel.setText("");
}
}
QString Terminal::getPortName()
{
return portLabel.text();
}
void Terminal::setPortName(QString name)
{
portLabel.setText(name);
}
void Terminal::setPosition(int x, int y)
{
int width = this->width();
int height = this->height();
this->setGeometry(x,y,width,height);
}
void Terminal::accept()
{
/*
QString text = termEditor->toPlainText();
QStringList list = text.split("\n");
*/
done(QDialog::Accepted);
}
void Terminal::reject()
{
done(QDialog::Rejected);
}
void Terminal::clearScreen()
{
termEditor->setPlainText("");
}
void Terminal::echoClicked()
{
QSettings settings(publisherKey, PropellerIdeGuiKey);
settings.setValue(terminalEchoOn,this->echoOnBox.isChecked());
}
void Terminal::print(QByteArray str)
{
QString text;
QTextCursor cur;
int size = str.length();
char *buff = str.data();
if(!echoOnBox.isChecked())
return;
for(int n = 0; n < size; n++) {
cur = termEditor->textCursor();
cur.movePosition(QTextCursor::End,QTextCursor::MoveAnchor);
text = termEditor->toPlainText();
int tlen = text.length();
if(!isprint(buff[n]))
continue;
switch(buff[n]) {
case '\b':
termEditor->setPlainText(text.mid(0,tlen-1));
break;
case '\r':
cur.insertText("\n");
break;
default:
cur.insertText(QString(str.at(n)));
break;
}
termEditor->setTextCursor(cur);
}
}
void Terminal::copyFromFile()
{
termEditor->copy();
}
void Terminal::cutFromFile()
{
termEditor->cut();
}
void Terminal::pasteToFile()
{
termEditor->paste();
}