You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
newValue/tpvs17/lpMain/QCamSettingDlg.cpp

286 lines
7.1 KiB
C++

4 years ago
#include "QCamSettingDlg.h"
#pragma execution_character_set("utf-8")
QCamSettingDlg::QCamSettingDlg(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
setWindowIcon(QIcon(":/image/leaper"));
// QGridLayout *pLayout = new QGridLayout(ui.widget);
// m_pImgViewer = new RoiImgViewer(ui.widget);
// m_pImgViewer->setObjectName("Imageview_Setting");
// pLayout->addWidget(m_pImgViewer);
// ui.widget->setLayout(pLayout);
connect(ui.btnOpenCam, SIGNAL(clicked()), this, SLOT(onButtonClicked()));//打开相机
connect(ui.btnStartCam, SIGNAL(clicked()), this, SLOT(onButtonClicked()));//运行相机
connect(ui.btnImgSizeApply, SIGNAL(clicked()), this, SLOT(onButtonClicked()));//应用参数
connect(ui.tp_config_add_camera_open_virfolder_btn, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
connect(ui.btn_add_camera_accept, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
connect(ui.btn_camera_cancel, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
}
QCamSettingDlg::~QCamSettingDlg()
{
if (m_pImgViewer)
{
delete m_pImgViewer;
m_pImgViewer = nullptr;
}
}
void QCamSettingDlg::setCoreCtrlPtr(ICoreCtrl* ptr)
{
m_pCoreCtl = ptr;
if (m_pCoreCtl)
{
FuncCallBack_StrInt camEvFunc = std::bind(&QCamSettingDlg::onCamEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
m_pCoreCtl->IRegisterCamEventCallBack(camEvFunc);
}
}
void QCamSettingDlg::onShowImage(QString serial , QImage img)
{
if (m_curCamKey != serial)
return;
// if (m_pImgViewer)
{
ui.imgViewer->setImg(img);
}
}
void QCamSettingDlg::onModCam(QString serial)
{
ui.cmb_camera_type->setDisabled(true);
ui.edit_add_camera_sn->setDisabled(true);
if (m_pCoreCtl)
{
QStringList lst = m_pCoreCtl->ICameraKeys();
if (lst.size() <= 0)
return;
m_curCamKey = serial;
ui.edit_add_camera_sn->setText(m_curCamKey);
QMap<QString, QString> map = m_pCoreCtl->IGetCamShowNames();
QString strShow = map[m_curCamKey];
ui.edit_camera_showname->setText(strShow);
TP_CAMERA_OPTION camOpt;
m_pCoreCtl->IGetCameraOption(m_curCamKey, camOpt);
ui.spbImgStartX->setValue(0);
ui.spbImgStartY->setValue(0);
ui.spbImgHeight->setValue(camOpt.height);
ui.spbImgWidth->setValue(camOpt.width);
ui.spb_camera_exposure->setValue(camOpt.exposure);
ui.spb_camera_gain->setValue(camOpt.gain);
emTpColorFormat color = camOpt.format;
if (color == TP_COLOR_Y800)
ui.cmb_camera_format->setCurrentIndex(0);
else
ui.cmb_camera_format->setCurrentIndex(1);
if (camOpt.status == TP_CAMERA_STATUS_UNINIT)// 未初始化(刚从配置文件加载)
{
ui.btnOpenCam->setText("打开");
ui.btnStartCam->setText("运行");
}
else if (camOpt.status == TP_CAMERA_STATUS_INITED)// 已初始化即加载DLL成功
{
ui.btnOpenCam->setText("打开");
ui.btnStartCam->setText("运行");
}
else if (camOpt.status == TP_CAMERA_STATUS_OPENED)// 已打开
{
ui.btnOpenCam->setText("关闭");
ui.btnStartCam->setText("运行");
}
else if (camOpt.status == TP_CAMERA_STATUS_STARTED)// 运行中
{
ui.btnOpenCam->setText("关闭");
ui.btnStartCam->setText("停止");
}
else if (camOpt.status == TP_CAMERA_STATUS_STOPPED)// 暂停
{
ui.btnOpenCam->setText("关闭");
ui.btnStartCam->setText("运行");
}
else if (camOpt.status == TP_CAMERA_STATUS_CLOSED)// 已关闭
{
ui.btnOpenCam->setText("打开");
ui.btnStartCam->setText("运行");
}
else {
}
}
}
void QCamSettingDlg::onCamEvent(const QString& serial, emTpCameraStatus status, bool ret)
{
if (m_curCamKey != serial)
return;
if (status == TP_CAMERA_STATUS_CLOSED && ret == true)
{
ui.btnOpenCam->setText("打开");
ui.btnStartCam->setText("运行");
ui.btnStartCam->setDisabled(true);
}
else if (status == TP_CAMERA_STATUS_OPENED && ret == true)
{
ui.btnOpenCam->setText("关闭");
ui.btnStartCam->setText("运行");
ui.btnStartCam->setDisabled(false);
}
else if (status == TP_CAMERA_STATUS_STARTED && ret == true)
{
ui.btnOpenCam->setText("关闭");
ui.btnStartCam->setText("停止");
ui.btnStartCam->setDisabled(false);
}
else if (status == TP_CAMERA_STATUS_STOPPED && ret == true)
{
ui.btnOpenCam->setText("关闭");
ui.btnStartCam->setText("运行");
ui.btnStartCam->setDisabled(false);
}
}
void QCamSettingDlg::onInitWidget(QString serial)
{
/* if (m_pCoreCtl)
{
QStringList lst = m_pCoreCtl->ICameraKeys();
if (lst.size() <= 0)
return;
m_curCamKey = serial;
ui.m_SerialNo->setText(m_curCamKey);
QMap<QString, QString> map = m_pCoreCtl->IGetCamShowNames();
QString strShow = map[m_curCamKey];
ui.m_ShowName->setText(strShow);
TP_CAMERA_OPTION camOpt;
m_pCoreCtl->IGetCameraOption(m_curCamKey, camOpt);
int h = camOpt.height;
int w = camOpt.width;
int e = camOpt.exposure;
int g = camOpt.gain;
ui.m_ImgWidth->setText(QString("%1").arg(w));
ui.m_ImgHeight->setText(QString("%1").arg(h));
ui.m_Expouse->setText(QString("%1").arg(e));
ui.m_Gain->setText(QString("%1").arg(g));
ui.lineEdit_3->setText(camOpt.folder);
{
int devType = camOpt.deviceType;
int index = 0;
switch (devType)
{
case 100:
index = 0;
onShowVirtualDir(true);
break;
case 140:
index = 1;
onShowVirtualDir(false);
break;
case 160:
index = 2;
onShowVirtualDir(false);
break;
default:
// break;
}
ui.comboBox->setCurrentIndex(index);
}
{
emTpColorFormat color = camOpt.format;
if (color == TP_COLOR_Y800)
ui.m_Pixformat->setCurrentIndex(0);
else
ui.m_Pixformat->setCurrentIndex(1);
}
if (camOpt.status == TP_CAMERA_STATUS_STARTED)
{
EnableUI(false);
ui.m_pbOpen->setText(tr("关闭"));
ui.m_pbTrigger->setDisabled(false);
}
else {
ui.m_pbOpen->setText(tr("打开"));
EnableUI(true);
ui.m_pbTrigger->setDisabled(true);
}
}*/
}
Q_SLOT void QCamSettingDlg::onButtonClicked()
{
QString strObj = sender()->objectName();
if ("btnOpenCam" == strObj)//打开相机
{
QString str = ui.btnOpenCam->text();
if ("打开" == str)
{
m_pCoreCtl->IOpenCamera(m_curCamKey);
}
else {
m_pCoreCtl->ICloseCamera(m_curCamKey);
}
}
else if ("btnStartCam" == strObj)//运行相机
{
QString str = ui.btnStartCam->text();
if ("运行" == str)
{
m_pCoreCtl->IStartCamera(m_curCamKey);
}
else {
m_pCoreCtl->IStopCamera(m_curCamKey);
}
}
else if ("btnImgSizeApply" == strObj)//应用参数
{
}
else if ("tp_config_add_camera_open_virfolder_btn" == strObj)
{
}
else if ("btn_add_camera_accept" == strObj)
{
if (m_pCoreCtl)
m_pCoreCtl->ISnapImage(QStringList() << m_curCamKey);
}
else if ("btn_camera_cancel" == strObj)
{
}
}
void QCamSettingDlg::onShowVirtualDir(bool bShow)
{
// ui.label_4->setVisible(bShow);
// ui.lineEdit_3->setVisible(bShow);
// ui.m_pbSetting->setVisible(bShow);
}
void QCamSettingDlg::EnableUI(bool b)
{
// ui.m_SerialNo->setDisabled(!b);
// ui.m_ShowName->setDisabled(!b);
// ui.comboBox->setDisabled(!b);
// ui.m_Pixformat->setDisabled(!b);
// ui.toolButton->setDisabled(!b);
// ui.comboBox_3->setDisabled(!b);
// ui.m_pbSetRect->setDisabled(!b);
// ui.m_ImgWidth->setDisabled(!b);
// ui.m_ImgHeight->setDisabled(!b);
}