2828from common import *
2929
3030from qt .core import QPoint , QPointF , QRectF , QTimer
31- from qt .gui import QIcon , QKeySequence , QMouseEvent , QPainterPath , QPen , QTransform
31+ from qt .gui import QIcon , QKeySequence , QMouseEvent , QPainterPath , QPen , QTransform , QPolygonF
3232from qt .widgets import QDialog , QDialogButtonBox , QFileDialog , QGraphicsPathItem , QGraphicsView , QLabel , QLineEdit , QMessageBox , QShortcut , QVBoxLayout
3333
3434
@@ -364,7 +364,7 @@ def undo(self, step=-1):
364364
365365 def redo (self ):
366366 self .undo (1 )
367-
367+
368368
369369class View (common .View ):
370370 def __init__ (self , scene ):
@@ -374,6 +374,7 @@ def __init__(self, scene):
374374 inf = - 1e10
375375 self .setSceneRect (QRectF (QPointF (- inf , - inf ), QPointF (inf , inf )))
376376 self .scale (50 , 50 ) #*1.00955
377+ self .hexcells_ui = False
377378
378379
379380 def mousePressEvent (self , e ):
@@ -411,6 +412,18 @@ def wheelEvent(self, e):
411412 d = e .delta ()
412413 self .zoom (1.0015 ** d ) #1.00005
413414
415+ @event_property
416+ def hexcells_ui (self ):
417+ self .viewport ().update ()
418+ self .setViewportUpdateMode (QGraphicsView .FullViewportUpdate if self .hexcells_ui else QGraphicsView .MinimalViewportUpdate )
419+
420+ def drawBackground (self , g , rect ):
421+ if self .hexcells_ui :
422+ pts = [(- 13.837 , 8.321 ), (- 13.837 , - 4.232 ), (- 9.843 , - 8.274 ), (11.713 , - 8.274 ), (11.713 , - 5.421 ), (13.837 , - 5.421 ), (13.837 , 8.321 )]
423+ poly = QPolygonF ([rect .center () + QPointF (* p ) for p in pts ])
424+ g .setPen (QPen (qt .gray , 0 ))
425+ g .drawPolygon (poly )
426+
414427
415428
416429class MainWindow (common .MainWindow ):
@@ -509,6 +522,10 @@ def __init__(self):
509522
510523 menu .addSeparator ()
511524
525+ self .enable_hexcells_ui_action = action = make_check_action ("Show Hexcells &UI" , self , 'hexcells_ui' )
526+ action .setChecked (False )
527+ action .setStatusTip ("Show the borders of Hexcells UI to see the limit of level size." )
528+ menu .addAction (action )
512529 self .enable_statusbar_action = action = make_check_action ("Show &Status Bar" , self , 'statusbar_visible' )
513530 action .setChecked (True )
514531 menu .addAction (action )
@@ -549,6 +566,7 @@ def __init__(self):
549566 secondary_cell_action = 'double' if next(v for v, a in secondary_action_group.items() if a.isChecked()) else 'right'; secondary_action_group[v=='double'].setChecked(True)
550567 default_black = next(v for v, a in black_show_info_group.items() if a.isChecked()); black_show_info_group[v].setChecked(True)
551568 default_blue = next(v for v, a in blue_show_info_group.items() if a.isChecked()); blue_show_info_group[v].setChecked(True)
569+ hexcells_ui = enable_hexcells_ui_action.isChecked(); enable_hexcells_ui_action.setChecked(v)
552570 status_bar = enable_statusbar_action.isChecked(); enable_statusbar_action.setChecked(v)
553571 undo_history_length = scene.undo_history_length; scene.undo_history_length = v
554572 antialiasing = view.antialiasing; view.antialiasing = v
@@ -580,6 +598,13 @@ def status(self, value):
580598 self .statusBar ().showMessage (value )
581599 app .processEvents ()
582600
601+ @property
602+ def hexcells_ui (self ):
603+ self .view .hexcells_ui
604+ @hexcells_ui .setter
605+ def hexcells_ui (self , value ):
606+ self .view .hexcells_ui = value
607+
583608 @property
584609 def statusbar_visible (self ):
585610 return self .statusBar ().isVisible ()
@@ -661,6 +686,12 @@ def accepted():
661686
662687 dialog .exec_ ()
663688
689+ def center_on (self , x , y ):
690+ self .view .centerOn (x * cos30 , y / 2 + 0.3 )
691+
692+ def copy (self ):
693+ common .MainWindow .copy (self )
694+ self .center_on (* common .level_center )
664695
665696 def save_file (self , fn = None ):
666697 if not fn :
@@ -680,6 +711,7 @@ def save_file(self, fn=None):
680711 self .current_file = fn
681712 self .last_used_folder = os .path .dirname (fn )
682713 self .status = "Done" , 1
714+ self .center_on (* common .level_center )
683715 return True
684716 except ValueError as e :
685717 QMessageBox .critical (None , "Error" , str (e ))
@@ -688,6 +720,7 @@ def save_file(self, fn=None):
688720
689721 def prepare (self ):
690722 self .view .fitInView (self .scene .itemsBoundingRect ().adjusted (- 0.5 , - 0.5 , 0.5 , 0.5 ), qt .KeepAspectRatio )
723+ self .center_on (16 , 16 )
691724 self .no_changes ()
692725 self .scene .undo_step ()
693726
0 commit comments