From c283720a99886c847b0f9782015097ab81b7d7cf Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Mon, 15 Dec 2025 12:57:36 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=BE=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=D0=B1=D0=BB=D0=B8=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D1=8F=20Issue=20#?= =?UTF-8?q?3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Canvas.cpp | 23 +++++++++++++++++++---- Canvas.h | 1 + 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Canvas.cpp b/Canvas.cpp index d3e9b89..ea9487c 100644 --- a/Canvas.cpp +++ b/Canvas.cpp @@ -186,7 +186,7 @@ void Canvas::remove_constraints() void Canvas::mousePressEvent(QMouseEvent* event) { - QPointF scene = event->pos(); + QPointF scene = screenToLogical(event->pos()); #ifdef _DEBUG qDebug() << "Scene point in" << scene.x() << scene.y(); @@ -449,7 +449,7 @@ void Canvas::mouseMoveEvent(QMouseEvent* event) { // ====================== Перемещение точки ====================== if (draggedPoint) { - QPointF pos = event->pos() - dragOffset; + QPointF pos = screenToLogical(event->pos()) - dragOffset; // Обновляем все связанные точки (совпадающие, горизонтальные, вертикальные) for (Point* pair : points) { @@ -472,7 +472,7 @@ void Canvas::mouseMoveEvent(QMouseEvent* event) // ====================== Перемещение линии ====================== else if (draggedLine) { - QPointF newCenter = event->pos() - dragOffset; + QPointF newCenter = screenToLogical(event->pos()) - dragOffset; QPointF oldCenter( (*draggedLine->p1.x + *draggedLine->p2.x) / 2.0, (*draggedLine->p1.y + *draggedLine->p2.y) / 2.0 @@ -529,6 +529,12 @@ void Canvas::paintEvent(QPaintEvent* event) QPainter p(this); p.setRenderHint(QPainter::Antialiasing, true); + p.translate(width() / 2.0, height() / 2.0); + + p.setPen(Qt::red); + p.drawLine(-5, 0, 5, 0); + p.drawLine(0, -5, 0, 5); + // ====================== Решение системы уравнений ====================== if (!params.empty()) { @@ -587,4 +593,13 @@ void Canvas::paintEvent(QPaintEvent* event) p.setPen(Qt::NoPen); p.drawEllipse(QPointF(*current_line->p1.x, *current_line->p1.y), 6, 6); } -} \ No newline at end of file +} + +QPointF Canvas::screenToLogical(const QPointF& screenPos) const +{ + QPointF logical = screenPos; + logical.rx() -= width() / 2.0; + logical.ry() -= height() / 2.0; + + return logical; +} diff --git a/Canvas.h b/Canvas.h index d39d906..5e2de41 100644 --- a/Canvas.h +++ b/Canvas.h @@ -58,6 +58,7 @@ protected: void paintEvent(QPaintEvent* event) override; private: + QPointF screenToLogical(const QPointF& screenPos) const; // ====================== Методы поиска и выбора ====================== /// Найти линию под указанной позицией From a6cf2bb13ed2e943829e1d2bd702fe4bb9a5b675 Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Mon, 15 Dec 2025 15:27:48 +0300 Subject: [PATCH 2/2] =?UTF-8?q?Debug=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BE=20=D1=82=D0=B5=D0=B3?= =?UTF-8?q?=D0=B5=20=D0=BB=D0=B8=D0=BD=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Canvas.cpp | 31 +++++++++++++++++++++++-------- Canvas.h | 11 ++++++++++- GCS/Geo.h | 2 +- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/Canvas.cpp b/Canvas.cpp index ea9487c..ddb260c 100644 --- a/Canvas.cpp +++ b/Canvas.cpp @@ -76,11 +76,11 @@ void Canvas::changeMode(Mode _mode) // Методы поиска и проверки // =================================================================== -Line* Canvas::findAt(QPointF& pos) +Line* Canvas::findAt(QPointF& pos, qreal tolerance) { // TODO: реализовать проверку, находится ли точка на линии for (Line* line : lines) { - if (line->contains(pos)) { + if (line->contains(pos, tolerance)) { return line; } } @@ -186,7 +186,7 @@ void Canvas::remove_constraints() void Canvas::mousePressEvent(QMouseEvent* event) { - QPointF scene = screenToLogical(event->pos()); + QPointF scene = UCS_POSITION; #ifdef _DEBUG qDebug() << "Scene point in" << scene.x() << scene.y(); @@ -373,9 +373,9 @@ void Canvas::mousePressEvent(QMouseEvent* event) } else { // Линии уже параллельны - сообщаем об ошибке -#ifdef _DEBUG + #ifdef _DEBUG qDebug() << "Line" << current_line << "and" << found << "are parallel. Abort!"; -#endif + #endif QMessageBox::warning(this, QString("Wrong"), @@ -449,7 +449,7 @@ void Canvas::mouseMoveEvent(QMouseEvent* event) { // ====================== Перемещение точки ====================== if (draggedPoint) { - QPointF pos = screenToLogical(event->pos()) - dragOffset; + QPointF pos = UCS_POSITION - dragOffset; // Обновляем все связанные точки (совпадающие, горизонтальные, вертикальные) for (Point* pair : points) { @@ -472,7 +472,7 @@ void Canvas::mouseMoveEvent(QMouseEvent* event) // ====================== Перемещение линии ====================== else if (draggedLine) { - QPointF newCenter = screenToLogical(event->pos()) - dragOffset; + QPointF newCenter = UCS_POSITION - dragOffset; QPointF oldCenter( (*draggedLine->p1.x + *draggedLine->p2.x) / 2.0, (*draggedLine->p1.y + *draggedLine->p2.y) / 2.0 @@ -499,9 +499,12 @@ void Canvas::mouseMoveEvent(QMouseEvent* event) } } } - update(); } + #ifdef _DEBUG + else + showObjectTag(WIDGET_POSITION); + #endif } void Canvas::mouseReleaseEvent(QMouseEvent* event) @@ -595,6 +598,18 @@ void Canvas::paintEvent(QPaintEvent* event) } } +#ifdef _DEBUG +void Canvas::showObjectTag(QPointF pos) +{ + QPointF l = screenToLogical(pos); + Line* lineUnderCursor = findAt(l, 2.0); + if (lineUnderCursor && lineUnderCursor != draggedLine) { + QString Text = QString("Tag Line: %1").arg(lineUnderCursor->get_tag()); + QToolTip::showText(mapToGlobal(pos.toPoint()), Text, this); + } +} +#endif + QPointF Canvas::screenToLogical(const QPointF& screenPos) const { QPointF logical = screenPos; diff --git a/Canvas.h b/Canvas.h index 5e2de41..e01429c 100644 --- a/Canvas.h +++ b/Canvas.h @@ -1,9 +1,13 @@ #pragma once +#define WIDGET_POSITION event->pos() +#define UCS_POSITION screenToLogical(WIDGET_POSITION) + #include #include #include #include +#include #ifdef _DEBUG #include @@ -58,11 +62,16 @@ protected: void paintEvent(QPaintEvent* event) override; private: + +#ifdef _DEBUG + void showObjectTag(QPointF pos); +#endif + QPointF screenToLogical(const QPointF& screenPos) const; // ====================== Методы поиска и выбора ====================== /// Найти линию под указанной позицией - Line* findAt(QPointF& position); + Line* findAt(QPointF& pos, qreal tolerance = 5.0); /// Найти точку в указанной позиции с заданной точностью Point* findPointAt(QPointF position, qreal tolerance = 5.0); diff --git a/GCS/Geo.h b/GCS/Geo.h index 7c513b0..42e183d 100644 --- a/GCS/Geo.h +++ b/GCS/Geo.h @@ -239,7 +239,7 @@ public: void set_tag(int); int get_tag(); - bool contains(QPointF, qreal tol = 5.0) const; + bool contains(QPointF, qreal tol) const; };