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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user