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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -467,7 +467,8 @@ protected:
|
||||
viewer,
|
||||
placement,
|
||||
colorManager.dimConstrDeactivatedColor,
|
||||
/*autoDistance = */ true))
|
||||
/*autoDistance = */ true,
|
||||
/*avoidMouseCursor = */ true))
|
||||
.get();
|
||||
|
||||
QObject::connect(parameter, &Gui::EditableDatumLabel::valueChanged, [=](double value) {
|
||||
|
||||
Reference in New Issue
Block a user