Skip to content

Commit

Permalink
Draft: fix snapper icons
Browse files Browse the repository at this point in the history
* Add convenience function to get 3D views from MDI area
* Use 'inherits' instead of 'QMetaObject.className()' to check more reliably for sub-classes
  • Loading branch information
wwmayer committed Aug 11, 2022
1 parent cb96332 commit 2b5b7cd
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/Mod/Draft/draftguitools/gui_snapper.py
Expand Up @@ -1157,13 +1157,18 @@ def get_cursor_size(self):
# This should be in device-independent pixels
return 32

def get_quarter_widget(self, mw):
views = []
for w in mw.findChild(QtGui.QMdiArea).findChildren(QtGui.QWidget):
if w.inherits("SIM::Coin3D::Quarter::QuarterWidget"):
views.append(w)
return views

def device_pixel_ratio(self):
device_pixel_ratio = 1
mw = Gui.getMainWindow()
for w in mw.findChild(QtGui.QMdiArea).findChildren(QtGui.QWidget):
if w.metaObject().className() == "SIM::Coin3D::Quarter::QuarterWidget":
if int(QtCore.qVersion().split('.')[0]) > 4:
device_pixel_ratio = w.devicePixelRatio()
for w in self.get_quarter_widget(Gui.getMainWindow()):
if int(QtCore.qVersion().split('.')[0]) > 4:
device_pixel_ratio = w.devicePixelRatio()
return device_pixel_ratio

def get_cursor_with_tail(self, base_icon_name, tail_icon_name=None):
Expand Down Expand Up @@ -1195,16 +1200,12 @@ def get_cursor_with_tail(self, base_icon_name, tail_icon_name=None):
def setCursor(self, mode=None):
"""Set or reset the cursor to the given mode or resets."""
if self.selectMode:
mw = Gui.getMainWindow()
for w in mw.findChild(QtGui.QMdiArea).findChildren(QtGui.QWidget):
if w.metaObject().className() == "SIM::Coin3D::Quarter::QuarterWidget":
w.unsetCursor()
for w in self.get_quarter_widget(Gui.getMainWindow()):
w.unsetCursor()
self.cursorMode = None
elif not mode:
mw = Gui.getMainWindow()
for w in mw.findChild(QtGui.QMdiArea).findChildren(QtGui.QWidget):
if w.metaObject().className() == "SIM::Coin3D::Quarter::QuarterWidget":
w.unsetCursor()
for w in self.get_quarter_widget(Gui.getMainWindow()):
w.unsetCursor()
self.cursorMode = None
else:
if mode != self.cursorMode:
Expand All @@ -1213,10 +1214,8 @@ def setCursor(self, mode=None):
if not (mode == 'passive'):
tail_icon_name = self.cursors[mode]
cur = self.get_cursor_with_tail(base_icon_name, tail_icon_name)
mw = Gui.getMainWindow()
for w in mw.findChild(QtGui.QMdiArea).findChildren(QtGui.QWidget):
if w.metaObject().className() == "SIM::Coin3D::Quarter::QuarterWidget":
w.setCursor(cur)
for w in self.get_quarter_widget(Gui.getMainWindow()):
w.setCursor(cur)
self.cursorMode = mode

def restack(self):
Expand Down

0 comments on commit 2b5b7cd

Please sign in to comment.