From bfe11d79760b1c66f0d645f3ca5aa679c24bd89b Mon Sep 17 00:00:00 2001 From: ob7 Date: Mon, 2 Dec 2024 00:13:01 -0900 Subject: [PATCH] apply grid color via css property --- gns3/graphics_view.py | 38 ++++++++++++++++++++++++++++++++++++-- gns3/style.py | 12 ++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/gns3/graphics_view.py b/gns3/graphics_view.py index d9461ea1e..2065ecc19 100644 --- a/gns3/graphics_view.py +++ b/gns3/graphics_view.py @@ -74,6 +74,10 @@ class GraphicsView(QtWidgets.QGraphicsView): :param parent: parent widget """ + # Class-level constants for default colors + DEFAULT_DRAWING_GRID_COLOR = QtGui.QColor(208, 208, 208) # #D0D0D0 + DEFAULT_NODE_GRID_COLOR = QtGui.QColor(190, 190, 190) # #BEBEBE + def __init__(self, parent): # Our parent is the central widget which parent is the main window. @@ -92,6 +96,8 @@ def __init__(self, parent): self._dragging = False self._grid_size = 75 self._drawing_grid_size = 25 + self._drawing_grid_color = self.DEFAULT_DRAWING_GRID_COLOR + self._node_grid_color = self.DEFAULT_NODE_GRID_COLOR self._last_mouse_position = None self._topology = Topology.instance() self._background_warning_msgbox = QtWidgets.QErrorMessage(self) @@ -1659,11 +1665,39 @@ def createDrawingItem(self, type, x, y, z, locked=False, rotation=0, svg=None, d self._topology.addDrawing(item) return item + @QtCore.Property(QtGui.QColor) + def drawingGridColor(self): + """Returns the drawing grid color""" + return self._drawing_grid_color + + @drawingGridColor.setter + def drawingGridColor(self, color): + """Sets the drawing grid color""" + self._drawing_grid_color = color + self.viewport().update() + + @QtCore.Property(QtGui.QColor) + def nodeGridColor(self): + """Returns the node grid color""" + return self._node_grid_color + + @nodeGridColor.setter + def nodeGridColor(self, color): + """Sets the node grid color""" + self._node_grid_color = color + self.viewport().update() + + def resetGridColors(self): + """Reset grid colors to defaults""" + self._drawing_grid_color = self.DEFAULT_DRAWING_GRID_COLOR + self._node_grid_color = self.DEFAULT_NODE_GRID_COLOR + self.viewport().update() + def drawBackground(self, painter, rect): super().drawBackground(painter, rect) if self._main_window.uiShowGridAction.isChecked(): - grids = [(self.drawingGridSize(), QtGui.QColor(208, 208, 208)), - (self.nodeGridSize(), QtGui.QColor(190, 190, 190))] + grids = [(self.drawingGridSize(), self._drawing_grid_color), + (self.nodeGridSize(), self._node_grid_color)] painter.save() for (grid, colour) in grids: if not grid: diff --git a/gns3/style.py b/gns3/style.py index 75631effe..f609f63b3 100644 --- a/gns3/style.py +++ b/gns3/style.py @@ -47,6 +47,10 @@ def setLegacyStyle(self): Sets the legacy GUI style. """ + graphics_view = self._mw.uiGraphicsView + if hasattr(graphics_view, 'resetGridColors'): + graphics_view.resetGridColors() + self._mw.setStyleSheet("") self._mw.uiNewProjectAction.setIcon(QtGui.QIcon(":/icons/new-project.svg")) self._mw.uiOpenProjectAction.setIcon(QtGui.QIcon(":/icons/open.svg")) @@ -99,6 +103,10 @@ def setClassicStyle(self): Sets the classic GUI style. """ + graphics_view = self._mw.uiGraphicsView + if hasattr(graphics_view, 'resetGridColors'): + graphics_view.resetGridColors() + self._mw.setStyleSheet("") self._mw.uiNewProjectAction.setIcon(self._getStyleIcon(":/classic_icons/new-project.svg", ":/classic_icons/new-project-hover.svg")) self._mw.uiOpenProjectAction.setIcon(self._getStyleIcon(":/classic_icons/open.svg", ":/classic_icons/open-hover.svg")) @@ -155,6 +163,10 @@ def setCharcoalStyle(self): Sets the charcoal GUI style. """ + graphics_view = self._mw.uiGraphicsView + if hasattr(graphics_view, 'resetGridColors'): + graphics_view.resetGridColors() + style_file = QtCore.QFile(":/styles/charcoal.css") style_file.open(QtCore.QFile.ReadOnly) style = QtCore.QTextStream(style_file).readAll()