Skip to content

Commit

Permalink
Allow tabbing to cycle through objects to snap
Browse files Browse the repository at this point in the history
To do this, the object snapping code has been refactored into a snapToObject function. This allows it to be called on different objects easily. A new base class which handles the tab event has been added.
  • Loading branch information
Moult authored and yorikvanhavre committed Feb 8, 2019
1 parent 18b5f23 commit 334a2a3
Show file tree
Hide file tree
Showing 2 changed files with 211 additions and 193 deletions.
17 changes: 14 additions & 3 deletions src/Mod/Draft/DraftGui.py
Expand Up @@ -270,7 +270,17 @@ def displayExternal(internValue,decimals=None,dim='Length',showUnit=True,unit=No
# Customized widgets
#---------------------------------------------------------------------------

class DraftDockWidget(QtGui.QWidget):
class DraftBaseWidget(QtGui.QWidget):
def __init__(self,parent = None):
QtGui.QWidget.__init__(self,parent)
def eventFilter(self, widget, event):
if event.type() == QtCore.QEvent.KeyPress and event.key()==QtCore.Qt.Key_Tab:
if hasattr(FreeCADGui,"Snapper"):
FreeCADGui.Snapper.cycleSnapObject()
return True
return QtGui.QWidget.eventFilter(self, widget, event)

class DraftDockWidget(DraftBaseWidget):
"custom Widget that emits a resized() signal when resized"
def __init__(self,parent = None):
QtGui.QWidget.__init__(self,parent)
Expand Down Expand Up @@ -359,7 +369,7 @@ def __init__(self):

if self.taskmode:
# add only a dummy widget, since widgets are created on demand
self.baseWidget = QtGui.QWidget()
self.baseWidget = DraftBaseWidget()
self.tray = QtGui.QToolBar(None)
self.tray.setObjectName("Draft tray")
self.tray.setWindowTitle("Draft tray")
Expand Down Expand Up @@ -505,6 +515,7 @@ def setupToolBar(self,task=False):
self.layout.addLayout(bl)
self.labelx = self._label("labelx", xl)
self.xValue = self._inputfield("xValue", xl) #width=60
self.xValue.installEventFilter(self.baseWidget)
self.xValue.setText(FreeCAD.Units.Quantity(0,FreeCAD.Units.Length).UserString)
self.labely = self._label("labely", yl)
self.yValue = self._inputfield("yValue", yl)
Expand Down Expand Up @@ -843,7 +854,7 @@ def taskUi(self,title="Draft",extra=None,icon="Draft_Draft"):
if self.taskmode:
self.isTaskOn = True
todo.delay(FreeCADGui.Control.closeDialog,None)
self.baseWidget = QtGui.QWidget()
self.baseWidget = DraftBaseWidget()
self.layout = QtGui.QVBoxLayout(self.baseWidget)
self.setupToolBar(task=True)
self.retranslateUi(self.baseWidget)
Expand Down

0 comments on commit 334a2a3

Please sign in to comment.