From caa612b978d84e40eefebee03df992bcee1bde81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Mon, 28 Jan 2019 16:07:49 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/libs@483 a8b55f48-bf90-11e4-a774-851b48703e85 --- qad/graphic/graphic.cpp | 60 ++-- qad/graphic/graphic.h | 5 +- qad/graphic/qpicalculator/mainwindow.ui | 347 +++++++++--------------- 3 files changed, 171 insertions(+), 241 deletions(-) diff --git a/qad/graphic/graphic.cpp b/qad/graphic/graphic.cpp index debef34..95a304b 100644 --- a/qad/graphic/graphic.cpp +++ b/qad/graphic/graphic.cpp @@ -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.); diff --git a/qad/graphic/graphic.h b/qad/graphic/graphic.h index 28f9c63..a78bfa2 100644 --- a/qad/graphic/graphic.h +++ b/qad/graphic/graphic.h @@ -343,7 +343,7 @@ protected: void roundDateTime(QDateTime & dt, int c[7]); void addDateTime(QDateTime & dt, int c[7], int mul = 1); QPointF absPoint(QPointF point) {return QPointF(qAbs(point.x()), qAbs(point.y()));} - QString pointCoords(QPointF point); + QString pointCoords(QPointF point, bool x = true, bool y = true); QPair gridMark(double v) const; Ui::Graphic * ui; @@ -362,7 +362,8 @@ protected: QRect margins_; QSize font_sz; QPoint startpos, curpos, prevpos, gridborder; - QString label_x, label_y, ppath; + QPointF startpos_r, curpos_r; + QString label_x, label_y, ppath, fp_size; Graphic::Buttons buttons_; Graphic::Alignment align; GraphicConf * conf; diff --git a/qad/graphic/qpicalculator/mainwindow.ui b/qad/graphic/qpicalculator/mainwindow.ui index dc76d26..234fed7 100644 --- a/qad/graphic/qpicalculator/mainwindow.ui +++ b/qad/graphic/qpicalculator/mainwindow.ui @@ -29,21 +29,6 @@ Calculator - - 2 - - - 2 - - - 2 - - - 2 - - - 2 - @@ -126,21 +111,6 @@ Variables - - 2 - - - 2 - - - 2 - - - 2 - - - 2 - @@ -178,21 +148,12 @@ - - 2 - :/icons/list-add.png:/icons/list-add.png - - - 16 - 16 - - @@ -204,12 +165,6 @@ :/icons/edit-delete.png:/icons/edit-delete.png - - - 16 - 16 - - Del @@ -240,12 +195,6 @@ :/icons/edit-clear.png:/icons/edit-clear.png - - - 16 - 16 - - @@ -269,177 +218,137 @@ Graphics - - - 2 - - - 2 - - - 2 - - - 2 - - - 2 - + - - - - 0 - 0 - - - - Qt::ScrollBarAlwaysOff - - - QAbstractItemView::ExtendedSelection - - - QAbstractItemView::ScrollPerPixel - - - QAbstractItemView::ScrollPerPixel - - - false - - - false - - - true - - - false - - - 50 - - - - On - - - - - Function - - - - - - - - 2 - - - - - - :/icons/list-add.png:/icons/list-add.png - - - - 16 - 16 - - - - - - - - false - - - - :/icons/edit-delete.png:/icons/edit-delete.png - - - - 16 - 16 - - - - Del - - - - - - - Qt::Vertical - - - QSizePolicy::Preferred - - - - 20 - 20 - - - - - - - - false - - - - :/icons/edit-clear.png:/icons/edit-clear.png - - - - 16 - 16 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - + - Qt::Vertical - - - - - - - Graphic::BorderInputs|Graphic::Configure|Graphic::CursorAxis|Graphic::Fullscreen|Graphic::Grid|Graphic::Save - - - true - - - false - - - false + Qt::Horizontal + + + + + + Qt::ScrollBarAlwaysOff + + + QAbstractItemView::ExtendedSelection + + + QAbstractItemView::ScrollPerPixel + + + QAbstractItemView::ScrollPerPixel + + + false + + + false + + + true + + + false + + + 50 + + + + On + + + + + Function + + + + + + + + + + + :/icons/list-add.png:/icons/list-add.png + + + + + + + false + + + + :/icons/edit-delete.png:/icons/edit-delete.png + + + Del + + + + + + + Qt::Vertical + + + QSizePolicy::Preferred + + + + 20 + 20 + + + + + + + + false + + + + :/icons/edit-clear.png:/icons/edit-clear.png + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Graphic::BorderInputs|Graphic::Configure|Graphic::CursorAxis|Graphic::Fullscreen|Graphic::Grid|Graphic::Save + + + true + + + false + + + false + +