22from .. import QtGui , QtCore , QtWidgets
33
44from ..constants import (VIEWER_BG_COLOR ,
5- VIEWER_GRID_SIZE ,
6- VIEWER_GRID_OVERLAY ,
7- VIEWER_GRID_COLOR )
5+ VIEWER_GRID_SIZE ,
6+ VIEWER_GRID_COLOR ,
7+ VIEWER_GRID_NONE ,
8+ VIEWER_GRID_DOTS ,
9+ VIEWER_GRID_LINES )
810
911
1012class NodeScene (QtWidgets .QGraphicsScene ):
1113
1214 def __init__ (self , parent = None ):
1315 super (NodeScene , self ).__init__ (parent )
1416 self .background_color = VIEWER_BG_COLOR
15- self .grid = VIEWER_GRID_OVERLAY
1617 self .grid_color = VIEWER_GRID_COLOR
17-
18+ self . _grid_mode = VIEWER_GRID_LINES
1819 self .setBackgroundBrush (self ._bg_qcolor )
1920
2021 def __repr__ (self ):
@@ -31,13 +32,32 @@ def _draw_grid(self, painter, rect, pen, grid_size):
3132 first_left = left - (left % grid_size )
3233 first_top = top - (top % grid_size )
3334
34- lines = []
35- lines .extend ([QtCore .QLineF (x , top , x , bottom ) for x in range (first_left , right , grid_size )])
35+ lines = [QtCore .QLineF (x , top , x , bottom ) for x in range (first_left , right , grid_size )]
3636 lines .extend ([QtCore .QLineF (left , y , right , y ) for y in range (first_top , bottom , grid_size )])
3737
3838 painter .setPen (pen )
3939 painter .drawLines (lines )
4040
41+ def _draw_dots (self , painter , rect , pen , grid_size ):
42+ zoom = self .viewer ().get_zoom ()
43+ if zoom < 0 :
44+ grid_size = int (abs (zoom ) / 0.3 + 1 ) * grid_size
45+
46+ left = int (rect .left ())
47+ right = int (rect .right ())
48+ top = int (rect .top ())
49+ bottom = int (rect .bottom ())
50+
51+ first_left = left - (left % grid_size )
52+ first_top = top - (top % grid_size )
53+
54+ pen .setWidth (grid_size / 10 )
55+ painter .setPen (pen )
56+
57+ for x in range (first_left , right , grid_size ):
58+ for y in range (first_top , bottom , grid_size ):
59+ painter .drawPoint (int (x ), int (y ))
60+
4161 def drawBackground (self , painter , rect ):
4262 super (NodeScene , self ).drawBackground (painter , rect )
4363
@@ -46,21 +66,20 @@ def drawBackground(self, painter, rect):
4666 painter .setRenderHint (QtGui .QPainter .Antialiasing , False )
4767 painter .setBrush (self .backgroundBrush ())
4868
49- if not self ._grid :
50- painter .restore ()
51- return
52-
53- zoom = self .viewer ().get_zoom ()
54-
55- if zoom > - 0.5 :
69+ if self ._grid_mode is VIEWER_GRID_DOTS :
5670 pen = QtGui .QPen (QtGui .QColor (* self .grid_color ), 0.65 )
57- self ._draw_grid (painter , rect , pen , VIEWER_GRID_SIZE )
58-
59- color = self ._bg_qcolor .darker (150 )
60- if zoom < - 0.0 :
61- color = color .darker (100 - int (zoom * 110 ))
62- pen = QtGui .QPen (color , 0.65 )
63- self ._draw_grid (painter , rect , pen , VIEWER_GRID_SIZE * 8 )
71+ self ._draw_dots (painter , rect , pen , VIEWER_GRID_SIZE )
72+ elif self ._grid_mode is VIEWER_GRID_LINES :
73+ zoom = self .viewer ().get_zoom ()
74+ if zoom > - 0.5 :
75+ pen = QtGui .QPen (QtGui .QColor (* self .grid_color ), 0.65 )
76+ self ._draw_grid (painter , rect , pen , VIEWER_GRID_SIZE )
77+
78+ color = self ._bg_qcolor .darker (150 )
79+ if zoom < - 0.0 :
80+ color = color .darker (100 - int (zoom * 110 ))
81+ pen = QtGui .QPen (color , 0.65 )
82+ self ._draw_grid (painter , rect , pen , VIEWER_GRID_SIZE * 8 )
6483
6584 painter .restore ()
6685
@@ -92,12 +111,12 @@ def viewer(self):
92111 return self .views ()[0 ] if self .views () else None
93112
94113 @property
95- def grid (self ):
96- return self ._grid
114+ def grid_mode (self ):
115+ return self ._grid_mode
97116
98- @grid .setter
99- def grid (self , mode = True ):
100- self ._grid = mode
117+ @grid_mode .setter
118+ def grid_mode (self , mode = VIEWER_GRID_LINES ):
119+ self ._grid_mode = mode
101120
102121 @property
103122 def grid_color (self ):
0 commit comments