qrc fixed, graphic FloatingAxisType, qpicalculator moved to PIEvaluator

This commit is contained in:
2020-08-27 17:23:18 +03:00
parent b92a1fa558
commit 05874e9d7e
20 changed files with 240 additions and 203 deletions

View File

@@ -8,6 +8,7 @@
#include <QTapAndHoldGesture>
#include <QPanGesture>
#include <QPinchGesture>
#include <QActionGroup>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
# include <QRandomGenerator>
#endif
@@ -37,6 +38,18 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
#endif
ui = new Ui::Graphic();
ui->setupUi(this);
QActionGroup * agroup = new QActionGroup(this);
agroup->addAction(ui->actionGuidesFree );
agroup->addAction(ui->actionGuidesTraceX);
agroup->addAction(ui->actionGuidesTraceY);
ui->actionGuidesFree ->setProperty("_value", (int)Free );
ui->actionGuidesTraceX->setProperty("_value", (int)TraceX);
ui->actionGuidesTraceY->setProperty("_value", (int)TraceY);
ui->actionGuidesFree->setChecked(true);
connect(agroup, SIGNAL(triggered(QAction*)), this, SLOT(actionGuidesTriggered(QAction*)));
ui->checkGuides->addAction(ui->actionGuidesFree );
ui->checkGuides->addAction(ui->actionGuidesTraceX);
ui->checkGuides->addAction(ui->actionGuidesTraceY);
line_x_min.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
line_x_max.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
((QBoxLayout * )ui->widgetLY->layout())->insertWidget(0, &line_y_min);
@@ -76,6 +89,7 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
emaxx = emaxy = DBL_MIN;
grad_x = grad_y = Auto;
axis_type_x = Numeric;
floating_axis_type = Free;
min_repaint_int = 25;
inc_x = 1.;
buffer = 0;
@@ -374,10 +388,7 @@ void Graphic::canvasMousePressEvent(QMouseEvent * e) {
emit graphicMousePressEvent(canvas2real(QPointF(e->pos())), e->button());
if (!navigation) return;
if (gestures && !need_mouse_pan) return;
#ifdef HAS_GL
canvas_gl->setCursor(guides ? Qt::BlankCursor : Qt::ArrowCursor);
#endif
ui->canvas_raster->setCursor(guides ? Qt::BlankCursor : Qt::ArrowCursor);
setGuidesCursor();
prevpos = e->pos();
startpos = prevpos;
startpos_r = canvas2real(startpos);
@@ -393,7 +404,7 @@ void Graphic::canvasMousePressEvent(QMouseEvent * e) {
return;
} else {
prevaction = curaction;
curaction = gaMove;
setCurrentAction(gaMove);
return;
}
}
@@ -419,10 +430,7 @@ void Graphic::canvasMouseReleaseEvent(QMouseEvent * e) {
if (gestures) return;
need_mouse_pan = false;
if (!navigation) return;
#ifdef HAS_GL
canvas_gl->setCursor(guides ? Qt::BlankCursor : Qt::ArrowCursor);
#endif
ui->canvas_raster->setCursor(guides ? Qt::BlankCursor : Qt::ArrowCursor);
setGuidesCursor();
QPointF tlp, brp;
QRect sr;
sr = QRect(startpos, curpos).normalized();
@@ -1149,14 +1157,58 @@ void Graphic::drawGuides() {
painter->resetTransform();
painter->setClipping(true);
painter->setClipRect(QRect(gridborder.x(), 0, wid - gridborder.x(), hei - gridborder.y()));
painter->drawLine(0, curpos.y(), wid, curpos.y());
painter->drawLine(curpos.x(), 0, curpos.x(), hei);
QString str = pointCoords(canvas2real(curpos)) + fp_size;
QPoint apos = curpos;
QPointF rpos = canvas2real(apos);
QString str;
str = pointCoords(rpos) + fp_size;
switch (floating_axis_type) {
case TraceX:
if (curGraphic >= 0 && curGraphic < graphics.size()) {
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;
case TraceY:
if (curGraphic >= 0 && curGraphic < graphics.size()) {
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;
default: break;
}
painter->drawLine(0, apos.y(), wid, apos.y());
painter->drawLine(apos.x(), 0, apos.x(), hei);
QPoint p = apos + QPoint(font_sz.height() / 4., -font_sz.height() / 4.);
QFontMetrics fm(font());
QRect r = fm.boundingRect(str);
QPoint p = curpos + QPoint(font_sz.height() / 4., -font_sz.height() / 4.);
if (r.width() + curpos.x() > wid - font_sz.height() / 2.) p.setX(curpos.x() - r.width() - font_sz.height() / 4.);
if (curpos.y() - r.height() < font_sz.height() / 8.) p.setY(curpos.y() + r.height() - font_sz.height() / 8.);
if (r.width() + apos.x() > wid - font_sz.height() / 2.) p.setX(apos.x() - r.width() - font_sz.height() / 4.);
if (apos.y() - r.height() < font_sz.height() / 8.) p.setY(apos.y() + r.height() - font_sz.height() / 8.);
painter->setPen(text_color);
painter->drawText(p, str);
}
@@ -1287,8 +1339,7 @@ void Graphic::setCurrentAction(GraphicAction action) {
curaction = action;
switch (action) {
case gaNone:
if (guides) setCanvasCursor(Qt::BlankCursor);
else setCanvasCursor(Qt::ArrowCursor);
setGuidesCursor();
break;
case gaZoomInRect:
setCanvasCursor(Qt::CrossCursor);
@@ -1314,6 +1365,14 @@ void Graphic::setCanvasCursor(QCursor cursor) {
}
void Graphic::setGuidesCursor() {
if (guides) {
setCanvasCursor(floating_axis_type == Free ? Qt::BlankCursor : Qt::CrossCursor);
} else
setCanvasCursor(Qt::ArrowCursor);
}
void Graphic::swapToBuffer() {
QImage timg;
#ifdef HAS_GL
@@ -1461,8 +1520,7 @@ void Graphic::on_buttonConfigure_clicked() {
void Graphic::on_checkGuides_toggled(bool checked) {
guides = checked;
if (guides) setCanvasCursor(Qt::BlankCursor);
else setCanvasCursor(Qt::ArrowCursor);
setGuidesCursor();
update();
}
@@ -1743,3 +1801,9 @@ void Graphic::on_checkExpandX_toggled(bool checked) {
only_expand_x = checked;
ui->checkExpandX->setIcon(checked ? icon_exp_x : icon_exp_sx);
}
void Graphic::actionGuidesTriggered(QAction * a) {
ui->checkGuides->setChecked(true);
setFloatingAxisType((FloatingAxisType)a->property("_value").toInt());
}