Files
gcs-nf/App/ToolsUI/tools_Index2/tools_Index2.cpp
T

239 lines
5.3 KiB
C++

#include "tools_Index2.h"
#include "ui_tools_Index2.h"
#include <QMimeData>
Tools_Index2::Tools_Index2(QWidget *parent) :
ToolsWidget(parent),
ui(new Ui::Tools_Index2)
{
ui->setupUi(this);
//load qss
QFile file(":/qss/Setting.qss");
file.open(QFile::ReadOnly);
QTextStream filetext(&file);
QString stylesheet = filetext.readAll();
this->setStyleSheet(stylesheet);
file.close();
this->setTop(true);
ui->horizontalSlider->hide();
PlayState = false;
ui->pushButton_Play->setFixedSize(150,50);
ui->pushButton_LastFrame->setFixedSize(150,50);
ui->pushButton_NextFrame->setFixedSize(150,50);
ui->pushButton_setPercent->setFixedSize(150,50);
ui->doubleSpinBox_setPercent->setFixedSize(150,50);
ui->comboBox_MultiSpeed->setFixedSize(150,50);
ui->label_percent->setFixedSize(150,50);
ui->comboBox_MultiSpeed->addItem("X1",1);
ui->comboBox_MultiSpeed->addItem("X2",2);
ui->comboBox_MultiSpeed->addItem("X5",5);
ui->comboBox_MultiSpeed->addItem("X10",10);
ui->comboBox_MultiSpeed->addItem("X20",20);
ui->comboBox_MultiSpeed->addItem("X50",50);
ui->comboBox_MultiSpeed->addItem("X100",100);
ui->comboBox_MultiSpeed->addItem("X200",200);
ui->comboBox_MultiSpeed->addItem("X500",500);
ui->comboBox_MultiSpeed->addItem("X1000",1000);
//
setAcceptDrops(true); //接收拖拽事件
}
Tools_Index2::~Tools_Index2()
{
delete ui;
}
void Tools_Index2::on_pushButton_file_clicked()
{
QFileDialog *dlg = new QFileDialog;
QString fileName = dlg->getOpenFileName(this, tr("Open File"),
"./log/tlog/",
tr("LogFile (*.Tlog *.log)"));
delete dlg;
if(!fileName.isEmpty())
{
setIniPlayStatus(fileName);
}
}
void Tools_Index2::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event)
update();
}
void Tools_Index2::dragEnterEvent(QDragEnterEvent *event)
{
if(event->mimeData()->hasUrls() )
{
QList<QUrl> urls = event->mimeData()->urls();
if(urls[0].isLocalFile() )
{
QString file_name(urls[0].toLocalFile() );
QFileInfo info(file_name);
if(info.suffix() == QString("tlog") )
{
event->acceptProposedAction();
return;
}
}
}
event->ignore();
}
void Tools_Index2::dropEvent(QDropEvent *event)
{
if(event->mimeData()->hasUrls() )
{
QList<QUrl> urls = event->mimeData()->urls();
if(urls[0].isLocalFile() )
{
QString file_name(urls[0].toLocalFile() );
QFileInfo info(file_name);
if(info.suffix() == QString("tlog") )
{
setIniPlayStatus(file_name);
}
}
}
event->ignore();
}
void Tools_Index2::setCurrentPercentage(float value)
{
ui->horizontalSlider->setValue(value * ui->horizontalSlider->maximum());
//ui->doubleSpinBox_Percent->setValue(value * 100);
ui->label_percent->setText(QString::number(value * 100));
}
void Tools_Index2::ReplayComplete()
{
PlayState = false;
ui->pushButton_Play->setText(tr("play"));
}
void Tools_Index2::on_horizontalSlider_sliderReleased()
{
if(isMove == false)
{
//读取暂停和播放状态
PlayState = PlayState?false:true;
//暂停和播放
emit setPlay(PlayState);
if(PlayState)//true
{
ui->pushButton_Play->setText(tr("pause"));
}
else
{
ui->pushButton_Play->setText(tr("play"));
}
}
}
void Tools_Index2::on_horizontalSlider_sliderPressed()
{
isMove = false;
}
void Tools_Index2::on_horizontalSlider_sliderMoved(int position)
{
isMove = true;
//设置比例
//qDebug() << (float)position/ui->horizontalSlider->maximum();
emit setPercentage((float)position/ui->horizontalSlider->maximum());
}
void Tools_Index2::on_pushButton_Play_clicked()
{
//读取暂停和播放状态
PlayState = PlayState?false:true;
//暂停和播放
emit setPlay(PlayState);
if(PlayState)//true
{
ui->pushButton_Play->setText(tr("pause"));
}
else
{
ui->pushButton_Play->setText(tr("play"));
}
}
void Tools_Index2::on_comboBox_MultiSpeed_currentIndexChanged(int index)
{
//qDebug() << ui->comboBox_MultiSpeed->currentData(Qt::UserRole).toDouble();
emit setMultiple(ui->comboBox_MultiSpeed->currentData(Qt::UserRole).toDouble());
}
void Tools_Index2::on_pushButton_NextFrame_clicked()
{
}
void Tools_Index2::on_pushButton_LastFrame_clicked()
{
}
void Tools_Index2::on_doubleSpinBox_Percent_valueChanged(double arg1)
{
//emit setPercentage(arg1);
}
void Tools_Index2::on_pushButton_setPercent_clicked()
{
double p = ui->doubleSpinBox_setPercent->value() * 0.01;
qDebug() << "p" << p;
emit setPercentage(p);
}
void Tools_Index2::on_pushButton_CSV_clicked()
{
qDebug() << "emit csv";
emit CreateCSV();
}
void Tools_Index2::setIniPlayStatus(QString const &file_name)
{
PlayState = false;
emit setFileName(file_name);
emit setPlay(PlayState);//暂停播放,跟底层关联起来
ui->pushButton_file->setText(file_name);
ui->horizontalSlider->setValue(0);
ui->pushButton_Play->setText("play");
ui->label_percent->setText("0");
ui->horizontalSlider->show();
}