修正终端

This commit is contained in:
hm
2020-12-18 16:40:49 +08:00
parent c14ceda341
commit 00b5369004
3 changed files with 82 additions and 37 deletions
+74 -35
View File
@@ -1,7 +1,7 @@
#include "tools_Index3.h"
#include "ui_tools_Index3.h"
QString STR2HTML(QString &str)
QString STR2HTML(QByteArray &str)
{
QString msg;
@@ -13,8 +13,8 @@ QString STR2HTML(QString &str)
msg.replace("\"",""");
msg.replace("\'","'");
msg.replace(" "," ");
msg.replace("\n","<br>");
msg.replace("\t","&nbsp;&nbsp;&nbsp;");
//msg.replace("\n","<br />");
msg.replace("\t","&nbsp;");
return msg;
}
@@ -61,6 +61,13 @@ Tools_Index3::Tools_Index3(QWidget *parent) :
this->setStyleSheet(stylesheet);
file.close();
timer = new QTimer();
timer->setInterval(1000);
connect(timer,&QTimer::timeout,
this,&Tools_Index3::timerout);
//log_te = ui->plainTextEdit;
//qInstallMessageHandler(myMessageOutput);
@@ -182,6 +189,15 @@ void Tools_Index3::keyPressEvent(QKeyEvent *event) //键盘按下事件
}
void Tools_Index3::timerout()
{
if(msgdata.size() > 0)
{
ui->textBrowser->append(msgdata);
msgdata.clear();
timer->stop();
}
}
void Tools_Index3::wheelEvent(QWheelEvent *event) //键盘按下事件
{
@@ -233,47 +249,66 @@ void Tools_Index3::wheelEvent(QWheelEvent *event) //键盘按下事件
void Tools_Index3::Recieve(QString msg)
{
QString str;
msgdata.append(msg);
if((QDateTime::currentMSecsSinceEpoch() - last) > 5000)
{
str.clear();
QString time = QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
str.append("<font color=\"#B452CD\">");
str.append(time);
str.append("</font>");
str.append("<font color=\"#00FF00\"> &lt;&lt; </font>");
ui->textBrowser->append(str);
str.clear();
}
last = QDateTime::currentMSecsSinceEpoch();
while (!msgdata.isEmpty()) {
if(!msgdata.contains("\n"))
{
return;
}
bool newline = false;
int idx = msgdata.indexOf('\n');
if (idx == -1) {
// Read the whole incoming buffer
idx = msgdata.size();
} else {
newline = true;
}
QByteArray fragment = msgdata.mid(0, idx);
msgdata.remove(0, idx + (newline ? 1 : 0));
QByteArray str;
if((QDateTime::currentMSecsSinceEpoch() - last) > 5000)
{
str.clear();
QString time = QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
str.append("<font color=\"#B452CD\">");
str.append(time);
str.append("</font>");
str.append("<font color=\"#00FF00\"> &lt;&lt; </font>");
ui->textBrowser->append(str);
str.clear();
}
last = QDateTime::currentMSecsSinceEpoch();
/*
QString time = QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
str.append("<font color=\"#B452CD\">");
str.append(time);
str.append("</font>");
str.append("<font color=\"#00FF00\"> &lt;&lt; </font>");
ui->textBrowser->append(str);
str.clear();
*/
str.append("<font color=\"#00FFFF\">");
str.append(STR2HTML(fragment));
//str.append(fragment);
str.append("</font>");
str.append("<font color=\"#00FFFF\">");
str.append(STR2HTML(msg));
str.append("</font>");
ui->textBrowser->append(str);
/*
str.append(fragment);
*/
ui->textBrowser->append(str);
QTextCursor cursor = ui->textBrowser->textCursor();
cursor.movePosition(QTextCursor::End);
ui->textBrowser->setTextCursor(cursor);
QTextCursor cursor = ui->textBrowser->textCursor();
cursor.movePosition(QTextCursor::End);
ui->textBrowser->setTextCursor(cursor);
}
}
void Tools_Index3::Transmit(QString msg)
@@ -320,14 +355,18 @@ void Tools_Index3::Transmit(QString msg)
/*
QString s;
s.append("nihhh\tok\t\t\tuu\tooo\n");
s.append("nihhh\tok\t\t\tuu\tooo\r\n");
s.append("nihhh\tok\tuu\tooo\n");
s.append("nihhh\tok\tuu\tooo\n");
s.append("nihhh ok uu ooo\n");
s.append("nihhh\tok\tuu\tooo");
s.append("nihhh\tok\tuu\tooo\n");
Recieve(s);
*/
}
void Tools_Index3::on_pushButton_clear_clicked()
+7 -1
View File
@@ -16,7 +16,7 @@
#include "QTextCursor"
#include "QWheelEvent"
#include "QTimer"
#include "QFile"
#include "QFileDialog"
#include "QDataStream"
@@ -54,6 +54,9 @@ protected:
void keyPressEvent(QKeyEvent *event);
private slots:
void timerout();
void on_pushButton_clear_clicked();
void on_pushButton_send_clicked();
@@ -77,6 +80,9 @@ private:
qint64 last;
QByteArray msgdata;
QTimer *timer = nullptr;
};
+1 -1
View File
@@ -29,7 +29,7 @@ VS_VERSION_INFO VERSIONINFO
VALUE "FileDescription", "UAV Ground Control System\0"
VALUE "FileVersion", "1.0.0.0\0"
VALUE "ProductVersion", "0.0.0.1\0"
VALUE "LegalCopyright", "Copyright © 2020 by HM - All Rights Reserved\0"
VALUE "LegalCopyright", "Copyright &copy; 2020 by HM - All Rights Reserved\0"
VALUE "LegalTrademarks", "xxx\0"
VALUE "OriginalFilename", "gcs_nf.exe\0"
VALUE "ProductName", "GCS\0"