78 lines
2.2 KiB
C++
78 lines
2.2 KiB
C++
|
|
#include "dialogcamerasetting.h"
|
|||
|
|
#include "ui_dialogcamerasetting.h"
|
|||
|
|
|
|||
|
|
#include <QDoubleValidator>
|
|||
|
|
|
|||
|
|
DialogCameraSetting::DialogCameraSetting(QWidget* parent)
|
|||
|
|
: QDialog(parent)
|
|||
|
|
, ui(new Ui::DialogCameraSetting)
|
|||
|
|
{
|
|||
|
|
ui->setupUi(this);
|
|||
|
|
setWindowTitle(QStringLiteral("相机设置"));
|
|||
|
|
|
|||
|
|
// 输入校验:曝光为微秒,增益为倍数
|
|||
|
|
ui->edit_exposure->setValidator(new QDoubleValidator(1.0, 1000000.0, 1, this));
|
|||
|
|
ui->edit_gain->setValidator(new QDoubleValidator(0.0, 100.0, 2, this));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
DialogCameraSetting::~DialogCameraSetting()
|
|||
|
|
{
|
|||
|
|
delete ui;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DialogCameraSetting::SetParams(const QString& serverIp, const DroneScrewCameraParams& cam)
|
|||
|
|
{
|
|||
|
|
m_serverIp = serverIp;
|
|||
|
|
m_camera = cam;
|
|||
|
|
loadToUi(serverIp, cam);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QString DialogCameraSetting::GetServerIp() const
|
|||
|
|
{
|
|||
|
|
return m_serverIp;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
DroneScrewCameraParams DialogCameraSetting::GetCameraParams() const
|
|||
|
|
{
|
|||
|
|
return m_camera;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DialogCameraSetting::loadToUi(const QString& serverIp, const DroneScrewCameraParams& cam)
|
|||
|
|
{
|
|||
|
|
if (ui->edit_ip) ui->edit_ip->setText(serverIp);
|
|||
|
|
if (ui->edit_exposure) ui->edit_exposure->setText(QString::number(cam.exposure, 'f', 1));
|
|||
|
|
if (ui->edit_gain) ui->edit_gain->setText(QString::number(cam.gain, 'f', 2));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DialogCameraSetting::collectFromUi()
|
|||
|
|
{
|
|||
|
|
if (ui->edit_ip) m_serverIp = ui->edit_ip->text().trimmed();
|
|||
|
|
if (ui->edit_exposure) { bool ok; double v = ui->edit_exposure->text().toDouble(&ok); if (ok) m_camera.exposure = v; }
|
|||
|
|
if (ui->edit_gain) { bool ok; double v = ui->edit_gain->text().toDouble(&ok); if (ok) m_camera.gain = v; }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DialogCameraSetting::on_btn_ok_clicked()
|
|||
|
|
{
|
|||
|
|
collectFromUi();
|
|||
|
|
accept();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DialogCameraSetting::on_btn_cancel_clicked()
|
|||
|
|
{
|
|||
|
|
reject();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DialogCameraSetting::on_btn_apply_clicked()
|
|||
|
|
{
|
|||
|
|
collectFromUi();
|
|||
|
|
emit applyRequested(m_serverIp, m_camera);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DialogCameraSetting::on_btn_reset_clicked()
|
|||
|
|
{
|
|||
|
|
// 仅把曝光/增益重置为默认值,Server IP 是用户特意配置的连接项,保持不动
|
|||
|
|
DroneScrewCameraParams def;
|
|||
|
|
if (ui->edit_exposure) ui->edit_exposure->setText(QString::number(def.exposure, 'f', 1));
|
|||
|
|
if (ui->edit_gain) ui->edit_gain->setText(QString::number(def.gain, 'f', 2));
|
|||
|
|
}
|