#include "DisplayWgt.h"
#include <QPainter>
#include <QMouseEvent>
DisplayWgt::DisplayWgt(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
m_shape = NoShape;
m_state = NormalState;
m_rectId = 0;
m_circleId = 0;
m_ellipseId = 0;
m_polygonId = 0;
m_bll = BllData::getInstance();
connect(m_bll, &BllData::updateImgDataSignal, this, &DisplayWgt::updateImgDataSlot);
connect(m_bll, &BllData::setDeleteStateEnableSignal, this, &DisplayWgt::setDeleteStateEnableSlot);
connect(m_bll, &BllData::setToolsShapeSignal, this, &DisplayWgt::setToolsShapeSlot);
connect(m_bll, &BllData::clearShapeSignal, this, &DisplayWgt::clearShapeSlot);
connect(m_bll, &BllData::setPointMoveLimitSignal, this, &DisplayWgt::setPointMoveLimitSlot);
connect(m_bll, &BllData::cancelPointMoveLimitSignal, this, &DisplayWgt::cancelPointMoveLimitSlot);
connect(m_bll, &BllData::PointMoveReflectShapeSignal, this, &DisplayWgt::PointMoveReflectShapeSlot);
connect(m_bll, &BllData::ShapeMoveReflectPointSignal, this, &DisplayWgt::ShapeMoveReflectPointSlot);
connect(m_bll, &BllData::deleteShapeSignal, this, &DisplayWgt::deleteShapeSlot);
}
DisplayWgt::~DisplayWgt()
{
}
void DisplayWgt::updateImgDataSlot(int min, int max) {
m_width = max - min;
m_center = (min + max) / 2;
m_paintEnable = true;
update();
}
void DisplayWgt::paintEvent(QPaintEvent* event) {
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
if (m_paintEnable) {
QRect target(0, 0, this->width(), this->height());
quint16* m_grayImg = BllData::getSingleImg();
uchar* m_img8bit = BllData::getImg8bit();
BllData::converToGray(m_grayImg, m_img8bit, m_width, m_center);
QImage image(m_img8bit, BllData::ImgCol, BllData::ImgRow, QImage::Format_Grayscale8);
p.drawImage(target, image);
}
p.setRenderHint(QPainter::Antialiasing, true);
p.setPen(QPen(Qt::yellow, 1));
if (m_singleCurve.size()) {
for (int i = 0; i < m_singleCurve.size() - 1; i++) {
QPoint p1(m_singleCurve[i].x(), m_singleCurve[i].y());
QPoint p2(m_singleCurve[i + 1].x(), m_singleCurve[i + 1].y());
p.drawLine(p1, p2);
}
}
if (m_Curves.size()) {
for (int i = 0; i < m_Curves.size(); i++) {
p.drawPolygon(m_Curves[i]);
}
}
/*for (int i = 0; i < m_vecpolygonAllP.size(); i++) {
int psize = m_vecpolygonAllP[i].size();
for (int j = 0; j < psize - 1; j++) {
QPoint p1 = m_vecpolygonAllP[i][j]->getPos();
QPoint p2 = m_vecpolygonAllP[i][j + 1]->getPos();
p.drawLine(p1, p2);
}
p.drawLine(m_vecpolygonAllP[i][0]->getPos(), m_vecpolygonAllP[i][psize - 1]->getPos());
}*/
for (int i = 0; i < m_polygonPointsWVec.size(); i++) {
int psize = m_polygonPointsWVec[i].size();
for (int j = 0; j < psize-1; j++) {
QPoint p1 = m_polygonPointsWVec[i][j]->getPos();
QPoint p2 = m_polygonPointsWVec[i][j + 1]->getPos();
p.drawLine(p1, p2);
}
p.drawLine(m_polygonPointsWVec[i][0]->getPos(), m_polygonPointsWVec[i][psize - 1]->getPos());
}
//绘制图形
if (m_state == ToolState) {
QPoint center;
int ra, ll, ss;
switch (m_shape) {
case RectShape:
p.drawRect(QRect(m_startP, m_endP));
break;
case CircleShape:
center.setX((m_startP.x() + m_endP.x()) / 2);
center.setY((m_startP.y() + m_endP.y()) / 2);
//ra = abs(m_startP.x() - m_endP.x()) / 2;
ra = sqrt(pow(center.x() - m_startP.x(), 2) + pow(center.y() - m_startP.y(), 2));
p.drawEllipse(center, ra, ra);
break;
case EllipseShape:
center.setX((m_startP.x() + m_endP.x()) / 2);
center.setY((m_startP.y() + m_endP.y()) / 2);
ll = abs(m_startP.x() - m_endP.x()) / 2;
ss = abs(m_startP.y() - m_endP.y()) / 2;
p.drawEllipse(center, ll, ss);
break;
default:
break;
}
}
}
void DisplayWgt::mouseMoveEvent(QMouseEvent* event) {
if (m_state == ToolState) {
switch (m_shape) {
case CurveShape:
m_singleCurve.append(event->pos());
break;
case RectShape:
case CircleShape:
case EllipseShape:
m_endP = event->pos();
break;
default:
break;
}
}
update();
}
void DisplayWgt::mousePressEvent(QMouseEvent* event) {
m_startP = event->pos();
if (event->button() == Qt::LeftButton)
{
if (m_state == ToolState) {
if (m_shape == CurveShape) {
m_singleCurve.append(event->pos());
}
else if (m_shape == PolygonShape) {
PointWidget* polygonp = new PointWidget(PolygonPoint, m_polygonId, event->pos(), this);
polygonp->show();
m_singlePolygonW.push_back(polygonp);
m_singlePolygon.push_back(event->pos());
}
else {
m_endP = m_startP;
}
}
else if (m_state == DeleteState) {
deleteFreeCurve(event->pos());
deletePolygonPoints(event->pos());
}
}
else {
if (m_state == ToolState&& m_shape == PolygonShape) {
if (m_singlePolygonW.size() < 3) {
return;
}
m_polygonPointsWVec.push_back(m_singlePolygonW);
QPolygon pts(m_singlePolygon);
m_polygonsVec.push_back(pts);
m_singlePolygonW.clear();
m_singlePolygon.clear();
m_polygonId++;
}
}
update();
}
void DisplayWgt::deleteFreeCurve(QPoint pos) {
for (int i = 0; i < m_Curves.size(); i++) {
QPolygon p = m_Curves[i];
if (p.containsPoint(pos, Qt::OddEvenFill)) {
qDebug() << "deleteFreeCurve--------pos: " << p;
m_Curves.remove(i);
break;
}
else {
qDebug() << "out range pos: " << pos;
}
}
}
void DisplayWgt::deletePolygonPoints(QPoint pos) {
int index = -1;
for (int i = 0; i < m_polygonsVec.size(); i++) {
QPolygon p = m_polygonsVec[i];
if (p.containsPoint(pos, Qt::OddEvenFill)) {
index = i;
m_polygonsVec.remove(i);
break;
}
else {
}
}
if (index != -1) {
int size = m_polygonPointsWVec[index].size();
for (int i = 0; i < size; i++) {
delete m_polygonPointsWVec[index][i];
}
m_polygonPointsWVec.remove(index);
m_polygonId--;
}
}
void DisplayWgt::mouseReleaseEvent(QMouseEvent* event) {
if (m_state == ToolState) {
int width = abs(m_startP.x() - m_endP.x());
int height = abs(m_startP.y() - m_endP.y());
if (m_shape == CurveShape) {
m_singleCurve.append(m_singleCurve[0]);
QPolygon polygon(m_singleCurve);
m_Curves.append(polygon);
m_singleCurve.clear();
}
else if (m_shape == RectShape) {
if (width < 10 || height<10) {
update();
return;
}
int rbx = m_endP.x() > m_startP.x() ? m_endP.x() : m_startP.x();
int rby = m_endP.y() > m_startP.y() ? m_endP.y() : m_startP.y();
RectWidget* rectw = new RectWidget(m_rectId, QPoint(rbx, rby), width, height,this);
rectw->show();
m_rectVec.push_back(rectw);
PointWidget* rectp = new PointWidget(RectPoint, m_rectId, QPoint(rbx, rby),this);
rectp->show();
m_rectPointVec.push_back(rectp);
m_rectId++;
}
else if (m_shape == CircleShape) {
if (width < 10 || height < 10) {
update();
return;
}
int ltx = m_startP.x() < m_endP.x() ? m_startP.x() : m_endP.x();
int lty = m_startP.y() < m_endP.y() ? m_startP.y() : m_endP.y();
int rbx = m_endP.x() > m_startP.x() ? m_endP.x() : m_startP.x();
int rby = m_endP.y() > m_startP.y() ? m_endP.y() : m_startP.y();
QPoint center((ltx + rbx) / 2, (lty + rby) / 2);
int ra = sqrt(pow(center.x() - m_startP.x(), 2) + pow(center.y() - m_startP.y(), 2));
CircleWidget* circlew = new CircleWidget(m_circleId, QPoint(ltx, lty), QPoint(rbx, rby), this);
circlew->show();
m_circleVec.push_back(circlew);
PointWidget* circlep = new PointWidget(CirclePoint, m_circleId, QPoint(rbx, rby), this);
circlep->show();
m_circlePointVec.push_back(circlep);
m_circleId++;
}
else if (m_shape == EllipseShape) {
if (width < 10 || height < 10) {
update();
return;
}
int ltx = m_startP.x() < m_endP.x() ? m
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
使用Qt实现绘图工具,包括绘制自由曲线,矩形,多边形等工具 (391个子文件)
moc_predefs.h.cbt 55B
DisplayWgt.cpp 14KB
moc_BllData.cpp 10KB
moc_BllData.cpp 10KB
moc_DisplayWgt.cpp 6KB
moc_DisplayWgt.cpp 6KB
ToolsWgt.cpp 5KB
moc_ToolsWgt.cpp 5KB
moc_ToolsWgt.cpp 5KB
CircleWidget.cpp 3KB
moc_EllipseWidget.cpp 3KB
moc_CircleWidget.cpp 3KB
moc_CircleWidget.cpp 3KB
moc_PointWidget.cpp 3KB
moc_PointWidget.cpp 3KB
moc_RectWidget.cpp 3KB
moc_RectWidget.cpp 3KB
RectWidget.cpp 2KB
EllipseWidget.cpp 2KB
PointWidget.cpp 2KB
qrc_ToolsWgt.cpp 1KB
qrc_ToolsWgt.cpp 1KB
BllData.cpp 1KB
main.cpp 187B
Browse.VC.db 51.77MB
opencv_world410d.dll 120.33MB
opencv_world410d.dll 120.33MB
opencv_world410.dll 70.42MB
opencv_ffmpeg410_64.dll 17.79MB
ToolsWgt.exe 444KB
ToolsWgt.vcxproj.filters 3KB
qtvars.vcxproj.filters 493B
core_c.h 129KB
types_c.h 72KB
imgproc_c.h 51KB
kmeans_index.h 37KB
cvdef.h 32KB
constants_c.h 31KB
dist.h 28KB
hierarchical_clustering_index.h 26KB
autotuned_index.h 21KB
kdtree_single_index.h 20KB
kdtree_index.h 20KB
lsh_table.h 19KB
types_c.h 18KB
cv_cpu_helper.h 18KB
lsh_index.h 16KB
result_set.h 15KB
index_testing.h 11KB
highgui_c.h 11KB
any.h 9KB
ui_ToolsWgt.h 9KB
ui_ToolsWgt.h 9KB
allocator.h 6KB
composite_index.h 6KB
nn_index.h 6KB
all_indices.h 6KB
cv_cpu_dispatch.h 6KB
saving.h 6KB
simplex_downhill.h 6KB
videoio_c.h 6KB
calib3d_c.h 5KB
cap_ios.h 5KB
interface.h 5KB
dynamic_bitset.h 5KB
defines.h 4KB
random.h 4KB
heap.h 4KB
logger.h 4KB
linear_index.h 4KB
cvconfig.h 3KB
matrix.h 3KB
ground_truth.h 3KB
params.h 3KB
BllData.h 3KB
object_factory.h 3KB
sampling.h 3KB
timer.h 3KB
ios.h 3KB
general.h 2KB
config.h 2KB
DisplayWgt.h 2KB
constants_c.h 2KB
ui_EllipseWidget.h 1KB
ui_CircleWidget.h 1KB
ui_CircleWidget.h 1KB
ui_PointWidget.h 1KB
ui_PointWidget.h 1KB
ui_RectWidget.h 1KB
ui_RectWidget.h 1KB
ui_DisplayWgt.h 1KB
ui_DisplayWgt.h 1KB
interface.h 1KB
CircleWidget.h 835B
RectWidget.h 796B
EllipseWidget.h 794B
ToolsWgt.h 727B
PointWidget.h 691B
interface.h 584B
constants_c.h 478B
共 391 条
- 1
- 2
- 3
- 4
资源评论
从前,有个傻子........
- 粉丝: 49
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于java+ssm+mysql的校友录系统开题报告.doc
- 基于java+ssm+mysql的校园心理健康网站开题报告.doc
- 基于Matlab的2DPSK调制解调系统仿真全部资料+详细文档.zip
- 基于MATLAB编程环境的行人检测系统,全部资料+详细文档.zip
- 基于matlab-cfs-模板匹配的车牌识别全部资料+详细文档.zip
- 基于matlab的激光扩束系统设计全部资料+详细文档.zip
- 基于matlab的线性模型摄像机定标全部资料+详细文档.zip
- 基于matlab的少帅下飞机动画演示全部资料+详细文档.zip
- 基于matlab的一些算法验证和仿真全部资料+详细文档.zip
- python入门-13.A-B problem-暴力解决不了问题~.py
- python入门-14.生日-happy bir…….py
- Python入门经典PDF
- python入门-15.平台-这不是是男人就下100层?.py
- 焊接地轨机器人模组sw18全套技术资料100%好用.zip
- 中国高程标准地图-附带全球shp+全国行政shp+南海诸岛shp+全国高程Tif+标准成图mxd文件
- http协议课程设计PDF
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功