-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalibdemo.cpp
104 lines (81 loc) · 2.42 KB
/
calibdemo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "calibdemo.h"
CalibDemo::CalibDemo(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
mousepress_x=0;
mousepress_y=0;
mousemove_x=0;
mousemove_y=0;
mouserelease_x=0;
mouserelease_y=0;
Rectw=0;
Recth=0;
setWindowFlags(windowFlags()& ~Qt::WindowMaximizeButtonHint);
setFixedSize(this->width(), this->height());
}
CalibDemo::~CalibDemo()
{
}
void CalibDemo::on_action_triggered()
{
QString filename = QFileDialog::getOpenFileName(this, tr("Chioce a picture!"), ".", tr("format(*.bmp *.png *.jpeg *.jpg *.tif *.tiff )"));
//QFile file(filename);
//if (!file.open(QIODevice::ReadOnly))
//{
// qDebug() << "Could not open file";
// exit(0);
//}
//QUrl::fromLocalFile(filename);
//filename_ = filename.toStdString();
CalibImage.load(filename);
}
void CalibDemo::paintEvent(QPaintEvent *e)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.drawImage(QPoint(10,60), CalibImage);
QPoint x1(mousepress_x, mousepress_y);
QPoint x2(mousemove_x, mousemove_y);
QPoint x3(mouserelease_x, mouserelease_y);
painter.drawLine(x1, x2);
//painter.drawLine(x1, x3);
//this->update();//不要在paintEvent()函数中调用update()或者repaint()
}
void CalibDemo::mouseMoveEvent(QMouseEvent *event)
{
Rectw = (mousepress_x - mousemove_x)*(mousepress_x - mousemove_x);
Recth = (mousepress_y - mousemove_y)*(mousepress_y - mousemove_y);
Length = sqrt(Rectw + Recth);
mousemove_x = event->pos().x() ;
mousemove_y = event->pos().y() ;
QString pos = QString("Length=%1pixels").arg(Length);
//QString pos = QString("%1,%2").arg(event->pos().x() - 20).arg(event->pos().y() - 40);
QToolTip::showText(event->globalPos(), pos, this);
this->update();
}
void CalibDemo::mousePressEvent(QMouseEvent *event)
{
mousepress_x = event->pos().x() ;
mousepress_y = event->pos().y() ;
//QString pos = QString("%1,%2").arg(event->pos().x() - 20).arg(event->pos().y() - 40);
//QToolTip::showText(event->globalPos(), pos, this);
}
void CalibDemo::mouseReleaseEvent(QMouseEvent *event)
{
//Rectw = abs(mousepress_x - mousemove_x);
//Recth = abs(mousepress_y - mousemove_y);
//mouserelease_x = event->pos().x() ;
//mouserelease_y = event->pos().y() ;
Calib =10/Length;//1cm=10mm,每个像素宽度为Length/10;
lennum = QString::number(Calib, 10,2);
ui.lineEdit->setText(lennum);
}
double CalibDemo::returnCalib()
{
return Calib;
}
void CalibDemo::on_pushButton_clicked()
{
emit sendCalib(returnCalib());
}