Skip to content

Commit

Permalink
Allow choosing the highlight color for items found in entity graph
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelma committed Aug 30, 2023
1 parent 6364080 commit f71ae46
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 4 additions & 4 deletions spinetoolbox/spine_db_editor/graphics_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(self, spine_db_editor, x, y, extent, db_map_ids):
self.setAcceptHoverEvents(True)
self.setCursor(Qt.ArrowCursor)
self.setToolTip(self._make_tool_tip())
self._highlighted = False
self._highligh_color = Qt.transparent
self._db_map_entity_class_lists = {}
self.label_item = EntityLabelItem(self)
self.label_item.setVisible(not self.has_dimensions)
Expand Down Expand Up @@ -253,8 +253,8 @@ def shape(self):
path.addPolygon(self.label_item.mapToItem(self, self.label_item.boundingRect()))
return path

def set_highlighted(self, highlighted):
self._highlighted = highlighted
def set_highligh_color(self, color):
self._highligh_color = color

def paint(self, painter, option, widget=None):
"""Shows or hides the selection halo."""
Expand All @@ -264,7 +264,7 @@ def paint(self, painter, option, widget=None):
else:
self._paint_as_deselected()
pen = self._bg.pen()
pen.setColor(Qt.yellow if self._highlighted else Qt.transparent)
pen.setColor(self._highligh_color)
width = 10 / self.scale()
pen.setWidth(width)
self._bg.setPen(pen)
Expand Down
14 changes: 9 additions & 5 deletions spinetoolbox/spine_db_editor/widgets/custom_qgraphicsviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import sys
from PySide6.QtCore import Qt, QTimeLine, Signal, Slot, QRectF
from PySide6.QtWidgets import QMenu, QGraphicsView, QInputDialog
from PySide6.QtWidgets import QMenu, QGraphicsView, QInputDialog, QColorDialog
from PySide6.QtGui import QCursor, QPainter, QIcon, QAction, QPageSize
from PySide6.QtPrintSupport import QPrinter
from ...helpers import CharIconEngine
Expand Down Expand Up @@ -197,12 +197,16 @@ def populate_context_menu(self):
self._menu.aboutToShow.connect(self._update_actions_visibility)

def _find(self):
expr, ok = QInputDialog.getText(self, "Find in graph...", "Enter strings to find separated by comma.")
expr, ok = QInputDialog.getText(self, "Find in graph...", "Enter entity names to find separated by comma.")
if not ok:
return
words = [x.strip() for x in expr.split(",")]
for item in self.entity_items:
item.set_highlighted(any(w in item.entity_name for w in words))
names = [x.strip() for x in expr.split(",")]
items = [item for item in self.entity_items if any(n == item.entity_name for n in names)]
if not items:
return
color = QColorDialog.getColor(Qt.yellow, self, "Choose highlight color")
for item in items:
item.set_highligh_color(color)

def increase_arc_length(self):
for item in self.entity_items:
Expand Down

0 comments on commit f71ae46

Please sign in to comment.