Browse Source

Tweak code for canvas group positions

See #1139

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.2.0-RC1
falkTX 4 years ago
parent
commit
1c675e7bb5
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 15 additions and 9 deletions
  1. +1
    -1
      source/frontend/patchcanvas/patchcanvas.py
  2. +14
    -8
      source/frontend/patchcanvas/utils.py

+ 1
- 1
source/frontend/patchcanvas/patchcanvas.py View File

@@ -363,7 +363,7 @@ def addGroup(group_id, group_name, split=SPLIT_UNDEF, icon=ICON_APPLICATION):
elif old_matching_group is not None and old_matching_group[0]: elif old_matching_group is not None and old_matching_group[0]:
group_sbox.setPos(old_matching_group[2]) group_sbox.setPos(old_matching_group[2])
else: else:
group_sbox.setPos(CanvasGetNewGroupPos(True))
group_sbox.setPos(group_box.x() + group_box.boundingRect().width() + 300, group_box.y())


canvas.last_z_value += 1 canvas.last_z_value += 1
group_sbox.setZValue(canvas.last_z_value) group_sbox.setZValue(canvas.last_z_value)


+ 14
- 8
source/frontend/patchcanvas/utils.py View File

@@ -36,21 +36,27 @@ def CanvasGetNewGroupPos(horizontal):
new_pos = QPointF(canvas.initial_pos) new_pos = QPointF(canvas.initial_pos)
items = canvas.scene.items() items = canvas.scene.items()


break_loop = False
while not break_loop:
#break_loop = False
while True:
break_for = False break_for = False
for i, item in enumerate(items): for i, item in enumerate(items):
if item and item.type() == CanvasBoxType: if item and item.type() == CanvasBoxType:
if item.sceneBoundingRect().contains(new_pos):
if item.sceneBoundingRect().adjusted(-5, -5, 5, 5).contains(new_pos):
itemRect = item.boundingRect()
if horizontal: if horizontal:
new_pos += QPointF(item.boundingRect().width() + 15, 0)
new_pos += QPointF(itemRect.width() + 50, 0)
else: else:
new_pos += QPointF(0, item.boundingRect().height() + 15)
itemHeight = itemRect.height()
if itemHeight < 30:
new_pos += QPointF(0, itemHeight + 50)
else:
new_pos.setY(item.scenePos().y() + itemHeight + 20)
break_for = True break_for = True
break break

if i >= len(items) - 1 and not break_for:
break_loop = True
else:
if not break_for:
break
#break_loop = True


return new_pos return new_pos




Loading…
Cancel
Save