Skip to content

Commit

Permalink
Wider worldbuilding timeline event widget, closes #1389
Browse files Browse the repository at this point in the history
  • Loading branch information
zkovari committed Oct 10, 2024
1 parent 3fc50e0 commit b3f646d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
21 changes: 15 additions & 6 deletions src/main/python/plotlyst/view/widget/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(self, backstory: BackstoryEvent, theme: TimelineTheme, parent=None)
self.textSummary.setViewportMargins(3, 0, 3, 0)
self.textSummary.setProperty('transparent', True)
self.textSummary.textChanged.connect(self._synopsisChanged)
incr_font(self.textSummary, 2)
incr_font(self.textSummary)

wdgTop = QWidget()
hbox(wdgTop, 0, 0)
Expand Down Expand Up @@ -155,7 +155,8 @@ def _remove(self):


class BackstoryCardPlaceholder(QWidget):
def __init__(self, card: BackstoryCard, alignment: int = Qt.AlignmentFlag.AlignRight, parent=None):
def __init__(self, card: BackstoryCard, alignment: int = Qt.AlignmentFlag.AlignRight, parent=None,
compact: bool = True):
super().__init__(parent)
self.alignment = alignment
self.card = card
Expand All @@ -165,9 +166,15 @@ def __init__(self, card: BackstoryCard, alignment: int = Qt.AlignmentFlag.AlignR
self.spacer.setFixedWidth(self.width() // 2 + 3)
if self.alignment == Qt.AlignmentFlag.AlignRight:
self.layout().addWidget(self.spacer)
self._layout.addWidget(self.card, alignment=Qt.AlignmentFlag.AlignLeft)
if compact:
self._layout.addWidget(self.card, alignment=Qt.AlignmentFlag.AlignLeft)
else:
self._layout.addWidget(self.card)
elif self.alignment == Qt.AlignmentFlag.AlignLeft:
self._layout.addWidget(self.card, alignment=Qt.AlignmentFlag.AlignRight)
if compact:
self._layout.addWidget(self.card, alignment=Qt.AlignmentFlag.AlignRight)
else:
self._layout.addWidget(self.card)
self.layout().addWidget(self.spacer)
else:
self.layout().addWidget(self.card)
Expand Down Expand Up @@ -223,12 +230,13 @@ def eventFilter(self, watched: QObject, event: QEvent) -> bool:
class TimelineWidget(QWidget):
changed = pyqtSignal()

def __init__(self, theme: Optional[TimelineTheme] = None, parent=None):
def __init__(self, theme: Optional[TimelineTheme] = None, parent=None, compact: bool = True):
self._spacers: List[QWidget] = []
super().__init__(parent)
if theme is None:
theme = TimelineTheme()
self._theme = theme
self._compact = compact
self._layout = vbox(self, spacing=0)
self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
self._lineTopMargin: int = 0
Expand Down Expand Up @@ -261,7 +269,8 @@ def refresh(self):
else:
alignment = Qt.AlignmentFlag.AlignLeft
prev_alignment = alignment
event = BackstoryCardPlaceholder(self.cardClass()(backstory, self._theme), alignment, parent=self)
event = BackstoryCardPlaceholder(self.cardClass()(backstory, self._theme), alignment, parent=self,
compact=self._compact)
event.card.deleteRequested.connect(self._remove)

self._spacers.append(event.spacer)
Expand Down
5 changes: 4 additions & 1 deletion src/main/python/plotlyst/view/widget/world/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,13 @@ def __init__(self, backstory: BackstoryEvent, parent=None):
super().__init__(backstory, parent)
self.refresh()

self.setMinimumWidth(250)
self.setMaximumWidth(450)


class EntityTimelineWidget(TimelineWidget):
def __init__(self, element: WorldBuildingEntityElement, parent=None):
super().__init__(TimelineTheme(timeline_color='#510442', card_bg_color='#E3D0BD'), parent)
super().__init__(TimelineTheme(timeline_color='#510442', card_bg_color='#E3D0BD'), parent, compact=False)
self.element = element
self.refresh()

Expand Down

0 comments on commit b3f646d

Please sign in to comment.