Debug информация о теге линии
This commit is contained in:
31
Canvas.cpp
31
Canvas.cpp
@@ -76,11 +76,11 @@ void Canvas::changeMode(Mode _mode)
|
|||||||
// Методы поиска и проверки
|
// Методы поиска и проверки
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
|
|
||||||
Line* Canvas::findAt(QPointF& pos)
|
Line* Canvas::findAt(QPointF& pos, qreal tolerance)
|
||||||
{
|
{
|
||||||
// TODO: реализовать проверку, находится ли точка на линии
|
// TODO: реализовать проверку, находится ли точка на линии
|
||||||
for (Line* line : lines) {
|
for (Line* line : lines) {
|
||||||
if (line->contains(pos)) {
|
if (line->contains(pos, tolerance)) {
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,7 +186,7 @@ void Canvas::remove_constraints()
|
|||||||
|
|
||||||
void Canvas::mousePressEvent(QMouseEvent* event)
|
void Canvas::mousePressEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
QPointF scene = screenToLogical(event->pos());
|
QPointF scene = UCS_POSITION;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
qDebug() << "Scene point in" << scene.x() << scene.y();
|
qDebug() << "Scene point in" << scene.x() << scene.y();
|
||||||
@@ -373,9 +373,9 @@ void Canvas::mousePressEvent(QMouseEvent* event)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Линии уже параллельны - сообщаем об ошибке
|
// Линии уже параллельны - сообщаем об ошибке
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
qDebug() << "Line" << current_line << "and" << found << "are parallel. Abort!";
|
qDebug() << "Line" << current_line << "and" << found << "are parallel. Abort!";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QMessageBox::warning(this,
|
QMessageBox::warning(this,
|
||||||
QString("Wrong"),
|
QString("Wrong"),
|
||||||
@@ -449,7 +449,7 @@ void Canvas::mouseMoveEvent(QMouseEvent* event)
|
|||||||
{
|
{
|
||||||
// ====================== Перемещение точки ======================
|
// ====================== Перемещение точки ======================
|
||||||
if (draggedPoint) {
|
if (draggedPoint) {
|
||||||
QPointF pos = screenToLogical(event->pos()) - dragOffset;
|
QPointF pos = UCS_POSITION - dragOffset;
|
||||||
|
|
||||||
// Обновляем все связанные точки (совпадающие, горизонтальные, вертикальные)
|
// Обновляем все связанные точки (совпадающие, горизонтальные, вертикальные)
|
||||||
for (Point* pair : points) {
|
for (Point* pair : points) {
|
||||||
@@ -472,7 +472,7 @@ void Canvas::mouseMoveEvent(QMouseEvent* event)
|
|||||||
|
|
||||||
// ====================== Перемещение линии ======================
|
// ====================== Перемещение линии ======================
|
||||||
else if (draggedLine) {
|
else if (draggedLine) {
|
||||||
QPointF newCenter = screenToLogical(event->pos()) - dragOffset;
|
QPointF newCenter = UCS_POSITION - dragOffset;
|
||||||
QPointF oldCenter(
|
QPointF oldCenter(
|
||||||
(*draggedLine->p1.x + *draggedLine->p2.x) / 2.0,
|
(*draggedLine->p1.x + *draggedLine->p2.x) / 2.0,
|
||||||
(*draggedLine->p1.y + *draggedLine->p2.y) / 2.0
|
(*draggedLine->p1.y + *draggedLine->p2.y) / 2.0
|
||||||
@@ -499,9 +499,12 @@ void Canvas::mouseMoveEvent(QMouseEvent* event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
#ifdef _DEBUG
|
||||||
|
else
|
||||||
|
showObjectTag(WIDGET_POSITION);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::mouseReleaseEvent(QMouseEvent* event)
|
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 Canvas::screenToLogical(const QPointF& screenPos) const
|
||||||
{
|
{
|
||||||
QPointF logical = screenPos;
|
QPointF logical = screenPos;
|
||||||
|
|||||||
11
Canvas.h
11
Canvas.h
@@ -1,9 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#define WIDGET_POSITION event->pos()
|
||||||
|
#define UCS_POSITION screenToLogical(WIDGET_POSITION)
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QPointF>
|
#include <QPointF>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QToolTip>
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@@ -58,11 +62,16 @@ protected:
|
|||||||
void paintEvent(QPaintEvent* event) override;
|
void paintEvent(QPaintEvent* event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
void showObjectTag(QPointF pos);
|
||||||
|
#endif
|
||||||
|
|
||||||
QPointF screenToLogical(const QPointF& screenPos) const;
|
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);
|
Point* findPointAt(QPointF position, qreal tolerance = 5.0);
|
||||||
|
|||||||
Reference in New Issue
Block a user