Skip to content

Commit e17e7fc

Browse files
authored
Merge pull request #3672 from ob7/enable-css-grid-colors
Add CSS Grid Color Customization Support
2 parents 2b98d51 + bfe11d7 commit e17e7fc

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

gns3/graphics_view.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ class GraphicsView(QtWidgets.QGraphicsView):
7474
:param parent: parent widget
7575
"""
7676

77+
# Class-level constants for default colors
78+
DEFAULT_DRAWING_GRID_COLOR = QtGui.QColor(208, 208, 208) # #D0D0D0
79+
DEFAULT_NODE_GRID_COLOR = QtGui.QColor(190, 190, 190) # #BEBEBE
80+
7781
def __init__(self, parent):
7882

7983
# Our parent is the central widget which parent is the main window.
@@ -92,6 +96,8 @@ def __init__(self, parent):
9296
self._dragging = False
9397
self._grid_size = 75
9498
self._drawing_grid_size = 25
99+
self._drawing_grid_color = self.DEFAULT_DRAWING_GRID_COLOR
100+
self._node_grid_color = self.DEFAULT_NODE_GRID_COLOR
95101
self._last_mouse_position = None
96102
self._topology = Topology.instance()
97103
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
16591665
self._topology.addDrawing(item)
16601666
return item
16611667

1668+
@QtCore.Property(QtGui.QColor)
1669+
def drawingGridColor(self):
1670+
"""Returns the drawing grid color"""
1671+
return self._drawing_grid_color
1672+
1673+
@drawingGridColor.setter
1674+
def drawingGridColor(self, color):
1675+
"""Sets the drawing grid color"""
1676+
self._drawing_grid_color = color
1677+
self.viewport().update()
1678+
1679+
@QtCore.Property(QtGui.QColor)
1680+
def nodeGridColor(self):
1681+
"""Returns the node grid color"""
1682+
return self._node_grid_color
1683+
1684+
@nodeGridColor.setter
1685+
def nodeGridColor(self, color):
1686+
"""Sets the node grid color"""
1687+
self._node_grid_color = color
1688+
self.viewport().update()
1689+
1690+
def resetGridColors(self):
1691+
"""Reset grid colors to defaults"""
1692+
self._drawing_grid_color = self.DEFAULT_DRAWING_GRID_COLOR
1693+
self._node_grid_color = self.DEFAULT_NODE_GRID_COLOR
1694+
self.viewport().update()
1695+
16621696
def drawBackground(self, painter, rect):
16631697
super().drawBackground(painter, rect)
16641698
if self._main_window.uiShowGridAction.isChecked():
1665-
grids = [(self.drawingGridSize(), QtGui.QColor(208, 208, 208)),
1666-
(self.nodeGridSize(), QtGui.QColor(190, 190, 190))]
1699+
grids = [(self.drawingGridSize(), self._drawing_grid_color),
1700+
(self.nodeGridSize(), self._node_grid_color)]
16671701
painter.save()
16681702
for (grid, colour) in grids:
16691703
if not grid:

gns3/style.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def setLegacyStyle(self):
4747
Sets the legacy GUI style.
4848
"""
4949

50+
graphics_view = self._mw.uiGraphicsView
51+
if hasattr(graphics_view, 'resetGridColors'):
52+
graphics_view.resetGridColors()
53+
5054
self._mw.setStyleSheet("")
5155
self._mw.uiNewProjectAction.setIcon(QtGui.QIcon(":/icons/new-project.svg"))
5256
self._mw.uiOpenProjectAction.setIcon(QtGui.QIcon(":/icons/open.svg"))
@@ -99,6 +103,10 @@ def setClassicStyle(self):
99103
Sets the classic GUI style.
100104
"""
101105

106+
graphics_view = self._mw.uiGraphicsView
107+
if hasattr(graphics_view, 'resetGridColors'):
108+
graphics_view.resetGridColors()
109+
102110
self._mw.setStyleSheet("")
103111
self._mw.uiNewProjectAction.setIcon(self._getStyleIcon(":/classic_icons/new-project.svg", ":/classic_icons/new-project-hover.svg"))
104112
self._mw.uiOpenProjectAction.setIcon(self._getStyleIcon(":/classic_icons/open.svg", ":/classic_icons/open-hover.svg"))
@@ -155,6 +163,10 @@ def setCharcoalStyle(self):
155163
Sets the charcoal GUI style.
156164
"""
157165

166+
graphics_view = self._mw.uiGraphicsView
167+
if hasattr(graphics_view, 'resetGridColors'):
168+
graphics_view.resetGridColors()
169+
158170
style_file = QtCore.QFile(":/styles/charcoal.css")
159171
style_file.open(QtCore.QFile.ReadOnly)
160172
style = QtCore.QTextStream(style_file).readAll()

0 commit comments

Comments
 (0)