Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 3 additions & 55 deletions Orange/canvas/gui/toolgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,6 @@ def __init__(self, parent=None, columns=4, buttonSize=None,
self.__toolButtonStyle = toolButtonStyle

self.__gridSlots = []

self.__buttonListener = ToolButtonEventListener(self)
self.__buttonListener.buttonRightClicked.connect(
self.__onButtonRightClick)

self.__buttonListener.buttonEnter.connect(
self.__onButtonEnter)

self.__mapper = QSignalMapper()
self.__mapper.mapped[QObject].connect(self.__onClicked)

Expand Down Expand Up @@ -317,7 +309,7 @@ def __insertActionButton(self, index, action):
self.__shiftGrid(index, 1)
button = self.createButtonForAction(action)

row = index / self.__columns
row = index // self.__columns
column = index % self.__columns

self.layout().addWidget(
Expand All @@ -331,7 +323,6 @@ def __insertActionButton(self, index, action):

self.__mapper.setMapping(button, action)
button.clicked.connect(self.__mapper.map)
button.installEventFilter(self.__buttonListener)
button.installEventFilter(self)

def __removeActionButton(self, action):
Expand All @@ -341,7 +332,6 @@ def __removeActionButton(self, action):
index = actions.index(action)
slot = self.__gridSlots.pop(index)

slot.button.removeEventFilter(self.__buttonListener)
slot.button.removeEventFilter(self)
self.__mapper.removeMappings(slot.button)

Expand Down Expand Up @@ -391,9 +381,6 @@ def __indexOf(self, button):
buttons = [slot.button for slot in self.__gridSlots]
return buttons.index(button)

def __onButtonRightClick(self, button):
pass

def __onButtonEnter(self, button):
action = button.defaultAction()
self.actionHovered.emit(action)
Expand All @@ -412,7 +399,8 @@ def eventFilter(self, obj, event):
if self.__focusMove(obj, key):
event.accept()
return True

elif etype == QEvent.HoverEnter and obj.parent() is self:
self.__onButtonEnter(obj)
return QFrame.eventFilter(self, obj, event)

def __focusMove(self, focus, key):
Expand All @@ -437,43 +425,3 @@ def __focusMove(self, focus, key):
return True
else:
return False


class ToolButtonEventListener(QObject):
"""
An event listener(filter) for :class:`QToolButtons`.
"""
buttonLeftClicked = Signal(QToolButton)
buttonRightClicked = Signal(QToolButton)
buttonEnter = Signal(QToolButton)
buttonLeave = Signal(QToolButton)

def __init__(self, parent=None):
QObject.__init__(self, parent)
self.button_down = None
self.button = None
self.button_down_pos = None

def eventFilter(self, obj, event):
if not isinstance(obj, QToolButton):
return False

if event.type() == QEvent.MouseButtonPress:
self.button = obj
self.button_down = event.button()
self.button_down_pos = event.pos()

elif event.type() == QEvent.MouseButtonRelease:
if self.button.underMouse():
if event.button() == Qt.RightButton:
self.buttonRightClicked.emit(self.button)
elif event.button() == Qt.LeftButton:
self.buttonLeftClicked.emit(self.button)

elif event.type() == QEvent.Enter:
self.buttonEnter.emit(obj)

elif event.type() == QEvent.Leave:
self.buttonLeave.emit(obj)

return False