Skip to content

Commit

Permalink
add center image button
Browse files Browse the repository at this point in the history
  • Loading branch information
Conengmo committed Nov 18, 2024
1 parent 6cad47a commit 56fd61a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
21 changes: 16 additions & 5 deletions battle_map_tv/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ def wheelEvent(self, event):

def mouseReleaseEvent(self, event):
super().mouseReleaseEvent(event)
self.store_position()

def set_position(self, position: tuple[int, int]):
self.setPos(
position[0] - self.pixmap().width() // 2,
position[1] - self.pixmap().height() // 2,
)
self.store_position()

def store_position(self):
position = (
self.pos().x() + self.pixmap().width() // 2,
self.pos().y() + self.pixmap().height() // 2,
Expand Down Expand Up @@ -99,16 +109,17 @@ def __init__(
do_raise=True,
)
except KeyError:
pass
self.center()
else:
self.pixmap_item.setPos(
position[0] - self.pixmap_item.pixmap().width() // 2,
position[1] - self.pixmap_item.pixmap().height() // 2,
)
self.pixmap_item.set_position(position)

def delete(self):
self.scene.removeItem(self.pixmap_item)

def center(self):
position = (int(self.scene.width() // 2), int(self.scene.height() // 2))
self.pixmap_item.set_position(position)

def rotate(self):
self.rotation = (self.rotation + 90) % 360
self.pixmap_item.setRotation(self.rotation)
Expand Down
8 changes: 8 additions & 0 deletions battle_map_tv/window_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ def open_file_dialog():
button.clicked.connect(self.image_window.restore_image)
container.addWidget(button)

def callback_button_center_image():
if self.image_window.image is not None:
self.image_window.image.center()

button = StyledButton("Center")
button.clicked.connect(callback_button_center_image)
container.addWidget(button)

def callback_button_rotate_image():
if self.image_window.image is not None:
self.image_window.image.rotate()
Expand Down

0 comments on commit 56fd61a

Please sign in to comment.