mirror of
https://github.com/rbreu/beeref.git
synced 2026-03-11 08:54:28 +00:00
Minor refactoring of BeePixmapItem.set_pos_center
This commit is contained in:
parent
829d0d19fc
commit
46768dce24
2 changed files with 12 additions and 2 deletions
|
|
@ -43,8 +43,7 @@ class BeePixmapItem(SelectableMixin, QtWidgets.QGraphicsPixmapItem):
|
|||
def set_pos_center(self, pos):
|
||||
"""Sets the position using the item's center as the origin point."""
|
||||
|
||||
center = self.mapToScene(QtCore.QPointF(self.width/2, self.height/2))
|
||||
self.setPos(pos - center)
|
||||
self.setPos(pos - self.center_scene_coords)
|
||||
|
||||
@property
|
||||
def width(self):
|
||||
|
|
|
|||
|
|
@ -33,6 +33,17 @@ class BeePixmapItemTestCase(BeeTestCase):
|
|||
assert item.pos().x() == -100
|
||||
assert item.pos().y() == -50
|
||||
|
||||
def test_set_pos_center_when_scaled(self):
|
||||
item = BeePixmapItem(QtGui.QImage())
|
||||
item.setScale(2)
|
||||
with patch('beeref.items.BeePixmapItem.width',
|
||||
new_callable=PropertyMock, return_value=200):
|
||||
with patch('beeref.items.BeePixmapItem.height',
|
||||
new_callable=PropertyMock, return_value=100):
|
||||
item.set_pos_center(QtCore.QPointF(0, 0))
|
||||
assert item.pos().x() == -200
|
||||
assert item.pos().y() == -100
|
||||
|
||||
def test_pixmap_to_bytes(self):
|
||||
item = BeePixmapItem(QtGui.QImage(self.imgfilename3x3))
|
||||
assert item.pixmap_to_bytes().startswith(b'\x89PNG')
|
||||
|
|
|
|||
Loading…
Reference in a new issue