git-svn-id: svn://db.shs.com.ru/libs@483 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2019-01-28 16:07:49 +00:00
parent 599963136e
commit caa612b978
3 changed files with 171 additions and 241 deletions

View File

@@ -73,6 +73,7 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), line_x_min(this), line_x_max
connect(canvas_gl, SIGNAL(keyPressEvent(QKeyEvent * )), this, SLOT(canvasKeyPressEvent(QKeyEvent * )));
canvas_gl->grabGesture(Qt::PinchGesture);
canvas_gl->grabGesture(Qt::PanGesture);
canvas_gl->setMouseTracking(true);
canvas_gl->installEventFilter(this);
#endif
ui->canvas_raster->grabGesture(Qt::PinchGesture);
@@ -199,6 +200,7 @@ void Graphic::canvasPaintEvent() {
QPainter p(canvas);
p.drawImage(0, 0, *buffer);
painter = &p;
fp_size.clear();
if (curpos != startpos) drawAction();
drawGuides();
return;
@@ -248,6 +250,7 @@ void Graphic::canvasPaintEvent() {
}
#endif
//p.setRenderHint(QPainter::HighQualityAntialiasing, aalias);
fp_size.clear();
if (!aalias) p.translate(-0.5, -0.5);
drawGraphics();
drawGuides();
@@ -264,9 +267,10 @@ void Graphic::canvasPaintEvent() {
void Graphic::canvasMouseMoveEvent(QMouseEvent * e) {
isHover = true;
curpos = e->pos();
QPointF rp = canvas2real(QPointF(e->pos())), srp = canvas2real(startpos), crp = canvas2real(curpos), dp;
QString cursorstr = tr("Cursor: ") + pointCoords(rp);
emit graphicMouseMoveEvent(rp, e->buttons());
curpos_r = canvas2real(curpos);
QPointF dp;
QString cursorstr = tr("Cursor: ") + pointCoords(curpos_r);
emit graphicMouseMoveEvent(curpos_r, e->buttons());
if (e->buttons() == Qt::NoButton) {
ui->status->setText(cursorstr);
if (guides) update();
@@ -276,20 +280,20 @@ void Graphic::canvasMouseMoveEvent(QMouseEvent * e) {
if (curaction != gaMove && (e->buttons() & Qt::RightButton) == Qt::RightButton) return;
switch (curaction) {
case gaZoomInRect:
ui->status->setText(tr("Selection") + ": " + pointCoords(srp) + " -> " +
pointCoords(crp) + ", " + tr("Size") + ": " + pointCoords(absPoint(crp - srp)));
ui->status->setText(tr("Selection") + ": " + pointCoords(startpos_r) + " -> " +
pointCoords(curpos_r) + ", " + tr("Size") + ": " + pointCoords(absPoint(curpos_r - startpos_r)));
repaintCanvas(true);
break;
case gaZoomRangeX:
ui->status->setText(tr("Range") + ": " + QString::number(srp.x(), 'f', 3) +
" -> " + QString::number(crp.x(), 'f', 3) + ", " + tr("Length") + ": " +
QString::number(qAbs(crp.x() - srp.x()), 'f', 3));
ui->status->setText(tr("Range") + ": " + QString::number(startpos_r.x(), 'f', 3) +
" -> " + QString::number(curpos_r.x(), 'f', 3) + ", " + tr("Length") + ": " +
QString::number(qAbs(curpos_r.x() - startpos_r.x()), 'f', 3));
repaintCanvas(true);
break;
case gaZoomRangeY:
ui->status->setText(tr("Range") + ": " + QString::number(srp.y(), 'f', 3) +
" -> " + QString::number(crp.y(), 'f', 3) + ", " + tr("Length") + ": " +
QString::number(qAbs(crp.y() - srp.y()), 'f', 3));
ui->status->setText(tr("Range") + ": " + QString::number(startpos_r.y(), 'f', 3) +
" -> " + QString::number(curpos_r.y(), 'f', 3) + ", " + tr("Length") + ": " +
QString::number(qAbs(curpos_r.y() - startpos_r.y()), 'f', 3));
repaintCanvas(true);
break;
case gaMove:
@@ -321,11 +325,13 @@ void Graphic::canvasMousePressEvent(QMouseEvent * e) {
ui->canvas_raster->setCursor(guides ? Qt::BlankCursor : Qt::ArrowCursor);
prevpos = e->pos();
startpos = prevpos;
startpos_r = canvas2real(startpos);
if (cancel) return;
if (e->button() == Qt::MidButton) curaction = gaMove;
if (e->button() == Qt::RightButton) {
if (bufferActive) {
curpos = startpos;
curpos_r = canvas2real(curpos);
repaintCanvas(true);
swapToNormal();
cancel = true;
@@ -917,19 +923,23 @@ void Graphic::drawAction() {
painter->setPen(selpen);
painter->setBrush(selbrush);
switch (curaction) {
case gaZoomInRect:
case gaZoomInRect: {
QSizeF rsz = QRectF(startpos_r, curpos_r).normalized().size();
painter->drawRect(QRect(startpos, curpos));
break;
fp_size = " x " + pointCoords(QPointF(rsz.width(), rsz.height()));
} break;
case gaZoomRangeX:
painter->drawLine(sx, hei, sx, 0);
painter->drawLine(cx, hei, cx, 0);
painter->fillRect(sx, 0, cx - sx, hei, selbrush);
break;
fp_size = " x " + pointCoords(QPointF(qAbs(startpos_r.x() - curpos_r.x()), 0.), true, false);
break;
case gaZoomRangeY:
painter->drawLine(gridborder.x(), sy, wid, sy);
painter->drawLine(gridborder.x(), cy, wid, cy);
painter->fillRect(gridborder.x(), sy, wid - gridborder.x(), cy - sy, selbrush);
break;
fp_size = " x " + pointCoords(QPointF(0., qAbs(startpos_r.y() - curpos_r.y())), false, true);
break;
default: break;
}
}
@@ -1144,10 +1154,20 @@ void Graphic::drawGraphics() {
}
QString Graphic::pointCoords(QPointF point) {
if (axis_type_x == Numeric)
return "(" + QString::number(point.x(), 'f', 3) + " ; " + QString::number(point.y(), 'f', 3) + ")";
return "(" + QDateTime::fromMSecsSinceEpoch(point.x()).toString() + " ; " + QString::number(point.y(), 'f', 3) + ")";
QString Graphic::pointCoords(QPointF point, bool x, bool y) {
QString ret = "(";
if (x) {
if (axis_type_x == Numeric)
ret += QString::number(point.x(), 'f', 3);
else
ret += QDateTime::fromMSecsSinceEpoch(point.x()).toString();
}
if (y) {
if (ret.size() > 1) ret += " ; ";
ret += QString::number(point.y(), 'f', 3);
}
ret += ")";
return ret;
}
@@ -1161,7 +1181,7 @@ void Graphic::drawGuides() {
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));
QString str = pointCoords(canvas2real(curpos)) + fp_size;
QFontMetrics fm(font());
QRect r = fm.boundingRect(str);
QPoint p = curpos + QPoint(font_sz.height() / 4., -font_sz.height() / 4.);