Fix ring boundingrect

master
En Yi 2018-07-10 16:32:19 +08:00
parent fbe3c63845
commit daef9e01b9
2 changed files with 13 additions and 8 deletions

View File

@ -17,6 +17,7 @@ class animBox(QGraphicsObject):
# Initialisation # Initialisation
def __init__(self, x, y, width, height, text, parent=None): def __init__(self, x, y, width, height, text, parent=None):
super().__init__(parent=parent) super().__init__(parent=parent)
#self.setParent(parent)
self.x = x self.x = x
self.y = y self.y = y
self.width = width self.width = width
@ -142,4 +143,5 @@ class animBox(QGraphicsObject):
def mousePressEvent(self, event): def mousePressEvent(self, event):
if ~self.freeze: if ~self.freeze:
self.length = 0
self.buttonClicked.emit(self.text) self.buttonClicked.emit(self.text)

View File

@ -23,6 +23,7 @@ class BaseSudokuItem(QGraphicsObject):
self.freeze = False self.freeze = False
class NumberPainter(BaseSudokuItem): class NumberPainter(BaseSudokuItem):
# TODO: Use different font to differentiate the status of a cell # TODO: Use different font to differentiate the status of a cell
@ -117,13 +118,11 @@ class SudokuGrid(BaseSudokuItem):
self.anim.finished.connect(self.finish_drawing) self.anim.finished.connect(self.finish_drawing)
def finish_drawing(self): def finish_drawing(self):
print('Grid drawn')
if self.length == self.width: if self.length == self.width:
self.drawn = True self.drawn = True
# Toggle the animation to be play forward or backward # Toggle the animation to be play forward or backward
def toggle_anim(self, toggling): def toggle_anim(self, toggling):
print('drawing grid')
if toggling: if toggling:
self.anim.setDirection(QAbstractAnimation.Forward) self.anim.setDirection(QAbstractAnimation.Forward)
else: else:
@ -223,27 +222,30 @@ class NumberRing(BaseSudokuItem):
else: else:
cell_string = str(i) cell_string = str(i)
btn = buttons.animBox(cell_x, cell_y, self.cell_width, btn = buttons.animBox(cell_x, cell_y, self.cell_width,
self.cell_height, cell_string, self) self.cell_height, cell_string, parent=self)
self.cell_buttons.append(btn) self.cell_buttons.append(btn)
self.setFlag(QGraphicsItem.ItemIsFocusable, True) self.setFlag(QGraphicsItem.ItemIsFocusable, True)
def boundingRect(self): def boundingRect(self):
return QRectF(-5, -5, self.cell_width+self.radius*2+10, return QRectF(-5-self.radius-self.cell_width/2, -5-self.radius-self.cell_height/2,
self.cell_height + self.radius * 2 + 10) self.cell_width+self.radius*2+10, self.cell_height + self.radius * 2 + 10)
# Reimplemented paint # Reimplemented paint
def paint(self, painter, style, widget=None): def paint(self, painter, style, widget=None):
#painter.setPen(self.default_pen)
#painter.drawRect(self.boundingRect())
pass pass
def connect_button_signals(self, func): def connect_button_signals(self, func):
for btn in self.cell_buttons: for btn in self.cell_buttons:
btn.buttonClicked.connect(func) btn.buttonClicked.connect(func)
print('Buttons Connected')
def freeze_buttons(self, state): #def freeze_buttons(self, state):
for btn in self.cell_buttons: # for btn in self.cell_buttons:
btn.freeze = state # btn.freeze = state
def focusOutEvent(self, event): def focusOutEvent(self, event):
self.setVisible(False) self.setVisible(False)
@ -261,6 +263,7 @@ class PlayMenu(BaseSudokuItem):
painter.setPen(self.default_pen) painter.setPen(self.default_pen)
painter.drawRect(self.rect.width()/2, self.rect.height()/2, painter.drawRect(self.rect.width()/2, self.rect.height()/2,
100, 100) 100, 100)
def boundingRect(self): def boundingRect(self):
return QRectF(self.rect.width()/2, self.rect.height()/2, return QRectF(self.rect.width()/2, self.rect.height()/2,
100, 100) 100, 100)