kb3最终版本
This commit is contained in:
@@ -13,7 +13,7 @@ QString STR2HTML(QString &str)
|
||||
msg.replace("\"",""");
|
||||
msg.replace("\'","'");
|
||||
msg.replace(" "," ");
|
||||
//msg.replace("\n","<br>");
|
||||
msg.replace("\n","<br>");
|
||||
msg.replace("\t"," ");
|
||||
|
||||
return msg;
|
||||
|
||||
@@ -1,383 +0,0 @@
|
||||
#include "tools_Index3.h"
|
||||
#include "ui_tools_Index3.h"
|
||||
|
||||
QString STR2HTML(QString &str)
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg.append(str);
|
||||
|
||||
msg.replace("&","&");
|
||||
msg.replace(">",">");
|
||||
msg.replace("<","<");
|
||||
msg.replace("\"",""");
|
||||
msg.replace("\'","'");
|
||||
msg.replace(" "," ");
|
||||
msg.replace("\n","<br>");
|
||||
msg.replace("\t"," ");
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||
{
|
||||
QString msgstr;
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
msgstr = QString::asprintf(">> Debug: %s \r\n", qPrintable(msg));
|
||||
break;
|
||||
case QtInfoMsg:
|
||||
msgstr = QString::asprintf(">> Info: %s \r\n", qPrintable(msg));
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
msgstr = QString::asprintf(">> Warning: %s \r\n", qPrintable(msg));
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
msgstr = QString::asprintf(">> Critical: %s \r\n", qPrintable(msg));
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
msgstr = QString::asprintf(">> Fatal: %s \r\n", qPrintable(msg));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Tools_Index3::Tools_Index3(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::Tools_Index3)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
m_parent = parent;
|
||||
|
||||
//load qss
|
||||
QFile file(":/qss/Setting.qss");
|
||||
file.open(QFile::ReadOnly);
|
||||
QTextStream filetext(&file);
|
||||
QString stylesheet = filetext.readAll();
|
||||
this->setStyleSheet(stylesheet);
|
||||
file.close();
|
||||
|
||||
//log_te = ui->plainTextEdit;
|
||||
|
||||
//qInstallMessageHandler(myMessageOutput);
|
||||
|
||||
ui->comboBox_EndType->addItem("CRLF","\r\n");
|
||||
ui->comboBox_EndType->addItem("LF","\n");
|
||||
ui->comboBox_EndType->addItem("CR","\r");
|
||||
ui->comboBox_EndType->setCurrentIndex(1);
|
||||
|
||||
}
|
||||
|
||||
Tools_Index3::~Tools_Index3()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void Tools_Index3::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
update();
|
||||
}
|
||||
|
||||
void Tools_Index3::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
setFloat();
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void Tools_Index3::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
/*
|
||||
QMenu *menu = new QMenu(this);
|
||||
|
||||
QAction *pAction = new QAction("float",this);
|
||||
|
||||
connect(pAction,SIGNAL(triggered(bool)),
|
||||
this,SLOT(setFloat()));
|
||||
|
||||
menu->addAction(pAction);
|
||||
menu->move(cursor().pos());
|
||||
menu->show();
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void Tools_Index3::setFloat(void)
|
||||
{
|
||||
if(this->parent())
|
||||
{
|
||||
this->setParent(nullptr);
|
||||
QScreen *screen=QGuiApplication::primaryScreen ();;
|
||||
this->move((screen->availableGeometry().width()-this->width())/2,(screen->availableGeometry().height()-this->height())/2);
|
||||
this->resize(800,480);
|
||||
this->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->setParent(m_parent);
|
||||
|
||||
this->move(0,0);
|
||||
this->hide();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void Tools_Index3::keyPressEvent(QKeyEvent *event) //键盘按下事件
|
||||
{
|
||||
switch(event->key())
|
||||
{
|
||||
case Qt::Key_Return:
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg = ui->lineEdit->text();
|
||||
|
||||
Transmit(msg);
|
||||
}break;
|
||||
case Qt::Key_Up:
|
||||
{
|
||||
if(History.size() > 0)
|
||||
{
|
||||
if(HistoryCount > 0)
|
||||
{
|
||||
HistoryCount --;
|
||||
}
|
||||
|
||||
QString msg;
|
||||
msg = History.at(HistoryCount);
|
||||
ui->lineEdit->setText(msg);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}break;
|
||||
case Qt::Key_Down:
|
||||
{
|
||||
if(History.size() > 0)
|
||||
{
|
||||
if(HistoryCount < History.size())
|
||||
{
|
||||
HistoryCount ++;
|
||||
}
|
||||
|
||||
if(HistoryCount >= History.size())
|
||||
{
|
||||
QString msg = "";
|
||||
ui->lineEdit->setText(msg);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
QString msg;
|
||||
msg = History.at(HistoryCount);
|
||||
ui->lineEdit->setText(msg);
|
||||
}
|
||||
}break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Tools_Index3::wheelEvent(QWheelEvent *event) //键盘按下事件
|
||||
{
|
||||
/*
|
||||
if(ui->lineEdit->)
|
||||
{
|
||||
if(event->angleDelta().y() > 0)
|
||||
{
|
||||
if(History.size() > 0)
|
||||
{
|
||||
if(HistoryCount > 0)
|
||||
{
|
||||
HistoryCount -= qAbs(event->angleDelta().y()/120);
|
||||
}
|
||||
|
||||
QString msg;
|
||||
msg = History.at(HistoryCount);
|
||||
ui->lineEdit->setText(msg);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else if(event->angleDelta().y() < 0)
|
||||
{
|
||||
if(History.size() > 0)
|
||||
{
|
||||
if(HistoryCount < History.size())
|
||||
{
|
||||
HistoryCount += qAbs(event->angleDelta().y()/120);
|
||||
}
|
||||
|
||||
if(HistoryCount >= History.size())
|
||||
{
|
||||
QString msg = "";
|
||||
ui->lineEdit->setText(msg);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
QString msg;
|
||||
msg = History.at(HistoryCount);
|
||||
ui->lineEdit->setText(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void Tools_Index3::Recieve(QString msg)
|
||||
{
|
||||
QString 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\"> << </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\"> << </font>");
|
||||
ui->textBrowser->append(str);
|
||||
str.clear();
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
str.append("<font color=\"#00FFFF\">");
|
||||
str.append(STR2HTML(msg));
|
||||
str.append("</font>");
|
||||
ui->textBrowser->append(str);
|
||||
|
||||
|
||||
QTextCursor cursor = ui->textBrowser->textCursor();
|
||||
cursor.movePosition(QTextCursor::End);
|
||||
ui->textBrowser->setTextCursor(cursor);
|
||||
|
||||
}
|
||||
|
||||
void Tools_Index3::Transmit(QString msg)
|
||||
{
|
||||
if(ui->lineEdit->text().isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
History.append(msg);
|
||||
HistoryCount = History.size();
|
||||
|
||||
msg.append(EndChar);
|
||||
|
||||
//清除时间间隔,保证每次发送出去返回肯定带时间
|
||||
last = 0;
|
||||
|
||||
QString time = QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
|
||||
|
||||
QString str;
|
||||
str.append("<font color=\"#B452CD\">");
|
||||
str.append(time);
|
||||
str.append("</font>");
|
||||
str.append("<font color=\"#FF0000\"> >> </font>");
|
||||
//ui->textBrowser->append(str);
|
||||
|
||||
|
||||
//str.clear();
|
||||
str.append("<font color=\"#FFFF00\">");
|
||||
str.append(msg);
|
||||
str.append("</font>");
|
||||
|
||||
ui->textBrowser->append(str);
|
||||
|
||||
QTextCursor cursor = ui->textBrowser->textCursor();
|
||||
cursor.movePosition(QTextCursor::End);
|
||||
ui->textBrowser->setTextCursor(cursor);
|
||||
|
||||
ui->lineEdit->clear();
|
||||
|
||||
emit Terminal_Transmit(msg);
|
||||
|
||||
|
||||
/*
|
||||
QString s;
|
||||
|
||||
s.append("nihhh\tok\t\t\tuu\tooo\n");
|
||||
s.append("nihhh\tok\tuu\tooo\n");
|
||||
s.append("nihhh\tok\tuu\tooo\n");
|
||||
|
||||
Recieve(s);
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Tools_Index3::on_pushButton_clear_clicked()
|
||||
{
|
||||
ui->lineEdit->clear();
|
||||
}
|
||||
|
||||
void Tools_Index3::on_pushButton_send_clicked()
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg = ui->lineEdit->text();
|
||||
Transmit(msg);
|
||||
}
|
||||
|
||||
void Tools_Index3::on_comboBox_EndType_currentIndexChanged(int index)
|
||||
{
|
||||
EndChar.clear();
|
||||
EndChar.append(ui->comboBox_EndType->currentData().toString());
|
||||
}
|
||||
|
||||
void Tools_Index3::on_pushButton_ClearWindow_clicked()
|
||||
{
|
||||
ui->textBrowser->clear();
|
||||
}
|
||||
|
||||
void Tools_Index3::on_pushButton_Save_clicked()
|
||||
{
|
||||
if(ui->textBrowser->toPlainText().size() > 0)
|
||||
{
|
||||
QFileDialog *dlg = new QFileDialog();
|
||||
QString fileName = dlg->getSaveFileName(this, tr("Selete Path of File..."),
|
||||
"./Tlog/",
|
||||
tr("terminal file (*.terminal)"));
|
||||
if(!fileName.isEmpty())
|
||||
{
|
||||
|
||||
QFile *log_file = nullptr;
|
||||
|
||||
log_file = new QFile(fileName);
|
||||
if(log_file->open(QIODevice::WriteOnly))
|
||||
{
|
||||
log_file->write(ui->textBrowser->toPlainText().toUtf8());
|
||||
|
||||
log_file->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//emit sho
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user