From 9d7682c01fee7fbe7c9a89eadc59ab0508d9d608 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Mon, 11 Mar 2024 17:54:07 +0100 Subject: [PATCH] Draft: Introduce mouse delay (#12624) * Draft: Introduce mouse delay - fixes #11807 * Draft: set default mouse delay to 1 --- src/Mod/Draft/DraftGui.py | 17 + .../Resources/ui/preferences-draftsnap.ui | 459 +++++++++++------- .../Draft/draftguitools/gui_base_original.py | 1 + src/Mod/Draft/draftguitools/gui_tool_utils.py | 2 + 4 files changed, 297 insertions(+), 182 deletions(-) diff --git a/src/Mod/Draft/DraftGui.py b/src/Mod/Draft/DraftGui.py index 4748012a98..d2d95d51b2 100644 --- a/src/Mod/Draft/DraftGui.py +++ b/src/Mod/Draft/DraftGui.py @@ -160,6 +160,7 @@ class DraftToolBar: def __init__(self): self.tray = None self.sourceCmd = None + self.mouse = True self.cancel = None self.pointcallback = None @@ -1096,6 +1097,8 @@ class DraftToolBar: if txt == "" or txt[0] in "0123456789.,-": self.updateSnapper() + if txt[0] in "0123456789.,-": + self.setMouseMode(False) return txt = txt[0].upper() @@ -1207,6 +1210,20 @@ class DraftToolBar: FreeCAD.Vector(self.x,self.y,self.z)) FreeCADGui.Snapper.trackLine.p2(last.add(delta)) + def setMouseMode(self, mode=True): + """Sets self.mouse True (default) or False and sets a timer + to set it back to True if applicable. self.mouse is then + used by gui_tools_utils.get_point() to know if the mouse can + update field values and point position or not.""" + if mode == True: + self.mouse = True + else: + delay = params.get_param("MouseDelay") + if delay: + if self.mouse is True: + self.mouse = False + QtCore.QTimer.singleShot(delay*1000, self.setMouseMode) + def checkEnterText(self): """this function checks if the entered text ends with two blank lines""" t = self.textValue.toPlainText() diff --git a/src/Mod/Draft/Resources/ui/preferences-draftsnap.ui b/src/Mod/Draft/Resources/ui/preferences-draftsnap.ui index 9fac2e398a..9285dbba98 100644 --- a/src/Mod/Draft/Resources/ui/preferences-draftsnap.ui +++ b/src/Mod/Draft/Resources/ui/preferences-draftsnap.ui @@ -7,7 +7,7 @@ 0 0 518 - 645 + 719 @@ -162,6 +162,12 @@ These lines are thicker than normal grid lines. Qt::Horizontal + + + 0 + 0 + + @@ -176,24 +182,24 @@ These lines are thicker than normal grid lines. The distance between grid lines - - 4 + + mm 9999.989999999999782 - + 1.000000000000000 - - mm - gridSpacing Mod/Draft + + 4 + @@ -263,7 +269,7 @@ These lines are thicker than normal grid lines. The color of the grid - + 50 50 @@ -287,71 +293,7 @@ These lines are thicker than normal grid lines. Snapping and modifier keys - - - - Snap symbol style - - - - - - - The style for snap symbols - - - snapStyle - - - Mod/Draft - - - - Draft classic style - - - - - Bitsnpieces style - - - - - - - - Qt::Horizontal - - - - - - - Snap symbol color - - - - - - - The color for snap symbols - - - - 255 - 170 - 255 - - - - snapcolor - - - Mod/Draft - - - - + If checked, snapping is activated without the need to press the Snap modifier key @@ -370,99 +312,7 @@ These lines are thicker than normal grid lines. - - - - false - - - Snap modifier - - - - - - - - 140 - 0 - - - - false - - - The Snap modifier key - - - 1 - - - modsnap - - - Mod/Draft - - - - Shift - - - - - Ctrl - - - - - Alt - - - - - - - - Constrain modifier - - - - - - - The Constrain modifier key - - - modconstrain - - - Mod/Draft - - - - Shift - - - - - Ctrl - - - - - Alt - - - - - - - - Alt modifier - - - - + The Alt modifier key. The function of this key depends on the command. @@ -493,6 +343,200 @@ These lines are thicker than normal grid lines. + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + + The color for snap symbols + + + + 255 + 170 + 255 + + + + snapcolor + + + Mod/Draft + + + + + + + false + + + Snap modifier + + + + + + + Constrain modifier + + + + + + + Alt modifier + + + + + + + Snap symbol color + + + + + + + The style for snap symbols + + + snapStyle + + + Mod/Draft + + + + Draft classic style + + + + + Bitsnpieces style + + + + + + + + Snap symbol style + + + + + + + false + + + + 140 + 0 + + + + The Snap modifier key + + + 1 + + + modsnap + + + Mod/Draft + + + + Shift + + + + + Ctrl + + + + + Alt + + + + + + + + The Constrain modifier key + + + modconstrain + + + Mod/Draft + + + + Shift + + + + + Ctrl + + + + + Alt + + + + + + + + Mouse delay + + + + + + + This is a delay during which the mouse is inactive, after entering +numbers manually in any of the coordinate fields. Setting this +to 0 disables the delay. If a delay of 1 is set, after enterting a numeric +value, the mouse will not update the field anymore during one +second, to avoid moving the mouse accidentally and modify the +entered value. If you use a very large value, for ex. 3600, mouse +movement will be disabled until the command finishes. + + + seconds + + + 1 + + + MouseDelay + + + Mod/Draft + + + @@ -501,6 +545,12 @@ These lines are thicker than normal grid lines. Qt::Vertical + + + 0 + 0 + + @@ -508,6 +558,26 @@ These lines are thicker than normal grid lines. qPixmapFromMimeSource + + Gui::QuantitySpinBox + QWidget +
Gui/QuantitySpinBox.h
+
+ + Gui::ColorButton + QPushButton +
Gui/Widgets.h
+
+ + Gui::PrefSpinBox + QSpinBox +
Gui/PrefWidgets.h
+
+ + Gui::PrefColorButton + Gui::ColorButton +
Gui/PrefWidgets.h
+
Gui::PrefCheckBox QCheckBox @@ -518,24 +588,9 @@ These lines are thicker than normal grid lines. QComboBox
Gui/PrefWidgets.h
- - Gui::PrefSpinBox - QSpinBox -
Gui/PrefWidgets.h
-
Gui::PrefQuantitySpinBox - QDoubleSpinBox -
Gui/PrefWidgets.h
-
- - Gui::ColorButton - QPushButton -
Gui/Widgets.h
-
- - Gui::PrefColorButton - Gui::ColorButton + Gui::QuantitySpinBox
Gui/PrefWidgets.h
@@ -546,24 +601,64 @@ These lines are thicker than normal grid lines. toggled(bool) checkBox_grid setDisabled(bool) + + + 20 + 20 + + + 20 + 20 + + checkBox_gridBorder toggled(bool) checkBox_gridShowHuman setEnabled(bool) + + + 20 + 20 + + + 20 + 20 + + checkBox_alwaysSnap toggled(bool) label_modsnap setDisabled(bool) + + + 20 + 20 + + + 20 + 20 + + checkBox_alwaysSnap toggled(bool) comboBox_modsnap setDisabled(bool) + + + 20 + 20 + + + 20 + 20 + + diff --git a/src/Mod/Draft/draftguitools/gui_base_original.py b/src/Mod/Draft/draftguitools/gui_base_original.py index 45777c35d4..ca3c263ada 100644 --- a/src/Mod/Draft/draftguitools/gui_base_original.py +++ b/src/Mod/Draft/draftguitools/gui_base_original.py @@ -128,6 +128,7 @@ class DraftTool: self.pos = [] self.support = None self.ui = Gui.draftToolBar + self.ui.mouse = True # reset mouse movement self.ui.sourceCmd = self self.view = gui_utils.get_3d_view() self.wp = WorkingPlane.get_working_plane() diff --git a/src/Mod/Draft/draftguitools/gui_tool_utils.py b/src/Mod/Draft/draftguitools/gui_tool_utils.py index 4a45b07ff1..b75645606d 100644 --- a/src/Mod/Draft/draftguitools/gui_tool_utils.py +++ b/src/Mod/Draft/draftguitools/gui_tool_utils.py @@ -190,6 +190,8 @@ def get_point(target, args, noTracker=False): returned by the `Snapper` or by the `ActiveView`. """ ui = Gui.draftToolBar + if not ui.mouse: + return None, None, None if target.node: last = target.node[-1]