From fc472601e4bc67ae58b8ff74e8de22bcb1b0a2e9 Mon Sep 17 00:00:00 2001 From: Paddle Date: Mon, 6 Nov 2023 22:39:30 +0100 Subject: [PATCH] EditableDatumLabel : Fix issue where the spinbox would get in the way of the cursor for angle. For example line angle. --- src/Gui/EditableDatumLabel.cpp | 17 +++++++++++++++-- src/Gui/EditableDatumLabel.h | 3 ++- src/Mod/Sketcher/Gui/DrawSketchController.h | 3 ++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Gui/EditableDatumLabel.cpp b/src/Gui/EditableDatumLabel.cpp index 4cab14416f..c7dc1afe7e 100644 --- a/src/Gui/EditableDatumLabel.cpp +++ b/src/Gui/EditableDatumLabel.cpp @@ -47,10 +47,12 @@ struct NodeData { EditableDatumLabel::EditableDatumLabel(View3DInventorViewer* view, const Base::Placement& plc, SbColor color, - bool autoDistance) + bool autoDistance, + bool avoidMouseCursor) : isSet(false) , autoDistance(autoDistance) , autoDistanceReverse(false) + , avoidMouseCursor(avoidMouseCursor) , value(0.0) , viewer(view) , spinBox(nullptr) @@ -246,8 +248,19 @@ void EditableDatumLabel::positionSpinbox() QSize wSize = spinBox->size(); QSize vSize = viewer->size(); QPoint pxCoord = viewer->toQPoint(viewer->getPointOnViewport(getTextCenterPoint())); + int posX = std::min(std::max(pxCoord.x() - wSize.width() / 2, 0), vSize.width() - wSize.width()); int posY = std::min(std::max(pxCoord.y() - wSize.height() / 2, 0), vSize.height() - wSize.height()); + + if (avoidMouseCursor) { + QPoint cursorPos = viewer->mapFromGlobal(QCursor::pos()); + int margin = static_cast(wSize.height() * 0.7); // NOLINT + if ((cursorPos.x() > posX - margin && cursorPos.x() < posX + wSize.width() + margin) + && (cursorPos.y() > posY - margin && cursorPos.y() < posY + wSize.height() + margin)) { + posY = cursorPos.y() + ((cursorPos.y() > pxCoord.y()) ? - wSize.height() - margin : margin); + } + } + pxCoord.setX(posX); pxCoord.setY(posY); spinBox->move(pxCoord); @@ -380,4 +393,4 @@ void EditableDatumLabel::setSpinboxVisibleToMouse(bool val) spinBox->setAttribute(Qt::WA_TransparentForMouseEvents, !val); } -#include "moc_EditableDatumLabel.cpp" +#include "moc_EditableDatumLabel.cpp" // NOLINT diff --git a/src/Gui/EditableDatumLabel.h b/src/Gui/EditableDatumLabel.h index 482aa044b7..e5c108bef7 100644 --- a/src/Gui/EditableDatumLabel.h +++ b/src/Gui/EditableDatumLabel.h @@ -45,7 +45,7 @@ class GuiExport EditableDatumLabel : public QObject Q_DISABLE_COPY(EditableDatumLabel) public: - EditableDatumLabel(View3DInventorViewer* view, const Base::Placement& plc, SbColor color, bool autoDistance = false); + EditableDatumLabel(View3DInventorViewer* view, const Base::Placement& plc, SbColor color, bool autoDistance = false, bool avoidMouseCursor = false); ~EditableDatumLabel() override; void activate(); @@ -76,6 +76,7 @@ public: bool isSet; bool autoDistance; bool autoDistanceReverse; + bool avoidMouseCursor; double value; // NOLINTEND diff --git a/src/Mod/Sketcher/Gui/DrawSketchController.h b/src/Mod/Sketcher/Gui/DrawSketchController.h index f7685ef38d..fc900f1a66 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchController.h +++ b/src/Mod/Sketcher/Gui/DrawSketchController.h @@ -467,7 +467,8 @@ protected: viewer, placement, colorManager.dimConstrDeactivatedColor, - /*autoDistance = */ true)) + /*autoDistance = */ true, + /*avoidMouseCursor = */ true)) .get(); QObject::connect(parameter, &Gui::EditableDatumLabel::valueChanged, [=](double value) {