291 lines
6.6 KiB
C++
291 lines
6.6 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include "../../Common/IO/Playback/RawFilePlayer.h"
|
|
|
|
#include <QMessageBox>
|
|
#include <QDebug>
|
|
#include <QDateTime>
|
|
#include <QFileDialog>
|
|
|
|
// MainWindow类的构造函数
|
|
MainWindow::MainWindow(QWidget* parent, ToolkitBase_Interface* pBaseInterface)
|
|
: QMainWindow(parent)
|
|
, m_pBaseInterface(pBaseInterface)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
/*
|
|
* default layout
|
|
*/
|
|
{
|
|
this->statusBar()->hide();
|
|
|
|
ui->widgetToolbar->hide();
|
|
|
|
int nWidth = ui->centralwidget->width() - 6;
|
|
m_nSize_Settings = 300;
|
|
|
|
ui->splitterHorizon->setSizes({nWidth, 0});
|
|
}
|
|
|
|
/*
|
|
*
|
|
*/
|
|
{
|
|
m_strCurrentFilePath = "";
|
|
|
|
m_pFrameParams = new FrameParams(nullptr);
|
|
|
|
ConfirmParams();
|
|
}
|
|
|
|
Connect();
|
|
InitStyles();
|
|
}
|
|
|
|
// MainWindow类的析构函数
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
// 重写鼠标双击事件
|
|
void MainWindow::mouseDoubleClickEvent(QMouseEvent* event)
|
|
{
|
|
if (nullptr != m_pBaseInterface)
|
|
{
|
|
m_pBaseInterface->OnNotify((int)ePluginCode_MediaXPlayer);
|
|
}
|
|
}
|
|
|
|
// 重写窗口大小调整事件
|
|
void MainWindow::resizeEvent(QResizeEvent* event)
|
|
{
|
|
QMainWindow::resizeEvent(event);
|
|
}
|
|
|
|
void MainWindow::Connect()
|
|
{
|
|
// menu
|
|
{
|
|
// media
|
|
connect(ui->m_action_OpenFile, &QAction::triggered, this, &MainWindow::OnMenuTriggered);
|
|
connect(ui->m_action_OpenDevice, &QAction::triggered, this, &MainWindow::OnMenuTriggered);
|
|
|
|
// view
|
|
connect(ui->m_action_ToolBar, &QAction::triggered, this, &MainWindow::OnMenuTriggered);
|
|
connect(ui->m_action_Settings, &QAction::triggered, this, &MainWindow::OnMenuTriggered);
|
|
}
|
|
|
|
// splitter
|
|
{
|
|
connect(ui->splitterHorizon, &QSplitter::splitterMoved, this, &MainWindow::OnSplitterMoved);
|
|
}
|
|
|
|
// btton
|
|
{
|
|
connect(ui->m_toolButton_OpenFile, &QToolButton::clicked, this, &MainWindow::OnButtonClicked);
|
|
connect(ui->m_toolButton_OpenDevice, &QToolButton::clicked, this, &MainWindow::OnButtonClicked);
|
|
connect(ui->m_toolButton_Settings, &QToolButton::clicked, this, &MainWindow::OnButtonClicked);
|
|
}
|
|
}
|
|
|
|
void MainWindow::Disconnect()
|
|
{}
|
|
|
|
void MainWindow::ConfirmParams()
|
|
{
|
|
/*
|
|
* Confirm File Params
|
|
*/
|
|
{
|
|
std::function<int(bool, const GFrameFormat&)> OnConfirmParams_File = [this](bool bOK, const GFrameFormat & varFrameFormat) -> int
|
|
{
|
|
if (nullptr != m_ptrPlayback.get())
|
|
{
|
|
RawFilePlayer* pRawFilePlayer = dynamic_cast<RawFilePlayer*>(m_ptrPlayback.get());
|
|
|
|
pRawFilePlayer->Stop();
|
|
}
|
|
|
|
m_ptrPlayback.reset();
|
|
|
|
m_ptrPlayback = std::shared_ptr<Playback>(new RawFilePlayer());
|
|
|
|
m_ptrPlayback->OpenFile(m_strCurrentFilePath, varFrameFormat);
|
|
|
|
m_ptrPlayback->Play();
|
|
|
|
return 0;
|
|
};
|
|
|
|
connect(m_pFrameParams, &FrameParams::sigConfirm_File, this, OnConfirmParams_File);
|
|
}
|
|
}
|
|
|
|
void MainWindow::SetSettingsVisible(bool bVisible)
|
|
{
|
|
int nWidth = ui->centralwidget->width() - 6;
|
|
|
|
if (bVisible)
|
|
{
|
|
ui->splitterHorizon->setHandleWidth(2);
|
|
|
|
if (m_nSize_Settings <= 0)
|
|
{
|
|
m_nSize_Settings = 300;
|
|
}
|
|
|
|
ui->splitterHorizon->setSizes({nWidth - m_nSize_Settings, m_nSize_Settings});
|
|
}
|
|
else
|
|
{
|
|
ui->splitterHorizon->setHandleWidth(0);
|
|
|
|
ui->splitterHorizon->setSizes({nWidth, 0});
|
|
}
|
|
}
|
|
|
|
bool MainWindow::BrowseRawFile()
|
|
{
|
|
QFileDialog varFileDialog(this);
|
|
|
|
varFileDialog.setWindowTitle(/*QString("%1").fromLocal8Bit(*/ tr("读取raw文件"));
|
|
varFileDialog.setDirectory(tr(""));
|
|
|
|
QString strExt = tr("raw files (*.raw *.dat);;all files (*.*) )");
|
|
varFileDialog.setNameFilter(strExt);
|
|
|
|
if (QFileDialog::Accepted == varFileDialog.exec())
|
|
{
|
|
QString strDir = varFileDialog.selectedFiles()[0];
|
|
|
|
m_strCurrentFilePath = strDir;
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void MainWindow::InitStyles()
|
|
{
|
|
QString fileName = ":/skin/qss/psblack.css";
|
|
if (!fileName.isEmpty()) {
|
|
QFile file(fileName);
|
|
|
|
if (file.open(QFile::ReadOnly))
|
|
{
|
|
QString str = file.readAll();
|
|
this->setStyleSheet(str);
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::OnMenuTriggered(bool bChecked)
|
|
{
|
|
/*
|
|
* 媒体
|
|
*/
|
|
{
|
|
if (sender() == ui->m_action_OpenFile)
|
|
{
|
|
if (!BrowseRawFile())
|
|
{
|
|
return;
|
|
}
|
|
|
|
QString strFilePath = m_strCurrentFilePath;
|
|
strFilePath = strFilePath.trimmed();
|
|
|
|
if (strFilePath.endsWith(".raw", Qt::CaseInsensitive) ||
|
|
strFilePath.endsWith(".dat", Qt::CaseInsensitive))
|
|
{
|
|
m_pFrameParams->SetFileType(true);
|
|
m_pFrameParams->SetCardCount(0);
|
|
m_pFrameParams->show();
|
|
m_pFrameParams->setAttribute(Qt::WA_ShowWithoutActivating);
|
|
}
|
|
else
|
|
{}
|
|
|
|
}
|
|
|
|
if (sender() == ui->m_action_OpenDevice)
|
|
{
|
|
m_pFrameParams->SetFileType(false);
|
|
m_pFrameParams->SetCardCount(3);
|
|
m_pFrameParams->show();
|
|
m_pFrameParams->setAttribute(Qt::WA_ShowWithoutActivating);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* 视图
|
|
*/
|
|
{
|
|
if (sender() == ui->m_action_ToolBar)
|
|
{
|
|
if (bChecked)
|
|
{
|
|
ui->widgetToolbar->show();
|
|
}
|
|
else
|
|
{
|
|
ui->widgetToolbar->hide();
|
|
}
|
|
}
|
|
|
|
if (sender() == ui->m_action_Settings)
|
|
{
|
|
SetSettingsVisible(bChecked);
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::OnSplitterMoved(int nPos, int nIndex)
|
|
{
|
|
if (sender() == ui->splitterHorizon)
|
|
{
|
|
QList<int> listSize = ui->splitterHorizon->sizes();
|
|
m_nSize_Settings = listSize.at(1);
|
|
|
|
if (0 >= m_nSize_Settings)
|
|
{
|
|
ui->m_action_Settings->setChecked(false);
|
|
|
|
ui->splitterHorizon->setHandleWidth(0);
|
|
}
|
|
else
|
|
{
|
|
if (!ui->m_action_Settings->isChecked())
|
|
{
|
|
ui->m_action_Settings->setChecked(true);
|
|
|
|
ui->splitterHorizon->setHandleWidth(2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::OnButtonClicked()
|
|
{
|
|
if (sender() == ui->m_toolButton_OpenFile)
|
|
{
|
|
ui->m_action_OpenFile->trigger();
|
|
}
|
|
|
|
if (sender() == ui->m_toolButton_OpenDevice)
|
|
{
|
|
ui->m_action_OpenDevice->trigger();
|
|
}
|
|
|
|
if (sender() == ui->m_toolButton_Settings)
|
|
{
|
|
ui->m_action_Settings->trigger();
|
|
}
|
|
}
|
|
|