Graphic tracing improvements
This commit is contained in:
@@ -110,7 +110,7 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
|||||||
text_color = palette().color(QPalette::WindowText);
|
text_color = palette().color(QPalette::WindowText);
|
||||||
grid_pen = QPen(palette().color(QPalette::Disabled, QPalette::WindowText), 0., Qt::DotLine);
|
grid_pen = QPen(palette().color(QPalette::Disabled, QPalette::WindowText), 0., Qt::DotLine);
|
||||||
graphics.append(GraphicType());
|
graphics.append(GraphicType());
|
||||||
curGraphic = 0;
|
curGraphic = curTrace = 0;
|
||||||
selpen = palette().color(QPalette::WindowText);
|
selpen = palette().color(QPalette::WindowText);
|
||||||
selpen.setStyle(Qt::DashLine);
|
selpen.setStyle(Qt::DashLine);
|
||||||
back_color = palette().color(QPalette::Base);
|
back_color = palette().color(QPalette::Base);
|
||||||
@@ -1156,44 +1156,35 @@ void Graphic::drawGuides() {
|
|||||||
QPointF rpos = canvas2real(apos);
|
QPointF rpos = canvas2real(apos);
|
||||||
QString str;
|
QString str;
|
||||||
str = pointCoords(rpos) + fp_size;
|
str = pointCoords(rpos) + fp_size;
|
||||||
|
auto trace_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);
|
||||||
|
double min_dist = -1, dist = 0.;
|
||||||
|
int index = -1;
|
||||||
|
for (int i = 0; i < pol.size(); ++i) {
|
||||||
|
if (!selrect.contains(pol[i])) continue;
|
||||||
|
dist = qAbs<double>((on_x ? pol[i].x() : pol[i].y()) - cursor);
|
||||||
|
if (min_dist > dist || min_dist < 0) {
|
||||||
|
min_dist = dist;
|
||||||
|
index = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (index >= 0) {
|
||||||
|
rpos = pol[index];
|
||||||
|
apos = real2canvas(rpos).toPoint();
|
||||||
|
str = pointCoords(pol[index]) + fp_size;
|
||||||
|
emit graphicTraceEvent(curTrace, rpos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
switch (floating_axis_type) {
|
switch (floating_axis_type) {
|
||||||
case TraceX:
|
case TraceX:
|
||||||
if (curGraphic >= 0 && curGraphic < graphics.size()) {
|
trace_func(true, rpos.x());
|
||||||
QPolygonF & pol(pause_ ? graphics[curGraphic].polyline_pause : graphics[curGraphic].polyline);
|
|
||||||
double cursor = rpos.x(), min_dist = -1, dist = 0.;
|
|
||||||
int index = -1;
|
|
||||||
for (int i = 0; i < pol.size(); ++i) {
|
|
||||||
dist = qAbs<double>(pol[i].x() - cursor);
|
|
||||||
if (min_dist > dist || min_dist < 0) {
|
|
||||||
min_dist = dist;
|
|
||||||
index = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (index >= 0) {
|
|
||||||
rpos = pol[index];
|
|
||||||
apos = real2canvas(rpos).toPoint();
|
|
||||||
str = pointCoords(pol[index]) + fp_size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case TraceY:
|
case TraceY:
|
||||||
if (curGraphic >= 0 && curGraphic < graphics.size()) {
|
trace_func(false, rpos.y());
|
||||||
QPolygonF & pol(pause_ ? graphics[curGraphic].polyline_pause : graphics[curGraphic].polyline);
|
|
||||||
double cursor = rpos.y(), min_dist = -1, dist = 0.;
|
|
||||||
int index = -1;
|
|
||||||
for (int i = 0; i < pol.size(); ++i) {
|
|
||||||
dist = qAbs<double>(pol[i].y() - cursor);
|
|
||||||
if (min_dist > dist || min_dist < 0) {
|
|
||||||
min_dist = dist;
|
|
||||||
index = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (index >= 0) {
|
|
||||||
rpos = pol[index];
|
|
||||||
apos = real2canvas(rpos).toPoint();
|
|
||||||
str = pointCoords(pol[index]) + fp_size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ public:
|
|||||||
bool gesturesNavigation() const {return gestures;}
|
bool gesturesNavigation() const {return gestures;}
|
||||||
bool isAutofitted() const {return isFit;}
|
bool isAutofitted() const {return isFit;}
|
||||||
int currentGraphic() const {return curGraphic;}
|
int currentGraphic() const {return curGraphic;}
|
||||||
|
int currentTraceGraphic() const {return curTrace;}
|
||||||
int graphicsCount() const {return graphics.size();}
|
int graphicsCount() const {return graphics.size();}
|
||||||
Graphic::Buttons buttons() const {return buttons_;}
|
Graphic::Buttons buttons() const {return buttons_;}
|
||||||
Graphic::Alignment buttonsPosition() const {return align;}
|
Graphic::Alignment buttonsPosition() const {return align;}
|
||||||
@@ -317,6 +318,7 @@ public slots:
|
|||||||
void update(bool force = false);
|
void update(bool force = false);
|
||||||
void updateGraphics() {findGraphicsRect(); update();}
|
void updateGraphics() {findGraphicsRect(); update();}
|
||||||
void setCurrentGraphic(int arg) {if (arg < 0 || arg >= graphics.size()) return; curGraphic = arg;}
|
void setCurrentGraphic(int arg) {if (arg < 0 || arg >= graphics.size()) return; curGraphic = arg;}
|
||||||
|
void setTraceGraphic(int arg) {if (arg < 0 || arg >= graphics.size()) return; curTrace = arg;}
|
||||||
void setGraphicsCount(int arg, bool update = true);
|
void setGraphicsCount(int arg, bool update = true);
|
||||||
void removeGraphic(int arg, bool update = true);
|
void removeGraphic(int arg, bool update = true);
|
||||||
|
|
||||||
@@ -371,7 +373,7 @@ protected:
|
|||||||
QPen grid_pen, selpen;
|
QPen grid_pen, selpen;
|
||||||
QColor back_color, text_color;
|
QColor back_color, text_color;
|
||||||
QVector<GraphicType> graphics;
|
QVector<GraphicType> graphics;
|
||||||
int curGraphic;
|
int curGraphic, curTrace;
|
||||||
GraphicAction curaction, prevaction;
|
GraphicAction curaction, prevaction;
|
||||||
QRectF grect, selrect, limit_, def_rect;
|
QRectF grect, selrect, limit_, def_rect;
|
||||||
QRect margins_;
|
QRect margins_;
|
||||||
@@ -437,6 +439,7 @@ signals:
|
|||||||
void graphicMousePressEvent(QPointF point, int buttons);
|
void graphicMousePressEvent(QPointF point, int buttons);
|
||||||
void graphicMouseReleaseEvent(QPointF point, int buttons);
|
void graphicMouseReleaseEvent(QPointF point, int buttons);
|
||||||
void graphicWheelEvent(QPointF point, int delta);
|
void graphicWheelEvent(QPointF point, int delta);
|
||||||
|
void graphicTraceEvent(int graphic, QPointF point);
|
||||||
void closeRequest(QWidget * );
|
void closeRequest(QWidget * );
|
||||||
void cleared();
|
void cleared();
|
||||||
void visualRectChanged();
|
void visualRectChanged();
|
||||||
|
|||||||
Reference in New Issue
Block a user