1397 lines
48 KiB
C++
1397 lines
48 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
, dlink(new DLink)
|
|
, savethread(new SaveThread)
|
|
, playthread(new PlayThread)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
//导入界面样式
|
|
QFile file(":/qss/Record.qss");
|
|
file.open(QFile::ReadOnly);
|
|
QTextStream filetext(&file);
|
|
QString stylesheet = filetext.readAll();
|
|
//this->setStyleSheet(stylesheet);
|
|
file.close();
|
|
|
|
setWindowIcon(QIcon(":/img/Dark/Logo.png"));
|
|
|
|
qDebug() << "MainThread:" << QThread::currentThreadId();
|
|
|
|
|
|
|
|
//设置语言
|
|
bool langflag = false;
|
|
language = Config::getSetting("lang",&langflag).toString();
|
|
if(langflag == true)
|
|
{
|
|
qDebug() << "language" << language;
|
|
}
|
|
else
|
|
{
|
|
Config::insertSetting("lang","CN");
|
|
qDebug() << "language" << language;
|
|
}
|
|
|
|
|
|
|
|
//设置表题
|
|
bool titleflag = false;
|
|
QString title = Config::getSetting("title",&titleflag).toString();
|
|
if(titleflag == true)
|
|
{
|
|
setWindowTitle(title);
|
|
}
|
|
else
|
|
{
|
|
Config::insertSetting("title","网络监控记录工具");
|
|
setWindowTitle("网络监控记录工具");
|
|
}
|
|
|
|
|
|
|
|
//设置数据连接在另外一个线程
|
|
connect(dlink,&DLink::showMessage,this,&MainWindow::showMessage);
|
|
|
|
//connect(dlink,&DLink::recieve,savethread,&SaveThread::setSave);
|
|
|
|
dlink->moveToThread(&dlink_thread);
|
|
dlink_thread.start();
|
|
dlink_thread.setPriority(QThread::TimeCriticalPriority);
|
|
|
|
//设置存储在另外一个线程
|
|
savethread->moveToThread(&save_thread);
|
|
|
|
// operate 信号发射后启动线程工作
|
|
connect(dlink,&DLink::recieve,savethread,&SaveThread::setSave);
|
|
// 启动线程
|
|
save_thread.start();
|
|
save_thread.setPriority(QThread::TimeCriticalPriority);
|
|
|
|
|
|
//读取配置
|
|
mode = Config::getSetting("mode").toBool();
|
|
|
|
savethread->setMode(mode);
|
|
|
|
|
|
//上来就是记录界面
|
|
ui->tabWidget->setCurrentIndex(0);
|
|
//读取设置
|
|
sockets = Config::getConnet();
|
|
|
|
//设置过滤器
|
|
ui->lineEdit_Port->setValidator(new QIntValidator(0,65535));
|
|
|
|
//QRegExp regExpIP("((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])[\\.]){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])");
|
|
//设置IP输入校验
|
|
//ui->lineEdit_Addr->setValidator(new QRegExpValidator(regExpIP ,ui->lineEdit_Addr));
|
|
|
|
//时间撮标签
|
|
timestamplb = new QLabel(QDateTime::currentDateTimeUtc().toString("yyyy/MM/dd.hh:mm:ss.zzz"));
|
|
|
|
timestamplb->resize(300,80);
|
|
|
|
timestamplb->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
|
|
|
ui->statusbar->addPermanentWidget(timestamplb);
|
|
|
|
timestamplb->hide();
|
|
|
|
|
|
//进度条
|
|
progressbar = new QProgressBar(this);
|
|
|
|
progressbar->resize(300,80);
|
|
|
|
progressbar->setRange(0,100);
|
|
|
|
progressbar->setFormat("%v");
|
|
|
|
progressbar->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
ui->statusbar->addPermanentWidget(progressbar);
|
|
|
|
progressbar->hide();
|
|
|
|
|
|
//记录按键
|
|
recordbtn = new QPushButton(tr("StartRecord"),this);
|
|
|
|
recordbtn->resize(120,80);
|
|
recordbtn->setFlat(true);
|
|
|
|
ui->statusbar->addPermanentWidget(recordbtn);
|
|
|
|
recordbtn->hide();
|
|
|
|
//开始记录-停止记录
|
|
connect(recordbtn,&QPushButton::clicked,this,[=](){
|
|
|
|
if(recordstate)//正在记录
|
|
{
|
|
recordbtn->setText(tr("StartRecord"));
|
|
recordstate = false;//停止记录
|
|
savethread->setRecordState(recordstate);
|
|
}
|
|
else
|
|
{
|
|
recordbtn->setText(tr("StopRecord"));
|
|
recordstate = true;//开始记录
|
|
|
|
logname = QString("%1").arg(QDateTime::currentDateTime().toString("yyyyMMddHHmmss"));
|
|
savethread->setLogName(logname);
|
|
savethread->setRecordState(recordstate);
|
|
}
|
|
});
|
|
|
|
|
|
//播放倍速
|
|
combox = new QComboBox(this);
|
|
|
|
combox->resize(40,40);
|
|
|
|
combox->addItem(tr("0.1x"),0.1);
|
|
combox->addItem(tr("0.2x"),0.2);
|
|
combox->addItem(tr("0.5x"),0.5);
|
|
combox->addItem(tr("1x"),1);
|
|
combox->addItem(tr("2x"),2);
|
|
combox->addItem(tr("5x"),5);
|
|
combox->addItem(tr("10x"),10);
|
|
combox->addItem(tr("20x"),20);
|
|
combox->addItem(tr("50x"),50);
|
|
combox->setCurrentIndex(3);
|
|
combox->hide();
|
|
|
|
ui->statusbar->addPermanentWidget(combox);
|
|
|
|
connect(combox,&QComboBox::currentTextChanged,this,[=](QString index){
|
|
qreal times = combox->currentData(Qt::UserRole).toDouble();
|
|
|
|
if(playthread)
|
|
{
|
|
playthread->setTimes(times);
|
|
}
|
|
});
|
|
|
|
|
|
QString modename;
|
|
if(mode == 0)
|
|
{
|
|
modename = tr("Record");
|
|
progressbar->hide();
|
|
recordbtn->show();
|
|
combox->hide();
|
|
timestamplb->hide();
|
|
}
|
|
else
|
|
{
|
|
modename = tr("Replay");
|
|
progressbar->show();
|
|
recordbtn->hide();
|
|
combox->show();
|
|
timestamplb->show();
|
|
}
|
|
|
|
//模式按键初始化
|
|
modebtn = new QPushButton(modename,this);
|
|
|
|
modebtn->resize(120,80);
|
|
modebtn->setFlat(true);
|
|
|
|
ui->statusbar->addPermanentWidget(modebtn);
|
|
|
|
connect(modebtn,&QPushButton::clicked,this,[=](){//按键槽函数
|
|
|
|
mode = (mode > 0)?(0x00):(0x01);
|
|
|
|
savethread->setMode(mode);
|
|
|
|
Config::insertSetting("mode",(mode)?(true):(false));
|
|
|
|
QString modename;
|
|
if(mode == 0)
|
|
{
|
|
modename = tr("Record");
|
|
|
|
progressbar->hide();
|
|
recordbtn->show();
|
|
combox->hide();
|
|
timestamplb->hide();
|
|
|
|
if(playthread)
|
|
{
|
|
playthread->resetState(true);
|
|
|
|
ui->horizontalSlider->setMaximum(1);
|
|
|
|
ui->horizontalSlider->setValue(0);
|
|
|
|
ui->label_status->setText(" "+ QString::number(0) + "/" + QString::number(0) + " ");
|
|
|
|
//解析完成
|
|
QString btn_default = QString("QPushButton{border-image: url(:/img/Dark/play_stop.png);}\n");
|
|
QString btn_hover = QString("QPushButton:hover{border-image: url(:/img/Dark/play_stop_enter.png);}\n");
|
|
QString btn_pressed = QString("QPushButton:pressed{border-image: url(:/img/Dark/play_stop_enter.png);}\n");
|
|
|
|
ui->pushButton_play->setStyleSheet(btn_default + btn_hover + btn_pressed);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
modename = tr("Replay");
|
|
|
|
progressbar->show();
|
|
recordbtn->hide();
|
|
combox->show();
|
|
timestamplb->show();
|
|
|
|
recordbtn->setText(tr("StartRecord"));
|
|
recordstate = false;
|
|
savethread->setRecordState(recordstate);
|
|
|
|
}
|
|
modebtn->setText(modename);
|
|
|
|
|
|
//更新一下端口
|
|
sockets = Config::getConnet();
|
|
|
|
if(sockets.size() > 0)
|
|
{
|
|
QTableWidget *table = ui->tableWidget_Socket;
|
|
|
|
for (const QMap<QVariant,QVariant> &item : qAsConst(sockets)) {
|
|
|
|
|
|
QLabel *logo = qobject_cast<QLabel *>(table->cellWidget(sockets.indexOf(item),0));
|
|
QString name = item.value("name").toString();
|
|
QString addr = item.value("ipaddr").toString();
|
|
QString port = item.value("port").toString();
|
|
|
|
//删除所有的端口,重新设置
|
|
QMetaObject::invokeMethod(dlink, "setup_multicast_close", Qt::QueuedConnection,
|
|
Q_ARG(const QHostAddress &, QHostAddress(addr)),
|
|
Q_ARG(const quint16 &, port.toUShort())
|
|
);
|
|
// dlink->setup_multicast_close(QHostAddress(addr),port.toUShort());
|
|
|
|
//记录模式
|
|
bool ret;
|
|
if(mode == 0)
|
|
{
|
|
QMetaObject::invokeMethod(dlink, "setup_multicast_recieve", Qt::BlockingQueuedConnection,
|
|
Q_RETURN_ARG(bool, ret),
|
|
Q_ARG(const QHostAddress &, QHostAddress(addr)),
|
|
Q_ARG(const quint16 &, port.toUInt() ),
|
|
Q_ARG(QHostAddress, QHostAddress("0.0.0.0")),
|
|
Q_ARG(quint16, 0)
|
|
);
|
|
if(ret)
|
|
{
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_listen.png"));
|
|
}
|
|
else
|
|
{
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_disconnected.png"));
|
|
}
|
|
}
|
|
else//回放模式
|
|
{
|
|
QMetaObject::invokeMethod(dlink, "setup_multicast_transmit", Qt::BlockingQueuedConnection,
|
|
Q_RETURN_ARG(bool, ret),
|
|
Q_ARG(const QHostAddress &, QHostAddress(addr)),
|
|
Q_ARG(const quint16 &, port.toUInt() ),
|
|
Q_ARG(QHostAddress, QHostAddress("0.0.0.0")),
|
|
Q_ARG(quint16, 0)
|
|
);
|
|
if(ret)
|
|
{
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_send.png"));
|
|
}
|
|
else
|
|
{
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_disconnected.png"));
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
//设置记录文件名
|
|
logname = QString("%1").arg(QDateTime::currentDateTime().toString("yyyyMMddHHmmss"));
|
|
|
|
//网络列表设置
|
|
QTableWidget *table = ui->tableWidget_Socket;
|
|
|
|
QStringList tabletitle;
|
|
tabletitle << tr("state") << tr("name") <<tr("ip") << tr("port") << tr("info");
|
|
|
|
table->setColumnCount(tabletitle.size()); //设置列数
|
|
table->setSelectionBehavior(QAbstractItemView::SelectRows); //设置选中模式为选中行
|
|
table->setSelectionMode ( QAbstractItemView::SingleSelection); //设置选择模式,选择单行
|
|
table->setAlternatingRowColors(true);
|
|
table->setEditTriggers(QAbstractItemView::NoEditTriggers); //不能编辑
|
|
table->setMouseTracking(true);
|
|
table->setFocus();
|
|
table->setFocusPolicy(Qt::StrongFocus);
|
|
|
|
QString tableStyleSheet;
|
|
tableStyleSheet.clear();
|
|
|
|
//tableStyleSheet.append("QTableWidget::item:selected { background-color: rgb(25, 115, 194);} \n");
|
|
tableStyleSheet.append("QTableWidget{ background-color: rgb(27, 26, 55) ; color: rgb(255, 255, 255);} \n");
|
|
|
|
tableStyleSheet.append("QTableWidget{ alternate-background-color: rgb(20, 20, 74);}");
|
|
|
|
table->setStyleSheet(tableStyleSheet);
|
|
|
|
table->setColumnWidth(0,30); //设置第1列的列宽(state)
|
|
table->setColumnWidth(1,100); //设置第2列的列宽(name)
|
|
table->setColumnWidth(2,130); //设置第1列的列宽(ip)
|
|
table->setColumnWidth(3,55); //设置第2列的列宽(port)
|
|
table->setColumnWidth(4,200); //设置第2列的列宽(info)
|
|
|
|
|
|
table->setHorizontalHeaderLabels(tabletitle);
|
|
QHeaderView* V_headerViewsocket = table->verticalHeader();
|
|
V_headerViewsocket->setHidden(true); //行名隐藏
|
|
|
|
QHeaderView* H_headerViewsocket = table->horizontalHeader();
|
|
H_headerViewsocket->setDefaultAlignment(Qt::AlignCenter); //表头信息显示居中靠左
|
|
H_headerViewsocket->setHighlightSections(false); //不高亮选中内容的所在列标题
|
|
H_headerViewsocket->setStretchLastSection(true);
|
|
//H_headerViewsocket->setSectionResizeMode(QHeaderView::Stretch);
|
|
H_headerViewsocket->setHidden(true);
|
|
|
|
|
|
if(sockets.size() > 0)
|
|
{
|
|
ui->lineEdit_Name->setText(sockets.last().value("name").toString());
|
|
ui->lineEdit_Addr->setText(sockets.last().value("ipaddr").toString());
|
|
ui->lineEdit_Port->setText(sockets.last().value("port").toString());
|
|
|
|
|
|
table->clear();
|
|
table->setRowCount(0);
|
|
for (QMap<QVariant,QVariant> item : qAsConst(sockets)) {
|
|
|
|
table->setRowCount(table->rowCount() + 1);
|
|
|
|
int idx = table->rowCount()-1;
|
|
|
|
QString name = item.value("name").toString();
|
|
QString ip = item.value("ipaddr").toString();
|
|
QString port = item.value("port").toString();
|
|
|
|
|
|
QLabel *logo = new QLabel();
|
|
logo->setPixmap(QPixmap(":/img/Dark/LED_Gray.png"));
|
|
logo->setAlignment(Qt::AlignCenter);
|
|
|
|
table->removeCellWidget(idx,0);
|
|
table->setCellWidget(idx,0,logo);
|
|
|
|
table->removeCellWidget(idx,1);
|
|
table->setItem(idx,1,new QTableWidgetItem(name));
|
|
|
|
table->removeCellWidget(idx,2);
|
|
table->setItem(idx,2,new QTableWidgetItem(ip));
|
|
|
|
table->removeCellWidget(idx,3);
|
|
table->setItem(idx,3,new QTableWidgetItem(port));
|
|
|
|
QLabel *status = new QLabel();
|
|
status->setAlignment(Qt::AlignLeft | Qt::AlignVCenter );
|
|
status->setStyleSheet("color: #FFFFFF; font: 12pt 黑体");
|
|
|
|
table->removeCellWidget(idx,4);
|
|
table->setCellWidget(idx,4,status);
|
|
|
|
bool ret;
|
|
if(mode == 0)
|
|
{
|
|
QMetaObject::invokeMethod(dlink, "setup_multicast_recieve", Qt::BlockingQueuedConnection,
|
|
Q_RETURN_ARG(bool, ret),
|
|
Q_ARG(const QHostAddress &, QHostAddress(ip) ),
|
|
Q_ARG(const quint16 &, port.toUInt() ),
|
|
Q_ARG(QHostAddress, QHostAddress("0.0.0.0")),
|
|
Q_ARG(quint16, 0)
|
|
);
|
|
if(ret)
|
|
{
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_listen.png"));
|
|
}
|
|
else
|
|
{
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_disconnected.png"));
|
|
}
|
|
}
|
|
else//回放模式
|
|
{
|
|
QMetaObject::invokeMethod(dlink, "setup_multicast_transmit", Qt::BlockingQueuedConnection,
|
|
Q_RETURN_ARG(bool, ret),
|
|
Q_ARG(const QHostAddress &, QHostAddress(ip) ),
|
|
Q_ARG(const quint16 &, port.toUInt() ),
|
|
Q_ARG(QHostAddress, QHostAddress("0.0.0.0")),
|
|
Q_ARG(quint16, 0)
|
|
);
|
|
if(ret)
|
|
{
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_send.png"));
|
|
}
|
|
else
|
|
{
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_disconnected.png"));
|
|
}
|
|
}
|
|
}
|
|
|
|
table->resizeColumnsToContents();
|
|
}
|
|
else
|
|
{
|
|
ui->lineEdit_Addr->setText("226.0.0.80");
|
|
ui->lineEdit_Port->setText("6070");
|
|
}
|
|
|
|
|
|
//列表双击
|
|
connect(ui->tableWidget_Socket,&QTableWidget::itemDoubleClicked,this,[=](QTableWidgetItem *item)
|
|
{
|
|
QTableWidget *table = ui->tableWidget_Socket;
|
|
|
|
int row=item->row();
|
|
int column = item->column();
|
|
|
|
QVariant name = table->item(row,1)->data(Qt::DisplayRole).toString();
|
|
QVariant ipaddr = table->item(row,2)->data(Qt::DisplayRole).toString();
|
|
QVariant port = table->item(row,3)->data(Qt::DisplayRole).toString();
|
|
|
|
QLineEdit *line = new QLineEdit(table);
|
|
line->setStyleSheet("background-color: #FFFFFF; font: 12pt 黑体");
|
|
line->setText(item->data(Qt::DisplayRole).toString());
|
|
table->removeCellWidget(row,column);
|
|
table->setCellWidget(row,column,line);
|
|
|
|
switch (column) {
|
|
default:
|
|
break;
|
|
case 3:{
|
|
line->setValidator(new QIntValidator(0,65535));
|
|
}break;
|
|
|
|
}
|
|
|
|
//编辑结束
|
|
connect(line,&QLineEdit::editingFinished,[=](){
|
|
if(line)
|
|
{
|
|
QString str = line->text();
|
|
|
|
if(column == 1)
|
|
{
|
|
if(Config::modifyConnet(name, ipaddr, port, str, ipaddr, port))
|
|
{
|
|
table->removeCellWidget(row,column);
|
|
item->setText(str);
|
|
|
|
//更新一下端口
|
|
sockets = Config::getConnet();
|
|
}
|
|
else
|
|
{
|
|
table->removeCellWidget(row,column);
|
|
}
|
|
}
|
|
else if(column == 2)
|
|
{
|
|
QHostAddress addr(str);
|
|
if(!addr.isNull())
|
|
{
|
|
if(Config::modifyConnet(name, ipaddr, port, name, addr.toString(), port))
|
|
{
|
|
table->removeCellWidget(row,column);
|
|
item->setText(addr.toString());
|
|
|
|
//修改连接
|
|
//记录模式
|
|
if(mode == 0)
|
|
{
|
|
QMetaObject::invokeMethod(dlink, "setup_multicast_recieve", Qt::QueuedConnection,
|
|
Q_ARG(const QHostAddress &, QHostAddress(ipaddr.toString())),
|
|
Q_ARG(const quint16 &, port.toUInt()),
|
|
Q_ARG(QHostAddress, addr),
|
|
Q_ARG(quint16, port.toUInt())
|
|
);
|
|
// dlink->setup_multicast_recieve(QHostAddress(ipaddr.toString()),port.toUInt(),addr,port.toUInt());
|
|
}
|
|
else//回放模式
|
|
{
|
|
QMetaObject::invokeMethod(dlink, "setup_multicast_transmit", Qt::QueuedConnection,
|
|
Q_ARG(const QHostAddress &, QHostAddress(ipaddr.toString())),
|
|
Q_ARG(const quint16 &, port.toUInt()),
|
|
Q_ARG(QHostAddress, addr),
|
|
Q_ARG(quint16, port.toUInt())
|
|
);
|
|
// dlink->setup_multicast_transmit(QHostAddress(ipaddr.toString()),port.toUInt(),addr,port.toUInt());
|
|
}
|
|
|
|
//更新一下端口
|
|
sockets = Config::getConnet();
|
|
}
|
|
else
|
|
{
|
|
table->removeCellWidget(row,column);
|
|
}
|
|
}
|
|
}
|
|
else if(column == 3)
|
|
{
|
|
bool ok = false;
|
|
uint16_t newport = str.toUShort(&ok);
|
|
if(ok)
|
|
{
|
|
if(Config::modifyConnet(name, ipaddr, port, name, ipaddr, QString::number(newport)))
|
|
{
|
|
table->removeCellWidget(row,column);
|
|
item->setText(str);
|
|
|
|
//修改连接
|
|
//记录模式
|
|
if(mode == 0)
|
|
{
|
|
QMetaObject::invokeMethod(dlink, "setup_multicast_recieve", Qt::QueuedConnection,
|
|
Q_ARG(const QHostAddress &, QHostAddress(ipaddr.toString()) ),
|
|
Q_ARG(const quint16 &, port.toUInt()),
|
|
Q_ARG(QHostAddress, QHostAddress(ipaddr.toString()) ),
|
|
Q_ARG(quint16, newport)
|
|
);
|
|
}
|
|
else//回放模式
|
|
{
|
|
QMetaObject::invokeMethod(dlink, "setup_multicast_transmit", Qt::QueuedConnection,
|
|
Q_ARG(const QHostAddress &, QHostAddress(ipaddr.toString()) ),
|
|
Q_ARG(const quint16 &, port.toUInt()),
|
|
Q_ARG(QHostAddress, QHostAddress(ipaddr.toString()) ),
|
|
Q_ARG(quint16, newport)
|
|
);
|
|
}
|
|
|
|
//更新一下端口
|
|
sockets = Config::getConnet();
|
|
}
|
|
else
|
|
{
|
|
table->removeCellWidget(row,column);
|
|
}
|
|
}
|
|
}
|
|
|
|
table->resizeColumnsToContents();
|
|
}
|
|
});
|
|
});
|
|
|
|
//添加按键按下
|
|
connect(ui->pushButton_add,&QPushButton::clicked,this,[=](){
|
|
//添加一组
|
|
bool ok = false;
|
|
QString name = ui->lineEdit_Name->text();
|
|
uint16_t portnumber = ui->lineEdit_Port->text().toUShort(&ok);
|
|
QHostAddress addr(ui->lineEdit_Addr->text());
|
|
if((!addr.isNull()) && (ok))
|
|
{
|
|
QString ip = addr.toString();
|
|
QString port = QString::number(portnumber);
|
|
|
|
if(Config::insertConnet(name, ip, port))
|
|
{
|
|
table->setRowCount(table->rowCount() + 1);
|
|
int idx = table->rowCount()-1;
|
|
|
|
QLabel *logo = new QLabel();
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_disconnected.png"));
|
|
logo->setAlignment(Qt::AlignCenter);
|
|
|
|
table->removeCellWidget(idx,0);
|
|
table->setCellWidget(idx,0,logo);
|
|
|
|
table->removeCellWidget(idx,1);
|
|
table->setItem(idx,1,new QTableWidgetItem(name));
|
|
|
|
table->removeCellWidget(idx,2);
|
|
table->setItem(idx,2,new QTableWidgetItem(ip));
|
|
|
|
table->removeCellWidget(idx,3);
|
|
table->setItem(idx,3,new QTableWidgetItem(port));
|
|
|
|
QLabel *status = new QLabel();
|
|
status->setAlignment(Qt::AlignLeft | Qt::AlignVCenter );
|
|
status->setStyleSheet("color: #FFFFFF; font: 12pt 黑体");
|
|
|
|
table->removeCellWidget(idx,4);
|
|
table->setCellWidget(idx,4,status);
|
|
|
|
//增加连接
|
|
//记录模式
|
|
bool ret;
|
|
if(mode == 0)
|
|
{
|
|
QMetaObject::invokeMethod(dlink, "setup_multicast_recieve", Qt::BlockingQueuedConnection,
|
|
Q_RETURN_ARG(bool, ret),
|
|
Q_ARG(const QHostAddress &, addr),
|
|
Q_ARG(const quint16 &, portnumber),
|
|
Q_ARG(QHostAddress, QHostAddress("0.0.0.0")),
|
|
Q_ARG(quint16, 0)
|
|
);
|
|
|
|
|
|
if(ret)
|
|
{
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_listen.png"));
|
|
}
|
|
else
|
|
{
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_disconnected.png"));
|
|
}
|
|
}
|
|
else//回放模式
|
|
{
|
|
QMetaObject::invokeMethod(dlink, "setup_multicast_transmit", Qt::BlockingQueuedConnection,
|
|
Q_RETURN_ARG(bool, ret),
|
|
Q_ARG(const QHostAddress &, addr),
|
|
Q_ARG(const quint16 &, portnumber),
|
|
Q_ARG(QHostAddress, QHostAddress("0.0.0.0")),
|
|
Q_ARG(quint16, 0)
|
|
);
|
|
|
|
|
|
if(ret)
|
|
{
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_send.png"));
|
|
}
|
|
else
|
|
{
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_disconnected.png"));
|
|
}
|
|
}
|
|
|
|
table->resizeColumnsToContents();
|
|
//更新一下端口
|
|
sockets = Config::getConnet();
|
|
}
|
|
}
|
|
});
|
|
|
|
//删除按键按下
|
|
connect(ui->pushButton_delete,&QPushButton::clicked,this,[=](){
|
|
//删除一组
|
|
QTableWidgetItem *item = table->currentItem();
|
|
|
|
if(item)
|
|
{
|
|
int row=item->row();
|
|
int column = item->column();
|
|
|
|
Q_UNUSED(column)
|
|
|
|
QString ip = table->item(row,2)->data(Qt::DisplayRole).toString();
|
|
QString port = table->item(row,3)->data(Qt::DisplayRole).toString();
|
|
|
|
if(Config::deleteConnet(ip,port))
|
|
{
|
|
//断开连接
|
|
QMetaObject::invokeMethod(dlink, "setup_multicast_close", Qt::QueuedConnection,
|
|
Q_ARG(const QHostAddress &, QHostAddress(ip) ),
|
|
Q_ARG(const quint16 &, port.toUShort())
|
|
);
|
|
// dlink->setup_multicast_close(QHostAddress(ip),port.toUShort());
|
|
|
|
table->removeRow(row);
|
|
|
|
//更新一下端口
|
|
sockets = Config::getConnet();
|
|
}
|
|
table->resizeColumnsToContents();
|
|
}
|
|
});
|
|
|
|
|
|
|
|
//回放列表
|
|
table = ui->tableWidget_File;
|
|
|
|
tabletitle.clear();
|
|
tabletitle << tr("name") << tr("size");
|
|
|
|
table->setColumnCount(tabletitle.size()); //设置列数
|
|
table->setSelectionBehavior(QAbstractItemView::SelectRows); //设置选中模式为选中行
|
|
table->setSelectionMode ( QAbstractItemView::SingleSelection); //设置选择模式,选择单行
|
|
table->setAlternatingRowColors(true);
|
|
table->setEditTriggers(QAbstractItemView::NoEditTriggers); //不能编辑
|
|
table->setMouseTracking(true);
|
|
table->setFocus();
|
|
table->setFocusPolicy(Qt::StrongFocus);
|
|
|
|
tableStyleSheet.clear();
|
|
//tableStyleSheet.append("QTableWidget::item:selected { background-color: rgb(25, 115, 194);} \n");
|
|
tableStyleSheet.append("QTableWidget{ background-color: rgb(27, 26, 55) ; color: rgb(255, 255, 255);} \n");
|
|
|
|
tableStyleSheet.append("QTableWidget{ alternate-background-color: rgb(20, 20, 74);}");
|
|
|
|
table->setStyleSheet(tableStyleSheet);
|
|
|
|
table->setColumnWidth(0,300); //设置第1列的列宽(name)
|
|
table->setColumnWidth(1,150); //设置第2列的列宽(size)
|
|
|
|
|
|
table->setHorizontalHeaderLabels(tabletitle);
|
|
QHeaderView* V_headerView = table->verticalHeader();
|
|
V_headerView->setHidden(true); //行名隐藏
|
|
|
|
QHeaderView* H_headerView = table->horizontalHeader();
|
|
H_headerView->setDefaultAlignment(Qt::AlignLeft); //表头信息显示居中靠左
|
|
H_headerView->setHighlightSections(false); //不高亮选中内容的所在列标题
|
|
H_headerView->setStretchLastSection(true);
|
|
H_headerView->setHidden(true);
|
|
|
|
|
|
connect(ui->tableWidget_File,&QTableWidget::itemDoubleClicked,this,[=](QTableWidgetItem *item)
|
|
{
|
|
//一旦双击,直接把上一次播放的线程停止掉
|
|
if(mode == 0)//记录模式
|
|
{
|
|
return;
|
|
}
|
|
|
|
if(play_state != 0x00)//停止播放
|
|
{
|
|
play_state = 0x00;
|
|
ui->horizontalSlider->setValue(0);
|
|
|
|
emit changedPlayState(play_state);
|
|
}
|
|
|
|
int row=item->row();
|
|
int column = item->column();
|
|
|
|
Q_UNUSED(column)
|
|
|
|
if(playthread)
|
|
{
|
|
playthread->resetData();
|
|
}
|
|
|
|
QString key = table->item(row,0)->data(Qt::DisplayRole).toString();
|
|
|
|
QString path = filelist.value(key);
|
|
|
|
select_file = path;
|
|
ui->label_selectfile->setText(path);
|
|
|
|
QString filename = select_file;
|
|
|
|
//解析开始
|
|
Parse *parse = new Parse;
|
|
|
|
parse->parseData(filename);
|
|
|
|
//进度条
|
|
connect(parse,&Parse::progress,[=](qint64 length,qint64 current){
|
|
if(progressbar)
|
|
{
|
|
progressbar->setRange(0,length);
|
|
progressbar->setValue(current);
|
|
}
|
|
});
|
|
|
|
|
|
//产生的文件
|
|
connect(parse,&Parse::frameList,this,[=](QList<QByteArray> data){
|
|
Q_UNUSED(data)
|
|
|
|
if(playthread)
|
|
{
|
|
//playthread->resetState(true);
|
|
|
|
ui->horizontalSlider->setMaximum(playthread->size() - 1);
|
|
|
|
ui->horizontalSlider->setValue(0);
|
|
|
|
ui->label_status->setText(" "+ QString::number(0) + "/" + QString::number(playthread->size() - 1) + " ");
|
|
|
|
}
|
|
//解析完成
|
|
showMessage(tr("parse complete"),10000);
|
|
|
|
QString btn_default = QString("QPushButton{border-image: url(:/img/Dark/play_stop.png);}\n");
|
|
QString btn_hover = QString("QPushButton:hover{border-image: url(:/img/Dark/play_stop_enter.png);}\n");
|
|
QString btn_pressed = QString("QPushButton:pressed{border-image: url(:/img/Dark/play_stop_enter.png);}\n");
|
|
|
|
ui->pushButton_play->setStyleSheet(btn_default + btn_hover + btn_pressed);
|
|
|
|
});
|
|
|
|
|
|
connect(parse,&Parse::frameok,playthread,&PlayThread::appendPlayData,Qt::DirectConnection);
|
|
|
|
//开始解析线程
|
|
QThreadPool::globalInstance()->start(parse,1);
|
|
});
|
|
|
|
|
|
QTimer *flushTimer = new QTimer();
|
|
flushTimer->setInterval(1000);
|
|
connect(flushTimer,&QTimer::timeout,this,[=](){
|
|
|
|
QStringList loglist = Config::getFiles("./log","bin");
|
|
|
|
if(loglist.size())
|
|
{
|
|
QTableWidget *table = ui->tableWidget_File;
|
|
|
|
if(lastloglist.size() != loglist.size())
|
|
{
|
|
table->clear();
|
|
table->setRowCount(0);
|
|
}
|
|
|
|
foreach (QString txt, loglist) {
|
|
|
|
QFileInfo info(txt);
|
|
|
|
size_t logsize = info.size();
|
|
|
|
filelist.insert(info.fileName(),txt);
|
|
|
|
int idx = loglist.indexOf(txt);
|
|
|
|
if(idx != -1)
|
|
{
|
|
QTableWidgetItem *item = table->item(idx,0);
|
|
|
|
if(!item)
|
|
{
|
|
table->setRowCount(table->rowCount() + 1);
|
|
|
|
table->setItem(idx,0,new QTableWidgetItem(info.fileName()));
|
|
table->setItem(idx,1,new QTableWidgetItem(QString::number(logsize)));
|
|
}
|
|
else
|
|
{
|
|
if(table->item(idx,0)->data(Qt::DisplayRole).toString() != info.fileName())
|
|
{
|
|
table->removeCellWidget(idx,0);
|
|
table->setItem(idx,0,new QTableWidgetItem(info.fileName()));
|
|
}
|
|
|
|
if(table->item(idx,1)->data(Qt::DisplayRole).toString() != QString::number(logsize))
|
|
{
|
|
table->removeCellWidget(idx,1);
|
|
table->setItem(idx,1,new QTableWidgetItem(QString::number(logsize)));
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
table->setRowCount(table->rowCount() + 1);
|
|
|
|
int idx = table->rowCount() -1;
|
|
|
|
table->removeCellWidget(idx,0);
|
|
table->setItem(idx,0,new QTableWidgetItem(info.fileName()));
|
|
|
|
table->removeCellWidget(idx,1);
|
|
table->setItem(idx,1,new QTableWidgetItem(QString::number(logsize)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastloglist = loglist;
|
|
}
|
|
});
|
|
|
|
connect(this,&MainWindow::destroyed,flushTimer,&QTimer::deleteLater);
|
|
|
|
flushTimer->start();
|
|
|
|
//connect(dlink,&DLink::recieve,this,&MainWindow::setSave);
|
|
//显示速度
|
|
connect(dlink,&DLink::status,this,[=](QHostAddress ip, quint16 port, qreal in_all, qreal in_rate, qreal in_frq,qreal out_all, qreal out_rate, qreal out_frq){
|
|
|
|
QTableWidget *table = ui->tableWidget_Socket;
|
|
|
|
for(int i=0;i<table->rowCount();i++){
|
|
|
|
int row=i;
|
|
QLabel *logo = qobject_cast<QLabel *>(table->cellWidget(row,0));
|
|
QVariant name = table->item(row,1)->data(Qt::DisplayRole).toString();
|
|
QVariant ipaddr = table->item(row,2)->data(Qt::DisplayRole).toString();
|
|
QVariant m_port = table->item(row,3)->data(Qt::DisplayRole).toString();
|
|
QLabel *status = qobject_cast<QLabel *>(table->cellWidget(row,4));
|
|
|
|
|
|
if((QHostAddress(ipaddr.toString()) == ip) &&
|
|
(m_port == port))
|
|
{
|
|
if(status)
|
|
{
|
|
if(mode == 0)
|
|
{
|
|
QString str;
|
|
QString all;
|
|
QString rate;
|
|
QString frq;
|
|
|
|
if(in_all >= (1024*1024))
|
|
{
|
|
all.append(tr("total %1 MB").arg(QString::number(in_all/(1024*1024),'f',1)));
|
|
}
|
|
else if(in_all >= 1024)
|
|
{
|
|
all.append(tr("total %1 KB").arg(QString::number(in_all/1024,'f',1)));
|
|
}
|
|
else
|
|
{
|
|
all.append(tr("total %1 B").arg(QString::number(in_all,'f',0)));
|
|
}
|
|
|
|
if(in_rate >= (1024*1024))
|
|
{
|
|
rate.append(tr("rate %1 MB/s").arg(QString::number(in_rate/(1024*1024),'f',1)));
|
|
}
|
|
else if(in_rate >= 1024)
|
|
{
|
|
rate.append(tr("rate %1 KB/s").arg(QString::number(in_rate/1024,'f',1)));
|
|
}
|
|
else
|
|
{
|
|
rate.append(tr("rate %1 B/s").arg(QString::number(in_rate,'f',0)));
|
|
}
|
|
|
|
frq.append(tr("frequency: %1 Hz").arg(QString::number(in_frq,'f',1)));
|
|
|
|
str.append(tr("input: %1; %2; %3").arg(all).arg(rate).arg(frq));
|
|
status->setText(str);
|
|
}
|
|
else
|
|
{
|
|
QString str;
|
|
QString all;
|
|
QString rate;
|
|
QString frq;
|
|
|
|
if(out_all >= (1024*1024))
|
|
{
|
|
all.append(tr("total %1 MB").arg(QString::number(out_all/(1024*1024),'f',1)));
|
|
}
|
|
else if(out_all >= 1024)
|
|
{
|
|
all.append(tr("total %1 KB").arg(QString::number(out_all/1024,'f',1)));
|
|
}
|
|
else
|
|
{
|
|
all.append(tr("total %1 B").arg(QString::number(out_all,'f',0)));
|
|
}
|
|
|
|
if(out_rate >= (1024*1024))
|
|
{
|
|
rate.append(tr("rate %1 MB/s").arg(QString::number(out_rate/(1024*1024),'f',1)));
|
|
}
|
|
else if(out_rate >= 1024)
|
|
{
|
|
rate.append(tr("rate %1 KB/s").arg(QString::number(out_rate/1024,'f',1)));
|
|
}
|
|
else
|
|
{
|
|
rate.append(tr("rate %1 B/s").arg(QString::number(out_rate,'f',0)));
|
|
}
|
|
|
|
frq.append(tr("frequency: %1 Hz").arg(QString::number(out_frq,'f',1)));
|
|
|
|
str.append(tr("output: %1; %2; %3").arg(all).arg(rate).arg(frq));
|
|
status->setText(str);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
//按键样式设置
|
|
QString last_default = QString("QPushButton{border-image: url(:/img/Dark/play_last.png);}\n");
|
|
QString last_hover = QString("QPushButton:hover{border-image: url(:/img/Dark/play_last_enter.png);}\n");
|
|
QString last_pressed = QString("QPushButton:pressed{border-image: url(:/img/Dark/play_last_enter.png);}\n");
|
|
|
|
ui->pushButton_last->setStyleSheet(last_default + last_hover + last_pressed);
|
|
|
|
|
|
QString btn_default = QString("QPushButton{border-image: url(:/img/Dark/play_stop.png);}\n");
|
|
QString btn_hover = QString("QPushButton:hover{border-image: url(:/img/Dark/play_stop_enter.png);}\n");
|
|
QString btn_pressed = QString("QPushButton:pressed{border-image: url(:/img/Dark/play_stop_enter.png);}\n");
|
|
|
|
ui->pushButton_play->setStyleSheet(btn_default + btn_hover + btn_pressed);
|
|
|
|
|
|
QString next_default = QString("QPushButton{border-image: url(:/img/Dark/play_next.png);}\n");
|
|
QString next_hover = QString("QPushButton:hover{border-image: url(:/img/Dark/play_next_enter.png);}\n");
|
|
QString next_pressed = QString("QPushButton:pressed{border-image: url(:/img/Dark/play_next_enter.png);}\n");
|
|
|
|
ui->pushButton_next->setStyleSheet(next_default + next_hover + next_pressed);
|
|
|
|
//显示进度条
|
|
connect(playthread,&PlayThread::progress,this,[=](uint64_t all,uint64_t current){
|
|
|
|
if(play_state != 2)
|
|
{
|
|
ui->horizontalSlider->setMaximum(all);
|
|
ui->horizontalSlider->setValue(current);
|
|
}
|
|
|
|
ui->label_status->setText(" "+ QString::number(current) + "/" + QString::number(all) + " ");
|
|
|
|
current_frame = current;
|
|
total_frame = all;
|
|
|
|
//如果两个数相等,并且不是开始,那么就可以停止
|
|
if((current == (all - 1)) && (current != 0))
|
|
{
|
|
QString btn_default = QString("QPushButton{border-image: url(:/img/Dark/play_stop.png);}\n");
|
|
QString btn_hover = QString("QPushButton:hover{border-image: url(:/img/Dark/play_stop_enter.png);}\n");
|
|
QString btn_pressed = QString("QPushButton:pressed{border-image: url(:/img/Dark/play_stop_enter.png);}\n");
|
|
|
|
ui->pushButton_play->setStyleSheet(btn_default + btn_hover + btn_pressed);
|
|
|
|
showMessage(tr("play complete"),10000);
|
|
}
|
|
|
|
//结束,设置按键失效
|
|
});
|
|
|
|
//显示进度条
|
|
connect(playthread,&PlayThread::delaytime,this,[=](qint64 length,qint64 current){
|
|
progressbar->setRange(0,length);
|
|
progressbar->setValue(current);
|
|
});
|
|
|
|
//设置游标位置
|
|
connect(this,&MainWindow::changedframe,this,[=](int64_t pos){
|
|
if(playthread)
|
|
{
|
|
playthread->setNewPos(pos);
|
|
}
|
|
});
|
|
|
|
//设置播放状态
|
|
connect(this,&MainWindow::changedPlayState,this,[=](uint8_t state){
|
|
if(playthread)
|
|
{
|
|
playthread->setPlayState(state);
|
|
}
|
|
});
|
|
|
|
//时间撮显示
|
|
connect(playthread,&PlayThread::timestamp,this,[=](QDateTime time){
|
|
timestamplb->setText(time.toString("yyyy/MM/dd.hh:mm:ss.zzz"));
|
|
});
|
|
|
|
//发给dlink发出去
|
|
//connect(playthread,&PlayThread::transmit,dlink,&DLink::transmit,Qt::DirectConnection);
|
|
connect(playthread,&PlayThread::transmit,dlink,&DLink::transmit);
|
|
|
|
|
|
//回放发送设置界面(这个想办法用其他办法,这个有点浪费时间)
|
|
connect(playthread,&PlayThread::transmit,this,[=](QHostAddress p_ip,quint16 p_port,QByteArray data){
|
|
|
|
Q_UNUSED(data)
|
|
|
|
QString ip = p_ip.toString();
|
|
QString port = QString::number(p_port);
|
|
|
|
//添加一组
|
|
//先读取,看看是不是存在,可以得到名字
|
|
if(Config::insertConnet(ip, ip, port))//配置文件里面已经存在
|
|
{
|
|
QTableWidget *table = ui->tableWidget_Socket;
|
|
|
|
table->setRowCount(table->rowCount() + 1);
|
|
int idx = table->rowCount()-1;
|
|
|
|
QLabel *logo = new QLabel();
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_disconnected.png"));
|
|
logo->setAlignment(Qt::AlignCenter);
|
|
|
|
table->removeCellWidget(idx,0);
|
|
table->setCellWidget(idx,0,logo);
|
|
|
|
table->removeCellWidget(idx,1);
|
|
table->setItem(idx,1,new QTableWidgetItem(ip));//name
|
|
|
|
table->removeCellWidget(idx,2);
|
|
table->setItem(idx,2,new QTableWidgetItem(ip));//ip
|
|
|
|
table->removeCellWidget(idx,3);
|
|
table->setItem(idx,3,new QTableWidgetItem(port));//port
|
|
|
|
QLabel *status = new QLabel();
|
|
status->setAlignment(Qt::AlignLeft | Qt::AlignVCenter );
|
|
status->setStyleSheet("color: #FFFFFF; font: 12pt 黑体");
|
|
|
|
table->removeCellWidget(idx,4);
|
|
table->setCellWidget(idx,4,status);
|
|
|
|
//增加连接
|
|
//记录模式
|
|
bool ret;
|
|
if(mode == 0)
|
|
{
|
|
QMetaObject::invokeMethod(dlink, "setup_multicast_recieve", Qt::BlockingQueuedConnection,
|
|
Q_RETURN_ARG(bool, ret),
|
|
Q_ARG(const QHostAddress &, p_ip),
|
|
Q_ARG(const quint16 &, p_port),
|
|
Q_ARG(QHostAddress, QHostAddress("0.0.0.0")),
|
|
Q_ARG(quint16, 0)
|
|
);
|
|
|
|
if(ret)
|
|
{
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_listen.png"));
|
|
}
|
|
else
|
|
{
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_disconnected.png"));
|
|
}
|
|
}
|
|
else//回放模式
|
|
{
|
|
QMetaObject::invokeMethod(dlink, "setup_multicast_transmit", Qt::BlockingQueuedConnection,
|
|
Q_RETURN_ARG(bool, ret),
|
|
Q_ARG(const QHostAddress &, p_ip),
|
|
Q_ARG(const quint16 &, p_port),
|
|
Q_ARG(QHostAddress, QHostAddress("0.0.0.0")),
|
|
Q_ARG(quint16, 0)
|
|
);
|
|
|
|
if(ret)
|
|
{
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_send.png"));
|
|
}
|
|
else
|
|
{
|
|
logo->setPixmap(QPixmap(":/img/Dark/Info_disconnected.png"));
|
|
}
|
|
}
|
|
|
|
table->resizeColumnsToContents();
|
|
//更新一下端口
|
|
sockets = Config::getConnet();
|
|
}
|
|
});
|
|
|
|
|
|
//关闭程序的时候线程线程处理
|
|
connect(this,&MainWindow::destroyed,this,[=](){
|
|
if(playthread)
|
|
{
|
|
play_state = 0;
|
|
emit changedPlayState(play_state);
|
|
|
|
playthread->setplay_control(false);
|
|
|
|
playthread->disconnect(playthread,nullptr,nullptr,nullptr);
|
|
|
|
playthread->deleteLater();
|
|
}
|
|
});
|
|
|
|
|
|
//游标移动设置
|
|
connect(ui->horizontalSlider,&QSlider::sliderMoved,this,[=](int value){
|
|
if(playthread)
|
|
{
|
|
play_state = 2;
|
|
emit changedPlayState(play_state);
|
|
|
|
QString btn_default = QString("QPushButton{border-image: url(:/img/Dark/play_pause.png);}\n");
|
|
QString btn_hover = QString("QPushButton:hover{border-image: url(:/img/Dark/play_pause_enter.png);}\n");
|
|
QString btn_pressed = QString("QPushButton:pressed{border-image: url(:/img/Dark/play_pause_enter.png);}\n");
|
|
|
|
ui->pushButton_play->setStyleSheet(btn_default + btn_hover + btn_pressed);
|
|
|
|
playthread->setNewPos(value);
|
|
}
|
|
|
|
});
|
|
|
|
//启动播放线程,设置优先级为1
|
|
QThreadPool::globalInstance()->start(playthread,1);
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
save_thread.quit();
|
|
save_thread.wait();
|
|
|
|
play_thread.quit();
|
|
play_thread.wait();
|
|
|
|
decode_thread.quit();
|
|
decode_thread.wait();
|
|
|
|
dlink_thread.quit();
|
|
dlink_thread.wait();
|
|
|
|
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::resizeEvent(QResizeEvent *e)
|
|
{
|
|
/*
|
|
QTableWidget *table = ui->tableWidget_File;
|
|
|
|
table->setColumnWidth(0,300); //设置第1列的列宽(name)
|
|
table->setColumnWidth(1,150); //设置第2列的列宽(size)
|
|
*/
|
|
}
|
|
|
|
void MainWindow::showMessage(const QString &message,int TimeOut)
|
|
{
|
|
//用于全局显示状态
|
|
ui->statusbar->showMessage(message,TimeOut);
|
|
}
|
|
|
|
void MainWindow::on_pushButton_last_clicked()
|
|
{
|
|
if(mode == 0)//记录模式
|
|
{
|
|
return;
|
|
}
|
|
|
|
//暂停播放
|
|
if(play_state != 0x00)//正在播放
|
|
{
|
|
play_state = 0x02;
|
|
emit changedPlayState(play_state);//先暂停
|
|
|
|
if(current_frame > 0)
|
|
{
|
|
current_frame -= 1;
|
|
}
|
|
|
|
QString play = QString("border-image: url(:/img/Dark/play_pause.png)");
|
|
ui->pushButton_play->setStyleSheet(play);
|
|
|
|
emit changedframe(current_frame);
|
|
|
|
}
|
|
//上一帧
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_play_clicked()
|
|
{
|
|
if(mode == 0)//记录模式
|
|
{
|
|
return;
|
|
}
|
|
|
|
if(play_state == 0x02)//暂停了
|
|
{
|
|
play_state = 0x01;
|
|
emit changedPlayState(play_state);
|
|
|
|
QString btn_default = QString("QPushButton{border-image: url(:/img/Dark/play_run.png);}\n");
|
|
QString btn_hover = QString("QPushButton:hover{border-image: url(:/img/Dark/play_run_enter.png);}\n");
|
|
QString btn_pressed = QString("QPushButton:pressed{border-image: url(:/img/Dark/play_run_enter.png);}\n");
|
|
|
|
ui->pushButton_play->setStyleSheet(btn_default + btn_hover + btn_pressed);
|
|
}
|
|
else if(play_state == 0x01)//正在播放
|
|
{
|
|
play_state = 0x02;
|
|
emit changedPlayState(play_state);
|
|
|
|
QString btn_default = QString("QPushButton{border-image: url(:/img/Dark/play_pause.png);}\n");
|
|
QString btn_hover = QString("QPushButton:hover{border-image: url(:/img/Dark/play_pause_enter.png);}\n");
|
|
QString btn_pressed = QString("QPushButton:pressed{border-image: url(:/img/Dark/play_pause_enter.png);}\n");
|
|
|
|
ui->pushButton_play->setStyleSheet(btn_default + btn_hover + btn_pressed);
|
|
|
|
}
|
|
else if(play_state == 0x00)//没有播放,可以播放
|
|
{
|
|
if(playthread)
|
|
{
|
|
if(playthread->size() <= 0)
|
|
{
|
|
showMessage(tr("please load a record file"),10000);
|
|
return ;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
showMessage(tr("play function is inhibited, please reboot"),10000);
|
|
return ;
|
|
}
|
|
|
|
|
|
QString btn_default = QString("QPushButton{border-image: url(:/img/Dark/play_run.png);}\n");
|
|
QString btn_hover = QString("QPushButton:hover{border-image: url(:/img/Dark/play_run_enter.png);}\n");
|
|
QString btn_pressed = QString("QPushButton:pressed{border-image: url(:/img/Dark/play_run_enter.png);}\n");
|
|
|
|
ui->pushButton_play->setStyleSheet(btn_default + btn_hover + btn_pressed);
|
|
|
|
if(playthread)
|
|
{
|
|
//playthread->playData(playdata,port_data);
|
|
|
|
//port_data.clear();
|
|
//playdata.clear();
|
|
play_state = 0x01;
|
|
emit changedPlayState(play_state);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_next_clicked()
|
|
{
|
|
if(mode == 0)//记录模式
|
|
{
|
|
return;
|
|
}
|
|
|
|
if(play_state != 0x00)//正在播放
|
|
{
|
|
play_state = 0x02;//暂停
|
|
|
|
QString play = QString("border-image: url(:/img/Dark/play_pause.png)");
|
|
ui->pushButton_play->setStyleSheet(play);
|
|
|
|
emit changedPlayState(play_state);
|
|
|
|
if(current_frame < total_frame)
|
|
{
|
|
current_frame += 1;
|
|
}
|
|
emit changedframe(current_frame);
|
|
}
|
|
|
|
//暂停播放
|
|
|
|
//下一帧
|
|
}
|