From 23bf4e745d098bf4d7c8bf43d38f8fc2466a7146 Mon Sep 17 00:00:00 2001 From: 0penBrain <48731257+0penBrain@users.noreply.github.com> Date: Sun, 12 Apr 2020 12:00:41 +0200 Subject: [PATCH] [Sketcher] Ensure datum edit dialog is fully shown over the main window --- src/Mod/Sketcher/Gui/EditDatumDialog.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp index 131ca74ac7..737e4bf864 100644 --- a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp +++ b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp @@ -136,8 +136,17 @@ void EditDatumDialog::exec(bool atCursor) connect(&dlg, SIGNAL(accepted()), this, SLOT(accepted())); connect(&dlg, SIGNAL(rejected()), this, SLOT(rejected())); - if (atCursor) - dlg.setGeometry(QCursor::pos().x() - dlg.geometry().width() / 2, QCursor::pos().y(), dlg.geometry().width(), dlg.geometry().height()); + if (atCursor) { + dlg.show(); // Need to show the dialog so geometry is computed + QRect pg = dlg.parentWidget()->geometry(); + int Xmin = pg.x() + 10; + int Ymin = pg.y() + 10; + int Xmax = pg.x() + pg.width() - dlg.geometry().width() - 10; + int Ymax = pg.y() + pg.height() - dlg.geometry().height() - 10; + int x = Xmax < Xmin ? (Xmin + Xmax)/2 : std::min(std::max(QCursor::pos().x(), Xmin), Xmax); + int y = Ymax < Ymin ? (Ymin + Ymax)/2 : std::min(std::max(QCursor::pos().y(), Ymin), Ymax); + dlg.setGeometry(x, y, dlg.geometry().width(), dlg.geometry().height()); + } dlg.exec(); }