Skip to content

Commit c9e54c8

Browse files
committed
use right click to remove tiles from configuration
1 parent 0b77aff commit c9e54c8

1 file changed

Lines changed: 25 additions & 10 deletions

File tree

src/widgets/widget_tile.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ class Tile(BaseTile):
1616
def __init__(self, tile_id: int, width=64, height=64) -> None:
1717
super().__init__(tile_id)
1818
self.setMaximumSize(width, height)
19-
20-
self.mousePressEvent = self.openDialog
2119
self.hovered = False
2220
self.selected = False
2321
self.dialog = TileSettingsDialog(self)
2422
self.alpha = None
2523
self.setMouseTracking(True)
2624
self.lock = True # lock as long as empty
27-
self.data_checked = False # true after checked
25+
self.tile_checked: int = 0 # 0 = unchecked, 1 = configured, 2 = removed
2826
self.image: Optional[QImage] = None
2927

3028
def paintEvent(self,
@@ -49,20 +47,30 @@ def paintPixmapExists(self, qp: QPainter):
4947
qp.fillRect(0, 0, self.width() - 1, self.height() - 1, QColor(255, 255, 255, 100))
5048

5149
if self.tile_data:
52-
if self.data_checked:
53-
qp.setPen(QPen(QColor(0, 255, 0, 255), 10))
54-
qp.drawText(self.width() - 20, self.height() - 20, 20, 20, Qt.AlignmentFlag.AlignVCenter, "✔️")
55-
else:
50+
if self.tile_checked == 0:
5651
qp.setPen(QPen(QColor(255, 255, 0, 255), 10))
5752
qp.drawText(self.width() - 20, self.height() - 20, 20, 20, Qt.AlignmentFlag.AlignVCenter, "?")
53+
elif self.tile_checked == 1:
54+
qp.setPen(QPen(QColor(0, 255, 0, 255), 10))
55+
qp.drawText(self.width() - 20, self.height() - 20, 20, 20, Qt.AlignmentFlag.AlignVCenter, "✔️")
56+
elif self.tile_checked == 2:
57+
qp.setPen(QPen(QColor(255, 0, 0, 255), 10))
58+
qp.drawText(self.width() - 20, self.height() - 20, 20, 20, Qt.AlignmentFlag.AlignVCenter, "❌")
5859

5960
# draw outline
6061
pen = QPen(QColor(0, 0, 0, 127), 1)
6162
pen.setStyle(Qt.PenStyle.DotLine)
6263
qp.setPen(pen)
6364
qp.drawRect(0, 0, self.width() - 1, self.height() - 1)
6465

65-
def openDialog(self, _):
66+
def mousePressEvent(self, event):
67+
if event.button() == Qt.MouseButton.RightButton:
68+
self.rightMouseButtonClicked()
69+
else:
70+
self.leftMouseButtonClicked()
71+
super().mousePressEvent(event)
72+
73+
def leftMouseButtonClicked(self):
6674
# one does not simply configure locked tiles
6775
if self.lock:
6876
return
@@ -81,14 +89,21 @@ def openDialog(self, _):
8189
if ret == 1:
8290
# update tile data in handler
8391
self.tile_data = self.dialog.getTileData()
84-
print(self.tile_data.con)
85-
self.data_checked = True
92+
self.tile_checked = 1
8693
TileHandler.instance().updateTileStorage(self)
8794

8895
# mark tile as deselected after dialog
8996
self.selected = False
9097
self.update()
9198

99+
def rightMouseButtonClicked(self):
100+
if self.lock:
101+
return
102+
103+
TileHandler.instance().removeTileFromStorage(self.tile_id)
104+
self.tile_checked = 2
105+
self.update()
106+
92107
def enterEvent(self, event):
93108
self.hovered = True
94109
self.update()

0 commit comments

Comments
 (0)