233 lines
5.5 KiB
C++
233 lines
5.5 KiB
C++
#include "frmImageFlip.h"
|
|
#include <QMessageBox>
|
|
#include <QDesktopWidget>
|
|
|
|
frmImageFlip::frmImageFlip(QString toolName, QToolBase* toolBase, QWidget* parent)
|
|
: Toolnterface(toolName, toolBase, parent)
|
|
{
|
|
ui.setupUi(this);
|
|
toolTitleName = toolName;
|
|
//FramelessWindowHint属性设置窗口去除边框
|
|
//WindowMinimizeButtonHint 属性设置在窗口最小化时,点击任务栏窗口可以显示出原窗口
|
|
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);
|
|
//设置窗体在屏幕中间位置
|
|
QDesktopWidget* desktop = QApplication::desktop();
|
|
move((desktop->width() - this->width()) / 2, (desktop->height() - this->height()) / 2);
|
|
//设置窗口背景透明
|
|
setAttribute(Qt::WA_TranslucentBackground);
|
|
this->setWindowIcon(QIcon(":/resource/flip.png"));
|
|
//初始化标题栏
|
|
initTitleBar();
|
|
//图像显示
|
|
view = new QGraphicsViews;
|
|
ui.imageLayout->addWidget(view);
|
|
}
|
|
|
|
frmImageFlip::~frmImageFlip()
|
|
{
|
|
this->deleteLater();
|
|
}
|
|
|
|
void frmImageFlip::initTitleBar()
|
|
{
|
|
m_titleBar = new MyTitleBar(this);
|
|
m_titleBar->move(0, 0);
|
|
connect(m_titleBar, SIGNAL(signalButtonCloseClicked()), this, SLOT(onButtonCloseClicked()));
|
|
m_titleBar->setStyleSheet("background-color: rgba(178, 178, 178,0);color:white;font-size:16px");
|
|
m_titleBar->setTitleIcon(":/resource/flip.png");
|
|
m_titleBar->setTitleContent(toolTitleName);
|
|
m_titleBar->setButtonType(ONLY_CLOSE_BUTTON);
|
|
m_titleBar->setTitleWidth(this->width());
|
|
}
|
|
|
|
void frmImageFlip::paintEvent(QPaintEvent* event)
|
|
{
|
|
//设置背景色
|
|
QPainter painter(this);
|
|
QPainterPath pathBack;
|
|
pathBack.setFillRule(Qt::WindingFill);
|
|
pathBack.addRoundedRect(QRect(0, 0, this->width(), this->height()), 3, 3);
|
|
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
|
|
painter.fillPath(pathBack, QBrush(QColor(160, 160, 160)));
|
|
return QWidget::paintEvent(event);
|
|
}
|
|
|
|
void frmImageFlip::onButtonCloseClicked()
|
|
{
|
|
this->close();
|
|
}
|
|
|
|
int frmImageFlip::Execute(const QString toolname)
|
|
{
|
|
bool link_state = false;
|
|
image_index = 0;
|
|
QString str = ui.txtLinkImage->text();
|
|
strs.reserve(100);
|
|
strs.clear();
|
|
strs = str.split(".");
|
|
if (strs.size() == 1)
|
|
{
|
|
GetToolBase()->m_Tools[tool_index].PublicResult.State = false;
|
|
return -1;
|
|
}
|
|
for (int i = 0; i < GetToolBase()->m_Tools.size(); i++)
|
|
{
|
|
if (GetToolBase()->m_Tools[i].PublicToolName == strs[0])
|
|
{
|
|
//获取的图像在工具数组中的索引
|
|
image_index = i;
|
|
link_state = true;
|
|
}
|
|
if (GetToolBase()->m_Tools[i].PublicToolName == toolname)
|
|
{
|
|
//工具在工具数组中的索引
|
|
tool_index = i;
|
|
}
|
|
}
|
|
if (link_state == false)
|
|
{
|
|
GetToolBase()->m_Tools[tool_index].PublicResult.State = false;
|
|
return -2;
|
|
}
|
|
int result = RunToolPro();
|
|
if (result == -1)
|
|
{
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int frmImageFlip::RunToolPro()
|
|
{
|
|
try
|
|
{
|
|
srcImage = GetToolBase()->m_Tools[image_index].PublicImage.OutputImage;
|
|
dstImage = cv::Mat();
|
|
switch (ui.comboFlip->currentIndex()) {
|
|
case 0:
|
|
srcImage.copyTo(dstImage);
|
|
break;
|
|
case 1:
|
|
cv::flip(srcImage, dstImage, 0); //上下翻转
|
|
break;
|
|
case 2:
|
|
cv::flip(srcImage, dstImage, 1); //左右翻转
|
|
break;
|
|
case 3:
|
|
cv::flip(srcImage, dstImage, -1); //上下左右同时翻转
|
|
break;
|
|
}
|
|
GetToolBase()->m_Tools[tool_index].PublicImage.OutputImage = dstImage;
|
|
GetToolBase()->m_Tools[tool_index].PublicResult.State = true;
|
|
return 0;
|
|
}
|
|
catch (...)
|
|
{
|
|
GetToolBase()->m_Tools[tool_index].PublicResult.State = false;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
int frmImageFlip::ExecuteLink(const int int_link, const QString str_link, const QMap<QString, gVariable::Global_Var> variable_link)
|
|
{
|
|
try
|
|
{
|
|
gvariable.global_variable_link = variable_link;
|
|
if (int_link == 1)
|
|
{
|
|
strs.clear();
|
|
strs = str_link.split(".");
|
|
if (strs.size() == 1 || strs[1] != "图像")
|
|
{
|
|
QMessageBox msgBox(QMessageBox::Icon::NoIcon, "错误", "输入的链接错误!");
|
|
msgBox.setWindowIcon(QIcon(":/resource/error.png"));
|
|
msgBox.exec();
|
|
return -1;
|
|
}
|
|
ui.txtLinkImage->setText(str_link);
|
|
}
|
|
return 0;
|
|
}
|
|
catch (...)
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
int frmImageFlip::ExecuteAllLink(const QMap<QString, gVariable::Global_Var> g_variable_link)
|
|
{
|
|
try
|
|
{
|
|
gvariable.global_variable_link = g_variable_link;
|
|
return 0;
|
|
}
|
|
catch (...)
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
void frmImageFlip::on_btnExecute_clicked()
|
|
{
|
|
ui.btnExecute->setEnabled(false);
|
|
QApplication::processEvents();
|
|
Execute(GetToolName());
|
|
QImage img(Mat2QImage(dstImage));
|
|
view->DispImage(img);
|
|
ui.btnExecute->setEnabled(true);
|
|
}
|
|
|
|
void frmImageFlip::on_btnLinkImage_clicked()
|
|
{
|
|
QConfig::nFormState = 1;
|
|
}
|
|
|
|
void frmImageFlip::on_btnDelLinkImage_clicked()
|
|
{
|
|
ui.txtLinkImage->clear();
|
|
}
|
|
|
|
QImage frmImageFlip::Mat2QImage(const cv::Mat& mat)
|
|
{
|
|
if (mat.empty())
|
|
{
|
|
return QImage();
|
|
}
|
|
if (mat.type() == CV_8UC1)
|
|
{
|
|
QImage image(mat.cols, mat.rows, QImage::Format_Indexed8);
|
|
image.setColorCount(256);
|
|
for (int i = 0; i < 256; i++)
|
|
{
|
|
image.setColor(i, qRgb(i, i, i));
|
|
}
|
|
uchar* pSrc = mat.data;
|
|
for (int row = 0; row < mat.rows; row++)
|
|
{
|
|
uchar* pDest = image.scanLine(row);
|
|
memcpy(pDest, pSrc, mat.cols);
|
|
pSrc += mat.step;
|
|
}
|
|
return image;
|
|
}
|
|
else if (mat.type() == CV_8UC3)
|
|
{
|
|
const uchar* pSrc = (const uchar*)mat.data;
|
|
QImage image(pSrc, mat.cols, mat.rows, mat.step, QImage::Format_RGB888);
|
|
return image.rgbSwapped();
|
|
}
|
|
else if (mat.type() == CV_8UC4)
|
|
{
|
|
const uchar* pSrc = (const uchar*)mat.data;
|
|
QImage image(pSrc, mat.cols, mat.rows, mat.step, QImage::Format_ARGB32);
|
|
return image.copy();
|
|
}
|
|
else
|
|
{
|
|
return QImage();
|
|
}
|
|
}
|
|
|
|
//全局变量控制
|
|
int QConfig::nFormState = 0;
|