qt: improve images
authorNiki Roo <niki@nikiroo.be>
Thu, 27 Mar 2025 12:12:18 +0000 (13:12 +0100)
committerNiki Roo <niki@nikiroo.be>
Thu, 27 Mar 2025 12:12:18 +0000 (13:12 +0100)
gamiki/qt/tiles.py

index b2d91814c8eff531433cd59667bde34d4d6f1afc..a409152843c2949f8222fd088f3116ddff573099 100755 (executable)
@@ -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"