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.);

View File

@@ -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<QString, QString> 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;

View File

@@ -29,21 +29,6 @@
<string>Calculator</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QTreeWidget" name="treeHistory">
<property name="horizontalScrollBarPolicy">
@@ -126,21 +111,6 @@
<string>Variables</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QTreeWidget" name="treeVariables">
<property name="horizontalScrollBarPolicy">
@@ -178,21 +148,12 @@
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QToolButton" name="buttonVarAdd">
<property name="icon">
<iconset resource="../../utils/qad_utils.qrc">
<normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
</widget>
</item>
<item>
@@ -204,12 +165,6 @@
<iconset resource="../../utils/qad_utils.qrc">
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="shortcut">
<string>Del</string>
</property>
@@ -240,12 +195,6 @@
<iconset resource="../../utils/qad_utils.qrc">
<normaloff>:/icons/edit-clear.png</normaloff>:/icons/edit-clear.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
</widget>
</item>
<item>
@@ -269,177 +218,137 @@
<attribute name="title">
<string>Graphics</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QTreeWidget" name="treeGraphics">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="horizontalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="itemsExpandable">
<bool>false</bool>
</property>
<property name="allColumnsShowFocus">
<bool>true</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<attribute name="headerDefaultSectionSize">
<number>50</number>
</attribute>
<column>
<property name="text">
<string>On</string>
</property>
</column>
<column>
<property name="text">
<string>Function</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QToolButton" name="buttonGraphicAdd">
<property name="icon">
<iconset resource="../../utils/qad_utils.qrc">
<normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonGraphicDel">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../../utils/qad_utils.qrc">
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="shortcut">
<string>Del</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="buttonGraphicClear">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../../utils/qad_utils.qrc">
<normaloff>:/icons/edit-clear.png</normaloff>:/icons/edit-clear.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="Graphic" name="graphic">
<property name="buttons">
<set>Graphic::BorderInputs|Graphic::Configure|Graphic::CursorAxis|Graphic::Fullscreen|Graphic::Grid|Graphic::Save</set>
</property>
<property name="antialiasing">
<bool>true</bool>
</property>
<property name="borderInputsVisible">
<bool>false</bool>
</property>
<property name="legendVisible">
<bool>false</bool>
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QTreeWidget" name="treeGraphics">
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="horizontalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="itemsExpandable">
<bool>false</bool>
</property>
<property name="allColumnsShowFocus">
<bool>true</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<attribute name="headerDefaultSectionSize">
<number>50</number>
</attribute>
<column>
<property name="text">
<string>On</string>
</property>
</column>
<column>
<property name="text">
<string>Function</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QToolButton" name="buttonGraphicAdd">
<property name="icon">
<iconset resource="../../utils/qad_utils.qrc">
<normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonGraphicDel">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../../utils/qad_utils.qrc">
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
</property>
<property name="shortcut">
<string>Del</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="buttonGraphicClear">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../../utils/qad_utils.qrc">
<normaloff>:/icons/edit-clear.png</normaloff>:/icons/edit-clear.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="Graphic" name="graphic">
<property name="buttons">
<set>Graphic::BorderInputs|Graphic::Configure|Graphic::CursorAxis|Graphic::Fullscreen|Graphic::Grid|Graphic::Save</set>
</property>
<property name="antialiasing">
<bool>true</bool>
</property>
<property name="borderInputsVisible">
<bool>false</bool>
</property>
<property name="legendVisible">
<bool>false</bool>
</property>
</widget>
</widget>
</item>
</layout>