EditableDatumLabel : Fix issue where the spinbox would get in the way of the cursor for angle. For example line angle.

This commit is contained in:
Paddle
2023-11-06 22:39:30 +01:00
committed by abdullahtahiriyo
parent f8be4d5f45
commit fc472601e4
3 changed files with 19 additions and 4 deletions

View File

@@ -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<int>(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