Skip to content

Commit

Permalink
Support map areas (#1381)
Browse files Browse the repository at this point in the history
* Support map areas

* Add secondary selector and domain

* progress

* progress

* moveable

* Progress

* Persist square and circle areas

* move pos

* fewer points for path

* persist path

* add area on left click only

* activate

* toolbar

* set color

* set location

* disable icons for now
  • Loading branch information
zkovari authored Oct 7, 2024
1 parent 7a455c0 commit eb66f8e
Show file tree
Hide file tree
Showing 4 changed files with 438 additions and 223 deletions.
65 changes: 39 additions & 26 deletions src/main/python/plotlyst/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,35 @@ def default_stages() -> List[SceneStage]:
SceneStage('Proofread'), SceneStage('Final')]


class GraphicsItemType(Enum):
CHARACTER = 'character'
STICKER = 'sticker'
EVENT = 'event'
COMMENT = 'comment'
SETUP = 'setup'
NOTE = 'note'
IMAGE = 'image'
MAP_MARKER = 'map_marker'
ICON = 'icon'
MAP_AREA_SQUARE = 'map_area_square'
MAP_AREA_CIRCLE = 'map_area_circle'
MAP_AREA_CUSTOM = 'map_area_custom'

def mimeType(self) -> str:
return f'application/node-{self.value}'


NODE_SUBTYPE_GOAL = 'goal'
NODE_SUBTYPE_CONFLICT = 'conflict'
NODE_SUBTYPE_DISTURBANCE = 'disturbance'
NODE_SUBTYPE_BACKSTORY = 'backstory'
NODE_SUBTYPE_INTERNAL_CONFLICT = 'internal_conflict'
NODE_SUBTYPE_QUESTION = 'question'
NODE_SUBTYPE_FORESHADOWING = 'foreshadowing'
NODE_SUBTYPE_TOOL = 'tool'
NODE_SUBTYPE_COST = 'cost'


class VariableType(Enum):
Text = 0

Expand Down Expand Up @@ -2148,17 +2177,27 @@ def __hash__(self):
return hash(self.key)


@dataclass
class Point:
x: float
y: float


@dataclass
class WorldBuildingMarker:
x: float
y: float
type: GraphicsItemType = GraphicsItemType.MAP_MARKER
name: str = ''
description: str = ''
color: str = '#ef233c'
color_selected: str = '#A50C1E'
icon: str = 'mdi.circle'
size: int = field(default=0, metadata=config(exclude=exclude_if_empty))
height: int = field(default=0, metadata=config(exclude=exclude_if_empty))
width: int = field(default=0, metadata=config(exclude=exclude_if_empty))
ref: Optional[uuid.UUID] = field(default=None, metadata=config(exclude=exclude_if_empty))
points: List[Point] = field(default_factory=list, metadata=config(exclude=exclude_if_empty))


@dataclass
Expand Down Expand Up @@ -3406,32 +3445,6 @@ def default_tags() -> Dict[TagType, List[Tag]]:
return tags


class GraphicsItemType(Enum):
CHARACTER = 'character'
STICKER = 'sticker'
EVENT = 'event'
COMMENT = 'comment'
SETUP = 'setup'
NOTE = 'note'
IMAGE = 'image'
MAP_MARKER = 'map_marker'
ICON = 'icon'

def mimeType(self) -> str:
return f'application/node-{self.value}'


NODE_SUBTYPE_GOAL = 'goal'
NODE_SUBTYPE_CONFLICT = 'conflict'
NODE_SUBTYPE_DISTURBANCE = 'disturbance'
NODE_SUBTYPE_BACKSTORY = 'backstory'
NODE_SUBTYPE_INTERNAL_CONFLICT = 'internal_conflict'
NODE_SUBTYPE_QUESTION = 'question'
NODE_SUBTYPE_FORESHADOWING = 'foreshadowing'
NODE_SUBTYPE_TOOL = 'tool'
NODE_SUBTYPE_COST = 'cost'


@dataclass
class Node(CharacterBased):
x: float
Expand Down
9 changes: 9 additions & 0 deletions src/main/python/plotlyst/view/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ def _text_color_with_rgb(r: int, g: int, b: int) -> str:
return 'black' if hsp > 171.5 else WHITE_COLOR


def stronger_color(hex_color: str, factor: float = 1.5) -> str:
color = QColor(hex_color)
h, s, v, a = color.getHsv()
s = min(255, int(s * factor)) # Scale up the saturation but cap at 255
v = max(0, int(v / factor)) # Darken the color
color.setHsv(h, s, v, a)
return color.name()


def action(text: str, icon: Optional[QIcon] = None, slot=None, parent=None, checkable: bool = False,
tooltip: str = '', incr_font_: Optional[int] = None) -> QAction:
_action = QAction(text)
Expand Down
2 changes: 0 additions & 2 deletions src/main/python/plotlyst/view/widget/graphics/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ def mousePressEvent(self, event: QMouseEvent) -> None:
self.setDragMode(QGraphicsView.DragMode.NoDrag)
self._moveOriginX = event.pos().x()
self._moveOriginY = event.pos().y()
else:
self.setDragMode(QGraphicsView.DragMode.RubberBandDrag)
super(BaseGraphicsView, self).mousePressEvent(event)

@overrides
Expand Down
Loading

0 comments on commit eb66f8e

Please sign in to comment.