扫描区域传值由像素改为毫米,解决精度误差问题

This commit is contained in:
yangjiaxuan 2023-07-28 15:34:02 +08:00
parent 07d7a64046
commit dc247f4e15
5 changed files with 57 additions and 15 deletions

View File

@ -1,4 +1,4 @@
#include "cutdialog.h"
#include "cutdialog.h"
#include "ui_cutdialog.h"
#include <QDebug>
#include <QToolTip>
@ -196,6 +196,25 @@ void cutDialog::setCutRectPixel(QRectF &rect)
update();
}
QRectF cutDialog::getCutRectMM()const
{
double x = paperWidth * realRate * m_startPoint.x() / scaleRec.width();
double y = paperHeight * realRate * m_startPoint.y() / scaleRec.height();
double w = paperWidth * realRate * m_rect.width() / scaleRec.width();
double h = paperHeight * realRate * m_rect.height() / scaleRec.height();
return QRectF(x, y, w, h);
}
void cutDialog::setCutRectMM(QRectF& rect)
{
m_startPoint.setX(scaleRec.width() * rect.x() / (paperWidth * realRate));
m_startPoint.setY(scaleRec.height() * rect.y() / (paperHeight * realRate));
m_endPoint.setX(m_startPoint.x() + scaleRec.width() * rect.width() / (paperWidth * realRate));
m_endPoint.setY(m_startPoint.y() + scaleRec.height() * rect.height() / (paperHeight * realRate));
m_rect = QRectF(m_startPoint, m_endPoint);
update();
}
int cutDialog::getCutRectRight() const
{
return getPaperSize().width()*m_rect.right()/scaleRec.right();

View File

@ -1,4 +1,4 @@
#ifndef CUTDIALOG_H
#ifndef CUTDIALOG_H
#define CUTDIALOG_H
#include <QWidget>
@ -35,6 +35,8 @@ public:
QPointF getCutRectStartPos()const;
QRectF getCutRectPixel()const;
void setCutRectPixel(QRectF& rect);
QRectF getCutRectMM()const;
void setCutRectMM(QRectF& rect);
int getCutRectRight()const;
int getCutRectBottom()const;
void refreshView();

View File

@ -1,4 +1,4 @@
#include "cutpapertool.h"
#include "cutpapertool.h"
#include "ui_cutpapertool.h"
#include <QDebug>
#include <QValidator>
@ -57,6 +57,24 @@ void CutPaperTool::setCutRectPixel(QRectF &rect)
ui->widget->refreshView();
}
QRectF CutPaperTool::getCutRectMM()
{
return QRectF(ui->widget->getCutRectMM());
}
void CutPaperTool::setCutRectMM(QRectF& rect)
{
ui->widget->setCutRectMM(rect);
ui->startXEdt->setText(QString::number(rect.x()));
ui->startYEdt->setText(QString::number(rect.y()));
ui->rectWidth->setText(QString::number(rect.width()));
ui->rectHeight->setText(QString::number(rect.height()));
update();
setSizeLabel();
ui->widget->refreshView();
}
int CutPaperTool::getUnit()
{
return ui->comboBox_2->currentIndex();

View File

@ -1,4 +1,4 @@
#ifndef CUTPAPERTOOL_H
#ifndef CUTPAPERTOOL_H
#define CUTPAPERTOOL_H
#include <QDialog>
@ -17,6 +17,8 @@ public:
~CutPaperTool();
QRectF getCutRectPixel();
void setCutRectPixel(QRectF& rect);
QRectF getCutRectMM();
void setCutRectMM(QRectF& rect);
int getUnit();
private:

View File

@ -1330,22 +1330,22 @@ void hg_settingdialog::slot_cutButtonClicked()
{
//int width = 0.03937 * m_cutWidth * m_dpiValue;
//int height = 0.03937 * m_cutHeight * m_dpiValue;
qreal left = 0.03937 * m_cutLeftValue * m_dpiValue;
qreal top = 0.03937 * m_cutTopValue * m_dpiValue;
qreal right = 0.03937 * m_cutRightValue * m_dpiValue;
qreal bottom = 0.03937 * m_cutBottomValue * m_dpiValue;
//qreal left = 0.03937 * m_cutLeftValue * m_dpiValue;
//qreal top = 0.03937 * m_cutTopValue * m_dpiValue;
//qreal right = 0.03937 * m_cutRightValue * m_dpiValue;
//qreal bottom = 0.03937 * m_cutBottomValue * m_dpiValue;
CutPaperTool dlg(m_dpiValue, m_paperSizeValue, 300, 0, this);
QRectF rc(left, top, right - left, bottom - top);
dlg.setCutRectPixel(rc);
QRectF rc(m_cutLeftValue, m_cutTopValue, m_cutRightValue - m_cutLeftValue, m_cutBottomValue - m_cutTopValue);
dlg.setCutRectMM(rc);
if (dlg.exec())
{
QRectF rcRet = dlg.getCutRectPixel();
QRectF rcRet = dlg.getCutRectMM();
m_cutLeftValue = rcRet.left() / (0.03937 * m_dpiValue);
m_cutTopValue = rcRet.top() / (0.03937 * m_dpiValue);
m_cutRightValue = rcRet.right() / (0.03937 * m_dpiValue);
m_cutBottomValue = rcRet.bottom() / (0.03937 * m_dpiValue);
m_cutLeftValue = rcRet.left();
m_cutTopValue = rcRet.top();
m_cutRightValue = rcRet.right();
m_cutBottomValue = rcRet.bottom();
SANE_Int info;
SANE_Word value = SANE_FIX(m_cutLeftValue);
@ -2785,6 +2785,7 @@ void hg_settingdialog::updateSchemeFromUi(gb::sane_config_schm* schm)
SANE_Fixed init = 0;
m_saneAPI.sane_control_option_api(m_devHandle, i, SANE_ACTION_GET_VALUE, &init, &method);
float vv = SANE_UNFIX(init);
schm->config_changed(i, (char*)&init, sizeof(init));
}
else if (opt->type == SANE_TYPE_BOOL)