Commit 87da2c1e authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Make sure Autocompletion box is always on top

parent 5e1952e8
......@@ -166,7 +166,7 @@ class EditableText(QGraphicsTextItem, object):
self.set_text_alignment()
# Increase the Z value of the text area so that the autocompleter
# always appear on top of text's siblings (parents's followers)
self.setZValue(1)
self.setZValue(self.zValue() + 1)
# context is used for advanced autocompletion
self.context = ''
# Set cursor when mouse goes over the text
......@@ -375,15 +375,27 @@ class EditableText(QGraphicsTextItem, object):
unicode(self))
self.scene().undo_stack.push(undo_cmd)
self.set_text_alignment()
# Reset Z-Values that were increased when getting focus
parent = self.parentItem()
top_level = parent.top_level()
top_level.setZValue(top_level.zValue() - 1)
parent.setZValue(parent.zValue() - 1)
super(EditableText, self).focusOutEvent(event)
# pylint: disable=C0103
def focusInEvent(self, event):
''' When user starts editing text, save previous state for Undo '''
super(EditableText, self).focusInEvent(event)
# Make the Z-value of items to make sure the
# completer will always be on top of other symbols
parent = self.parentItem()
top_level = parent.top_level()
top_level.setZValue(top_level.zValue() + 1)
parent.setZValue(parent.zValue() + 1)
# Trigger a select - side effect makes the toolbar update
try:
self.parentItem().select(True)
parent.select(True)
except AttributeError:
# Some parents may not be selectable (e.g. Signalroute)
pass
......@@ -396,7 +408,7 @@ class EditableText(QGraphicsTextItem, object):
self.setTextWidth(-1)
if not self.editing:
self.oldText = unicode(self)
self.oldSize = self.parentItem().boundingRect()
self.oldSize = parent.boundingRect()
self.editing = True
def __str__(self):
......
......@@ -586,6 +586,19 @@ class Symbol(QObject, QGraphicsPathItem, object):
''' Implemented in the relevant subclass '''
pass
def top_level(self):
''' If the item is in a branch, return the highest level in the branch,
e.g. the starting state. '''
top_level = self
while top_level.hasParent:
# The "or top_level.parent" below is due to a Pyside/Qt bug
# of the parentItem() function. It can happen that even when
# the parent has explicitely been set with "setParentItem",
# a subsequent call to parentItem returns None. Seems to happen
# if the parent has not been added yet to the scene.
top_level = top_level.parentItem() or top_level.parent
return top_level
# pylint: disable=R0914
def cam(self, old_pos, new_pos, ignore=None):
''' Collision Avoidance Manoeuvre for top level symbols '''
......@@ -594,19 +607,26 @@ class Symbol(QObject, QGraphicsPathItem, object):
# a model from a file, some items may be connected together
# and CAM called *before* the top-level item has been inserted.
return
if self.hasParent:
top_level = self.top_level()
if top_level != self:
# Exectute CAM on top level of this item
top_level = self
while top_level.hasParent:
# The "or top_level.parent" below is due to a Pyside/Qt bug
# of the parentItem() function. It can happen that even when
# the parent has explicitely been set with "setParentItem",
# a subsequent call to parentItem returns None. Seems to happen
# if the parent has not been added yet to the scene.
top_level = top_level.parentItem() or top_level.parent
top_level.cam(top_level.position, top_level.position)
return
# if self.hasParent:
# # Exectute CAM on top level of this item
# top_level = self
# while top_level.hasParent:
# # The "or top_level.parent" below is due to a Pyside/Qt bug
# # of the parentItem() function. It can happen that even when
# # the parent has explicitely been set with "setParentItem",
# # a subsequent call to parentItem returns None. Seems to happen
# # if the parent has not been added yet to the scene.
# top_level = top_level.parentItem() or top_level.parent
# top_level.cam(top_level.position, top_level.position)
# return
# In case CAM is called due to object move, go to the new position
delta = new_pos - old_pos
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment