From: Niki Roo Date: Thu, 27 Mar 2025 12:12:18 +0000 (+0100) Subject: qt: improve images X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=1fe2e71789d3f3a31faefaca85b5461b971c870a;p=gamiki.git qt: improve images --- diff --git a/gamiki/qt/tiles.py b/gamiki/qt/tiles.py index b2d9181..a409152 100755 --- a/gamiki/qt/tiles.py +++ b/gamiki/qt/tiles.py @@ -42,6 +42,8 @@ class Cover(QWidget): self.cover_size = size else: self.cover_size = 48 if (CoverMode.LIST in self.cover_mode) else 200 + + self.pixmap=QPixmap(self.game["Icon"] if ("Icon" in self.game) else "") self.initUI() makeMouseAware(self, [self, self.cover]) @@ -66,17 +68,28 @@ class Cover(QWidget): self.line2.setAlignment(Qt.AlignRight) self._resetMinMax() + + def _resetPixmap(self): + crop = self.pixmap + + w = self.pixmap.width() + h = self.pixmap.height() + crop = self.pixmap.copy( + int((w - h) / 2) if w > h else 0, + int((h - w) / 2) if h > w else 0, + min(w, h), min(w, h) + ) + + self.cover.setPixmap(crop) def initUI(self): self._initUI_text() - - pixmap = QPixmap(self.game["Icon"] if ("Icon" in self.game) else "") - + self.cover = QLabel() - self.cover.setPixmap(pixmap) self.cover.setScaledContents(True) self.cover.setMinimumSize(self.cover_size, self.cover_size) self.cover.setMaximumSize(self.cover_size, self.cover_size) + self._resetPixmap() line1sub = QWidget() hlay = QHBoxLayout() @@ -156,9 +169,6 @@ class List(QWidget): cover.onClick.connect(lambda game: self.onClick.emit(game)) covers.append(cover) return covers - - def _on_click(self, game): - print(repr(game)) class Grid(List): def __init__(self, games: list[Game], icon_size: int = 0): @@ -176,8 +186,8 @@ if __name__ == '__main__': app = QApplication(argv) game1 = Game(None, PurePath("")) - game1["Name"] = "Super Buba" - game1["Icon"] = "./buba.jpg" + game1["Name"] = "Super Sheep" + game1["Icon"] = "./super-sheep.jpg" game1._init() game2 = Game(None, PurePath("")) game2["Name"] = "Super Buba II: le retour de la nouvelle bête"