177 lines
7.6 KiB
C++
177 lines
7.6 KiB
C++
#include "dialog_imgproc_autocrop.h"
|
|
#include "ui_dialog_imgproc_autocrop.h"
|
|
#include <QAbstractButton>
|
|
#include <QPushButton>
|
|
#include <QMouseEvent>
|
|
#include <QDebug>
|
|
#include "app_cfg.h"
|
|
|
|
Dialog_ImgProc_AutoCrop::Dialog_ImgProc_AutoCrop(QWidget *parent)
|
|
: QDialog(parent)
|
|
, ui(new Ui::Dialog_ImgProc_AutoCrop)
|
|
, m_example_flag(-1)
|
|
, m_btnGroup_polygon(this)
|
|
, m_btnGroup_backgroundColor(this)
|
|
, m_isCrop(false)
|
|
, m_isDeskew(false)
|
|
, m_isFillBlank(false)
|
|
, m_isConvex(true)
|
|
, m_isAutoColor(true)
|
|
, m_isUseAdvancedParam(false)
|
|
, m_threshold(40)
|
|
, m_noise(8)
|
|
, m_indent(5)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
m_btnGroup_polygon.addButton(ui->rbtn_convex);
|
|
m_btnGroup_polygon.addButton(ui->rbtn_concave);
|
|
m_btnGroup_backgroundColor.addButton(ui->rbtn_autoColor);
|
|
m_btnGroup_backgroundColor.addButton(ui->rbtn_defaultColor);
|
|
|
|
ui->cbtn_crop->setChecked(getCfgValue("autoCrop", "crop", false));
|
|
ui->cbtn_corrSkew->setChecked(getCfgValue("autoCrop", "deskew", false));
|
|
ui->gbox_fillBlank->setChecked(getCfgValue("autoCrop", "fillBlank", false));
|
|
bool convex = getCfgValue("autoCrop", "convex", true);
|
|
if (convex)
|
|
ui->rbtn_convex->setChecked(true);
|
|
else
|
|
ui->rbtn_concave->setChecked(true);
|
|
bool autoColor = getCfgValue("autoCrop", "autoColor", true);
|
|
if (autoColor)
|
|
ui->rbtn_autoColor->setChecked(true);
|
|
else
|
|
ui->rbtn_defaultColor->setChecked(true);
|
|
ui->gbox_param->setChecked(getCfgValue("autoCrop", "useAdvancedParam", false));
|
|
ui->spin_threshold->setValue(getCfgValue("autoCrop", "threshold", 40));
|
|
ui->spin_noise->setValue(getCfgValue("autoCrop", "noise", 8));
|
|
ui->spin_indent->setValue(getCfgValue("autoCrop", "indent", 5));
|
|
|
|
ui->lab_imgBefore->setPixmap(QPixmap::fromImage(QImage()));
|
|
ui->lab_arrow->setPixmap(QPixmap::fromImage(QImage()));
|
|
ui->lab_imgAfter->setPixmap(QPixmap::fromImage(QImage()));
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("ok"));
|
|
ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("cancel"));
|
|
ui->buttonBox->button(QDialogButtonBox::RestoreDefaults)->setText(tr("restore default"));
|
|
|
|
this->setMouseTracking(true);
|
|
}
|
|
|
|
Dialog_ImgProc_AutoCrop::~Dialog_ImgProc_AutoCrop()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void Dialog_ImgProc_AutoCrop::mouseMoveEvent(QMouseEvent *event)
|
|
{
|
|
QRect rect_cbtn_crop(ui->cbtn_crop->mapTo(this, QPoint(0, 0)), ui->cbtn_crop->size());
|
|
QRect rect_cbtn_corrSkew(ui->cbtn_corrSkew->mapTo(this, QPoint(0, 0)), ui->cbtn_corrSkew->size());
|
|
QRect rect_gbox_fillBlank(ui->gbox_fillBlank->mapTo(this, QPoint(0, 0)), ui->gbox_fillBlank->size());
|
|
QRect rect_rbtn_convex(ui->rbtn_convex->mapTo(this, QPoint(0, 0)), ui->rbtn_convex->size());
|
|
QRect rect_rbtn_concave(ui->rbtn_concave->mapTo(this, QPoint(0, 0)), ui->rbtn_concave->size());
|
|
QRect rect_rbtn_autoColor(ui->rbtn_autoColor->mapTo(this, QPoint(0, 0)), ui->rbtn_autoColor->size());
|
|
QRect rect_rbtn_defaultColor(ui->rbtn_defaultColor->mapTo(this, QPoint(0, 0)), ui->rbtn_defaultColor->size());
|
|
|
|
if (rect_cbtn_crop.contains(event->pos()) && m_example_flag != 0)
|
|
updateExample(0);
|
|
else if (rect_cbtn_corrSkew.contains(event->pos()) && m_example_flag != 1)
|
|
updateExample(1);
|
|
else if (rect_gbox_fillBlank.contains(event->pos()))
|
|
{
|
|
if(ui->gbox_fillBlank->isChecked())
|
|
{
|
|
if(rect_rbtn_convex.contains(event->pos()) && m_example_flag != 3)
|
|
updateExample(3);
|
|
else if(rect_rbtn_concave.contains(event->pos()) && m_example_flag != 4)
|
|
updateExample(4);
|
|
else if (rect_rbtn_autoColor.contains(event->pos()) && m_example_flag != 5)
|
|
updateExample(5);
|
|
else if (rect_rbtn_defaultColor.contains(event->pos()) && m_example_flag != 6)
|
|
updateExample(6);
|
|
else if(m_example_flag < 2 || m_example_flag > 6)
|
|
updateExample(2);
|
|
}
|
|
else if(m_example_flag != 2)
|
|
updateExample(2);
|
|
}
|
|
QDialog::mouseMoveEvent(event);
|
|
}
|
|
|
|
void Dialog_ImgProc_AutoCrop::on_buttonBox_clicked(QAbstractButton *button)
|
|
{
|
|
if(ui->buttonBox->standardButton(button) == QDialogButtonBox::RestoreDefaults)
|
|
{
|
|
ui->cbtn_crop->setChecked(false);
|
|
ui->cbtn_corrSkew->setChecked(false);
|
|
ui->gbox_fillBlank->setChecked(false);
|
|
ui->rbtn_convex->setChecked(true);
|
|
ui->rbtn_autoColor->setChecked(true);
|
|
ui->gbox_param->setChecked(false);
|
|
ui->spin_threshold->setValue(40);
|
|
ui->spin_noise->setValue(8);
|
|
ui->spin_indent->setValue(5);
|
|
}
|
|
}
|
|
|
|
void Dialog_ImgProc_AutoCrop::on_buttonBox_accepted()
|
|
{
|
|
m_isCrop = ui->cbtn_crop->isChecked();
|
|
saveCfgValue("autoCrop", "crop", m_isCrop);
|
|
m_isDeskew = ui->cbtn_corrSkew->isChecked();
|
|
saveCfgValue("autoCrop", "deskew", m_isDeskew);
|
|
m_isFillBlank = ui->gbox_fillBlank->isChecked();
|
|
saveCfgValue("autoCrop", "fillBlank", m_isFillBlank);
|
|
m_isConvex = ui->rbtn_convex->isChecked();
|
|
saveCfgValue("autoCrop", "convex", m_isConvex);
|
|
m_isAutoColor = ui->rbtn_autoColor->isChecked();
|
|
saveCfgValue("autoCrop", "autoColor", m_isAutoColor);
|
|
m_isUseAdvancedParam = ui->gbox_param->isChecked();
|
|
saveCfgValue("autoCrop", "useAdvancedParam", m_isUseAdvancedParam);
|
|
m_threshold = ui->spin_threshold->value();
|
|
saveCfgValue("autoCrop", "threshold", m_threshold);
|
|
m_noise = ui->spin_noise->value();
|
|
saveCfgValue("autoCrop", "noise", m_noise);
|
|
m_indent = ui->spin_indent->value();
|
|
saveCfgValue("autoCrop", "indent", m_indent);
|
|
}
|
|
|
|
void Dialog_ImgProc_AutoCrop::updateExample(int example)
|
|
{
|
|
if(m_example_flag == -1)
|
|
ui->lab_arrow->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_arrow.png")));
|
|
m_example_flag = example;
|
|
switch (example) {
|
|
case 0:
|
|
ui->lab_imgBefore->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_black_before.png")));
|
|
ui->lab_imgAfter->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_crop_after.png")));
|
|
break;
|
|
case 1:
|
|
ui->lab_imgBefore->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_deskew_before.png")));
|
|
ui->lab_imgAfter->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_deskew_after.png")));
|
|
break;
|
|
case 2:
|
|
ui->lab_imgBefore->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_black_before.png")));
|
|
ui->lab_imgAfter->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_black_after.png")));
|
|
break;
|
|
case 3:
|
|
ui->lab_imgBefore->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_fillblack_before.png")));
|
|
ui->lab_imgAfter->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_fillblack_convex.png")));
|
|
break;
|
|
case 4:
|
|
ui->lab_imgBefore->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_fillblack_before.png")));
|
|
ui->lab_imgAfter->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_fillblack_concave.png")));
|
|
break;
|
|
case 5:
|
|
ui->lab_imgBefore->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_fillcolor_before.png")));
|
|
ui->lab_imgAfter->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_fillcolor_auto.png")));
|
|
break;
|
|
case 6:
|
|
ui->lab_imgBefore->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_fillcolor_before.png")));
|
|
ui->lab_imgAfter->setPixmap(QPixmap::fromImage(QImage(":images/image_rsc/example/example_fillcolor_default.png")));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|