7 """ Interface for classes containing VispaWidgets
9 Only makes sense if implementing class also inherits QWidget or class inheriting QWidget.
19 """ Returns a list of all selected widgets.
21 if hasattr(self,
"_selectedWidgets"):
23 return [child
for child
in self.children()
if hasattr(child,
"isSelected")
and child.isSelected()]
26 """ Forward selection information to super class if it is a VispaWidgetOwner.
28 logging.debug(self.__class__.__name__ +
": widgetSelected()")
30 if isinstance(self, QObject):
31 if not hasattr(self,
"_selectedWidgets"):
39 self._selectedWidgets.append(widget)
41 for widget
in [child
for child
in self.
_selectedWidgets if hasattr(child,
"isSelected")
and not child.isSelected()]:
42 self._selectedWidgets.remove(widget)
44 if isinstance(self.parent(), VispaWidgetOwner):
48 """ Forward selection information to super class if it is a VispaWidgetOwner.
51 if isinstance(self, QObject):
52 if isinstance(self.parent(), VispaWidgetOwner):
59 for child
in self.children():
60 if child != widget
and hasattr(child,
"isSelected")
and child.isSelected():
61 child.setDragReferencePoint(pos - child.pos())
64 """ Tell parent widget has moved.
66 Only informs parent if it is a VispaWidgetOwner, too.
68 if isinstance(self.parent(), VispaWidgetOwner):
71 if hasattr(self,
"_lastMovedWidgets"):
72 self._lastMovedWidgets.append(widget)
75 for child
in self.children():
76 if hasattr(child,
"dragReferencePoint")
and child != widget
and hasattr(child,
"isSelected")
and child.isSelected():
77 if hasattr(child,
"setPreviousDragPosition"):
78 child.setPreviousDragPosition(child.pos())
79 child.move(widget.pos() - child.dragReferencePoint())
80 self._lastMovedWidgets.append(child)
85 if hasattr(self,
"_lastMovedWidgets"):
90 """ This function is called from the delete() function of VispaWidget.
95 """ Calls delete() method of selected child widgets if multi-select is activated.
97 if self.multiSelectEnabled()
and ( event.key() == Qt.Key_Backspace
or event.key() == Qt.Key_Delete ):
98 selection = self.selectedWidgets()[:]
99 for widget
in selection:
103 """ Deselects all widgets except the widget given as exception.
107 for child
in self.children():
108 if child != exception:
109 if hasattr(child,
'select'):
112 self._selectedWidgets.append(child)
114 if isinstance(child, VispaWidgetOwner):
115 child.deselectAllWidgets(exception)
119 """ Calls deselectAllWidgets.
122 if event.modifiers() != Qt.ControlModifier:
124 if multiSelectEnabled:
130 eventX = event.pos().
x()
131 eventY = event.pos().
y()
132 startX = self._selectionRectStartPos.x()
133 startY = self._selectionRectStartPos.y()
137 self.update(self._selectionRect.united(oldRect).adjusted(-5, -5, 5, 5))
150 for child
in self.children():
151 if hasattr(child,
"select")
and hasattr(child,
"isSelected")
and self._selectionRect.contains(child.geometry())
and not child.isSelected():
152 child.select(
True,
True)
153 self.update(self._selectionRect.adjusted(-5, -5, 5, 5))