From f2660f2f0b9edb09255c509f0596a506b147399f Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@qq.com> Date: Thu, 5 May 2022 10:03:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=89=AB=E6=8F=8F=E5=88=B0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=B8=AD=EF=BC=8C=E5=A4=9A=E5=BC=A0=E5=90=88?= =?UTF-8?q?=E6=88=90=E6=97=B6=EF=BC=8C=E7=82=B9=E5=87=BB=E7=BB=A7=E7=BB=AD?= =?UTF-8?q?=E6=89=AB=E6=8F=8F=E4=B8=8D=E4=BC=9A=E5=90=88=E6=88=90=E5=88=B0?= =?UTF-8?q?=E5=90=8C=E4=B8=80=E4=B8=AA=E6=96=87=E4=BB=B6=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scanner/cutdialog.cpp | 447 +++++++++++ app/scanner/cutdialog.h | 100 +++ app/scanner/cutdialog.ui | 44 ++ app/scanner/cutpapertool.cpp | 217 ++++++ app/scanner/cutpapertool.h | 59 ++ app/scanner/cutpapertool.ui | 276 +++++++ app/scanner/gaosixy.cpp | 54 ++ app/scanner/gaosixy.h | 17 + app/scanner/mainwindow.cpp | 40 +- app/scanner/setpicclrtool.cpp | 313 ++++++++ app/scanner/setpicclrtool.h | 82 +++ app/scanner/setpicclrtool.ui | 167 +++++ app/scanner/widget.cpp | 855 ++++++++++++++++++++++ app/scanner/widget.h | 132 ++++ app/scanner/widget.ui | 91 +++ build-qt/windows/HGSolution/HGScanner.pro | 14 + 16 files changed, 2897 insertions(+), 11 deletions(-) create mode 100644 app/scanner/cutdialog.cpp create mode 100644 app/scanner/cutdialog.h create mode 100644 app/scanner/cutdialog.ui create mode 100644 app/scanner/cutpapertool.cpp create mode 100644 app/scanner/cutpapertool.h create mode 100644 app/scanner/cutpapertool.ui create mode 100644 app/scanner/gaosixy.cpp create mode 100644 app/scanner/gaosixy.h create mode 100644 app/scanner/setpicclrtool.cpp create mode 100644 app/scanner/setpicclrtool.h create mode 100644 app/scanner/setpicclrtool.ui create mode 100644 app/scanner/widget.cpp create mode 100644 app/scanner/widget.h create mode 100644 app/scanner/widget.ui diff --git a/app/scanner/cutdialog.cpp b/app/scanner/cutdialog.cpp new file mode 100644 index 00000000..6c0d8c00 --- /dev/null +++ b/app/scanner/cutdialog.cpp @@ -0,0 +1,447 @@ +#include "cutdialog.h" +#include "ui_cutdialog.h" +#include +#include +#include + +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 == "A3") h_w = 420.0/297; + else if(paperType == "A4") h_w = 297.0/210; + else if(paperType == std::string("A4横向").c_str()) h_w = 210/297.0; + else if(paperType == "A5") h_w = 210.0/148; + else if(paperType == std::string("A5横向").c_str()) h_w = 148/210.0; + else if(paperType == "A6") h_w = 148.0/105; + else if(paperType == std::string("A6横向").c_str()) h_w = 105/148.0; + else if(paperType == "B4") h_w = 353.0/250; + else if(paperType == "B5") h_w = 250.0/176; + else if(paperType == std::string("B5横向").c_str()) h_w = 176/250.0; + else if(paperType == "B6") h_w = 176.0/125; + else if(paperType == std::string("B6横向").c_str()) h_w = 125/176.0; + else if(paperType == std::string("信封").c_str()) h_w = 279.0/210; + else if(paperType == std::string("信封横向").c_str()) h_w = 210.0/279; + else if(paperType == std::string("双倍信封").c_str()) h_w = 850.0/550; + else if(paperType == "Legal") h_w = 2800.0/1700; + else if(paperType == std::string("最大尺寸").c_str()) h_w = 3307.0*2/2338; + else if(paperType == std::string("匹配原始尺寸").c_str()) { + 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(std::string("横向").c_str())) paperWidth = paperWidth*h_w*1.5; + double realW = paperWidth; + + if(paperType == "A3" || paperType == std::string("A4横向").c_str()) realRate = 297.0/realW; + else if(paperType == "A4" || paperType == std::string("A5横向").c_str()) realRate = 210.0/realW; + else if(paperType == "A5" || paperType == std::string("A6横向").c_str()) realRate = 148.0/realW; + else if(paperType == "A6") realRate = 105.0/realW; + else if(paperType == "B4" || paperType == std::string("B5横向").c_str()) realRate = 250.0/realW; + else if(paperType == "B5" || paperType == std::string("B6横向").c_str()) realRate = 176.0/realW; + else if(paperType == "B6") realRate = 125.0/realW; + else if(paperType == std::string("信封").c_str()) realRate = 216.0/realW; + else if(paperType == std::string("信封横向").c_str()) realRate = 279.0/realW; + else if(paperType == std::string("双倍信封").c_str()) realRate = 432.0/realW; + else if(paperType == "Legal") realRate = 297.0/realW; + else if(paperType == std::string("最大尺寸").c_str()) realRate = 297.0/realW; + else if(paperType == std::string("匹配原始尺寸").c_str()) { + 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); + painter.drawRect(m_rect); + painter.setPen(QPen(Qt::red,1)); + painter.setBrush(Qt::red); + painter.drawEllipse(m_rect.left()-2,(m_rect.bottom()-m_rect.top())/2+m_rect.top()-2,4,4); + painter.drawEllipse(m_rect.left()-2,m_rect.top()-2,4,4); + painter.drawEllipse(m_rect.left()-2,m_rect.bottom()-2,4,4); + painter.drawEllipse(m_rect.right()-2,m_rect.top()-2,4,4); + painter.drawEllipse(m_rect.right()-2,m_rect.bottom()-2,4,4); + painter.drawEllipse(m_rect.right()-2,(m_rect.bottom()-m_rect.top())/2+m_rect.top()-2,4,4); + painter.drawEllipse((m_rect.right()-m_rect.left())/2+m_rect.left()-2,m_rect.top()-2,4,4); + painter.drawEllipse((m_rect.right()-m_rect.left())/2+m_rect.left()-2,m_rect.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; +} diff --git a/app/scanner/cutdialog.h b/app/scanner/cutdialog.h new file mode 100644 index 00000000..2f77ef2a --- /dev/null +++ b/app/scanner/cutdialog.h @@ -0,0 +1,100 @@ +#ifndef CUTDIALOG_H +#define CUTDIALOG_H + +#include +#include +#include +#include + +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 diff --git a/app/scanner/cutdialog.ui b/app/scanner/cutdialog.ui new file mode 100644 index 00000000..de03c34e --- /dev/null +++ b/app/scanner/cutdialog.ui @@ -0,0 +1,44 @@ + + + cutDialog + + + true + + + + 0 + 0 + 321 + 342 + + + + + 0 + 0 + + + + + 2 + 0 + + + + + 2 + 0 + + + + true + + + cutDialog + + + + + + diff --git a/app/scanner/cutpapertool.cpp b/app/scanner/cutpapertool.cpp new file mode 100644 index 00000000..2fdd48f9 --- /dev/null +++ b/app/scanner/cutpapertool.cpp @@ -0,0 +1,217 @@ +#include "cutpapertool.h" +#include "ui_cutpapertool.h" +#include +#include + +CutPaperTool::CutPaperTool(QWidget *parent) : + QDialog(parent), + ui(new Ui::CutPaperTool) +{ + ui->setupUi(this); + 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(); + this->setFixedWidth(ui->widget->width()+20); +} + +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()+20); + 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(); +} diff --git a/app/scanner/cutpapertool.h b/app/scanner/cutpapertool.h new file mode 100644 index 00000000..cf6d40eb --- /dev/null +++ b/app/scanner/cutpapertool.h @@ -0,0 +1,59 @@ +#ifndef CUTPAPERTOOL_H +#define CUTPAPERTOOL_H + +#include +#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 diff --git a/app/scanner/cutpapertool.ui b/app/scanner/cutpapertool.ui new file mode 100644 index 00000000..b1ff26fc --- /dev/null +++ b/app/scanner/cutpapertool.ui @@ -0,0 +1,276 @@ + + + CutPaperTool + + + + 0 + 0 + 461 + 281 + + + + + 0 + 0 + + + + 自定义扫描区域 + + + + + + + + 纸张尺寸: + + + + + + + A4 + + + + + + + (210*297) + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + DPI(像素/英寸): + + + Qt::AlignJustify|Qt::AlignVCenter + + + + + + + 200 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 单位: + + + + + + + + 毫米(mm) + + + + + 英寸(in) + + + + + 像素(px) + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 初始化选择区域 + + + + + + + + + + 0 + 0 + + + + + + + + + + x: + + + + + + + + + + mm + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + y: + + + + + + + + + + mm + + + + + + + + + + + w: + + + + + + + + + + mm + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + h: + + + + + + + + + + mm + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + cutDialog + QWidget +
cutdialog.h
+ 1 +
+
+ + +
diff --git a/app/scanner/gaosixy.cpp b/app/scanner/gaosixy.cpp new file mode 100644 index 00000000..15de754a --- /dev/null +++ b/app/scanner/gaosixy.cpp @@ -0,0 +1,54 @@ +#include "gaosixy.h" +#include +#include +#include + +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]; + } + +} diff --git a/app/scanner/gaosixy.h b/app/scanner/gaosixy.h new file mode 100644 index 00000000..4b446756 --- /dev/null +++ b/app/scanner/gaosixy.h @@ -0,0 +1,17 @@ +#ifndef GAOSIXY_H +#define GAOSIXY_H + +#include +#include + +class GaoSiXY +{ +public: + GaoSiXY(); + void solve(double **a,int n,double *recv);//用于计算曲线方程 + +private: + +}; + +#endif // GAOSIXY_H diff --git a/app/scanner/mainwindow.cpp b/app/scanner/mainwindow.cpp index 216c345f..a6b7c49b 100644 --- a/app/scanner/mainwindow.cpp +++ b/app/scanner/mainwindow.cpp @@ -862,13 +862,16 @@ void MainWindow::on_scan_working(QString workingInfo) void MainWindow::on_scan_finish(QString finishInfo, int err) { - if (nullptr != m_scanImgFmtWriter) + if (0 == m_scanType) { - HGImgFmt_CloseImageWriter(m_scanImgFmtWriter); - m_scanImgFmtWriter = nullptr; - m_thumb->addItem(m_scanFileName); - m_scanFileName.clear(); - ++m_aquireIntoSaveParam.m_fileNameStartIndex; + if (nullptr != m_scanImgFmtWriter) + { + HGImgFmt_CloseImageWriter(m_scanImgFmtWriter); + m_scanImgFmtWriter = nullptr; + m_thumb->addItem(m_scanFileName); + m_scanFileName.clear(); + ++m_aquireIntoSaveParam.m_fileNameStartIndex; + } } m_isScanning = false; @@ -919,12 +922,27 @@ void MainWindow::on_continueScan() void MainWindow::on_stopScan() { - if (!cur_dev_.is_online() || !m_isScanning) - { - return; - } + m_scanType = 0; + m_dialogLog->updateStatus(cur_dev_.is_online() && 0 != m_scanType, m_isScanning); - sane_cancel(cur_dev_.handle()); + if (!m_isScanning) + { + if (nullptr != m_scanImgFmtWriter) + { + HGImgFmt_CloseImageWriter(m_scanImgFmtWriter); + m_scanImgFmtWriter = nullptr; + m_thumb->addItem(m_scanFileName); + m_scanFileName.clear(); + ++m_aquireIntoSaveParam.m_fileNameStartIndex; + } + } + else + { + if (cur_dev_.is_online()) + { + sane_cancel(cur_dev_.handle()); + } + } } void MainWindow::on_statusInfoDblClick() diff --git a/app/scanner/setpicclrtool.cpp b/app/scanner/setpicclrtool.cpp new file mode 100644 index 00000000..fb7c5bc2 --- /dev/null +++ b/app/scanner/setpicclrtool.cpp @@ -0,0 +1,313 @@ +#include "setpicclrtool.h" +#include "ui_setpicclrtool.h" +#include "widget.h" +#include +#include + +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 gray = getGrayALLPoint(); + for (size_t i = 0; i < length; i++) + table[i] = static_cast(gray[static_cast(i)]); +} + +void setPicClrTool::getRGBTable(uchar *table, size_t length) +{ + if (length != 768) + throw "length is not 768."; + + QVector rgb = getRgbALLPoint(); + QVector red = getRedALLPoint(); + QVector green = getGreenALLPoint(); + QVector 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(blue[rgb[static_cast(i)]]); + table[i * 3 + 1] = static_cast(green[rgb[static_cast(i)]]); + table[i * 3 + 2] = static_cast(red[rgb[static_cast(i)]]); + } +} + +//void setPicClrTool::setGrayTable(const uchar *table, size_t length) +//{ +// QVector gray; +// for (size_t i = 0; i < length; i++) +// gray[static_cast(i)] = int(table[i]); +// //ui->widget->setGrayALLPoint(gray); +//} + +//void setPicClrTool::setRGBTable(const uchar *table, size_t length) +//{ +// QVector rgb; +// QVector red; +// QVector green; +// QVector 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 > setPicClrTool::getRGBKeyTable() +{ + QVector> plv; + plv.append(getRgbKeyPoint()); + plv.append(getRedKeyPoint()); + plv.append(getGreenKeyPoint()); + plv.append(getBlueKeyPoint()); + return plv; +} + +void setPicClrTool::setRGBKeyTable(QVector > &plv) +{ + setRgbKeyPoint(plv[0]); + setRedKeyPoint(plv[1]); + setGreenKeyPoint(plv[2]); + setBlueKeyPoint(plv[3]); +} + +QList setPicClrTool::getGrayKeyTable() +{ + return getGrayKeyPoint(); +} + +void setPicClrTool::setGrayKeyTable(QList &plv) +{ + setGrayKeyPoint(plv); +} + +QVector setPicClrTool::getRgbALLPoint() +{ + return ui->widget->getRgbALLPoint(); +} + +QList setPicClrTool::getRgbKeyPoint() const +{ + qDebug() << "setRgb" << ui->widget->getRgbKeyPoint(); + return ui->widget->getRgbKeyPoint(); +} + +void setPicClrTool::setRgbKeyPoint(const QList &pVec) +{ + qDebug() << "setRgb" << pVec; + ui->widget->setRgbKeyPoint(pVec); +} + +QList setPicClrTool::getRedKeyPoint() const +{ + return ui->widget->getRedKeyPoint(); +} + +void setPicClrTool::setRedKeyPoint(const QList &pVec) +{ + ui->widget->setRedKeyPoint(pVec); +} + +QList setPicClrTool::getBlueKeyPoint() const +{ + return ui->widget->getBlueKeyPoint(); +} + +void setPicClrTool::setBlueKeyPoint(const QList &pVec) +{ + ui->widget->setBlueKeyPoint(pVec); +} + +QList setPicClrTool::getGreenKeyPoint() const +{ + return ui->widget->getGreenKeyPoint(); +} + +void setPicClrTool::setGreenKeyPoint(const QList &pVec) +{ + ui->widget->setGreenKeyPoint(pVec); +} + +QList setPicClrTool::getGrayKeyPoint() const +{ + return ui->widget->getGrayKeyPoint(); +} + +void setPicClrTool::setGrayKeyPoint(const QList &pVec) +{ + ui->widget->setGrayKeyPoint(pVec); +} + +QVector setPicClrTool::getRedALLPoint() +{ + return ui->widget->getRedALLPoint(); +} + +QVector setPicClrTool::getBlueALLPoint() +{ + return ui->widget->getBlueALLPoint(); +} + +QVector setPicClrTool::getGreenALLPoint() +{ + return ui->widget->getGreenALLPoint(); +} + +QVector 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(); +} + +void setPicClrTool::on_buttonBox_rejected() +{ + ui->widget->initAllLstPnt(); + close(); +} diff --git a/app/scanner/setpicclrtool.h b/app/scanner/setpicclrtool.h new file mode 100644 index 00000000..59c4c25b --- /dev/null +++ b/app/scanner/setpicclrtool.h @@ -0,0 +1,82 @@ +#ifndef SETPICCLRTOOL_H +#define SETPICCLRTOOL_H + +//#include "colorlinesetdef.h" +#include + +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> getRGBKeyTable(); + void setRGBKeyTable(QVector>& plv); + QList getGrayKeyTable(); + void setGrayKeyTable(QList &plv); + + +private: + QVector getRgbALLPoint(); + QVector getRedALLPoint(); + QVector getBlueALLPoint(); + QVector getGreenALLPoint(); + QVector getGrayALLPoint(); + + QList getRgbKeyPoint()const; + void setRgbKeyPoint(const QList& pVec); + QList getRedKeyPoint()const; + void setRedKeyPoint(const QList& pVec); + QList getBlueKeyPoint()const; + void setBlueKeyPoint(const QList& pVec); + QList getGreenKeyPoint()const; + void setGreenKeyPoint(const QList& pVec); + QList getGrayKeyPoint()const; + void setGrayKeyPoint(const QList& 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 linePoint; + QList greenLine; + QList redLine; + QList blueLine; + QList rgbLine; + QList grayLine; +}; + +#endif // SETPICCLRTOOL_H diff --git a/app/scanner/setpicclrtool.ui b/app/scanner/setpicclrtool.ui new file mode 100644 index 00000000..6f5e5b8b --- /dev/null +++ b/app/scanner/setpicclrtool.ui @@ -0,0 +1,167 @@ + + + setPicClrTool + + + + 0 + 0 + 259 + 341 + + + + 自定义色调曲线 + + + + + + + + + 自定 + + + + + 负片(RGB) + + + + + 彩色负片(RGB) + + + + + 较暗(RGB) + + + + + 较亮(RGB) + + + + + + + + + + + + false + + + + RGB + + + + + + + + + + + + + + + + + + + + 绿 + + + + + + + + 初始化 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + true + + + Qt::StrongFocus + + + + + + + + + 输入: + + + + + + + true + + + + + + + 输出: + + + + + + + true + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + Widget + QWidget +
widget.h
+ 1 +
+
+ + +
diff --git a/app/scanner/widget.cpp b/app/scanner/widget.cpp new file mode 100644 index 00000000..71c943bf --- /dev/null +++ b/app/scanner/widget.cpp @@ -0,0 +1,855 @@ +#include "widget.h" +#include "ui_widget.h" +#include "gaosixy.h" +#include +#include +#include +#include +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 &plst) +{ + rgbLine = QList(plst); +} + +QList Widget::getLstPnt_RGB() const +{ + return rgbLine; +} + +void Widget::setLstPnt_RED(const QList &plst) +{ + redLine = QList(plst); +} + +void Widget::setLstPnt_BLUE(const QList &plst) +{ + blueLine = QList(plst); +} + +QList Widget::getLstPnt_BLUE() const +{ + return blueLine; +} + +void Widget::setLstPnt_GREEN(const QList &plst) +{ + greenLine = QList(plst); +} + +QList Widget::getLstPnt_GREEN() const +{ + return greenLine; +} + +void Widget::setLstPnt_GRAY(const QList &plst) +{ + grayLine = QList(plst); +} + +QList Widget::getLstPnt_GRAY() const +{ + return grayLine; +} + +QVector Widget::getRgbALLPoint() +{ + return rgbALLPoint; +} + +QList Widget::getRgbKeyPoint() const +{ + return rgbLine; +} + +void Widget::setRgbKeyPoint(const QList &pLst) +{ + if(pLst.size() > 4) return; + rgbLine = QList(pLst); + pointLst.clear(); + pointLst = QList(rgbLine); + drawLineFromPoint(rgbLine, RGB); + update(); +} + +QVector Widget::getRedALLPoint() +{ + return redALLPoint; +} + +QList Widget::getRedKeyPoint() const +{ + return redLine; +} + +void Widget::setRedKeyPoint(const QList &pLst) +{ + if(pLst.size() > 4) return; + redLine = QList(pLst); + drawLineFromPoint(redLine, RED); + update(); +} + +QVector Widget::getBlueALLPoint() +{ + return blueALLPoint; +} + +QList Widget::getBlueKeyPoint() const +{ + return blueLine; +} + +void Widget::setBlueKeyPoint(const QList &pLst) +{ + if(pLst.size() > 4) return; + blueLine = QList(pLst); + drawLineFromPoint(blueLine, BLUE); + update(); +} + +QVector Widget::getGreenALLPoint() +{ + return greenALLPoint; +} + +QList Widget::getGreenKeyPoint() const +{ + return greenLine; +} + +void Widget::setGreenKeyPoint(const QList &pLst) +{ + if(pLst.size() > 4) return; + greenLine = QList(pLst); + drawLineFromPoint(greenLine, GREEN); + update(); +} + +QVector Widget::getGrayALLPoint() +{ + return grayALLPoint; +} + +QList Widget::getGrayKeyPoint() const +{ + return grayLine; +} + +void Widget::setGrayKeyPoint(const QList &pLst) +{ + if(pLst.size() > 4) return; + grayLine = QList(pLst); + pointLst.clear(); + pointLst = QList(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 &hist) +{ + rgbBackColor = QVector(hist); +} + +QVector Widget::getHist_RED() const +{ + return redBackColor; +} + +void Widget::setHist_RED(const QVector &hist) +{ + redBackColor = QVector(hist); +} + +QVector Widget::getHist_RGB() const +{ + return rgbBackColor; +} + +void Widget::setHist_GREEN(const QVector &hist) +{ + greenBackColor = QVector(hist); +} + +QVector Widget::getHist_GREEN() const +{ + return greenBackColor; +} + +void Widget::setHist_BLUE(const QVector &hist) +{ + blueBackColor = QVector(hist); +} + +QVector Widget::getHist_BLUE() const +{ + return blueBackColor; +} + +void Widget::setHist_GRAY(const QVector &hist) +{ + grayBackColor = QVector(hist); +} + +QVector 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 &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 dashes; + qreal space = 3; + dashes << 5 << space << 5 < &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 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(pointLst); + } + else if(selectCol == RED){ + redLine.clear(); + redLine = QList(pointLst); + }else if(selectCol == BLUE){ + blueLine.clear(); + blueLine = QList(pointLst); + }else if(selectCol == RGB){ + rgbLine.clear(); + rgbLine = QList(pointLst); + }else if(selectCol == GRAY){ + grayLine.clear(); + grayLine = QList(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 &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 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(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(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(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(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(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 &all) +{ + allLinePntSet = QVector(all); +} + diff --git a/app/scanner/widget.h b/app/scanner/widget.h new file mode 100644 index 00000000..0ff62115 --- /dev/null +++ b/app/scanner/widget.h @@ -0,0 +1,132 @@ +#ifndef WIDGET_H +#define WIDGET_H + +#include +#include +//#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& plst); //设置生成RGB曲线的关键点(<=4) + QList getLstPnt_RGB()const; //获取生成RGB曲线的关键点 + void setLstPnt_RED(const QList& plst); + QList getLstPnt_RED()const; + void setLstPnt_BLUE(const QList& plst); + QList getLstPnt_BLUE()const; + void setLstPnt_GREEN(const QList& plst); + QList getLstPnt_GREEN()const; + void setLstPnt_GRAY(const QList& plst); + QList getLstPnt_GRAY()const; + + QVector getRgbALLPoint(); + QList getRgbKeyPoint()const; + void setRgbKeyPoint(const QList& pVec); + QVector getRedALLPoint(); + QList getRedKeyPoint()const; + void setRedKeyPoint(const QList& pVec); + QVector getBlueALLPoint(); + QList getBlueKeyPoint()const; + void setBlueKeyPoint(const QList& pVec); + QVector getGreenALLPoint(); + QList getGreenKeyPoint()const; + void setGreenKeyPoint(const QList& pVec); + QVector getGrayALLPoint(); + QList getGrayKeyPoint()const; + void setGrayKeyPoint(const QList& pVec); + + void setHist_RGB(const QVector& hist);//设置RGB的背景直方图 + QVector getHist_RGB()const;//获取RGB的背景直方图 + void setHist_RED(const QVector& hist); + QVector getHist_RED()const; + void setHist_BLUE(const QVector& hist); + QVector getHist_BLUE()const; + void setHist_GREEN(const QVector& hist); + QVector getHist_GREEN()const; + void setHist_GRAY(const QVector& hist); + QVector getHist_GRAY()const; + + void getCurLineLUT(uchar* table, size_t length = 256);//获取当前曲线上的所有点并存入table + QVector 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& 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&);//画背景直方图 + void drawBackColorBySlc(QPainter&);//画不同的背景直方图 + void drawCoorScale(QPainter&);//画虚线刻度 + void drawLineFromPoint(QList &plst, const int &col);//根据多点求出曲线方程,并画出曲线 + void drawAllPoint(QPainter&);//画出生成曲线的关键点 + void drawCurveByColor(QPainter&);//画不同的颜色曲线 + void drawLineByVector(QPainter&,QVector&);//将数组的所有点连接绘制曲线 + int caculateAllMi(int num,int n);//计算num的n次方的值 + +private: + Ui::Widget *ui; + QVector rgbBackColor; + QVector redBackColor; + QVector blueBackColor; + QVector greenBackColor; + QVector grayBackColor; + QVector rgbALLPoint; + QVector redALLPoint; + QVector blueALLPoint; + QVector greenALLPoint; + QVector grayALLPoint; + QVector allLinePntSet; + QVector linePoints; + + //QList points; + QList pointLst; + QList linePoint; + QList greenLine; + QList redLine; + QList blueLine; + QList rgbLine; + QList grayLine; + QColor color; + + unsigned char allLinePoints[256]; + bool leftMouseMv; + bool newPoint; + bool clickLine; + int dragPoint; + int selectCol; +}; + +#endif // WIDGET_H diff --git a/app/scanner/widget.ui b/app/scanner/widget.ui new file mode 100644 index 00000000..aaf5af1c --- /dev/null +++ b/app/scanner/widget.ui @@ -0,0 +1,91 @@ + + + Widget + + + + 0 + 0 + 556 + 484 + + + + Widget + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + 0 + + + + true + + + Qt::WheelFocus + + + 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))} + + + + + + + + 0 + 20 + + + + true + + + Qt::NoFocus + + + + + + + + 0 + 0 + + + + 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))} + + + + + + + + + diff --git a/build-qt/windows/HGSolution/HGScanner.pro b/build-qt/windows/HGSolution/HGScanner.pro index ee543550..ad8d7e7c 100644 --- a/build-qt/windows/HGSolution/HGScanner.pro +++ b/build-qt/windows/HGSolution/HGScanner.pro @@ -45,6 +45,8 @@ INCLUDEPATH += $$PWD/../../../../sdk/include/ SOURCES += \ ../../../app/scanner/app_cfg.cpp \ + ../../../app/scanner/cutdialog.cpp \ + ../../../app/scanner/cutpapertool.cpp \ ../../../app/scanner/device_menu.cpp \ ../../../app/scanner/dialog_aquireinto.cpp \ ../../../app/scanner/dialog_clrcache.cpp \ @@ -64,11 +66,14 @@ SOURCES += \ ../../../app/scanner/dialog_passwordchange.cpp \ ../../../app/scanner/dialog_saveas.cpp \ ../../../app/scanner/dialog_savequality.cpp \ + ../../../app/scanner/gaosixy.cpp \ ../../../app/scanner/graphicsscene.cpp \ ../../../app/scanner/hg_settingdialog.cpp \ ../../../app/scanner/main.cpp \ ../../../app/scanner/mainwindow.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/dialog_admin.cpp \ @@ -83,6 +88,8 @@ SOURCES += \ HEADERS += \ ../../../app/scanner/app_cfg.h \ + ../../../app/scanner/cutdialog.h \ + ../../../app/scanner/cutpapertool.h \ ../../../app/scanner/device_menu.h \ ../../../app/scanner/dialog_aquireinto.h \ ../../../app/scanner/dialog_clrcache.h \ @@ -102,10 +109,13 @@ HEADERS += \ ../../../app/scanner/dialog_passwordchange.h \ ../../../app/scanner/dialog_saveas.h \ ../../../app/scanner/dialog_savequality.h \ + ../../../app/scanner/gaosixy.h \ ../../../app/scanner/graphicsscene.h \ ../../../app/scanner/hg_settingdialog.h \ ../../../app/scanner/mainwindow.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/dialog_admin.h \ @@ -119,6 +129,8 @@ HEADERS += \ ../../../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 \ @@ -139,6 +151,8 @@ FORMS += \ ../../../app/scanner/dialog_saveas.ui \ ../../../app/scanner/dialog_savequality.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/dialog_log.ui