graphic free trace mode

This commit is contained in:
2021-10-22 21:23:01 +03:00
parent 4717e8e8de
commit b9943a460a
3 changed files with 57 additions and 7 deletions

View File

@@ -104,14 +104,17 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
#endif
QActionGroup * agroup = new QActionGroup(this);
agroup->addAction(ui->graphic_actionGuidesFree );
agroup->addAction(ui->graphic_actionGuidesTrace );
agroup->addAction(ui->graphic_actionGuidesTraceX);
agroup->addAction(ui->graphic_actionGuidesTraceY);
ui->graphic_actionGuidesFree ->setProperty("_value", (int)Free );
ui->graphic_actionGuidesTraceX->setProperty("_value", (int)TraceX);
ui->graphic_actionGuidesTraceY->setProperty("_value", (int)TraceY);
ui->graphic_actionGuidesFree ->setProperty("_value", (int)Free );
ui->graphic_actionGuidesTrace ->setProperty("_value", (int)TraceXY);
ui->graphic_actionGuidesTraceX->setProperty("_value", (int)TraceX );
ui->graphic_actionGuidesTraceY->setProperty("_value", (int)TraceY );
ui->graphic_actionGuidesFree->setChecked(true);
connect(agroup, SIGNAL(triggered(QAction*)), this, SLOT(actionGuidesTriggered(QAction*)));
ui->graphic_checkGuides ->addAction(ui->graphic_actionGuidesFree );
ui->graphic_checkGuides ->addAction(ui->graphic_actionGuidesTrace );
ui->graphic_checkGuides ->addAction(ui->graphic_actionGuidesTraceX);
ui->graphic_checkGuides ->addAction(ui->graphic_actionGuidesTraceY);
ui->graphic_buttonAutofit->addAction(ui->graphic_actionExpandX);
@@ -1365,7 +1368,7 @@ void Graphic::drawGuides() {
QPointF rpos = canvas2real(apos);
QString str;
str = pointCoords(rpos) + fp_size;
auto trace_func = [&](bool on_x, double cursor) {
auto trace_axis_func = [&](bool on_x, double cursor) {
if (curTrace >= 0 && curTrace < graphics.size()) {
if (graphics[curTrace].visible) {
QPolygonF & pol(pause_ ? graphics[curTrace].polyline_pause : graphics[curTrace].polyline);
@@ -1388,12 +1391,45 @@ void Graphic::drawGuides() {
}
}
};
auto trace_free_func = [&](QPointF cursor) {
double min_dist = -1;
int gr = -1, mag_dist = fontHeight(this) * 2;
QPointF point, scale = getScale(), dp;
for (int g = 0; g < graphics.size(); ++g) {
if (graphics[g].visible) {
QPolygonF & pol(pause_ ? graphics[g].polyline_pause : graphics[g].polyline);
double dist = 0.;
for (int i = 0; i < pol.size(); ++i) {
point = pol[i];
if (!selrect.contains(point)) continue;
dp = point - cursor;
dp = QPointF(dp.x() * scale.x(), dp.y() * scale.y());
if (dp.manhattanLength() <= mag_dist) {
dist = QVector2D(dp).lengthSquared();
if (min_dist > dist || min_dist < 0) {
min_dist = dist;
gr = g;
rpos = point;
}
}
}
}
if (gr >= 0) {
apos = real2canvas(rpos).toPoint();
str = graphics[gr].name + ": " + pointCoords(rpos) + fp_size;
emit graphicTraceEvent(curTrace, point);
}
}
};
switch (floating_axis_type) {
case TraceXY:
trace_free_func(rpos);
break;
case TraceX:
trace_func(true, rpos.x());
trace_axis_func(true, rpos.x());
break;
case TraceY:
trace_func(false, rpos.y());
trace_axis_func(false, rpos.y());
break;
default: break;
}