Skip to content

Commit

Permalink
Adjust other beats inside the same act upon act resize, closes #1375
Browse files Browse the repository at this point in the history
  • Loading branch information
zkovari committed Oct 4, 2024
1 parent 3429187 commit b3b6800
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/main/python/plotlyst/view/widget/structure/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,12 @@ def _refreshBeatButtonDragStatus(self, btn: _BeatButton):
else:
btn.setDragEnabled(False)

def _actResized(self, pos: int, index: int):
def _actResized(self, pos: int, act: int):
old_percentage = 0
new_percentage = 0

for beat in self._beats.keys():
if beat.ends_act and beat.act == index:
if beat.ends_act and beat.act == act:
old_percentage = beat.percentage
beat.percentage = self._percentageForX(pos - self._beatHeight // 2)
new_percentage = beat.percentage
Expand All @@ -595,5 +596,31 @@ def _actResized(self, pos: int, index: int):
elif con.percentage_end == old_percentage:
con.percentage_end = new_percentage

act_percentages = self._calculateActPercentages()

for beat in self._beats.keys():
if beat.act == act:
if beat.ends_act:
continue
act_start_percentage = act_percentages[beat.act - 1][0]
act_range = old_percentage - act_start_percentage

if act_range > 0:
relative_percentage = (beat.percentage - act_start_percentage) / act_range
new_act_range = new_percentage - act_start_percentage
beat.percentage = act_start_percentage + (relative_percentage * new_act_range)

self._rearrangeBeats()
self.actsResized.emit()

def _calculateActPercentages(self):
total_width = self._actsSplitter.width()
percentages = []
for act_button in self._acts:
button_geometry = act_button.geometry()
act_start = button_geometry.left()
act_width = button_geometry.width()
act_start_percentage = act_start / total_width
act_end_percentage = (act_start + act_width) / total_width
percentages.append((act_start_percentage, act_end_percentage))
return percentages

0 comments on commit b3b6800

Please sign in to comment.