app修改为直接调用twain和sane

This commit is contained in:
yangjiaxuan 2023-05-04 14:55:26 +08:00
parent 8ac9811919
commit e7d9e3d0d0
41 changed files with 1310 additions and 8902 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,464 +0,0 @@
#include "cutdialog.h"
#include "ui_cutdialog.h"
#include <QDebug>
#include <QToolTip>
#include <qpainterpath.h>
#include "HGString.h"
#include "sane/sane_option_definitions.h"
cutDialog::cutDialog(QWidget *parent) :
QWidget(parent),
ui(new Ui::cutDialog)
{
ui->setupUi(this);
divisor = 8;
dpi = 1;
sizeType = 0;
paperWidth = 185;
h_w = 260.0/185.0;
sizeRate = 1;
paperHeight = paperWidth*h_w;
this->setFixedSize(paperWidth,paperHeight);
setMouseTracking(true);
m_startPoint = QPoint(10,10);
m_endPoint = QPoint(50,50);
m_mouse_down = false;
initAllCorner();
}
cutDialog::~cutDialog()
{
delete ui;
}
void cutDialog::setPaperSize(QString type, const int w)
{
paperType = type;
if (paperType == OPTION_VALUE_ZZCC_A3) h_w = 420.0 / 297.0;
else if (paperType == OPTION_VALUE_ZZCC_8K) h_w = 390.0 / 270.0;
else if (paperType == OPTION_VALUE_ZZCC_16K) h_w = 270.0 / 190.0;
else if (paperType == OPTION_VALUE_ZZCC_16KHX) h_w = 190.0 / 270.0;
else if (paperType == OPTION_VALUE_ZZCC_A4) h_w = 297.0 / 210.0;
else if (paperType == OPTION_VALUE_ZZCC_A4HX) h_w = 210.0 / 297.0;
else if (paperType == OPTION_VALUE_ZZCC_A5) h_w = 210.0 / 148.0;
else if (paperType == OPTION_VALUE_ZZCC_A5HX) h_w = 148.0 / 210.0;
else if (paperType == OPTION_VALUE_ZZCC_A6) h_w = 148.0 / 105.0;
else if (paperType == OPTION_VALUE_ZZCC_A6HX) h_w = 105.0 / 148.0;
else if (paperType == OPTION_VALUE_ZZCC_B4) h_w = 353.0 / 250.0;
else if (paperType == OPTION_VALUE_ZZCC_B5) h_w = 250.0 / 176.0;
else if (paperType == OPTION_VALUE_ZZCC_B5HX) h_w = 176.0 / 250.0;
else if (paperType == OPTION_VALUE_ZZCC_B6) h_w = 176.0 / 125.0;
else if (paperType == OPTION_VALUE_ZZCC_B6HX) h_w = 125.0 / 176.0;
else if (paperType == OPTION_VALUE_ZZCC_Letter) h_w = 279.0 / 216.0;
else if (paperType == OPTION_VALUE_ZZCC_LetterHX) h_w = 216.0 / 279.0;
else if (paperType == OPTION_VALUE_ZZCC_DoubleLetter) h_w = 559.0 / 216.0;
else if (paperType == OPTION_VALUE_ZZCC_LEGAL) h_w = 356.0 / 216.0;
else if (paperType == OPTION_VALUE_ZZCC_SLSJ) h_w = 560.0 / 270.0;
else if(paperType == OPTION_VALUE_ZZCC_ZDSMCC) h_w = 3307.0*2/2338;
else if(paperType == OPTION_VALUE_ZZCC_PPYSCC) {
if(dpi == 100.0) h_w = 1795.0/1189;
if(dpi == 150.0) h_w = 1795.0/1784;
if(dpi == 200.0) h_w = 3307.0/2338;
if(dpi == 240.0) h_w = 4308.0/2854;
if(dpi == 200.0) h_w = 5385.0/3567;
};
if(type.contains("3")) divisor = 2;
else if (type.contains("4")) divisor = 4;
else if (type.contains("5")) divisor = 6;
else if (type.contains("6")) divisor = 8;
else divisor = 4;
paperWidth = w;
if(type.contains(StdStringToUtf8("横向").c_str()))
paperWidth = paperWidth*h_w*1.5;
double realW = paperWidth;
if (paperType == OPTION_VALUE_ZZCC_A3 || paperType == OPTION_VALUE_ZZCC_A4HX) realRate = 297.0 / realW;
else if (paperType == OPTION_VALUE_ZZCC_A4 || paperType == OPTION_VALUE_ZZCC_A5HX) realRate = 210.0 / realW;
else if (paperType == OPTION_VALUE_ZZCC_A5 || paperType == OPTION_VALUE_ZZCC_A6HX) realRate = 148.0 / realW;
else if (paperType == OPTION_VALUE_ZZCC_A6) realRate = 105.0 / realW;
else if (paperType == OPTION_VALUE_ZZCC_16K) realRate = 190.0 / realW;
else if (paperType == OPTION_VALUE_ZZCC_8K || paperType == OPTION_VALUE_ZZCC_16KHX) realRate = 270.0 / realW;
else if (paperType == OPTION_VALUE_ZZCC_B4 || paperType == OPTION_VALUE_ZZCC_B5HX) realRate = 250.0 / realW;
else if (paperType == OPTION_VALUE_ZZCC_B5 || paperType == OPTION_VALUE_ZZCC_B6HX) realRate = 176.0 / realW;
else if (paperType == OPTION_VALUE_ZZCC_B6) realRate = 125.0 / realW;
else if (paperType == OPTION_VALUE_ZZCC_Letter) realRate = 216.0 / realW;
else if (paperType == OPTION_VALUE_ZZCC_LetterHX) realRate = 279.0 / realW;
else if (paperType == OPTION_VALUE_ZZCC_DoubleLetter) realRate = 216.0 / realW;
else if (paperType == OPTION_VALUE_ZZCC_LEGAL) realRate = 216.0 / realW;
else if (paperType == OPTION_VALUE_ZZCC_SLSJ) realRate = 270.0 / realW;
else if(paperType == OPTION_VALUE_ZZCC_ZDSMCC) realRate = 297.0/realW;
else if(paperType == OPTION_VALUE_ZZCC_PPYSCC) {
if(dpi == 100.0) realRate = 1189.0*0.039377/dpi/realW;
if(dpi == 150.0) realRate = 1784*0.039377/dpi/realW;
if(dpi == 200.0) realRate = 2338*0.039377/dpi/realW;
if(dpi == 240.0) realRate = 2854*0.039377/dpi/realW;
if(dpi == 200.0) realRate = 3567*0.039377/dpi/realW;
};
paperHeight = paperWidth*h_w;
this->setFixedSize(paperWidth+4,paperHeight+4);
scaleRec = QRectF(0,0,paperWidth,paperHeight+0.5);
m_rect = QRectF(m_startPoint,m_endPoint);
update();
refreshView();
}
void cutDialog::setDpiValue(const double d)
{
dpi = d;
if(sizeType == PIXEL) sizeRate = 0.03937*dpi;
update();
}
void cutDialog::setSizeType(const SIZETYPE &t)
{
sizeType = t;
switch (sizeType) {
case MILLIM:
sizeRate = 1;
break;
case INCH:
sizeRate = 0.03937;
break;
case PIXEL:
sizeRate = 0.03937*dpi;
break;
}
update();
}
void cutDialog::setCutRectWidth(double w)
{
m_endPoint.setX(m_startPoint.x()+scaleRec.width()*w/getPaperSize().width());
update();
}
void cutDialog::setCutRectHeight(double h)
{
m_endPoint.setY(m_startPoint.y()+scaleRec.height()*h/getPaperSize().height());
update();
}
void cutDialog::setCutRectStartX(double x)
{
m_startPoint.setX(scaleRec.width()*x/getPaperSize().width());
update();
}
void cutDialog::setCutRectStartY(double y)
{
m_startPoint.setY(scaleRec.height()*y/getPaperSize().height());
update();
}
QSizeF cutDialog::getPaperSize() const
{
double realW = paperWidth*realRate*sizeRate;
double realH = paperHeight*realRate*sizeRate;
return QSizeF(realW,realH);
}
QSizeF cutDialog::getCutRectSize() const
{
double realCutW = getPaperSize().width()*m_rect.width()/scaleRec.width();
double realCutH = getPaperSize().height()*m_rect.height()/scaleRec.height();
return QSizeF(realCutW,realCutH);
}
QPointF cutDialog::getCutRectStartPos() const
{
double realCutX = getPaperSize().width()*m_startPoint.x()/scaleRec.width();
double realCutY = getPaperSize().height()*m_startPoint.y()/scaleRec.height();
return QPointF(realCutX,realCutY);
}
QRectF cutDialog::getCutRectPixel() const
{
double x = 0.03937*dpi*paperWidth*realRate*m_startPoint.x()/scaleRec.width();
double y = 0.03937*dpi*paperHeight*realRate*m_startPoint.y()/scaleRec.height();
double w = 0.03937*dpi*paperWidth*realRate*m_rect.width()/scaleRec.width();
double h = 0.03937*dpi*paperHeight*realRate*m_rect.height()/scaleRec.height();
return QRectF(x,y,w,h);
}
void cutDialog::setCutRectPixel(QRectF &rect)
{
m_startPoint.setX(scaleRec.width()*rect.x()/(paperWidth*realRate*0.03937*dpi));
m_startPoint.setY(scaleRec.height()*rect.y()/(paperHeight*realRate*0.03937*dpi));
m_endPoint.setX(m_startPoint.x()+scaleRec.width()*rect.width()/(paperWidth*realRate*0.03937*dpi));
m_endPoint.setY(m_startPoint.y()+scaleRec.height()*rect.height()/(paperHeight*realRate*0.03937*dpi));
update();
}
int cutDialog::getCutRectRight() const
{
return getPaperSize().width()*m_rect.right()/scaleRec.right();
}
int cutDialog::getCutRectBottom() const
{
return getPaperSize().height()*m_rect.bottom()/scaleRec.bottom();
}
void cutDialog::mousePressEvent(QMouseEvent *event)
{
int x = event->x()/**paperWidth/width()*/;
int y = event->y()/**paperHeight/height()*/;
m_moveStart = QPoint(x,y);
m_mouse_down = event->button() == Qt::LeftButton;
update();
}
void cutDialog::mouseMoveEvent(QMouseEvent *event)
{
int x = event->x()/**paperWidth/width()*/;
int y = event->y()/**paperHeight/height()*/;
if(m_mouse_down){
int dx = m_moveStart.x() - x;
int dy = m_moveStart.y() - y;
m_moveStart = QPoint(x,y);
if(m_leftCorn){
m_startPoint.setX(x);
}else if(m_rightCorn){
m_endPoint.setX(x);
}else if(m_topCorn){
m_startPoint.setY(y);
}else if(m_bottomCorn){
m_endPoint.setY(y);
}else if(m_leftTop){
m_startPoint.setX(x);
m_startPoint.setY(y);
}else if(m_leftBottom){
m_startPoint.setX(x);
m_endPoint.setY(y);
}else if(m_rightTop){
m_startPoint.setY(y);
m_endPoint.setX(x);
}else if(m_rightBottom){
m_endPoint.setX(x);
m_endPoint.setY(y);
}
else if(!m_out){
if(m_startPoint.x() - dx < 0) dx = 0;
if(m_startPoint.y() - dy < 0) dy = 0;
if(m_endPoint.x() - dx > scaleRec.right()) dx = 0;
if(m_endPoint.y() - dy > scaleRec.bottom()) dy = 0;
m_startPoint.setX(m_rect.left()-dx);
m_startPoint.setY(m_rect.top()-dy);
m_endPoint.setX(m_rect.right()-dx);
m_endPoint.setY(m_rect.bottom()-dy);
}
if(m_startPoint.x()<=0) m_startPoint.setX(0);
if(m_startPoint.y()<=0) m_startPoint.setY(0);
if(m_endPoint.x()>=scaleRec.width()) m_endPoint.setX(scaleRec.right());
if(m_endPoint.y()>=scaleRec.height()) m_endPoint.setY(scaleRec.bottom());
if(qAbs(m_startPoint.x() - m_endPoint.x()) <= 10 || m_startPoint.x() > m_endPoint.x()){
m_startPoint.setX(m_rect.left());
m_endPoint.setX(m_rect.right());
}
if(qAbs(m_startPoint.y() - m_endPoint.y()) <= 10 || m_startPoint.y() > m_endPoint.y()){
m_startPoint.setY(m_rect.top());
m_endPoint.setY(m_rect.bottom());
}
update();
}else{
mousePosition(QPoint(x,y));
}
}
void cutDialog::mouseReleaseEvent(QMouseEvent *)
{
m_mouse_down = false;
update();
}
void cutDialog::enterEvent(QEvent *)
{
emit lineEditEnable(false);
}
void cutDialog::leaveEvent(QEvent *)
{
emit lineEditEnable(true);
}
void cutDialog::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.translate(0,0);
drawScale(painter);
drawCutRect(painter);
drawTransparentColor(painter);
if(m_mouse_down){
if(sizeType == INCH || sizeType == MILLIM){
emit cutRectX(QString::number(getCutRectStartPos().x(),'f',2).toDouble());
emit cutRectY(QString::number(getCutRectStartPos().y(),'f',2).toDouble());
emit cutRectWidth(QString::number(getCutRectSize().width(),'f',2).toDouble());
emit cutRectHeight(QString::number(getCutRectSize().height(),'f',2).toDouble());
}else{
emit cutRectX(double(int(getCutRectStartPos().x())));
emit cutRectY(double(int(getCutRectStartPos().y())));
emit cutRectWidth(double(int(getCutRectSize().width())));
emit cutRectHeight(double(int(getCutRectSize().height())));
}
}
painter.end();
}
void cutDialog::drawScale(QPainter& painter)
{
painter.setPen(QPen(Qt::black,1));
scaleRec = QRectF(0,0,paperWidth,paperHeight+0.5);
painter.drawRect(scaleRec);
for(int i = 6 ; i <= paperWidth-6; i++){
if(int(paperWidth/2) == i || int(paperWidth/4) == i || int(paperWidth*3/4) == i){
painter.setPen(QPen(Qt::gray,1));
painter.drawLine(i,0,i,paperHeight);
painter.setPen(QPen(Qt::black,1));
}
if(i%divisor == 0){
painter.drawLine(i,paperHeight-4,i,paperHeight);
painter.drawLine(i,0,i,4);
}
if(i%(divisor*5) == 0){
painter.drawLine(i,paperHeight-8,i,paperHeight);
painter.drawLine(i,0,i,8);
}
}
for(int i = 6 ; i <= paperHeight-6; i++){
if(int(paperHeight/2) == i || int(paperHeight/4) == i || int(paperHeight*3/4) == i){
painter.setPen(QPen(Qt::gray,1));
painter.drawLine(0,i,paperWidth,i);
painter.setPen(QPen(Qt::black,1));
}
if(i%divisor == 0){
painter.drawLine(0,i,4,i);
painter.drawLine(paperWidth,i,paperWidth-4,i);
}
if(i%(divisor*5) == 0){
painter.drawLine(0,i,8,i);
painter.drawLine(paperWidth,i,paperWidth-8,i);
}
}
}
void cutDialog::drawCutRect(QPainter &painter)
{
painter.setPen(QPen(Qt::green,1));
m_rect = QRectF(m_startPoint,m_endPoint);
QRectF r(m_rect);
if(r.right() + 6 > paperWidth)
r.setRight(paperWidth - 6);
if(r.bottom() + 2 > paperHeight)
r.setBottom(paperHeight - 2);
painter.drawRect(r);
painter.setPen(QPen(Qt::red,1));
painter.setBrush(Qt::red);
painter.drawEllipse(r.left()-2,(r.bottom()-r.top())/2+r.top()-2,4,4);
painter.drawEllipse(r.left()-2,r.top()-2,4,4);
painter.drawEllipse(r.left()-2,r.bottom()-2,4,4);
painter.drawEllipse(r.right()-2,r.top()-2,4,4);
painter.drawEllipse(r.right()-2,r.bottom()-2,4,4);
painter.drawEllipse(r.right()-2,(r.bottom()-r.top())/2+r.top()-2,4,4);
painter.drawEllipse((r.right()-r.left())/2+r.left()-2,r.top()-2,4,4);
painter.drawEllipse((r.right()-r.left())/2+r.left()-2,r.bottom()-2,4,4);
}
void cutDialog::drawTransparentColor(QPainter &painter)
{
QPainterPath painterPath;
QPainterPath p;
p.addRect(scaleRec);
painterPath.addRect(m_rect);
QPainterPath drawPath =p.subtracted(painterPath);
painter.setOpacity(0.7);
painter.fillPath(drawPath,QBrush(Qt::gray));
}
void cutDialog::mousePosition(const QPoint& e)
{
initAllCorner();
QRectF r = QRectF(m_rect);
int x = e.x();
int y = e.y();
m_left = qAbs(x - r.left()) < 5;
m_right = qAbs(x - r.right()) < 5;
m_bottom = qAbs(y - r.bottom()) < 5;
m_top = qAbs(y - r.top()) < 5;
m_out = r.left()-x>=5 || x-r.right()>=5 || r.top()-y>=5 || y-r.bottom()>=5;
bool lorr = m_left | m_right;
bool torb = m_top | m_bottom;
if(lorr && torb)
{
if((m_left && m_top) || (m_right && m_bottom))
setCursor(Qt::SizeFDiagCursor);
else
setCursor(Qt::SizeBDiagCursor);
}
else if(lorr)
setCursor(Qt::SizeHorCursor);
else if(torb)
setCursor(Qt::SizeVerCursor);
else if(!m_out)
{
setCursor(Qt::SizeAllCursor);
m_bottom = m_left = m_right = m_top = false;
}else if(m_out){
setCursor(Qt::ArrowCursor);
m_bottom = m_left = m_right = m_top = false;
}
if(m_left && m_top) m_leftTop = true;
else if(m_left && m_bottom) m_leftBottom = true;
else if(m_right && m_top) m_rightTop = true;
else if(m_right && m_bottom) m_rightBottom = true;
else if(m_left && !m_top && !m_bottom) m_leftCorn = true;
else if(m_right && !m_top && !m_bottom) m_rightCorn = true;
else if(m_top && !m_left && !m_right) m_topCorn = true;
else if(m_bottom && !m_left && !m_right) m_bottomCorn = true;
else initAllCorner();
}
void cutDialog::refreshView()
{
if(sizeType == INCH){
emit cutRectX(QString::number(getCutRectStartPos().x(),'f',2).toDouble());
emit cutRectY(QString::number(getCutRectStartPos().y(),'f',2).toDouble());
emit cutRectWidth(QString::number(getCutRectSize().width(),'f',2).toDouble());
emit cutRectHeight(QString::number(getCutRectSize().height(),'f',2).toDouble());
}else{
emit cutRectX(QString::number(getCutRectStartPos().x(),'f',0).toDouble());
emit cutRectY(QString::number(getCutRectStartPos().y(),'f',0).toDouble());
emit cutRectWidth(double(int(getCutRectSize().width())));
emit cutRectHeight(double(int(getCutRectSize().height())));
}
}
void cutDialog::initAllCorner()
{
m_left = false;
m_right = false;
m_bottom = false;
m_top = false;
m_leftCorn = false;
m_rightCorn = false;
m_topCorn = false;
m_bottomCorn = false;
m_leftTop = false;
m_leftBottom = false;
m_rightTop = false;
m_rightBottom = false;
}

View File

@ -1,100 +0,0 @@
#ifndef CUTDIALOG_H
#define CUTDIALOG_H
#include <QWidget>
#include <QMouseEvent>
#include <QPainter>
#include <QCursor>
namespace Ui {
class cutDialog;
}
enum SIZETYPE{
MILLIM ,
INCH,
PIXEL
};
class cutDialog : public QWidget
{
Q_OBJECT
public:
explicit cutDialog(QWidget *parent = nullptr);
~cutDialog();
void setPaperSize(QString type = "A1", const int w = 200);
void setDpiValue(const double d);
void setSizeType(const SIZETYPE& t);
void setCutRectWidth(double w);
void setCutRectHeight(double h);
void setCutRectStartX(double x);
void setCutRectStartY(double y);
QSizeF getPaperSize()const;
QSizeF getCutRectSize()const;
QPointF getCutRectStartPos()const;
QRectF getCutRectPixel()const;
void setCutRectPixel(QRectF& rect);
int getCutRectRight()const;
int getCutRectBottom()const;
void refreshView();
signals:
void cutRectX(double x);
void cutRectY(double y);
void cutRectWidth(double w);
void cutRectHeight(double h);
void lineEditEnable(bool b);
private:
void mousePressEvent(QMouseEvent*);
void mouseMoveEvent(QMouseEvent*);
void mouseReleaseEvent(QMouseEvent*);
void enterEvent(QEvent*);
void leaveEvent(QEvent*);
//void resizeEvent(QResizeEvent*);
void paintEvent(QPaintEvent *);
void drawScale(QPainter &painter);
void drawCutRect(QPainter &painter);
void drawTransparentColor(QPainter &painter);
void drawPaperSize();
void mousePosition(const QPoint &e);
void initAllCorner();
//void mouseChangeRect(int dx,int dy);
private:
Ui::cutDialog *ui;
QPointF m_startPoint;
QPointF m_endPoint;
QPointF m_moveStart;
QRectF m_rect;
QRectF scaleRec;
QString paperType;
double paperWidth;
double paperHeight;
int divisor;
int sizeType;
double dpi;
double h_w;
double realRate;
double sizeRate;
bool m_mouse_down;
bool m_left;
bool m_right;
bool m_bottom;
bool m_top;
bool m_leftCorn;
bool m_rightCorn;
bool m_topCorn;
bool m_bottomCorn;
bool m_leftTop;
bool m_rightTop;
bool m_leftBottom;
bool m_rightBottom;
bool m_out;
};
#endif // CUTDIALOG_H

View File

@ -1,44 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>cutDialog</class>
<widget class="QWidget" name="cutDialog">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>321</width>
<height>342</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>2</width>
<height>0</height>
</size>
</property>
<property name="baseSize">
<size>
<width>2</width>
<height>0</height>
</size>
</property>
<property name="mouseTracking">
<bool>true</bool>
</property>
<property name="windowTitle">
<string>cutDialog</string>
</property>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@ -1,219 +0,0 @@
#include "cutpapertool.h"
#include "ui_cutpapertool.h"
#include <QDebug>
#include <QValidator>
CutPaperTool::CutPaperTool(QWidget *parent) :
QDialog(parent),
ui(new Ui::CutPaperTool)
{
ui->setupUi(this);
setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
connect(ui->widget,SIGNAL(cutRectX(double)),this,SLOT(cutRectXSlot(double)));
connect(ui->widget,SIGNAL(cutRectY(double)),this,SLOT(cutRectYSlot(double)));
connect(ui->widget,SIGNAL(cutRectWidth(double)),this,SLOT(cutRectWidthSlot(double)));
connect(ui->widget,SIGNAL(cutRectHeight(double)),this,SLOT(cutRectHeightSlot(double)));
connect(ui->widget,SIGNAL(lineEditEnable(bool)),this,SLOT(lineEditEnableSlot(bool)));
//setDpi(200);
//setPaperType(200,"A4",400);
ui->widget->setSizeType(MILLIM);
setSizeLabel();
//ui->pbtn_init->setFixedWidth(160);
this->setFixedWidth(ui->widget->width()+40);
}
CutPaperTool::~CutPaperTool()
{
delete ui;
}
void CutPaperTool::paintEvent(QPaintEvent *)
{
}
void CutPaperTool::setPaperType(const int d, const QString &t, const int& w)
{
dpi = d;
ui->dpiLab->setText(QString::number(dpi));
ui->widget->setDpiValue(dpi);
paperType = t;
ui->paperLab->setText(paperType);
ui->widget->setPaperSize(paperType,w);
//ui->widget->refreshView();
setSizeLabel();
this->setFixedWidth(ui->widget->width()+40);
setSizeInit();
}
QRectF CutPaperTool::getCutRectPixel()
{
return QRectF(ui->widget->getCutRectPixel());
}
void CutPaperTool::setCutRect(QRectF &rect)
{
ui->widget->setCutRectPixel(rect);
ui->startXEdt->setText(QString::number(rect.x()/dpi/0.03937));
ui->startYEdt->setText(QString::number(rect.y()/dpi/0.03937));
ui->rectWidth->setText(QString::number(rect.width()/dpi/0.03937));
ui->rectHeight->setText(QString::number(rect.height()/dpi/0.03937));
}
void CutPaperTool::setSizeLabel()
{
QString wSize;
QString hSize;
if(ui->comboBox_2->currentIndex() == INCH){
wSize = QString::number(ui->widget->getPaperSize().width(),'f',2);
hSize = QString::number(ui->widget->getPaperSize().height(),'f',2);
}
else {
wSize = QString::number(int(ui->widget->getPaperSize().width()+0.001));
hSize = QString::number(int(ui->widget->getPaperSize().height()+0.001));
}
ui->sizeLabel->setText("("+wSize + " * " +hSize+")");
}
void CutPaperTool::setSizeInit()
{
ui->widget->setCutRectStartX(0);
ui->widget->setCutRectStartY(0);
ui->widget->setCutRectWidth(ui->widget->getPaperSize().width());
ui->widget->setCutRectHeight(ui->widget->getPaperSize().height());
ui->startXEdt->setText("0");
ui->startYEdt->setText("0");
ui->rectWidth->setText(QString::number(int(ui->widget->getPaperSize().width())));
ui->rectHeight->setText(QString::number(int(ui->widget->getPaperSize().height())));
}
void CutPaperTool::setSizeInit(QRectF& rect){
setSizeInit();
if(rect != QRectF(0,0,0,0))
setCutRect(rect);
}
void CutPaperTool::cutRectXSlot(double x)
{
ui->startXEdt->setText(QString::number(x));
}
void CutPaperTool::cutRectYSlot(double y)
{
ui->startYEdt->setText(QString::number(y));
}
void CutPaperTool::cutRectWidthSlot(double w)
{
ui->rectWidth->setText(QString::number(w));
}
void CutPaperTool::cutRectHeightSlot(double h)
{
ui->rectHeight->setText(QString::number(h));
}
void CutPaperTool::lineEditEnableSlot(bool b)
{
ui->startXEdt->setEnabled(b);
ui->startYEdt->setEnabled(b);
ui->rectWidth->setEnabled(b);
ui->rectHeight->setEnabled(b);
}
void CutPaperTool::on_startXEdt_textEdited(QString arg1)
{
double x = arg1.toDouble();
if(x >ui->widget->getCutRectRight()) {
//arg1.chop(1);
//x = arg1.toDouble();
//x = ui->widget->getCutRectRight();
return ;
}
if(type == PIXEL) x = arg1.toInt();
ui->widget->setCutRectStartX(x);
}
void CutPaperTool::on_startYEdt_textEdited(QString arg1)
{
double y = arg1.toDouble();
if(y >ui->widget->getCutRectBottom()) {
//arg1.chop(1);
//y = arg1.toDouble();
return ;
}
if(type == PIXEL) y = arg1.toInt();
ui->widget->setCutRectStartY(y);
}
void CutPaperTool::on_rectWidth_textEdited(QString arg1)
{
double v = arg1.toDouble();
if(v > ui->widget->getPaperSize().width() - ui->widget->getCutRectStartPos().x()) {
//arg1.chop(1);
//v = arg1.toDouble();
//v=ui->widget->getPaperSize().width() - ui->widget->getCutRectStartPos().x();
return ;
}
if(type == PIXEL) v = arg1.toInt();
ui->widget->setCutRectWidth(v);
}
void CutPaperTool::on_rectHeight_textEdited(QString arg1)
{
double v = arg1.toDouble();
if(v > ui->widget->getPaperSize().height() - ui->widget->getCutRectStartPos().y()) {
//arg1.chop(1);
//v = arg1.toDouble();
//v = ui->widget->getPaperSize().height() - ui->widget->getCutRectStartPos().y();
return ;
}
if(type == PIXEL) v = arg1.toInt();
ui->widget->setCutRectHeight(v);
}
void CutPaperTool::on_comboBox_2_currentIndexChanged(int index)
{
switch(index){
case 0:
ui->xLabel->setText("mm");
ui->yLabel->setText("mm");
ui->wLabel->setText("mm");
ui->hLabel->setText("mm");
ui->widget->setSizeType(MILLIM);
break;
case 1:
ui->xLabel->setText("in");
ui->yLabel->setText("in");
ui->wLabel->setText("in");
ui->hLabel->setText("in");
ui->widget->setSizeType(INCH);
break;
case 2:
ui->xLabel->setText("px");
ui->yLabel->setText("px");
ui->wLabel->setText("px");
ui->hLabel->setText("px");
ui->widget->setSizeType(PIXEL);
break;
}
update();
setSizeLabel();
ui->widget->refreshView();
}
void CutPaperTool::on_buttonBox_accepted()
{
accept();
}
void CutPaperTool::on_buttonBox_rejected()
{
reject();
}
void CutPaperTool::on_pbtn_init_clicked()
{
setSizeInit();
}

View File

@ -1,59 +0,0 @@
#ifndef CUTPAPERTOOL_H
#define CUTPAPERTOOL_H
#include <QDialog>
#include "cutdialog.h"
namespace Ui {
class CutPaperTool;
}
class CutPaperTool : public QDialog
{
Q_OBJECT
public:
explicit CutPaperTool(QWidget *parent = nullptr);
~CutPaperTool();
void setPaperType(const int dpi, const QString& t,const int& w=200);
QRectF getCutRectPixel();
void setCutRect(QRectF& rect);
void setSizeInit();
void setSizeInit(QRectF& rect);
private:
void paintEvent(QPaintEvent *);
void setSizeLabel();
private slots:
void cutRectXSlot(double x);
void cutRectYSlot(double y);
void cutRectWidthSlot(double w);
void cutRectHeightSlot(double h);
void lineEditEnableSlot(bool b);
void on_startXEdt_textEdited(QString arg1);
void on_startYEdt_textEdited(QString arg1);
void on_rectWidth_textEdited(QString arg1);
void on_rectHeight_textEdited(QString arg1);
void on_comboBox_2_currentIndexChanged(int index);
void on_buttonBox_accepted();
void on_buttonBox_rejected();
void on_pbtn_init_clicked();
private:
Ui::CutPaperTool *ui;
SIZETYPE type;
int dpi;
QString paperType;
};
#endif // CUTPAPERTOOL_H

View File

@ -1,298 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CutPaperTool</class>
<widget class="QWidget" name="CutPaperTool">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>439</width>
<height>676</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>自定义扫描区域</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>纸张尺寸:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="paperLab">
<property name="text">
<string>A4</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="sizeLabel">
<property name="text">
<string>(210*297)</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>DPI(像素/英寸)</string>
</property>
<property name="alignment">
<set>Qt::AlignJustify|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="dpiLab">
<property name="text">
<string>200</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>单位:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_2">
<item>
<property name="text">
<string>毫米mm</string>
</property>
</item>
<item>
<property name="text">
<string>英寸in)</string>
</property>
</item>
<item>
<property name="text">
<string>像素px</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pbtn_init">
<property name="text">
<string>初始化选择区域</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_4">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>421</width>
<height>430</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="cutDialog" name="widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>x:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="startXEdt"/>
</item>
<item>
<widget class="QLabel" name="xLabel">
<property name="text">
<string>mm</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>y:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="startYEdt"/>
</item>
<item>
<widget class="QLabel" name="yLabel">
<property name="text">
<string>mm</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="wLabel_2">
<property name="text">
<string>w:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="rectWidth"/>
</item>
<item>
<widget class="QLabel" name="wLabel">
<property name="text">
<string>mm</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>h:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="rectHeight"/>
</item>
<item>
<widget class="QLabel" name="hLabel">
<property name="text">
<string>mm</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>cutDialog</class>
<extends>QWidget</extends>
<header location="global">cutdialog.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -1,189 +0,0 @@
#include "device_menu.h"
#define ACTION_DEVICE_NAME_PROPERTY "device_name"
device_menu::device_menu(QWidget *parent)
: QMenu(parent)
, cur_action_(nullptr), none_action_(nullptr)
{
group_action_ = new QActionGroup(this);
deviceMenuUpdate(nullptr);
connect(group_action_, SIGNAL(triggered(QAction*)), this, SLOT(on_act_triggered(QAction*)));
}
device_menu::device_menu(const QString &title, QWidget *parent)
: QMenu(title, parent)
, cur_action_(nullptr), none_action_(nullptr)
{
group_action_ = new QActionGroup(this);
deviceMenuUpdate(nullptr);
connect(group_action_, SIGNAL(triggered(QAction*)), this, SLOT(on_act_triggered(QAction*)));
}
QMenu* device_menu::find_device_menu(const QString& dev_name)
{
std::lock_guard<std::mutex> lock(mutex_);
std::vector<POPMENU>::iterator it = std::find(menus_.begin(), menus_.end(), dev_name);
if(it == menus_.end())
return nullptr;
else
return it->menu;
}
QAction* device_menu::find_device_config(const QString& dev_name, const QString& cfg_name)
{
std::lock_guard<std::mutex> lock(mutex_);
std::vector<POPMENU>::iterator it = std::find(menus_.begin(), menus_.end(), dev_name);
if(it == menus_.end())
return NULL;
for(size_t i = 0; i < it->actions.size(); ++i)
{
if(it->actions[i]->text() == cfg_name)
return it->actions[i];
}
return NULL;
}
void device_menu::connectedDevice(const QString &device)
{
QMenu* menu = find_device_menu(device);
if (menu)
menu->setEnabled(true);
}
void device_menu::disconnectedDevice(const QString &device)
{
QMenu* menu = find_device_menu(device);
if (menu)
menu->setEnabled(false);
}
void device_menu::setOptionChecked(const QString &device, const QString &opt, bool checked)
{
QAction* act = find_device_config(device, opt);
if(act)
{
act->setChecked(checked);
if(checked)
cur_action_ = act;
else
{
if(cur_action_ == act)
cur_action_ = nullptr;
}
}
else if(checked)
cur_action_ = nullptr;
}
void device_menu::get_online_devices(QList<QString>& dev_names)
{
std::lock_guard<std::mutex> lock(mutex_);
for(size_t i = 0; i < menus_.size(); ++i)
{
if(menus_[i].menu->isEnabled())
dev_names.push_back(menus_[i].menu->title());
}
}
void device_menu::deviceMenuUpdate(dev_que* que)
{
std::lock_guard<std::mutex> lock(mutex_);
cur_action_ = nullptr;
if(none_action_)
{
removeAction(none_action_);
none_action_ = nullptr;
}
for(size_t i = 0; i < menus_.size(); ++i)
menus_[i].menu->setEnabled(false);
if (!que || que->scanners() == 0)
{
if(menus_.empty())
{
none_action_ = addAction(tr("no device"));
none_action_->setEnabled(false);
}
return;
}
for (size_t i = 0; i < que->scanners(); i++)
{
SCANNER s = que->get_at(i);
std::vector<POPMENU>::iterator it = std::find(menus_.begin(), menus_.end(), QString::fromStdString((s.name)));
POPMENU pm;
std::vector<std::string> schemes;
if(it == menus_.end())
pm.menu = addMenu(QString::fromStdString(s.name));
else
{
pm = *it;
menus_.erase(it);
}
pm.menu->setEnabled(true);
pm.menu->setToolTipsVisible(true);
for(size_t j = 0; j < pm.actions.size(); ++j)
{
pm.menu->removeAction(pm.actions[j]);
group_action_->removeAction(pm.actions[j]);
}
pm.actions.clear();
s.cfg->get_all_schemes(schemes);
for (size_t j = 0; j < schemes.size(); j++)
{
QAction *child = group_action_->addAction(QString::fromStdString(schemes[j]));
child->setProperty(ACTION_DEVICE_NAME_PROPERTY, QVariant(QString::fromStdString(s.name)));
child->setCheckable(true);
if(que->opened_scanner_name() == s.name &&
schemes[j] == s.cfg->get_current_scheme_name())
{
cur_action_ = child;
child->setChecked(true);
}
pm.menu->addAction(child);
pm.actions.push_back(child);
QString tips;
if(tips.isNull())
{
tips = tr("default setting");
}
// child->setToolTip(tips);
}
menus_.push_back(pm);
s.cfg->release();
}
}
void device_menu::on_act_triggered(QAction* act)
{
QString deviceName = act->property(ACTION_DEVICE_NAME_PROPERTY).toString();
QString opt = act->text();
bool checked_now = act->isChecked();
if(cur_action_ == act)
{
checked_now = false;
act->setChecked(false);
cur_action_ = nullptr;
// emit scanOptionsChanged("", "", false);
// return;
}
else {
cur_action_ = act;
checked_now = true;
}
emit scanOptionsChanged(deviceName, opt, checked_now);
}

View File

@ -1,506 +0,0 @@
#ifndef DEVICE_MENU_H
#define DEVICE_MENU_H
#include <QMenu>
#include <mutex>
#include "sane/sane_ex.h"
#include "sane/sane_option_definitions.h"
#include "../../../sdk/include/huagao/hgscanner_error.h"
#include "cfg/gb_json.h"
#include "lang/app_language.h"
typedef struct _scanner
{
std::string name;
std::string model;
bool online;
gb::scanner_cfg *cfg;
}SCANNER;
class dev_que
{
std::vector<SCANNER> que_;
std::string root_dir_;
std::string opened_scanner_;
std::string applied_scheme_;
SANE_Handle handle_;
static void trans_number(const char* name, std::string& val, void* param)
{
if (strcmp(name, "tl-x") == 0
|| strcmp(name, "br-x") == 0
|| strcmp(name, "tl-y") == 0
|| strcmp(name, "br-y") == 0
|| strcmp(name, "gamma") == 0
|| strcmp(name, "search-hole-range-l") == 0
|| strcmp(name, "search-hole-range-r") == 0
|| strcmp(name, "search-hole-range-t") == 0
|| strcmp(name, "search-hole-range-b") == 0
|| strcmp(name, "feed-strength-value") == 0
)
{
float v = atof(val.c_str());
SANE_Fixed f = SANE_FIX(v);
val = std::string((char*)&f, sizeof(f));
}
else if (strcmp(name, "binary-threshold") == 0
|| strcmp(name, "bkg-color-range") == 0
|| strcmp(name, "noise-size") == 0
|| strcmp(name, "blank-sensitivity") == 0
|| strcmp(name, "resolution") == 0
|| strcmp(name, "brightness") == 0
|| strcmp(name, "contrast") == 0
|| strcmp(name, "threshold") == 0
|| strcmp(name, "anti-noise-level") == 0
|| strcmp(name, "margin") == 0
|| strcmp(name, "scan-count") == 0
|| strcmp(name, "askew-range") == 0
|| strcmp(name, "dog-ear-size") == 0
)
{
SANE_Int v = atoi(val.c_str());
val = std::string((char*)&v, sizeof(v));
}
else if (strcmp(val.c_str(), "true") == 0)
{
SANE_Bool b = SANE_TRUE;
val = std::string((char*)&b, sizeof(b));
}
else if (strcmp(val.c_str(), "false") == 0)
{
SANE_Bool b = SANE_FALSE;
val = std::string((char*)&b, sizeof(b));
}
}
static const char* title_2_name(const char* title, void* param)
{
struct
{
const char* name;
const char* title;
}g_opts[] = { {SANE_STD_OPT_NAME_RESTORE , OPTION_TITLE_HFMRSZ}
, {SANE_STD_OPT_NAME_HELP , OPTION_TITLE_BZ}
, {SANE_STD_OPT_NAME_IS_MULTI_OUT , OPTION_TITLE_DLSC}
, {SANE_STD_OPT_NAME_MULTI_OUT_TYPE , OPTION_TITLE_DLSCLX}
, {SANE_STD_OPT_NAME_COLOR_MODE , OPTION_TITLE_YSMS}
, {SANE_STD_OPT_NAME_BINARY_THRESHOLD , OPTION_TITLE_HBTXYZ}
, {SANE_STD_OPT_NAME_REVERSE_01 , OPTION_TITLE_HBTXFSSC}
, {SANE_STD_OPT_NAME_FILTER , OPTION_TITLE_HDHHBTX_CSYZQ}
, {SANE_STD_OPT_NAME_RID_MULTIOUT_RED , OPTION_TITLE_24WCSTX_DLSCCH}
, {SANE_STD_OPT_NAME_RID_ANSWER_SHEET_RED , OPTION_TITLE_24WCSTX_DTKCH}
, {SANE_STD_OPT_NAME_ERASE_BACKGROUND , OPTION_TITLE_BJYC}
, {SANE_STD_OPT_NAME_BKG_COLOR_RANGE , OPTION_TITLE_BJSCFDFW}
, {SANE_STD_OPT_NAME_SHARPEN , OPTION_TITLE_RHYMH}
, {SANE_STD_OPT_NAME_RID_MORR , OPTION_TITLE_QCMW}
, {SANE_STD_OPT_NAME_RID_GRID , OPTION_TITLE_CWW}
, {SANE_STD_OPT_NAME_ERROR_EXTENSION , OPTION_TITLE_CWKS}
, {SANE_STD_OPT_NAME_NOISE_OPTIMIZE , OPTION_TITLE_HBTXZDYH}
, {SANE_STD_OPT_NAME_NOISE_SIZE , OPTION_TITLE_ZDYHCC}
, {SANE_STD_OPT_NAME_PAPER , OPTION_TITLE_ZZCC}
, {SANE_STD_OPT_NAME_CUSTOM_AREA , OPTION_TITLE_ZDYSMQY}
, {SANE_STD_OPT_NAME_CUSTOM_AREA_LEFT , OPTION_TITLE_SMQYZCmm}
, {SANE_STD_OPT_NAME_CUSTOM_AREA_RIGHT , OPTION_TITLE_SMQYYCmm}
, {SANE_STD_OPT_NAME_CUSTOM_AREA_TOP , OPTION_TITLE_SMQYSCmm}
, {SANE_STD_OPT_NAME_CUSTOM_AREA_BOTTOM , OPTION_TITLE_SMQYXCmm}
, {SANE_STD_OPT_NAME_SIZE_CHECK , OPTION_TITLE_CCJC}
, {SANE_STD_OPT_NAME_PAGE , OPTION_TITLE_SMYM}
, {SANE_STD_OPT_NAME_DISCARD_BLANK_SENS , OPTION_TITLE_TGKBYLMD}
, {SANE_STD_OPT_NAME_RESOLUTION , OPTION_TITLE_FBL}
, {SANE_STD_OPT_NAME_TIME_TO_SLEEP , OPTION_TITLE_XMSJ}
, {SANE_STD_OPT_NAME_IMAGE_QUALITY , OPTION_TITLE_HZ}
, {SANE_STD_OPT_NAME_EXCHANGE ,OPTION_TITLE_JHZFM}
, {SANE_STD_OPT_NAME_SPLIT ,OPTION_TITLE_TXCF }
, {SANE_STD_OPT_NAME_ANTI_SKEW , OPTION_TITLE_ZDJP}
, {SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA , OPTION_TITLE_QYSDQX}
, {SANE_STD_OPT_NAME_GAMMA , OPTION_TITLE_JMZ}
, {SANE_STD_OPT_NAME_BRIGHTNESS , OPTION_TITLE_LDZ}
, {SANE_STD_OPT_NAME_CONTRAST , OPTION_TITLE_DBD}
, {SANE_STD_OPT_NAME_IS_PHOTO_MODE , OPTION_TITLE_ZPMS}
, {SANE_STD_OPT_NAME_ERASE_BLACK_FRAME , OPTION_TITLE_XCHK}
, {SANE_STD_OPT_NAME_DARK_SAMPLE , OPTION_TITLE_SSYZ}
, {SANE_STD_OPT_NAME_THRESHOLD , OPTION_TITLE_YZ}
, {SANE_STD_OPT_NAME_ANTI_NOISE_LEVEL , OPTION_TITLE_BJKZDJ}
, {SANE_STD_OPT_NAME_MARGIN , OPTION_TITLE_BYSJ}
, {SANE_STD_OPT_NAME_FILL_BKG_MODE , OPTION_TITLE_BJTCFS}
, {SANE_STD_OPT_NAME_IS_ANTI_PERMEATE , OPTION_TITLE_FZST}
, {SANE_STD_OPT_NAME_ANTI_PERMEATE_LEVEL , OPTION_TITLE_FZSTDJ}
, {SANE_STD_OPT_NAME_RID_HOLE_L , OPTION_TITLE_CKYCZC}
, {SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_L , OPTION_TITLE_ZCCKSSFWZFMBL}
, {SANE_STD_OPT_NAME_RID_HOLE_R , OPTION_TITLE_CKYCYC}
, {SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_R , OPTION_TITLE_YCCKSSFWZFMBL}
, {SANE_STD_OPT_NAME_RID_HOLE_T , OPTION_TITLE_CKYCSC}
, {SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_T , OPTION_TITLE_SCCKSSFWZFMBL}
, {SANE_STD_OPT_NAME_RID_HOLE_B , OPTION_TITLE_CKYCXC}
, {SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_B , OPTION_TITLE_XCCKSSFWZFMBL}
, {SANE_STD_OPT_NAME_IS_FILL_COLOR , OPTION_TITLE_SCTC}
, {SANE_STD_OPT_NAME_IS_ULTROSONIC_CHECK , OPTION_TITLE_CSBJC}
, {SANE_STD_OPT_NAME_DOUBLE_FEED_HANDLE , OPTION_TITLE_SZTPCL}
, {SANE_STD_OPT_NAME_IS_CHECK_STAPLE , OPTION_TITLE_ZDJC}
, {SANE_STD_OPT_NAME_SCAN_MODE , OPTION_TITLE_SMZS}
, {SANE_STD_OPT_NAME_SCAN_COUNT , OPTION_TITLE_SMSL}
, {SANE_STD_OPT_NAME_TEXT_DIRECTION , OPTION_TITLE_WGFX}
, {SANE_STD_OPT_NAME_IS_ROTATE_BKG_180 , OPTION_TITLE_BMXZ180}
, {SANE_STD_OPT_NAME_IS_CHECK_DOG_EAR , OPTION_TITLE_ZJJC}
, {SANE_STD_OPT_NAME_DOG_EAR_SIZE , OPTION_TITLE_ZJDX}
, {SANE_STD_OPT_NAME_IS_CHECK_ASKEW , OPTION_TITLE_WXJC}
, {SANE_STD_OPT_NAME_ASKEW_RANGE , OPTION_TITLE_WXRRD}
, {SANE_STD_OPT_NAME_FEED_STRENGTH , OPTION_TITLE_FZQD}
, {SANE_STD_OPT_NAME_IS_AUTO_FEED_STRENGTH , OPTION_TITLE_ZDFZQD}
, {SANE_STD_OPT_NAME_FEED_STRENGTH_VALUE , OPTION_TITLE_JZSBL}
, {SANE_STD_OPT_NAME_WAIT_TO_SCAN , OPTION_TITLE_DZSM}
, {SANE_STD_OPT_NAME_FOLD_TYPE , OPTION_TITLE_DZMS}
},
g_discard[] = { {SANE_STD_OPT_NAME_REVERSE_01 , "\351\273\221\347\231\275\345\233\276\345\203\217\345\217\215\350\211\262\350\276\223\345\207\272\357\274\210\346\255\243\345\270\270\351\242\234\350\211\262\344\270\272\357\274\2320-\351\273\221\350\211\262\357\274\2331-\347\231\275\350\211\262\357\274\211"} // 黑白图像反色输出正常颜色为0-黑色1-白色)
, {SANE_STD_OPT_NAME_FILTER , "\347\201\260\345\272\246\346\210\226\351\273\221\347\231\275\345\233\276\345\203\217 - \351\231\244\350\211\262"} // 灰度或黑白图像 - 除色
, {SANE_STD_OPT_NAME_IS_AUTO_FEED_STRENGTH , "\350\207\252\345\212\250\346\220\223\347\272\270\345\274\272\345\272\246"} // 自动搓纸强度
, {SANE_STD_OPT_NAME_FEED_STRENGTH_VALUE , "\346\220\223\347\272\270\351\230\210\345\200\274"} // " 搓纸阈值"
};
while (*title == ' ')
title++;
for (size_t i = 0; i < _countof(g_opts); ++i)
{
if (strcmp(title, g_opts[i].title) == 0)
return g_opts[i].name;
}
for (size_t i = 0; i < _countof(g_discard); ++i)
{
if (strcmp(title, g_discard[i].title) == 0)
return g_discard[i].name;
}
return title;
}
public:
dev_que() : handle_(nullptr)
{}
~dev_que()
{
close_scanner();
for(auto& v : que_)
v.cfg->release();
}
static void update_old_cfg(const char* conf)
{
gb::scanner_cfg::UDF func;
func.func_param = nullptr;
func.title2name = &dev_que::title_2_name;
func.trans_number = &dev_que::trans_number;
gb::scanner_cfg::update(conf, &func);
}
static void apply_scheme(SANE_Handle h, gb::sane_config_schm* schm)
{
SANE_Int count = 0, none = 0;
std::string name(""), val("");
none = sane_io_control(h, IO_CTRL_CODE_RESTORE_SETTINGS, NULL, NULL);
if(schm && schm->id_from_name(SANE_STD_OPT_NAME_COLOR_MODE) == -1)
{
SANE_Int dev_options = 0;
sane_control_option(h, 0, SANE_ACTION_GET_VALUE, &dev_options, nullptr);
for(int i = 1; i < dev_options; ++i)
{
const SANE_Option_Descriptor* opt = sane_get_option_descriptor(h, i);
if(!opt)
continue;
unsigned int n = i;
if(opt->type == SANE_TYPE_BOOL)
{
SANE_Bool v = SANE_TRUE;
sane_io_control(h, IO_CTRL_CODE_GET_DEFAULT_VALUE, &v, &n);
schm->set_default_value(i, opt->name, (char*)&v, sizeof(v));
}
else if (opt->type == SANE_TYPE_INT) {
SANE_Int v = 0;
sane_io_control(h, IO_CTRL_CODE_GET_DEFAULT_VALUE, &v, &n);
schm->set_default_value(i, opt->name, (char*)&v, sizeof(v));
}
else if(opt->type == SANE_TYPE_FIXED)
{
SANE_Fixed v = 0;
sane_io_control(h, IO_CTRL_CODE_GET_DEFAULT_VALUE, &v, &n);
schm->set_default_value(i, opt->name, (char*)&v, sizeof(v));
}
else {
char *buf = new char[opt->size + 4];
memset(buf, 0, opt->size + 4);
sane_io_control(h, IO_CTRL_CODE_GET_DEFAULT_VALUE, buf, &n);
std::string langCN(to_default_language(buf, nullptr));
schm->set_default_value(i, opt->name, &langCN[0], langCN.length());
delete[] buf;
}
}
}
if(schm && schm->first_config(name, val))
{
do
{
int id = schm->id_from_name(name.c_str());
if(id == -1)
{
if(gb::sane_config_schm::is_option_data(name))
{
if(name == SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA && val.length() == sizeof(SANE_Gamma))
{
unsigned int l = val.length();
sane_io_control(h, IO_CTRL_CODE_SET_CUSTOM_GAMMA, &val[0], &l);
}
}
}
else {
const SANE_Option_Descriptor* opt = reinterpret_cast<const SANE_Option_Descriptor*>(sane_get_option_descriptor(h, id));
if(opt)
{
if(opt->type == SANE_TYPE_STRING)
{
char *buf = new char[opt->size + 4];
memset(buf, 0, opt->size + 4);
strcpy(buf, val.c_str());
std::string langCN(from_default_language(buf, nullptr));
sane_control_option(h, id, SANE_ACTION_SET_VALUE, &langCN[0], &none);
delete[] buf;
}
else {
sane_control_option(h, id, SANE_ACTION_SET_VALUE, &val[0], &none);
}
}
}
}while(schm->next_config(name, val));
}
}
public:
void set_root_dir(const char* root)
{
root_dir_ = std::string(root) + PATH_SYMBOL;
}
void add_scanner(const char* sane_name)
{
bool found = false;
for(auto& v: que_)
{
if(v.name == sane_name)
{
found = true;
break;
}
}
if(!found)
{
SCANNER s;
size_t pos = 0;
s.model = s.name = sane_name;
s.cfg = nullptr;
pos = s.model.find(" - ");
if(pos != std::string::npos)
{
pos = s.model.find(" - ", pos + 3);
if(pos != std::string::npos)
s.model.erase(pos);
}
for(auto& v: que_)
{
if(v.model == s.model)
{
s.cfg = v.cfg;
s.cfg->add_ref();
break;
}
}
if(!s.cfg)
{
s.cfg = new gb::scanner_cfg();
s.cfg->load_file((root_dir_ + s.model + ".cfg").c_str());
}
s.online = true;
que_.push_back(s);
}
}
void get_schemes(const char* scanner_name, std::vector<std::string>& schemes)
{
schemes.clear();
for(auto& v : que_)
{
if(v.name == scanner_name)
{
v.cfg->get_all_schemes(schemes);
break;
}
}
}
SANE_Handle handle(void)
{
return handle_;
}
std::string opened_scanner_name(void)
{
return opened_scanner_;
}
std::string applied_scheme(void)
{
return applied_scheme_;
}
int open_scanner(const char* scanner_name, const char* scheme = nullptr)
{
SANE_Status statu = SANE_STATUS_GOOD;
close_scanner();
statu = sane_open(scanner_name, &handle_);
if(statu == SANE_STATUS_GOOD && handle_)
{
opened_scanner_ = scanner_name;
apply_scheme(scheme);
}
return statu;
}
int close_scanner(void)
{
if(handle_)
{
sane_close(handle_);
handle_ = nullptr;
opened_scanner_ = "";
applied_scheme_ = "";
}
return SANE_STATUS_GOOD;
}
int scanners(void)
{
return que_.size();
}
SCANNER get_at(int pos)
{
SCANNER s;
s.name = s.model = "";
s.cfg = nullptr;
if(pos >= 0 && pos < que_.size())
{
s = que_[pos];
s.cfg->add_ref();
}
return s;
}
bool is_online(const char* scanner = nullptr)
{
if(!scanner)
scanner = opened_scanner_.c_str();
for(auto& v : que_)
{
if(v.name == scanner)
return v.online;
}
return false;
}
void set_online(bool online, const char* scanner = nullptr)
{
if(!scanner)
scanner = opened_scanner_.c_str();
for(auto& v : que_)
{
if(v.name == scanner)
{
v.online = online;
break;
}
}
}
void get_scanners(std::vector<std::string>& que)
{
for(auto& v: que_)
que.push_back(v.name);
}
int apply_scheme(const char* scheme_name)
{
if(!handle_)
return SCANNER_ERR_NOT_OPEN;
for(auto& v: que_)
{
if(v.name == opened_scanner_)
{
gb::sane_config_schm* schm = v.cfg->get_scheme(scheme_name);
dev_que::apply_scheme(handle_, schm);
if(schm)
{
v.cfg->select_scheme(schm->get_scheme_name().c_str());
schm->release();
}
else {
v.cfg->select_scheme(scheme_name);
}
applied_scheme_ = v.cfg->get_current_scheme_name();
v.cfg->save();
break;
}
}
return SCANNER_ERR_OK;
}
};
class device_menu : public QMenu
{
Q_OBJECT
typedef struct _pop_menu
{
QMenu* menu;
std::vector<QAction*> actions;
bool operator==(const QString& menu_title)
{
return menu->title() == menu_title;
}
}POPMENU;
std::vector<POPMENU> menus_;
QAction* cur_action_;
QAction* none_action_;
QActionGroup* group_action_;
std::mutex mutex_;
QMenu* find_device_menu(const QString& dev_name);
QAction* find_device_config(const QString& dev_name, const QString& cfg_name);
public:
device_menu(QWidget* parent = nullptr);
device_menu(const QString& title, QWidget* parent = nullptr);
void deviceMenuUpdate(dev_que* que);
void connectedDevice(const QString& device);
void disconnectedDevice(const QString& device);
void setOptionChecked(const QString& device, const QString& opt, bool checked);
void get_online_devices(QList<QString>& dev_names);
signals:
void scanOptionsChanged(const QString& device, const QString& opt, bool checked_now);
private slots:
void on_act_triggered(QAction* act);
};
#endif // DEVICE_MENU_H

193
app/scanner/device_user.cpp Normal file
View File

@ -0,0 +1,193 @@
#include "device_user.h"
#include <QMessageBox>
#if defined(HG_CMP_MSC)
DeviceUserMgr::DeviceUserMgr(QWidget *wnd)
{
m_wnd = wnd;
m_twainDSM = nullptr;
HGTwain_CreateDSM((HWND)m_wnd->winId(), &m_twainDSM);
}
DeviceUserMgr::~DeviceUserMgr()
{
HGTwain_DestroyDSM(m_twainDSM);
m_twainDSM = nullptr;
}
class DeviceUser* DeviceUserMgr::OpenDeviceUser()
{
HGTwainDS ds = nullptr;
HGTwain_OpenSelectedDSEx(m_twainDSM, &ds);
if (nullptr == ds)
return nullptr;
return new DeviceUser(m_wnd, ds);
}
DeviceUser::DeviceUser(QWidget *wnd, HGTwainDS ds)
{
m_wnd = wnd;
m_twainDS = ds;
}
DeviceUser::~DeviceUser()
{
HGTwain_CloseDS(m_twainDS);
m_twainDS = nullptr;
}
QString DeviceUser::GetName()
{
HGChar devName[256];
HGTwain_GetDSName(m_twainDS, devName, 256);
return QString(devName);
}
HGResult DeviceUser::ShowSettingDlg()
{
return HGTwain_EnableDSUIOnly(m_twainDS, (HWND)m_wnd->winId(), DSCloseReqFunc, this);
}
HGResult DeviceUser::StartScan()
{
return HGTwain_EnableDS(m_twainDS, HGFALSE, nullptr, DSCloseReqFunc, this, DSImageFunc, this);
}
HGResult DeviceUser::StopScan()
{
return HGTwain_DisableDS(m_twainDS);
}
HGResult DeviceUser::GetDeviceCustomInfo(HGTwainDeviceCustomInfo *info)
{
return HGTwain_GetDSDeviceCustomInfo(m_twainDS, info);
}
void HGAPI DeviceUser::DSCloseReqFunc(HGTwainDS ds, HGPointer param)
{
DeviceUser* p = (DeviceUser*)param;
HGTwain_DisableDS(p->m_twainDS);
emit p->finishScan();
}
void HGAPI DeviceUser::DSImageFunc(HGTwainDS ds, HGImage image, HGPointer param)
{
DeviceUser* p = (DeviceUser*)param;
HGImage image2 = nullptr;
HGBase_CloneImage(image, 0, 0, &image2);
if (nullptr != image2)
{
emit p->newImage(image2);
}
}
#else
DeviceUserMgr::DeviceUserMgr(QWidget *wnd)
{
m_wnd = wnd;
m_saneMgr = nullptr;
HGSane_CreateManager(&m_saneMgr);
}
DeviceUserMgr::~DeviceUserMgr()
{
HGSane_DestroyManager(m_saneMgr);
m_saneMgr = nullptr;
}
class DeviceUser* DeviceUserMgr::OpenDeviceUser()
{
HGSaneSource source = nullptr;
HGSane_OpenSelectedSource(m_saneMgr, m_wnd, &source);
if (nullptr == source)
return nullptr;
HGUInt devCount = 0;
HGSane_GetDeviceCount(source, &devCount);
if (0 == devCount)
{
HGSane_CloseSource(source);
return nullptr;
}
else if (1 == devCount)
{
HGChar errInfo[256];
HGSaneDevice dev = nullptr;
HGSane_OpenDevice(source, 0, &dev, errInfo, 256);
if (nullptr == dev)
{
HGSane_CloseSource(source);
QMessageBox::information(m_wnd, tr("tips"), QString::fromUtf8(errInfo));
return nullptr;
}
return new DeviceUser(m_wnd, source, dev);
}
HGSaneDevice dev = nullptr;
HGSane_OpenSelectedDevice(source, m_wnd, &dev);
if (nullptr == dev)
{
HGSane_CloseSource(source);
return nullptr;
}
return new DeviceUser(m_wnd, source, dev);
}
DeviceUser::DeviceUser(QWidget *wnd, HGSaneSource source, HGSaneDevice dev)
{
m_wnd = wnd;
m_source = source;
m_saneDev = dev;
}
DeviceUser::~DeviceUser()
{
HGSane_CloseDevice(m_saneDev);
m_saneDev = nullptr;
HGSane_CloseSource(m_source);
m_source = nullptr;
}
QString DeviceUser::GetName()
{
HGChar devName[256];
HGSane_GetSourceName(m_source, devName, 256);
return QString(devName);
}
HGResult DeviceUser::ShowSettingDlg()
{
return HGSane_ShowDeviceSettingDlg(m_saneDev, m_wnd);
}
HGResult DeviceUser::StartScan()
{
return HGSane_StartDeviceWithUI(m_saneDev, m_wnd, DeviceImageFunc, this);
}
HGResult DeviceUser::StopScan()
{
return HGSane_StopDevice(m_saneDev);
}
HGResult DeviceUser::GetDeviceCustomInfo(HGSaneCustomInfo *info)
{
return HGSane_GetDeviceCustomInfo(m_saneDev, info);
}
void HGAPI DeviceUser::DeviceImageFunc(HGSaneDevice dev, HGImage image, HGPointer param)
{
DeviceUser* p = (DeviceUser*)param;
HGImage image2 = nullptr;
HGBase_CloneImage(image, 0, 0, &image2);
if (nullptr != image2)
{
emit p->newImage(image2);
}
}
#endif

109
app/scanner/device_user.h Normal file
View File

@ -0,0 +1,109 @@
#ifndef __DEVICE_USER_H__
#define __DEVICE_USER_H__
#include "base/HGDef.h"
#include <QDialog>
#if defined(HG_CMP_MSC)
#include "twain_user/HGTwain.h"
class DeviceUserMgr : public QObject
{
Q_OBJECT
public:
DeviceUserMgr(QWidget *wnd);
~DeviceUserMgr();
// 弹出设备选择对话框选择twain源
class DeviceUser* OpenDeviceUser();
private:
QWidget *m_wnd;
HGTwainDSM m_twainDSM;
};
class DeviceUser : public QObject
{
Q_OBJECT
friend class DeviceUserMgr;
DeviceUser(QWidget *wnd, HGTwainDS ds);
public:
~DeviceUser();
// 获取设备名字
QString GetName();
// 弹出配置对话框
HGResult ShowSettingDlg();
// 弹出扫描对话框
HGResult StartScan();
HGResult StopScan();
HGResult GetDeviceCustomInfo(HGTwainDeviceCustomInfo *info);
private:
static void HGAPI DSCloseReqFunc(HGTwainDS ds, HGPointer param);
static void HGAPI DSImageFunc(HGTwainDS ds, HGImage image, HGPointer param);
signals:
void newImage(void *image);
void finishScan();
private:
QWidget *m_wnd;
HGTwainDS m_twainDS;
};
#else
#include "sane_user/HGSane.h"
class DeviceUserMgr : public QObject
{
Q_OBJECT
public:
DeviceUserMgr(QWidget *wnd);
~DeviceUserMgr();
// 弹出设备选择对话框,选择设备
class DeviceUser* OpenDeviceUser();
private:
QWidget *m_wnd;
HGSaneManager m_saneMgr;
};
class DeviceUser : public QObject
{
Q_OBJECT
friend class DeviceUserMgr;
DeviceUser(QWidget *wnd, HGSaneSource source, HGSaneDevice dev);
public:
~DeviceUser();
// 获取设备名字
QString GetName();
// 弹出配置对话框
HGResult ShowSettingDlg();
// 弹出扫描对话框
HGResult StartScan();
HGResult StopScan();
HGResult GetDeviceCustomInfo(HGSaneCustomInfo *info);
private:
static void HGAPI DeviceImageFunc(HGSaneDevice dev, HGImage image, HGPointer param);
signals:
void newImage(void *image);
void finishScan();
private:
QWidget *m_wnd;
HGSaneSource m_source;
HGSaneDevice m_saneDev;
};
#endif
#endif /* __DEVICE_USER_H__ */

View File

@ -9,7 +9,6 @@
#include "base/HGBase.h"
#include "HGUIGlobal.h"
#include "app_cfg.h"
#include "ocrPdf.h"
#include <assert.h>
#define ARRAY_SIZE(a) sizeof(a) / sizeof(a[0])

View File

@ -9,7 +9,6 @@
#include "HGString.h"
#include <QMessageBox>
#include <QFile>
#include "ocrPdf.h"
#include "app_cfg.h"
Dialog_ExportImageFile::Dialog_ExportImageFile(const QString &destPath, const QString &destName, const QString &destExt,

View File

@ -1,179 +0,0 @@
#include "dialog_log.h"
#include "ui_dialog_log.h"
#include <QDateTime>
#include "app_cfg.h"
dialog_log::dialog_log(QWidget *parent)
: QDialog(parent)
, ui(new Ui::dialog_log), ind_scanning_(-1), img_received_(0), msg_fixed_scanning_("")
{
ui->setupUi(this);
setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
QHBoxLayout *bottom = new QHBoxLayout();
pbtn_clear = new QPushButton(this);
cBox_autoScroll = new QCheckBox(this);
pbtn_stop = new QPushButton(this);
pbtn_export = new QPushButton(this);
pbtn_continueScan = new QPushButton(this);
pbtn_finishScan = new QPushButton(this);
pbtn_stop->setVisible(false);
pbtn_continueScan->setVisible(false);
pbtn_finishScan->setVisible(false);
pbtn_stop->setText(tr("cancel scan"));
cBox_autoScroll->setText(tr("auto scroll"));
pbtn_clear->setText(tr("clear"));
pbtn_export->setText(tr("export images"));
pbtn_continueScan->setText(tr("continue scan"));
pbtn_finishScan->setText(tr("finish scan"));
bottom->addWidget(pbtn_clear);
bottom->addWidget(cBox_autoScroll);
bottom->addStretch();
bottom->addWidget(pbtn_stop);
bottom->addWidget(pbtn_export);
bottom->addWidget(pbtn_continueScan);
bottom->addWidget(pbtn_finishScan);
ui->verticalLayout->addItem(bottom);
cBox_autoScroll->setChecked(getCfgValue("log", "autoScroll", true));
connect(cBox_autoScroll, SIGNAL(stateChanged(int)), this, SLOT(on_cbox_autoScroll_stateChanged(int)));
connect(pbtn_stop, SIGNAL(clicked(bool)), this, SLOT(on_pbtn_stop_clicked()));
connect(pbtn_clear, SIGNAL(clicked(bool)), this, SLOT(on_pbtn_clear_clicked()));
connect(pbtn_export, SIGNAL(clicked(bool)), this, SLOT(on_pbtn_export_clicked()));
connect(pbtn_continueScan, SIGNAL(clicked(bool)), this, SLOT(on_pbtn_continuScan_cliked()));
connect(pbtn_finishScan, SIGNAL(clicked(bool)), this, SLOT(on_pbtn_finishScan_cliked()));
}
dialog_log::~dialog_log()
{
delete ui;
}
void dialog_log::addLog(const QString &log, bool err, int log_event)
{
if (ui->listWidget->count() > 1000)
{
for(int i = 0; i < 100; ++i)
{
QListWidgetItem *item = ui->listWidget->takeItem(0);
delete item;
}
}
QDateTime timeCurrent = QDateTime::currentDateTime();
QString time = timeCurrent.toString("[yy-MM-dd hh:mm:ss]");
ui->listWidget->addItem(time + " " + log);
int idx = ui->listWidget->count() - 1;
if(log_event == LOG_EVENT_SCAN_BEGINNING)
{
msg_fixed_scanning_ = (time + " " + log).toStdString();
ind_scanning_ = idx;
img_received_ = 0;
}
else if(log_event == LOG_EVENT_SCAN_STOPPED)
{
char utf8[128] = {0};
sprintf(utf8, tr("(epicycle scanning images %u picture)").toStdString().c_str(), img_received_);
if(ind_scanning_ >= 0 && ind_scanning_ < idx)
ui->listWidget->item(ind_scanning_)->setText(QString::fromStdString(msg_fixed_scanning_));
if (idx >= 0)
ui->listWidget->item(idx)->setText(time + " " + log + QString::fromStdString(utf8));
ind_scanning_ = -1;
msg_fixed_scanning_ = "";
}
if (idx >= 0)
ui->listWidget->item(idx)->setTextColor(err ? Qt::red : Qt::black);
if (cBox_autoScroll->isChecked())
{
ui->listWidget->scrollToItem(ui->listWidget->item(idx));
}
}
void dialog_log::updateStatus(bool online, bool isScanning)
{
if (!online)
{
pbtn_stop->hide();
pbtn_export->hide();
pbtn_continueScan->hide();
pbtn_finishScan->hide();
}
else
{
if (isScanning)
{
pbtn_stop->show();
pbtn_export->hide();
pbtn_continueScan->hide();
pbtn_finishScan->hide();
}
else
{
pbtn_stop->hide();
if(img_received_)
pbtn_export->show();
pbtn_continueScan->show();
pbtn_finishScan->show();
}
}
}
void dialog_log::image_received_from_scanner(void)
{
img_received_++;
if(ind_scanning_ >= 0 && ind_scanning_ < ui->listWidget->count())
{
char count[20];
sprintf(count, "(%d)", img_received_);
ui->listWidget->item(ind_scanning_)->setText(QString::fromStdString(msg_fixed_scanning_ + count));
}
}
void dialog_log::closeEvent(QCloseEvent *event)
{
(void)event;
on_pbtn_stop_clicked();
}
void dialog_log::on_pbtn_export_clicked()
{
emit exportScanned();
}
void dialog_log::on_pbtn_continuScan_cliked()
{
img_received_ = 0;
emit continueScan();
}
void dialog_log::on_pbtn_finishScan_cliked()
{
close();
}
void dialog_log::on_cbox_autoScroll_stateChanged(int state)
{
(void)state;
saveCfgValue("log", "autoScroll", cBox_autoScroll->isChecked());
}
void dialog_log::on_pbtn_stop_clicked(void)
{
emit stopScan();
}
void dialog_log::on_pbtn_clear_clicked()
{
ui->listWidget->clear();
ind_scanning_ = -1;
}

View File

@ -1,69 +0,0 @@
#ifndef DIALOG_SCANNERLOG_H
#define DIALOG_SCANNERLOG_H
#include <QDialog>
#include <QPushButton>
#include <QCheckBox>
class QLabel;
namespace Ui {
class dialog_log;
}
enum
{
INFO_DLG_FLAG_INFO_LIST = 1 << 1,
INFO_DLG_FLAG_PROGRESS = 1 << 2
};
enum
{
LOG_EVENT_DONT_CARE = 0,
LOG_EVENT_SCAN_BEGINNING,
LOG_EVENT_SCAN_STOPPED,
};
class QListWidgetItem;
class dialog_log : public QDialog
{
Q_OBJECT
int ind_scanning_;
int img_received_;
std::string msg_fixed_scanning_;
public:
explicit dialog_log(QWidget *parent = nullptr);
~dialog_log();
void addLog(const QString &log, bool err, int log_event = LOG_EVENT_DONT_CARE);
void updateStatus(bool online, bool isScanning);
void image_received_from_scanner(void);
public:
QPushButton *pbtn_export;
signals:
void stopScan();
void continueScan();
void exportScanned();
private:
void closeEvent(QCloseEvent *event);
private slots:
void on_cbox_autoScroll_stateChanged(int state);
void on_pbtn_stop_clicked(void);
void on_pbtn_clear_clicked();
void on_pbtn_export_clicked();
void on_pbtn_continuScan_cliked();
void on_pbtn_finishScan_cliked();
private:
Ui::dialog_log *ui;
QPushButton *pbtn_stop;
QCheckBox *cBox_autoScroll;
QPushButton *pbtn_clear;
QPushButton *pbtn_continueScan;
QPushButton *pbtn_finishScan;
};
#endif // DIALOG_SCANNERLOG_H

View File

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>dialog_log</class>
<widget class="QDialog" name="dialog_log">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>531</width>
<height>161</height>
</rect>
</property>
<property name="windowTitle">
<string>日志</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout"/>
</item>
<item>
<widget class="QListWidget" name="listWidget"/>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -4,7 +4,6 @@
#include "base/HGBase.h"
#include "HGUIGlobal.h"
#include "app_cfg.h"
#include "ocrPdf.h"
#include <assert.h>
#include <qabstractproxymodel.h>
#include <QDateTime>

View File

@ -1,62 +0,0 @@
#include "dialog_upgradefirmware.h"
#include "ui_dialog_upgradefirmware.h"
#include <QMovie>
Dialog_upgradeFirmware::Dialog_upgradeFirmware(SANE_Handle handle, const std::string &upgradePath, QWidget *parent) :
QDialog(parent)
, m_handle(handle)
, m_upgradePath(upgradePath)
, m_status(SANE_STATUS_INVAL)
, ui(new Ui::Dialog_upgradeFirmware)
{
ui->setupUi(this);
setWindowTitle(tr("upgrade"));
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
ui->label_text->setText(tr("firmware upgrade in progress, please wait..."));
QMovie *movie = new QMovie(":images/image_rsc/logo/waiting.gif");
ui->label_gif->setMovie(movie);
movie->setCacheMode(QMovie::CacheAll);
movie->setScaledSize(QSize(ui->label_gif->width(), ui->label_gif->height()));
movie->start();
ui->label_gif->show();
connect(this, SIGNAL(finish()), this, SLOT(on_finish()), Qt::QueuedConnection);
HGBase_OpenThread(ThreadFunc, this, &m_thread);
}
Dialog_upgradeFirmware::~Dialog_upgradeFirmware()
{
if (nullptr != m_thread)
{
HGBase_CloseThread(m_thread);
m_thread = nullptr;
}
delete ui;
}
void HGAPI Dialog_upgradeFirmware::ThreadFunc(HGThread thread, HGPointer param)
{
(void)thread;
Dialog_upgradeFirmware *p = (Dialog_upgradeFirmware *)param;
SANE_Status rc = sane_io_control(p->m_handle, IO_CTRL_CODE_SET_FIRMWARE_UPGRADE, (void*)p->m_upgradePath.c_str(), NULL);
p->m_status = rc;
emit p->finish();
}
SANE_Status Dialog_upgradeFirmware::getUpgradeStatus()
{
return m_status;
}
void Dialog_upgradeFirmware::on_finish()
{
accept();
}

View File

@ -1,43 +0,0 @@
#ifndef DIALOG_UPGRADEFIRMWARE_H
#define DIALOG_UPGRADEFIRMWARE_H
#include <QDialog>
#include "base/HGThread.h"
#include "sane/sane_ex.h"
namespace Ui {
class Dialog_upgradeFirmware;
}
class Dialog_upgradeFirmware : public QDialog
{
Q_OBJECT
public:
explicit Dialog_upgradeFirmware(SANE_Handle handle, const std::string &upgradePath, QWidget *parent = nullptr);
~Dialog_upgradeFirmware();
private:
static void HGAPI ThreadFunc(HGThread thread, HGPointer param);
public:
SANE_Status getUpgradeStatus();
signals:
void finish();
private slots:
void on_finish();
private:
SANE_Handle m_handle;
std::string m_upgradePath;
SANE_Status m_status;
HGThread m_thread;
private:
Ui::Dialog_upgradeFirmware *ui;
};
#endif // DIALOG_UPGRADEFIRMWARE_H

View File

@ -1,127 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog_upgradeFirmware</class>
<widget class="QDialog" name="Dialog_upgradeFirmware">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>435</width>
<height>125</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>19</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_gif">
<property name="minimumSize">
<size>
<width>40</width>
<height>60</height>
</size>
</property>
<property name="text">
<string>gif</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_text">
<property name="text">
<string>text</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -1,54 +0,0 @@
#include "gaosixy.h"
#include <QDebug>
#include <stdlib.h>
#include <math.h>
GaoSiXY::GaoSiXY()
{
}
void GaoSiXY::solve(double**a,int n,double *recv)
{
int m = 0;
int i,j;
for(j = 0; j < n; j++){
double max = 0;
double imax = 0;
for(i = j; i < n; i++){
if(imax < fabs(a[i][j])){
imax = fabs(a[i][j]);
max = a[i][j];//得到各行中所在列最大元素
m = i;
}
}
if(fabs(a[j][j]) != max) {
double b = 0;
for(int k = j;k < n + 1; k++){
b = a[j][k];
a[j][k] = a[m][k];
a[m][k] = b; }
}
for(int r = j;r < n + 1;r++){
a[j][r] = a[j][r] / max;//让该行的所在列除以所在列的第一个元素目的是让首元素为1
}
for(i = j + 1;i < n; i++){
double c = a[i][j];
if(c == 0) continue;
for(int s = j;s < n + 1;s++){
//double tempdata = a[i][s];
a[i][s] = a[i][s] - a[j][s] * c;//前后行数相减使下一行或者上一行的首元素为0
}
}
}
for(i = n - 2; i >= 0; i--){
for(j = i + 1;j < n; j++){
a[i][n] = a[i][n] - a[j][n] * a[i][j];
}
}
for(int k = 0; k < n; k++){
recv[k] = a[k][n];
}
}

View File

@ -1,17 +0,0 @@
#ifndef GAOSIXY_H
#define GAOSIXY_H
#include <stdio.h>
#include <stdlib.h>
class GaoSiXY
{
public:
GaoSiXY();
void solve(double **a,int n,double *recv);//用于计算曲线方程
private:
};
#endif // GAOSIXY_H

File diff suppressed because it is too large Load Diff

View File

@ -1,141 +0,0 @@
#ifndef HG_SETTING_DIALOG_H
#define HG_SETTING_DIALOG_H
#include <QtWidgets>
#include <QSettings>
#include <algorithm>
#include "sane/sane_ex.h"
#include "cfg/gb_json.h"
#include "device_menu.h"
class hg_settingdialog : public QDialog
{
Q_OBJECT
int changed_count_;
bool save_;
bool clicked_gamma_;
dev_que *dev_que_;
gb::scanner_cfg *cur_cfg_;
gb::sane_config_schm *cur_scheme_;
void refresh_control_value(int op_id);
void on_select_scheme(bool apply_to_dev = true);
QString gen_gamma_file_path(void);
QMenu *top_menu_;
QLineEdit *edit_name_;
QPushButton *rename_;
QPushButton *apply_;
QPushButton *del_this_;
QPushButton *del_all_;
QLabel *custom_area_lable_;
QPushButton *btn_cut_area_;
QPushButton *btn_gamma_;
QTextEdit *sketch_;
QLineEdit *m_lineEdit_name;
void create_scheme_management_ui(QVBoxLayout* layout);
QString find_current_scheme_menu(int *scheme_id = nullptr);
static std::string property_combox_data_type_;
enum _cbox_type
{
COMBO_VAL_STRING = 0,
COMBO_VAL_INT,
COMBO_VAL_FLOAT,
};
public:
explicit hg_settingdialog(void *handle, QWidget *parent = nullptr,
dev_que* dev = nullptr);
~hg_settingdialog();
public:
void initUi();
void updateOpt();
void createUI();
void updateUIStatus();
QVector<QWidget*> find_control(int opt_num);
void keyPressEvent(QKeyEvent *e);
int get_changed_items(void);
private:
void *m_handle;
private:
QString m_qstrFileName;
QSettings *m_configIniWrite;
QSettings *m_configIniRead;
private:
void iniWrite(QString title, int id, QVariant value);
void iniRead(QString title, int id, QWidget *w);
QString md5(QString key);
const void* find_option_description(int id); // return const SANE_Option_Descriptor* pointer
const void* find_option_description(const std::string& title, int* id); // return const SANE_Option_Descriptor* pointer
virtual void closeEvent(QCloseEvent* e);
bool createMsgBoxUi(bool add, std::string &name);
std::string getCurUiShemeName(std::string name);
void save_scheme(void);
void cancel_setting(void);
void getAppVersion();
void apply_current_scheme(void);
private:
QVector<QPair<QPair<int, QVariant>, QString>> m_list_IdValueTitle;
QVector<QPair<const void*, QVariant>> m_list_defaultOptions; // default values of device
QVector<QPair<QObject*, QObject*>> m_list_sliderSpinbox;
QVector<QPair<int, const void*>> m_list_getOpt;
QVector<std::string> m_list_deviceNames;
QVector<QWidget*> m_list_widgets;
private slots:
void slot_checkedClicked();
void slot_sliderClicked(int value);
void slot_spinBoxClicked(int value);
void slot_doubleSpinboxClicked(double value);
void slot_string_list_comboBoxClicked();
void slot_pushButtonClicked();
void slot_cutButtonClicked();
void slot_gammaButtonClicked();
void slot_word_list_comboBoxClicked(int value);
void slot_lineEditInput();
void slot_buttonOkClicked();
void slot_buttonCancelClicked();
void slot_pushButton_scheme_management(void);
void on_current_scheme_changed(void);
void restore_2_default_settings(void);
private:
int m_dpiId;
int m_dpiValue;
int m_paperSizeId;
QString m_paperSizeValue;
int m_cutLeftId;
int m_cutTopId;
int m_cutRightId;
int m_cutBottomId;
double m_cutWidth; // 单位是毫米
double m_cutHeight; // 单位是毫米
double m_cutLeftValue; // 单位是毫米
double m_cutTopValue; // 单位是毫米
double m_cutRightValue; // 单位是毫米
double m_cutBottomValue; // 单位是毫米
int m_colorModeId;
QString m_colorModeValue;
SANE_Gamma m_gammaData;
QComboBox *comb_;
};
#endif // HG_SETTING_DIALOG_H

File diff suppressed because it is too large Load Diff

View File

@ -9,14 +9,12 @@
#include <QPropertyAnimation>
#include "HGImgView.h"
#include "HGImgThumb.h"
#include "sane/sane_ex.h"
#include "dialog_aquireinto.h"
#include "widget_imgproc_base.h"
#include "widget_imgproc_sidebar.h"
#include "imgfmt/HGImgFmt.h"
#include "VersionDll.h"
#include "device_menu.h"
#include "sane_device.h"
#include "device_user.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
@ -95,16 +93,6 @@ private slots:
void on_act_autoSave_triggered();
signals:
void sane_dev_arrive(QString devName, bool opened);
void sane_dev_remove(QString devName);
void sane_dev_error(QString errorInfo);
void sane_dev_readyStatus(QString promptInfo);
void pre_new_image(void *img);
void post_new_image(unsigned int ret, int statu);
void scan_working(QString workingInfo);
void scan_finish(QString finishInfo, int err);
private slots:
void on_AcquireInto2();
void on_reloadAcquireIntoCfg();
@ -125,18 +113,8 @@ private slots:
void on_dialog_multirotate_refreshImgFile(const QString &fileName);
void on_multiPageLineEditFinished();
void on_clearCache();
void on_sane_dev_arrive(QString devName, bool opened);
void on_sane_dev_remove(QString devName);
void on_sane_dev_error(QString errorInfo);
void on_sane_dev_readyStatus(QString promptInfo);
void on_pre_new_image(void *img);
void on_post_new_image(unsigned int ret, int statu);
void on_scan_working(QString workingInfo);
void on_scan_finish(QString finishInfo, int err);
void on_export_scanned_image(void);
void on_continueScan();
void on_stopScan();
void on_statusInfoDblClick();
void on_newImage(void *image);
void on_finishScan();
void on_wrong_image_decide(dialog_wrong_img* dlg, bool save);
void on_m_pbtn_push_clicked();
void on_dialog_sideBar_applyToImage(HGImage img, int brightness, int contrast, double gamma, bool enhanceText);
@ -216,8 +194,6 @@ private slots:
void on_act_imageEdit_triggered();
void on_scanOptions_changed(const QString &device, const QString &option, bool checked_now);
void on_act_sortPages_triggered();
void on_actionact_update_triggered();
@ -234,18 +210,15 @@ private slots:
void on_act_deleteFile_triggered();
public slots:
void my_url_handler(const QUrl& url);
void on_act_selectDevice_triggered();
protected:
virtual void closeEvent(QCloseEvent *e) override;
virtual void resizeEvent(QResizeEvent *e) override;
private:
static int sane_ex_callback(SANE_Handle hdev, int code, void *data, unsigned int* len, void *param);
static void HGAPI CrashFunc(HGPointer crashAddr, HGPointer param);
HGUInt getDpi();
QString getCacheFileName(HGImage img);
HGImage createImage();
int getMultiPageCount();
@ -255,21 +228,19 @@ private:
askIfClear startScanMessageBox(QWidget* parent);
QString passwordEncrypt(const QString& password);
QString passwordDecrypt(const QString& transcode);
bool open_scanner(const QString& name, const QString& scheme);
bool judgeDiskSpace(QString currentPath, bool showDlg = true);
bool judgeDiskSpace(QString currentPath);
void upgradeApp(QString pkgPath);
bool isLimitAccessFolder(int type); //type:1-aquire,2-aquireInto
static QString GetDevType(const QString& fwVersion, bool &canLock);
void deleteOverdueLogFile(const QString& logFilePath);
void deleteUpgradePkg(const QString& cfgFilePath);
QString getDevPid();
QString getDevSerialNum();
QString getDevFwVersionNum();
void initAcquireIntoComboBox();
void updateSideBar();
private:
Ui::MainWindow *ui;
DeviceUserMgr *m_devUserMgr;
DeviceUser *m_devUser;
QAction *m_act_acquireInto2;
QComboBox *m_cbtn_acquireIntoCfg;
QString m_currLang;
@ -291,8 +262,6 @@ private:
QPropertyAnimation *m_propertyAnimation;
QPropertyAnimation *m_propertyAnimation2;
dev_que dev_que_;
bool auto_save_changes_;
bool save_from_changed_;
typedef struct _save_opt
@ -349,7 +318,6 @@ private:
class HGLineEdit* m_multiPageLineEdit;
class Widget_StatusBar *m_wndStatusBar;
class dialog_log *m_dialogLog;
class Dialog_AquireInto *m_dialogAcquireinto;
class Dialog_FullScreen *m_dlgFullScreen;
};

View File

@ -69,6 +69,7 @@
<property name="title">
<string>menu_scan</string>
</property>
<addaction name="act_selectDevice"/>
<addaction name="act_scannerSettings"/>
<addaction name="separator"/>
<addaction name="act_acquire"/>
@ -168,13 +169,7 @@
<addaction name="act_help"/>
<addaction name="act_about"/>
</widget>
<widget class="device_menu" name="menu_device">
<property name="title">
<string>menu_device</string>
</property>
</widget>
<addaction name="menu_file"/>
<addaction name="menu_device"/>
<addaction name="menu_scan"/>
<addaction name="menu_view"/>
<addaction name="menu_page"/>
@ -630,14 +625,12 @@
<string>act_enhanceText</string>
</property>
</action>
<action name="act_selectDevice">
<property name="text">
<string>act_selectDevice</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>device_menu</class>
<extends>QMenu</extends>
<header>device_menu.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="Scanner_resource.qrc"/>
</resources>

View File

@ -1,148 +0,0 @@
#include <iostream>
#include "base/HGBase.h"
#ifdef HG_CMP_MSC
#include <Windows.h>
#endif
#include <string>
#include "base/HGUtility.h"
std::string getOcrPath()
{
std::string ocrPath;
#ifdef HG_CMP_MSC
HKEY hKey = NULL;
#ifdef _WIN64
RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\Microtek\\Microtek OCR Engine V1", 0, KEY_QUERY_VALUE, &hKey);
#else
RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microtek\\Microtek OCR Engine V1", 0, KEY_QUERY_VALUE, &hKey);
#endif
if (NULL != hKey)
{
CHAR szData[MAX_PATH] = { 0 };
DWORD cbData = MAX_PATH;
if (ERROR_SUCCESS == RegQueryValueExA(hKey, "InstallPath_Fast", NULL, NULL, (LPBYTE)szData, &cbData))
{
ocrPath = szData;
}
RegCloseKey(hKey);
}
#endif
return ocrPath;
}
bool createOcrPdf(const std::string &imgPath, const std::string &dstFile, int languageType)
{
#ifdef HG_CMP_MSC
std::string ocrPath = getOcrPath();
if (ocrPath.empty())
return false;
DWORD len1 = GetEnvironmentVariableA("Path", NULL, 0);
char* env1 = (char *)malloc((size_t)len1 + 256);
if (NULL != env1)
{
memset(env1, 0, (size_t)len1 + 256);
GetEnvironmentVariableA("Path", env1, len1 + 256);
std::string ss(env1);
if (ss.find(ocrPath) == std::string::npos)
{
strcat(env1, ";");
strcat(env1, ocrPath.c_str());
SetEnvironmentVariableA("Path", env1);
}
free(env1);
}
char env2[256] = {0};
strcat(env2, ocrPath.c_str());
strcat(env2, "\\");
strcat(env2, "tessdata_f");
SetEnvironmentVariableA("TESSDATA_PREFIX", env2);
DeleteFileA(dstFile.c_str());
const int MY_PIPE_BUFFER_SIZE = 1024;
//初始化管道
HANDLE hPipeRead = NULL;
HANDLE hPipeWrite = NULL;
SECURITY_ATTRIBUTES saOutPipe;
::ZeroMemory(&saOutPipe, sizeof(saOutPipe));
saOutPipe.nLength = sizeof(SECURITY_ATTRIBUTES);
saOutPipe.lpSecurityDescriptor = NULL;
saOutPipe.bInheritHandle = TRUE;
CreatePipe(&hPipeRead, &hPipeWrite, &saOutPipe, MY_PIPE_BUFFER_SIZE);
PROCESS_INFORMATION ProcessInfo;
::ZeroMemory(&ProcessInfo, sizeof(ProcessInfo));
STARTUPINFOA StartupInfo;
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
StartupInfo.cb = sizeof(StartupInfo);
StartupInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
StartupInfo.hStdOutput = hPipeWrite;
StartupInfo.hStdError = hPipeWrite;
StartupInfo.wShowWindow = SW_HIDE;
HGChar prefix[256];
HGBase_GetFilePrefix(dstFile.c_str(), prefix, 256);
bool ret = false;
char cmd[1024] = {0};
if (0 == languageType)
{
sprintf(cmd, "tesseract.exe \"%s\" \"%s\" -l %s --psm %d --oem %d %s", imgPath.c_str(), prefix, "eng", 3, 3, "pdf");
}
else if (1 == languageType)
{
sprintf(cmd, "tesseract.exe \"%s\" \"%s\" -l %s --psm %d --oem %d %s", imgPath.c_str(), prefix, "chi_sim", 3, 3, "pdf");
}
else if (2 == languageType)
{
sprintf(cmd, "tesseract.exe \"%s\" \"%s\" -l %s --psm %d --oem %d %s", imgPath.c_str(), prefix, "chi_tra", 3, 3, "pdf");
}
else if (3 == languageType)
{
sprintf(cmd, "tesseract.exe \"%s\" \"%s\" -l %s --psm %d --oem %d %s", imgPath.c_str(), prefix, "jpn", 3, 3, "pdf");
}
else if (4 == languageType)
{
sprintf(cmd, "tesseract.exe \"%s\" \"%s\" -l %s --psm %d --oem %d %s", imgPath.c_str(), prefix, "kor", 3, 3, "pdf");
}
BOOL b = CreateProcessA(NULL, cmd, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &StartupInfo, &ProcessInfo);
if (b)
{
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
DWORD exitCode;
GetExitCodeProcess(ProcessInfo.hProcess, &exitCode);
if (0 == exitCode)
ret = true;
DWORD dwReadLen = 0;
DWORD dwStdLen = 0;
if (PeekNamedPipe(hPipeRead, NULL, 0, NULL, &dwReadLen, NULL) && dwReadLen > 0)
{
char szPipeOut[MY_PIPE_BUFFER_SIZE];
::ZeroMemory(szPipeOut, sizeof(szPipeOut));
if (ReadFile(hPipeRead, szPipeOut, dwReadLen, &dwStdLen, NULL))
{
}
}
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
}
CloseHandle(hPipeRead);
CloseHandle(hPipeWrite);
return ret;
#else
return false;
#endif
}

View File

@ -1,9 +0,0 @@
#ifndef __OCRPDF_H__
#define __OCRPDF_H__
#include <string>
std::string getOcrPath();
bool createOcrPdf(const std::string &imgPath, const std::string &dstFile, int languageType);//languageType is the index of the comboBox on export and save_as ui.
#endif /* __OCRPDF_H__ */

View File

@ -1,65 +0,0 @@
#include "sane_device.h"
sane_dev::sane_dev() : hdev_(nullptr), offline_(true), name_(""), cfg_name_("")
{}
sane_dev::~sane_dev()
{
close();
}
bool sane_dev::apply(gb::sane_config_schm* schm)
{
SANE_Int count = 0,
afterdo = 0;
bool ret = false;
return ret;
}
std::string sane_dev::name(void)
{
return name_;
}
std::string sane_dev::current_configuration_name(void)
{
return cfg_name_;
}
bool sane_dev::is_online(void)
{
return !offline_;
}
SANE_Handle sane_dev::handle(void)
{
return hdev_;
}
bool sane_dev::open(const std::string& name)
{
if(name_ == name)
return true;
close();
SANE_Status statu = sane_open(name.c_str(), &hdev_);
if(statu == SANE_STATUS_GOOD)
{
}
return statu == SANE_STATUS_GOOD;
}
void sane_dev::set_online(bool online)
{
offline_ = !online;
}
void sane_dev::close(void)
{
if(hdev_)
{
sane_close(hdev_);
hdev_ = nullptr;
}
offline_ = true;
name_ = "";
cfg_name_ = "";
}

View File

@ -1,38 +0,0 @@
#pragma once
#include <string>
#include "sane/sane_ex.h"
#include "cfg/gb_json.h"
class sane_dev
{
SANE_Handle hdev_;
bool offline_;
std::string name_;
std::string cfg_name_;
enum act_result
{
ACT_RESULT_NO_NEED = 0,
ACT_RESULT_FAILED,
ACT_RESULT_SUCCESS,
};
bool apply(gb::sane_config_schm* schm);
public:
sane_dev();
~sane_dev();
public:
std::string name(void);
std::string current_configuration_name(void);
bool is_online(void);
SANE_Handle handle(void);
bool open(const std::string& name);
void set_online(bool online);
void close(void);
};

View File

@ -1,315 +0,0 @@
#include "setpicclrtool.h"
#include "ui_setpicclrtool.h"
#include "widget.h"
#include <QDebug>
#include <QVariant>
setPicClrTool::setPicClrTool(QWidget *parent) :
QDialog(parent),
ui(new Ui::setPicClrTool)
{
ui->setupUi(this);
setMouseTracking(true);
ui->inputEdt->setEnabled(false);
ui->outputEdt->setEnabled(false);
ui->inputEdt->setValidator(new QIntValidator(0, 255, this));
ui->outputEdt->setValidator(new QIntValidator(0, 255, this));
ui->widget->setFocus(Qt::MouseFocusReason);
connect(ui->widget,SIGNAL(mouseCoordSig(QPoint)),this,SLOT(mouseCoordSlot(QPoint)));
connect(ui->widget,SIGNAL(dragPointChecked(bool)),this,SLOT(lineEditEnable(bool)));
connect(ui->widget,SIGNAL(lineChangeSig()),this,SLOT(lineChangeSlot()));
}
setPicClrTool::~setPicClrTool()
{
delete ui;
}
void setPicClrTool::getGrayTable(uchar *table, size_t length)
{
QVector<int> gray = getGrayALLPoint();
for (size_t i = 0; i < length; i++)
table[i] = static_cast<uchar>(gray[static_cast<int>(i)]);
}
void setPicClrTool::getRGBTable(uchar *table, size_t length)
{
if (length != 768)
throw "length is not 768.";
QVector<int> rgb = getRgbALLPoint();
QVector<int> red = getRedALLPoint();
QVector<int> green = getGreenALLPoint();
QVector<int> blue = getBlueALLPoint();
for (size_t i = 0; i < 256; i++)
{
//if (i == 255)
// int a = 0;
//table member order is B\G\R
table[i * 3 + 0] = static_cast<uchar>(blue[rgb[static_cast<int>(i)]]);
table[i * 3 + 1] = static_cast<uchar>(green[rgb[static_cast<int>(i)]]);
table[i * 3 + 2] = static_cast<uchar>(red[rgb[static_cast<int>(i)]]);
}
}
//void setPicClrTool::setGrayTable(const uchar *table, size_t length)
//{
// QVector<int> gray;
// for (size_t i = 0; i < length; i++)
// gray[static_cast<int>(i)] = int(table[i]);
// //ui->widget->setGrayALLPoint(gray);
//}
//void setPicClrTool::setRGBTable(const uchar *table, size_t length)
//{
// QVector<int> rgb;
// QVector<int> red;
// QVector<int> green;
// QVector<int> blue;
// for(int i = 0; i < 256; i++){
// rgb.append(i);
// }
// for (size_t i = 0; i < length; i++){
// red.append(int(table[i * 3 + 0]));
// green.append(int(table[i * 3 + 1]));
// blue.append(int(table[i * 3 + 2]));
// }
//}
void setPicClrTool::setColorMode(int colorMode)
{
QVariant v(6);
if(colorMode == 0)
{
ui->colorSetCmb->setItemData(1,v,Qt::UserRole - 1);
}
else
{
ui->comboBox->setItemData(2,v,Qt::UserRole - 1);
ui->colorSetCmb->setItemData(0,v,Qt::UserRole - 1);
ui->colorSetCmb->setItemData(2,v,Qt::UserRole - 1);
ui->colorSetCmb->setItemData(3,v,Qt::UserRole - 1);
ui->colorSetCmb->setItemData(4,v,Qt::UserRole - 1);
ui->colorSetCmb->setCurrentIndex(1);
}
}
QVector<QList<QPoint> > setPicClrTool::getRGBKeyTable()
{
QVector<QList<QPoint>> plv;
plv.append(getRgbKeyPoint());
plv.append(getRedKeyPoint());
plv.append(getGreenKeyPoint());
plv.append(getBlueKeyPoint());
return plv;
}
void setPicClrTool::setRGBKeyTable(QVector<QList<QPoint> > &plv)
{
setRgbKeyPoint(plv[0]);
setRedKeyPoint(plv[1]);
setGreenKeyPoint(plv[2]);
setBlueKeyPoint(plv[3]);
}
QList<QPoint> setPicClrTool::getGrayKeyTable()
{
return getGrayKeyPoint();
}
void setPicClrTool::setGrayKeyTable(QList<QPoint> &plv)
{
setGrayKeyPoint(plv);
}
QVector<int> setPicClrTool::getRgbALLPoint()
{
return ui->widget->getRgbALLPoint();
}
QList<QPoint> setPicClrTool::getRgbKeyPoint() const
{
qDebug() << "setRgb" << ui->widget->getRgbKeyPoint();
return ui->widget->getRgbKeyPoint();
}
void setPicClrTool::setRgbKeyPoint(const QList<QPoint> &pVec)
{
qDebug() << "setRgb" << pVec;
ui->widget->setRgbKeyPoint(pVec);
}
QList<QPoint> setPicClrTool::getRedKeyPoint() const
{
return ui->widget->getRedKeyPoint();
}
void setPicClrTool::setRedKeyPoint(const QList<QPoint> &pVec)
{
ui->widget->setRedKeyPoint(pVec);
}
QList<QPoint> setPicClrTool::getBlueKeyPoint() const
{
return ui->widget->getBlueKeyPoint();
}
void setPicClrTool::setBlueKeyPoint(const QList<QPoint> &pVec)
{
ui->widget->setBlueKeyPoint(pVec);
}
QList<QPoint> setPicClrTool::getGreenKeyPoint() const
{
return ui->widget->getGreenKeyPoint();
}
void setPicClrTool::setGreenKeyPoint(const QList<QPoint> &pVec)
{
ui->widget->setGreenKeyPoint(pVec);
}
QList<QPoint> setPicClrTool::getGrayKeyPoint() const
{
return ui->widget->getGrayKeyPoint();
}
void setPicClrTool::setGrayKeyPoint(const QList<QPoint> &pVec)
{
ui->widget->setGrayKeyPoint(pVec);
}
QVector<int> setPicClrTool::getRedALLPoint()
{
return ui->widget->getRedALLPoint();
}
QVector<int> setPicClrTool::getBlueALLPoint()
{
return ui->widget->getBlueALLPoint();
}
QVector<int> setPicClrTool::getGreenALLPoint()
{
return ui->widget->getGreenALLPoint();
}
QVector<int> setPicClrTool::getGrayALLPoint()
{
return ui->widget->getGrayALLPoint();
}
void setPicClrTool::mouseCoordSlot(QPoint pos)
{
ui->inputEdt->setText(QString::number(pos.x()));
ui->outputEdt->setText(QString::number(pos.y()));
}
void setPicClrTool::lineEditEnable(bool a)
{
ui->inputEdt->setEnabled(a);
ui->outputEdt->setEnabled(a);
}
void setPicClrTool::lineChangeSlot()
{
ui->comboBox->setCurrentIndex(0);
}
void setPicClrTool::on_colorSetCmb_currentIndexChanged(int index)
{
(void)index;
/* switch(index){
case RED:
ui->widget->updateCurLinePnt(RED);
break;
case GREEN:
ui->widget->updateCurLinePnt(GREEN);
break;
case BLUE:
ui->widget->updateCurLinePnt(BLUE);
break;
case RGB:
ui->widget->updateCurLinePnt(RGB);
break;
case GRAY:
ui->widget->updateCurLinePnt(GRAY);
break;
}*/
}
void setPicClrTool::on_comboBox_currentIndexChanged(int index)
{
if(index == 0){
ui->widget->initAllLstPnt();
ui->widget->updateCurLinePnt(ui->colorSetCmb->currentIndex());
return ;
}
ui->widget->initAllLstPnt();
if(index == 1){
rgbLine.clear();
rgbLine.append(QPoint(0,255));
rgbLine.append(QPoint(255,0));
ui->widget->setLstPnt_RGB(rgbLine);
}else if(index == 2){
redLine.clear();
redLine.append(QPoint(33,255));
redLine.append(QPoint(185,0));
redLine.append(QPoint(119,127));
greenLine.clear();
greenLine.append(QPoint(28,255));
greenLine.append(QPoint(132,0));
greenLine.append(QPoint(77,127));
blueLine.clear();
blueLine.append(QPoint(25,255));
blueLine.append(QPoint(108,0));
blueLine.append(QPoint(60,127));
ui->widget->setLstPnt_RED(redLine);
ui->widget->setLstPnt_GREEN(greenLine);
ui->widget->setLstPnt_BLUE(blueLine);
}else if(index == 4){
rgbLine.clear();
rgbLine.append(QPoint(0,0));
rgbLine.append(QPoint(255,255));
rgbLine.append(QPoint(103,125));
ui->widget->setLstPnt_RGB(rgbLine);
}else if(index == 3){
rgbLine.clear();
rgbLine.append(QPoint(0,0));
rgbLine.append(QPoint(255,255));
rgbLine.append(QPoint(130,101));
ui->widget->setLstPnt_RGB(rgbLine);
}
ui->widget->updateCurLinePnt(ui->colorSetCmb->currentIndex());
}
void setPicClrTool::on_inputEdt_textChanged(const QString &arg1)
{
ui->widget->setXCoorVal(arg1.toInt());
}
void setPicClrTool::on_outputEdt_textChanged(const QString &arg1)
{
ui->widget->setYCoorVal(arg1.toInt());
}
void setPicClrTool::on_pushButton_clicked()
{
ui->widget->initSelectColLine(ui->colorSetCmb->currentIndex());
}
void setPicClrTool::on_buttonBox_accepted()
{
//close();
accept();
}
void setPicClrTool::on_buttonBox_rejected()
{
ui->widget->initAllLstPnt();
//close();
reject();
}

View File

@ -1,82 +0,0 @@
#ifndef SETPICCLRTOOL_H
#define SETPICCLRTOOL_H
//#include "colorlinesetdef.h"
#include <QDialog>
namespace Ui {
class setPicClrTool;
}
class setPicClrTool : public QDialog
{
Q_OBJECT
public:
explicit setPicClrTool(QWidget *parent = nullptr);
~setPicClrTool();
void getGrayTable(uchar* table, size_t length = 256);
void getRGBTable(uchar* table, size_t length = 768);
// void setGrayTable(const uchar* table, size_t length = 256);
// void setRGBTable(const uchar* table, size_t length = 768);
void setColorMode(int colorMode);
QVector<QList<QPoint>> getRGBKeyTable();
void setRGBKeyTable(QVector<QList<QPoint>>& plv);
QList<QPoint> getGrayKeyTable();
void setGrayKeyTable(QList<QPoint> &plv);
private:
QVector<int> getRgbALLPoint();
QVector<int> getRedALLPoint();
QVector<int> getBlueALLPoint();
QVector<int> getGreenALLPoint();
QVector<int> getGrayALLPoint();
QList<QPoint> getRgbKeyPoint()const;
void setRgbKeyPoint(const QList<QPoint>& pVec);
QList<QPoint> getRedKeyPoint()const;
void setRedKeyPoint(const QList<QPoint>& pVec);
QList<QPoint> getBlueKeyPoint()const;
void setBlueKeyPoint(const QList<QPoint>& pVec);
QList<QPoint> getGreenKeyPoint()const;
void setGreenKeyPoint(const QList<QPoint>& pVec);
QList<QPoint> getGrayKeyPoint()const;
void setGrayKeyPoint(const QList<QPoint>& pVec);
private slots:
void mouseCoordSlot(QPoint);//set QLineEdit value by QPoint setting
void lineEditEnable(bool);//set 2 LineEdit enable status
void lineChangeSlot();
void on_colorSetCmb_currentIndexChanged(int index);
void on_comboBox_currentIndexChanged(int index);
void on_inputEdt_textChanged(const QString &arg1);
void on_outputEdt_textChanged(const QString &arg1);
void on_pushButton_clicked();
void on_buttonBox_accepted();
void on_buttonBox_rejected();
private:
Ui::setPicClrTool *ui;
QList<QPoint> linePoint;
QList<QPoint> greenLine;
QList<QPoint> redLine;
QList<QPoint> blueLine;
QList<QPoint> rgbLine;
QList<QPoint> grayLine;
};
#endif // SETPICCLRTOOL_H

View File

@ -1,167 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>setPicClrTool</class>
<widget class="QWidget" name="setPicClrTool">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>259</width>
<height>341</height>
</rect>
</property>
<property name="windowTitle">
<string>自定义色调曲线</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1,0,0">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QComboBox" name="comboBox">
<item>
<property name="text">
<string>自定义</string>
</property>
</item>
<item>
<property name="text">
<string>负片RGB</string>
</property>
</item>
<item>
<property name="text">
<string>彩色负片RGB</string>
</property>
</item>
<item>
<property name="text">
<string>较暗RGB</string>
</property>
</item>
<item>
<property name="text">
<string>较亮RGB</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="4,2,1">
<item>
<widget class="QComboBox" name="colorSetCmb">
<property name="mouseTracking">
<bool>false</bool>
</property>
<item>
<property name="text">
<string>RGB</string>
</property>
</item>
<item>
<property name="text">
<string>灰</string>
</property>
</item>
<item>
<property name="text">
<string>红</string>
</property>
</item>
<item>
<property name="text">
<string>蓝</string>
</property>
</item>
<item>
<property name="text">
<string>绿</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>初始化</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="Widget" name="widget" native="true">
<property name="mouseTracking">
<bool>true</bool>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>输入:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="inputEdt">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>输出:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="outputEdt">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Widget</class>
<extends>QWidget</extends>
<header location="global">widget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -1,855 +0,0 @@
#include "widget.h"
#include "ui_widget.h"
#include "gaosixy.h"
#include <iostream>
#include <QPainter>
#include <QVector>
#include <QDebug>
using namespace std;
enum COLOR_TPYE
{
RGB,
GRAY,
RED,
BLUE,
GREEN
};
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
setWindowTitle(tr("zuobiaozhou")); //设置标题栏标题
//resize(300,300); //设置窗口初始大小
//ui->table->setWindowFlags(Qt::WindowStaysOnTopHint);
initAllLstPnt();
initInterface();
}
Widget::~Widget()
{
delete ui;
}
void Widget::setLstPnt_RGB(const QList<QPoint> &plst)
{
rgbLine = QList<QPoint>(plst);
}
QList<QPoint> Widget::getLstPnt_RGB() const
{
return rgbLine;
}
void Widget::setLstPnt_RED(const QList<QPoint> &plst)
{
redLine = QList<QPoint>(plst);
}
void Widget::setLstPnt_BLUE(const QList<QPoint> &plst)
{
blueLine = QList<QPoint>(plst);
}
QList<QPoint> Widget::getLstPnt_BLUE() const
{
return blueLine;
}
void Widget::setLstPnt_GREEN(const QList<QPoint> &plst)
{
greenLine = QList<QPoint>(plst);
}
QList<QPoint> Widget::getLstPnt_GREEN() const
{
return greenLine;
}
void Widget::setLstPnt_GRAY(const QList<QPoint> &plst)
{
grayLine = QList<QPoint>(plst);
}
QList<QPoint> Widget::getLstPnt_GRAY() const
{
return grayLine;
}
QVector<int> Widget::getRgbALLPoint()
{
return rgbALLPoint;
}
QList<QPoint> Widget::getRgbKeyPoint() const
{
return rgbLine;
}
void Widget::setRgbKeyPoint(const QList<QPoint> &pLst)
{
if(pLst.size() > 4) return;
rgbLine = QList<QPoint>(pLst);
pointLst.clear();
pointLst = QList<QPoint>(rgbLine);
drawLineFromPoint(rgbLine, RGB);
update();
}
QVector<int> Widget::getRedALLPoint()
{
return redALLPoint;
}
QList<QPoint> Widget::getRedKeyPoint() const
{
return redLine;
}
void Widget::setRedKeyPoint(const QList<QPoint> &pLst)
{
if(pLst.size() > 4) return;
redLine = QList<QPoint>(pLst);
drawLineFromPoint(redLine, RED);
update();
}
QVector<int> Widget::getBlueALLPoint()
{
return blueALLPoint;
}
QList<QPoint> Widget::getBlueKeyPoint() const
{
return blueLine;
}
void Widget::setBlueKeyPoint(const QList<QPoint> &pLst)
{
if(pLst.size() > 4) return;
blueLine = QList<QPoint>(pLst);
drawLineFromPoint(blueLine, BLUE);
update();
}
QVector<int> Widget::getGreenALLPoint()
{
return greenALLPoint;
}
QList<QPoint> Widget::getGreenKeyPoint() const
{
return greenLine;
}
void Widget::setGreenKeyPoint(const QList<QPoint> &pLst)
{
if(pLst.size() > 4) return;
greenLine = QList<QPoint>(pLst);
drawLineFromPoint(greenLine, GREEN);
update();
}
QVector<int> Widget::getGrayALLPoint()
{
return grayALLPoint;
}
QList<QPoint> Widget::getGrayKeyPoint() const
{
return grayLine;
}
void Widget::setGrayKeyPoint(const QList<QPoint> &pLst)
{
if(pLst.size() > 4) return;
grayLine = QList<QPoint>(pLst);
pointLst.clear();
pointLst = QList<QPoint>(grayLine);
drawLineFromPoint(grayLine, GRAY);
update();
}
void Widget::initAllLstPnt()
{
pointLst.clear();
pointLst.append(QPoint(0,0));
pointLst.append(QPoint(255,255));
redLine.clear();
redLine.append(QPoint(0,0));
redLine.append(QPoint(255,255));
blueLine.clear();
blueLine.append(QPoint(0,0));
blueLine.append(QPoint(255,255));
greenLine.clear();
greenLine.append(QPoint(0,0));
greenLine.append(QPoint(255,255));
rgbLine.clear();
rgbLine.append(QPoint(0,0));
rgbLine.append(QPoint(255,255));
grayLine.clear();
grayLine.append(QPoint(0,0));
grayLine.append(QPoint(255,255));
drawLineFromPoint(redLine, RED);
drawLineFromPoint(rgbLine, RGB);
drawLineFromPoint(greenLine, GREEN);
drawLineFromPoint(blueLine, BLUE);
drawLineFromPoint(grayLine, GRAY);
}
void Widget::initInterface()
{
color = Qt::gray;
selectCol = RGB;
leftMouseMv = false;
newPoint = false;
clickLine = false;
dragPoint = -1;
setMouseTracking(true);
ui->widget_2->setStyleSheet("QWidget{background-color:qlineargradient("
"spread:pad, x1:0, y1:0, x2:1, y2:0, "
"stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255))}");
ui->widget->setStyleSheet("QWidget{background-color:qlineargradient("
"spread:pad, x1:0, y1:1, x2:0, y2:0, "
"stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255))}");
}
void Widget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing,true); //开启抗锯齿
painter.translate(ui->widget->width(),ui->widget->height()); //坐标系统平移变换,把原点平移
painter.scale(ui->table->width() / 258.0,ui->table->height() / 258.0); //坐标系统比例变换,使绘制的图形随窗口的放大而放大
painter.scale(1,-1);
drawCoordinate(painter);
drawBackColorBySlc(painter);
drawCoorScale(painter);
drawCurveByColor(painter);
drawAllPoint(painter);
if(dragPoint < 0){
setMouseTracking(true);
emit dragPointChecked(false);
}
painter.end();
}
void Widget::mousePressEvent(QMouseEvent *event)
{
int x = (event->x() - ui->widget->width())*258/ui->table->width();
int y = (height() - event->y()-ui->widget_2->height())*258/ui->table->height();
//qDebug() << x << y;
if(event->button() == Qt::LeftButton){
newPoint = false;
dragPoint = -1;
clickLine = false;
for(int i = 0; i < linePoint.size();i++){
int px = linePoint.at(i).x();
int py = linePoint.at(i).y();
if(qAbs(x-px) <= 6 && qAbs(y-py) <= 6)
{
newPoint = true;
for(int j = 0; j < pointLst.size(); j++){
int lx = pointLst.at(j).x();
int ly = pointLst.at(j).y();
if(qAbs(x-lx) <= 6 && qAbs(y-ly) <= 6){
dragPoint = j;
clickLine = true;
leftMouseMv = true;
newPoint = false;
emit dragPointChecked(true);
setMouseTracking(false);
update();
break;
}
}
if(newPoint && pointLst.size() < 4 && x > pointLst.at(0).x() && x < pointLst.at(1).x()){
pointLst.append(QPoint(x,y));
dragPoint = pointLst.size()-1;
leftMouseMv = true;
clickLine = true;
emit dragPointChecked(true);
setMouseTracking(false);
update();
}
}
}
}
else if(event->button() == Qt::RightButton){
for(int j = 0; j < pointLst.size(); j++){
int lx = pointLst.at(j).x();
int ly = pointLst.at(j).y();
if(qAbs(x-lx) <= 7 && qAbs(y-ly) <= 5){
if(j > 1)
pointLst.removeAt(j);
if(j == dragPoint){
dragPoint = -1;
emit dragPointChecked(false);
}else if(j > dragPoint){
dragPoint = dragPoint;
}else {
dragPoint = dragPoint-1;
}
update();
break;
}
}
}
if(!clickLine){
dragPoint = -1;
emit dragPointChecked(false);
setMouseTracking(true);
update();
}
emit mouseCoordSig(QPoint(x,y));
}
void Widget::mouseMoveEvent(QMouseEvent *event)
{
int x = (event->x() - ui->widget->width())*258/ui->table->width();
int y = (height() - event->y()-ui->widget_2->height())*258/ui->table->height();
if(x < 0) x = 0;
if(y < 0) y = 0;
if(x >= 255) x = 255;
if(y >= 255) y = 255;
//qDebug() << x << y;
if(leftMouseMv && dragPoint >= 0)
{
if(pointLst[dragPoint] != pointLst.at(0) && pointLst[dragPoint] != pointLst.at(1)){
if(x <= pointLst.at(0).x()) x = pointLst.at(0).x() + 1;
if(x >= pointLst.at(1).x()) x = pointLst.at(1).x() - 1;
if(pointLst.size() == 4){
if(dragPoint == 2){
if(pointLst[2].x() > pointLst[3].x() && x <= pointLst[3].x())
x = pointLst[3].x() + 1;
if(pointLst[2].x() < pointLst[3].x() && x >= pointLst[3].x())
x = pointLst[3].x() - 1;
}
else if(dragPoint == 3){
if(pointLst[2].x() < pointLst[3].x() && x <= pointLst[2].x())
x = pointLst[2].x() + 1;
if(pointLst[2].x() > pointLst[3].x() && x >= pointLst[2].x())
x = pointLst[2].x() - 1;
}
}
}
else if(pointLst[dragPoint] == pointLst.at(0)){
int min = 999;
for(int i = 1; i < pointLst.size(); i++){
if(min > pointLst[i].x()) min = pointLst[i].x();
}
if(x >= min) x = min-1;
}
else if(pointLst[dragPoint] == pointLst.at(1)){
if(pointLst.size() > 2){
int max = 0;
for(int i = 2; i < pointLst.size(); i++){
if(max < pointLst[i].x()) max = pointLst[i].x();
}
if(x <= max) x = max+1;
}
else if(pointLst.size() <= 2)
if(x <= pointLst.at(0).x()) x = pointLst.at(0).x()+1;
}
pointLst[dragPoint].setX(x);
pointLst[dragPoint].setY(y);
emit lineChangeSig();
update();
}
emit mouseCoordSig(QPoint(x,y));
}
void Widget::mouseReleaseEvent(QMouseEvent *)
{
leftMouseMv = false;
}
void Widget::enterEvent(QEvent *)
{
setFocus(Qt::MouseFocusReason);
}
void Widget::leaveEvent(QEvent *)
{
if(dragPoint < 0)
emit mouseLeaveSig();
}
void Widget::setHist_RGB(const QVector<int> &hist)
{
rgbBackColor = QVector<int>(hist);
}
QVector<int> Widget::getHist_RED() const
{
return redBackColor;
}
void Widget::setHist_RED(const QVector<int> &hist)
{
redBackColor = QVector<int>(hist);
}
QVector<int> Widget::getHist_RGB() const
{
return rgbBackColor;
}
void Widget::setHist_GREEN(const QVector<int> &hist)
{
greenBackColor = QVector<int>(hist);
}
QVector<int> Widget::getHist_GREEN() const
{
return greenBackColor;
}
void Widget::setHist_BLUE(const QVector<int> &hist)
{
blueBackColor = QVector<int>(hist);
}
QVector<int> Widget::getHist_BLUE() const
{
return blueBackColor;
}
void Widget::setHist_GRAY(const QVector<int> &hist)
{
grayBackColor = QVector<int>(hist);
}
QVector<int> Widget::getHist_GRAY() const
{
return grayBackColor;
}
void Widget::drawCoordinate(QPainter &painter)
{
painter.setBrush(QColor(79,79,79));
painter.drawRect(0, 0, 260, 260);
painter.drawLine(-2000,0,2000,0);
painter.drawLine(0,1500,0,-1500);
}
void Widget::drawBackgroudColor(QPainter &painter,QVector<int> &curCol)
{
painter.setPen(QPen(color,1));
painter.setBrush(color);
int max = 0;
for(int i = 0; i < curCol.size(); i++)
{
if(curCol.at(i) > max)
{
max = curCol.at(i);
}
}
for(int i = 0; i < curCol.size(); i++)
{
painter.drawRect(i, 0, 1, curCol.at(i)*255/max);
}
}
void Widget::drawBackColorBySlc(QPainter &painter)
{
switch(selectCol){
case RGB:
drawBackgroudColor(painter,rgbBackColor);
break;
case GREEN:
drawBackgroudColor(painter,greenBackColor);
break;
case BLUE:
drawBackgroudColor(painter,blueBackColor);
break;
case RED:
drawBackgroudColor(painter,redBackColor);
break;
case GRAY:
drawBackgroudColor(painter,grayBackColor);
break;
}
}
void Widget::drawCoorScale(QPainter &painter)
{
painter.setPen(QPen(Qt::gray,1));
for(int i = 0; i < 260 ; i+=50)
{
if(i%50 == 0 && i >=50)
{
QVector<qreal> dashes;
qreal space = 3;
dashes << 5 << space << 5 <<space;
QPen pen;
pen.setDashPattern(dashes);
pen.setWidth(1);
painter.setPen(pen);
painter.drawLine(i,300,i,0);
painter.drawLine(0,i,300,i);
}
}
QLine line(0,0,255,255);
painter.drawLine(line);
}
void Widget::drawLineFromPoint(QList<QPoint> &plst, const int& col)
{
double **a;
int len = plst.size();
a = new double *[len];
for(int i = 0; i < len; i++){
a[i] = new double[len+1];
}
/*******通过pointLst的所有点给二维数组赋值生成行列式*******/
for(int i = 0; i < len; i++){
for(int j = 0;j < len + 1; j++){
if(j < len)
a[i][j] = caculateAllMi(plst.at(i).x(),len-j-1);
if(j == len)
a[i][j] = plst.at(i).y();
}
}
/*******调用高斯消元法计算曲线方程的系数值********/
GaoSiXY gaoSi;
double *result = new double[len] ;
gaoSi.solve(a,len,result);
/********保存曲线方程 x 的系数(a,b,c,d....)********/
QList<double> xiNum;
for(int i = 0; i < len; i++){
xiNum.append(*(result+i));
}
linePoint.clear();
linePoints.clear();
for(int i = 0; i < 256; i++){
int x = i;
double yVal = 0;
for(int j = 0; j < len; j++){
yVal += xiNum.at(j)*caculateAllMi(x,len-j-1);
}
int y = (int)yVal;
if(y > 255) y = 255;
if(y < 0) y = 0;
if(x < plst.at(0).x()) y = plst.at(0).y();
if(x > plst.at(1).x()) y = plst.at(1).y();
allLinePoints[x] = y;
linePoints.append(y);
linePoint.append(QPoint(x,y));
}
if(col == RED){
redALLPoint.clear();
for(int i = 0; i < linePoint.size(); i++)
redALLPoint.append(linePoint.at(i).y());
}
if(col == GREEN){
greenALLPoint.clear();
for(int i = 0; i < linePoint.size(); i++)
greenALLPoint.append(linePoint.at(i).y());
}
if(col == BLUE){
blueALLPoint.clear();
for(int i = 0; i < linePoint.size(); i++)
blueALLPoint.append(linePoint.at(i).y());
}
if(col == GRAY){
grayALLPoint.clear();
for(int i = 0; i < linePoint.size(); i++)
grayALLPoint.append(linePoint.at(i).y());
}
if(col == RGB){
rgbALLPoint.clear();
for(int i = 0; i < linePoint.size(); i++)
{
rgbALLPoint.append(linePoint.at(i).y());
}
}
for(int i = 0;i < len; i++){
delete[] a[i];
}
delete []a;
}
void Widget::drawAllPoint(QPainter &painter)
{
if(pointLst.size() > 0)
{
painter.setPen(QPen(Qt::white,1));
painter.setBrush(Qt::white);
for(int i = 0; i < pointLst.size(); i++){
painter.drawEllipse(pointLst.at(i),3,3);
}
if(dragPoint >= 0){
painter.setPen(QPen(QColor(0, 245, 255),2));
painter.drawEllipse(pointLst[dragPoint],4,4);
}
}
if(selectCol == GREEN){
greenLine.clear();
greenLine = QList<QPoint>(pointLst);
}
else if(selectCol == RED){
redLine.clear();
redLine = QList<QPoint>(pointLst);
}else if(selectCol == BLUE){
blueLine.clear();
blueLine = QList<QPoint>(pointLst);
}else if(selectCol == RGB){
rgbLine.clear();
rgbLine = QList<QPoint>(pointLst);
}else if(selectCol == GRAY){
grayLine.clear();
grayLine = QList<QPoint>(pointLst);
}
}
void Widget::drawCurveByColor(QPainter &painter)
{
qDebug() << selectCol;
switch (selectCol) {
case RGB:
painter.setPen(QPen(Qt::white,1));
drawLineFromPoint(rgbLine, RGB);
drawLineByVector(painter,rgbALLPoint);
if(redLine.size()>2 || redLine.at(0)!= QPoint(0,0) || redLine.at(1)!= QPoint(255,255)){
painter.setPen(QPen(Qt::red,1));
drawLineFromPoint(redLine,RED);
drawLineByVector(painter,redALLPoint);
}
if(blueLine.size()>2 || blueLine.at(0)!= QPoint(0,0) || blueLine.at(1)!= QPoint(255,255)){
painter.setPen(QPen(Qt::blue,1));
drawLineFromPoint(blueLine, BLUE);
drawLineByVector(painter,blueALLPoint);
}
if(greenLine.size()>2 || greenLine.at(0)!= QPoint(0,0) || greenLine.at(1)!= QPoint(255,255)){
painter.setPen(QPen(Qt::green,1));
drawLineFromPoint(greenLine, BLUE);
drawLineByVector(painter,greenALLPoint);
}
break;
case RED:
painter.setPen(QPen(Qt::red,1));
drawLineFromPoint(redLine,RED);
drawLineByVector(painter,redALLPoint);
break;
case BLUE:
painter.setPen(QPen(Qt::blue,1));
drawLineFromPoint(blueLine, BLUE);
drawLineByVector(painter,blueALLPoint);
break;
case GREEN:
painter.setPen(QPen(Qt::green,1));
drawLineFromPoint(greenLine, GREEN);
drawLineByVector(painter,greenALLPoint);
break;
case GRAY:
painter.setPen(QPen(Qt::white,1));
drawLineFromPoint(grayLine, GRAY);
drawLineByVector(painter,grayALLPoint);
break;
default:
break;
}
drawLineFromPoint(pointLst, -1);
}
void Widget::drawLineByVector(QPainter &painter,QVector<int> &pVec)
{
for(int i = 0; i < pVec.size()-1; i++){
painter.drawLine(QPoint(i,pVec.at(i)),QPoint(i+1,pVec.at(i+1)));
}
update();
}
int Widget::caculateAllMi(int num, int n)
{
int val = 1;
if(n == 0) return 1;
for(int i = 0; i < n; i++){
val *= num;
}
return val;
}
void Widget::getCurLineLUT(uchar *table, size_t length)
{
for(size_t i = 0; i < length; i++)
{
table[i] = allLinePoints[i];
}
}
QVector<unsigned char> Widget::getCurLinePntVec()
{
return linePoints;
}
void Widget::updateCurLinePnt(const int& colType)
{
dragPoint = -1;
selectCol = colType;
if(selectCol == GREEN){
color = QColor(202, 255, 112);
pointLst.clear();
pointLst = QList<QPoint>(greenLine);
ui->widget_2->setStyleSheet("QWidget{background-color:qlineargradient("
"spread:pad, x1:0, y1:0, x2:1, y2:0, "
"stop:0 rgba(0, 0, 0, 255), stop:1 rgba(0, 255, 0, 255))}");
ui->widget->setStyleSheet("QWidget{background-color:qlineargradient("
"spread:pad, x1:0, y1:1, x2:0, y2:0, "
"stop:0 rgba(0, 0, 0, 255), stop:1 rgba(0, 255, 0, 255))}");
}else if(selectCol == BLUE){
color = QColor(131, 111, 255);
pointLst.clear();
pointLst = QList<QPoint>(blueLine);
ui->widget_2->setStyleSheet("QWidget{background-color:qlineargradient("
"spread:pad, x1:0, y1:0, x2:1, y2:0, "
"stop:0 rgba(0, 0, 0, 255), stop:1 rgba(0, 0, 255, 255))}");
ui->widget->setStyleSheet("QWidget{background-color:qlineargradient("
"spread:pad, x1:0, y1:1, x2:0, y2:0, "
"stop:0 rgba(0, 0, 0, 255), stop:1 rgba(0, 0, 255, 255))}");
}else if(selectCol == RED){
color = QColor(255, 160, 122);
pointLst.clear();
pointLst = QList<QPoint>(redLine);
ui->widget_2->setStyleSheet("QWidget{background-color:qlineargradient("
"spread:pad, x1:0, y1:0, x2:1, y2:0, "
"stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 0, 0, 255))}");
ui->widget->setStyleSheet("QWidget{background-color:qlineargradient("
"spread:pad, x1:0, y1:1, x2:0, y2:0, "
"stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 0, 0, 255))}");
}else if(selectCol == GRAY){
color = Qt::gray;
pointLst.clear();
pointLst = QList<QPoint>(grayLine);
ui->widget_2->setStyleSheet("QWidget{background-color:qlineargradient("
"spread:pad, x1:0, y1:0, x2:1, y2:0, "
"stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255))}");
ui->widget->setStyleSheet("QWidget{background-color:qlineargradient("
"spread:pad, x1:0, y1:1, x2:0, y2:0, "
"stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255))}");
}else if(selectCol == RGB){
color = Qt::gray;
pointLst.clear();
pointLst = QList<QPoint>(rgbLine);
ui->widget_2->setStyleSheet("QWidget{background-color:qlineargradient("
"spread:pad, x1:0, y1:0, x2:1, y2:0, "
"stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255))}");
ui->widget->setStyleSheet("QWidget{background-color:qlineargradient("
"spread:pad, x1:0, y1:1, x2:0, y2:0, "
"stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255))}");
}
update();
}
void Widget::setXCoorVal(const int &xVal)
{
if(dragPoint >= 0){
int x = xVal;
if(pointLst[dragPoint] != pointLst.at(0) && pointLst[dragPoint] != pointLst.at(1)){
if(pointLst.size() == 3 && x > pointLst.at(0).x() && x < pointLst.at(1).x())
pointLst[dragPoint].setX(x);
if(pointLst.size() == 4){
if(dragPoint == 2){
if(pointLst[2].x() > pointLst[3].x() && x > pointLst[3].x() && x < pointLst[1].x())
pointLst[dragPoint].setX(x);
if(pointLst[2].x() < pointLst[3].x() && x < pointLst[3].x() && x > pointLst[0].x())
pointLst[dragPoint].setX(x);
}
else if(dragPoint == 3){
if(pointLst[2].x() < pointLst[3].x() && x > pointLst[2].x() && x < pointLst[1].x())
pointLst[dragPoint].setX(x);
if(pointLst[2].x() > pointLst[3].x() && x < pointLst[2].x() && x > pointLst[0].x())
pointLst[dragPoint].setX(x);
}
}
}
else if(pointLst[dragPoint] == pointLst.at(0)){
int min = 999;
for(int i = 1; i < pointLst.size(); i++){
if(min > pointLst[i].x()) min = pointLst[i].x();
}
if(x < min) pointLst[dragPoint].setX(x);
}
else if(pointLst[dragPoint] == pointLst.at(1)){
if(pointLst.size() > 2){
int max = 0;
for(int i = 2; i < pointLst.size(); i++){
if(max < pointLst[i].x()) max = pointLst[i].x();
}
if(x > max) pointLst[dragPoint].setX(x);
}
else if(pointLst.size() <= 2)
if(x > pointLst.at(0).x()) pointLst[dragPoint].setX(x);
}
update();
}
}
void Widget::setYCoorVal(const int &yVal)
{
if(dragPoint >= 0){
pointLst[dragPoint].setY(yVal);
update();
}
}
void Widget::initSelectColLine(const int& colType)
{
pointLst.clear();
pointLst.append(QPoint(0,0));
pointLst.append(QPoint(255,255));
switch(colType){
case RED:
redLine.clear();
redLine.append(QPoint(0,0));
redLine.append(QPoint(255,255));
break;
case BLUE:
blueLine.clear();
blueLine.append(QPoint(0,0));
blueLine.append(QPoint(255,255));
break;
case GREEN:
greenLine.clear();
greenLine.append(QPoint(0,0));
greenLine.append(QPoint(255,255));
break;
case GRAY:
grayLine.clear();
grayLine.append(QPoint(0,0));
grayLine.append(QPoint(255,255));
break;
case RGB:
initAllLstPnt();
break;
}
dragPoint = -1;
leftMouseMv = false;
newPoint = false;
clickLine = false;
setMouseTracking(true);
qDebug() << "init";
updateCurLinePnt(colType);
}
void Widget::SetAllLinePnt(QVector<int> &all)
{
allLinePntSet = QVector<int>(all);
}

View File

@ -1,132 +0,0 @@
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QMouseEvent>
//#include "colorlinesetdef.h"
namespace Ui {
class Widget;
}
//
//enum COLOR_TPYE
//{
// RGB,
// GRAY,
// RED,
// BLUE,
// GREEN
//};
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = nullptr);
~Widget();
void initAllLstPnt(); //初始化所有颜色曲线
void setLstPnt_RGB(const QList<QPoint>& plst); //设置生成RGB曲线的关键点<=4)
QList<QPoint> getLstPnt_RGB()const; //获取生成RGB曲线的关键点
void setLstPnt_RED(const QList<QPoint>& plst);
QList<QPoint> getLstPnt_RED()const;
void setLstPnt_BLUE(const QList<QPoint>& plst);
QList<QPoint> getLstPnt_BLUE()const;
void setLstPnt_GREEN(const QList<QPoint>& plst);
QList<QPoint> getLstPnt_GREEN()const;
void setLstPnt_GRAY(const QList<QPoint>& plst);
QList<QPoint> getLstPnt_GRAY()const;
QVector<int> getRgbALLPoint();
QList<QPoint> getRgbKeyPoint()const;
void setRgbKeyPoint(const QList<QPoint>& pVec);
QVector<int> getRedALLPoint();
QList<QPoint> getRedKeyPoint()const;
void setRedKeyPoint(const QList<QPoint>& pVec);
QVector<int> getBlueALLPoint();
QList<QPoint> getBlueKeyPoint()const;
void setBlueKeyPoint(const QList<QPoint>& pVec);
QVector<int> getGreenALLPoint();
QList<QPoint> getGreenKeyPoint()const;
void setGreenKeyPoint(const QList<QPoint>& pVec);
QVector<int> getGrayALLPoint();
QList<QPoint> getGrayKeyPoint()const;
void setGrayKeyPoint(const QList<QPoint>& pVec);
void setHist_RGB(const QVector<int>& hist);//设置RGB的背景直方图
QVector<int> getHist_RGB()const;//获取RGB的背景直方图
void setHist_RED(const QVector<int>& hist);
QVector<int> getHist_RED()const;
void setHist_BLUE(const QVector<int>& hist);
QVector<int> getHist_BLUE()const;
void setHist_GREEN(const QVector<int>& hist);
QVector<int> getHist_GREEN()const;
void setHist_GRAY(const QVector<int>& hist);
QVector<int> getHist_GRAY()const;
void getCurLineLUT(uchar* table, size_t length = 256);//获取当前曲线上的所有点并存入table
QVector<unsigned char> getCurLinePntVec();//获取当前曲线上的所有点
void setXCoorVal(const int &xVal);//设置被选中的点的X坐标
void setYCoorVal(const int &yVal);//设置被选中的点的Y坐标
void updateCurLinePnt(const int& colType);//根据当前所选颜色colType重绘界面
void initSelectColLine(const int& colType);//初始化当前所选颜色colType界面的曲线
void SetAllLinePnt(QVector<int>& all);//设置自定义曲线的所有点
signals:
void dragPointChecked(bool);//曲线上的点被选中的信号
void mouseLeaveSig();//鼠标离开控件的信号
void mouseCoordSig(QPoint pos);//鼠标的坐标信号
void lineChangeSig();
private:
void initInterface();//初始化界面
void paintEvent(QPaintEvent *);
void mousePressEvent(QMouseEvent*);
void mouseMoveEvent(QMouseEvent*);
void mouseReleaseEvent(QMouseEvent*);
void enterEvent(QEvent*);
void leaveEvent(QEvent*);
void drawCoordinate(QPainter&);//画直角坐标
void drawBackgroudColor(QPainter&,QVector<int>&);//画背景直方图
void drawBackColorBySlc(QPainter&);//画不同的背景直方图
void drawCoorScale(QPainter&);//画虚线刻度
void drawLineFromPoint(QList<QPoint> &plst, const int &col);//根据多点求出曲线方程,并画出曲线
void drawAllPoint(QPainter&);//画出生成曲线的关键点
void drawCurveByColor(QPainter&);//画不同的颜色曲线
void drawLineByVector(QPainter&,QVector<int>&);//将数组的所有点连接绘制曲线
int caculateAllMi(int num,int n);//计算num的n次方的值
private:
Ui::Widget *ui;
QVector<int> rgbBackColor;
QVector<int> redBackColor;
QVector<int> blueBackColor;
QVector<int> greenBackColor;
QVector<int> grayBackColor;
QVector<int> rgbALLPoint;
QVector<int> redALLPoint;
QVector<int> blueALLPoint;
QVector<int> greenALLPoint;
QVector<int> grayALLPoint;
QVector<int> allLinePntSet;
QVector<unsigned char> linePoints;
//QList<QPoint> points;
QList<QPoint> pointLst;
QList<QPoint> linePoint;
QList<QPoint> greenLine;
QList<QPoint> redLine;
QList<QPoint> blueLine;
QList<QPoint> rgbLine;
QList<QPoint> grayLine;
QColor color;
unsigned char allLinePoints[256];
bool leftMouseMv;
bool newPoint;
bool clickLine;
int dragPoint;
int selectCol;
};
#endif // WIDGET_H

View File

@ -1,91 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Widget</class>
<widget class="QWidget" name="Widget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>556</width>
<height>484</height>
</rect>
</property>
<property name="windowTitle">
<string>Widget</string>
</property>
<layout class="QGridLayout" name="gridLayout" rowstretch="50,1" columnstretch="1,50">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QWidget" name="widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="mouseTracking">
<bool>true</bool>
</property>
<property name="focusPolicy">
<enum>Qt::WheelFocus</enum>
</property>
<property name="styleSheet">
<string notr="true">QWidget{background-color:qlineargradient(spread:pad, x1:0, y1:1, x2:0, y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255))}</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QWidget" name="table" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
<property name="mouseTracking">
<bool>true</bool>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QWidget" name="widget_2" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">QWidget{background-color:qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255))}</string>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@ -79,9 +79,9 @@ win32 {
}
LIBS += -lgdi32 -lgdiplus -ldbghelp -luser32 -ladvapi32
LIBS += -L$$PWD/../../build/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE} -l$${OEM_PREFIX}Base -l$${OEM_PREFIX}ImgFmt \
-l$${OEM_PREFIX}ImgProc
LIBS += -L$$PWD/../../../../sdk/lib/win/$${MY_ARCH}/OEM/$${OEM_NAME} -lsane -llang
LIBS += -L$$PWD/../../build/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE} -l$${OEM_PREFIX}Base -l$${OEM_PREFIX}ImgFmt -l$${OEM_PREFIX}ImgProc\
-l$${OEM_PREFIX}TwainUI -l$${OEM_PREFIX}TwainUser
LIBS += -L$$PWD/../../../../sdk/lib/win/$${MY_ARCH}/OEM/$${OEM_NAME} -llang
# sane.dll
LIBS += -L$$PWD/../../../../release/win/$${MY_ARCH}/OEM/$${OEM_NAME}
@ -112,7 +112,7 @@ unix {
MY_ARCH = loongarch64
MY_ARCH2 = loongarch64
}
s
CONFIG += unversioned_libname unversioned_soname
QMAKE_CXXFLAGS += -fvisibility=hidden
QMAKE_LFLAGS += -static-libstdc++ -static-libgcc
@ -120,9 +120,10 @@ unix {
QMAKE_LFLAGS += -z defs -B direct
LIBS += -lpthread -ldl
LIBS += -L$$PWD/../../build/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE} -l$${OEM_PREFIX2}Base -l$${OEM_PREFIX2}ImgFmt \
-l$${OEM_PREFIX2}ImgProc
LIBS += -L$$PWD/../../../../release/$${MY_OS}/$${MY_ARCH2} -lsane-$${OEM_PREFIX3}sane -llang
LIBS += -L$$PWD/../../build/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE} -l$${OEM_PREFIX2}Base -l$${OEM_PREFIX2}ImgFmt -l$${OEM_PREFIX2}ImgProc\
-l$${OEM_PREFIX2}SaneUI -l$${OEM_PREFIX2}SaneUser
LIBS += -L$$PWD/../../../../release/$${MY_OS}/$${MY_ARCH2} -llang
}
INCLUDEPATH += $$PWD/../../../app/scanner
@ -186,11 +187,6 @@ SOURCES += \
../../../app/scanner/HGUIGlobal.cpp \
../../../app/scanner/VersionDll.cpp \
../../../app/scanner/app_cfg.cpp \
../../../app/scanner/cfg/cJSON.c \
../../../app/scanner/cfg/gb_json.cpp \
../../../app/scanner/cutdialog.cpp \
../../../app/scanner/cutpapertool.cpp \
../../../app/scanner/device_menu.cpp \
../../../app/scanner/dialog_admin.cpp \
../../../app/scanner/dialog_aquireinto.cpp \
../../../app/scanner/dialog_clrcache.cpp \
@ -204,7 +200,6 @@ SOURCES += \
../../../app/scanner/dialog_imgproc_autocrop.cpp \
../../../app/scanner/dialog_input.cpp \
../../../app/scanner/dialog_insertindex.cpp \
../../../app/scanner/dialog_log.cpp \
../../../app/scanner/dialog_logmanager.cpp \
../../../app/scanner/dialog_moveto.cpp \
../../../app/scanner/dialog_multirotate.cpp \
@ -215,18 +210,12 @@ SOURCES += \
../../../app/scanner/dialog_savemessagebox.cpp \
../../../app/scanner/dialog_updateprogress.cpp \
../../../app/scanner/dialog_upgrade.cpp \
../../../app/scanner/dialog_upgradefirmware.cpp \
../../../app/scanner/dialog_writesettings.cpp \
../../../app/scanner/dialog_wrong_img.cpp \
../../../app/scanner/gaosixy.cpp \
../../../app/scanner/device_user.cpp \
../../../app/scanner/graphicsscene.cpp \
../../../app/scanner/hg_settingdialog.cpp \
../../../app/scanner/main.cpp \
../../../app/scanner/mainwindow.cpp \
../../../app/scanner/ocrPdf.cpp \
../../../app/scanner/sane_device.cpp \
../../../app/scanner/setpicclrtool.cpp \
../../../app/scanner/widget.cpp \
../../../app/scanner/widget_imgproc_base.cpp \
../../../app/scanner/widget_statusbar.cpp \
../../../app/scanner/widget_imgproc_sidebar.cpp \
@ -238,12 +227,6 @@ HEADERS += \
../../../app/scanner/HGUIGlobal.h \
../../../app/scanner/VersionDll.h \
../../../app/scanner/app_cfg.h \
../../../app/scanner/cfg/cJSON.h \
../../../app/scanner/cfg/gb_json.h \
../../../app/scanner/custom_file_dialog.h \
../../../app/scanner/cutdialog.h \
../../../app/scanner/cutpapertool.h \
../../../app/scanner/device_menu.h \
../../../app/scanner/dialog_admin.h \
../../../app/scanner/dialog_aquireinto.h \
../../../app/scanner/dialog_clrcache.h \
@ -257,7 +240,6 @@ HEADERS += \
../../../app/scanner/dialog_imgproc_autocrop.h \
../../../app/scanner/dialog_input.h \
../../../app/scanner/dialog_insertindex.h \
../../../app/scanner/dialog_log.h \
../../../app/scanner/dialog_logmanager.h \
../../../app/scanner/dialog_moveto.h \
../../../app/scanner/dialog_multirotate.h \
@ -268,25 +250,17 @@ HEADERS += \
../../../app/scanner/dialog_savemessagebox.h \
../../../app/scanner/dialog_updateprogress.h \
../../../app/scanner/dialog_upgrade.h \
../../../app/scanner/dialog_upgradefirmware.h \
../../../app/scanner/dialog_writesettings.h \
../../../app/scanner/dialog_wrong_img.h \
../../../app/scanner/gaosixy.h \
../../../app/scanner/dialog_wrong_img.h \ \
../../../app/scanner/device_user.h \
../../../app/scanner/graphicsscene.h \
../../../app/scanner/hg_settingdialog.h \
../../../app/scanner/mainwindow.h \
../../../app/scanner/ocrPdf.h \
../../../app/scanner/sane_device.h \
../../../app/scanner/setpicclrtool.h \
../../../app/scanner/widget.h \
../../../app/scanner/widget_imgproc_base.h \
../../../app/scanner/widget_statusbar.h \
../../../app/scanner/widget_imgproc_sidebar.h \
../../../utility/HGString.h
FORMS += \
../../../app/scanner/cutdialog.ui \
../../../app/scanner/cutpapertool.ui \
../../../app/scanner/dialog_admin.ui \
../../../app/scanner/dialog_aquireinto.ui \
../../../app/scanner/dialog_clrcache.ui \
@ -300,7 +274,6 @@ FORMS += \
../../../app/scanner/dialog_imgproc_autocrop.ui \
../../../app/scanner/dialog_input.ui \
../../../app/scanner/dialog_insertindex.ui \
../../../app/scanner/dialog_log.ui \
../../../app/scanner/dialog_logmanager.ui \
../../../app/scanner/dialog_moveto.ui \
../../../app/scanner/dialog_multirotate.ui \
@ -311,12 +284,9 @@ FORMS += \
../../../app/scanner/dialog_savemessagebox.ui \
../../../app/scanner/dialog_updateprogress.ui \
../../../app/scanner/dialog_upgrade.ui \
../../../app/scanner/dialog_upgradefirmware.ui \
../../../app/scanner/dialog_writesettings.ui \
../../../app/scanner/dialog_wrong_img.ui \
../../../app/scanner/mainwindow.ui \
../../../app/scanner/setpicclrtool.ui \
../../../app/scanner/widget.ui \
../../../app/scanner/widget_imgproc_base.ui \
../../../app/scanner/widget_statusbar.ui \
../../../app/scanner/widget_imgproc_sidebar.ui