/ app / widgets / card_widget.py
card_widget.py
 1  '''
 2  	SuperFormat is a program that converts files into various formats
 3  	Copyright (C) 2025 daroi
 4  
 5      This program is free software: you can redistribute it and/or modify
 6      it under the terms of the GNU General Public License as published by
 7      the Free Software Foundation, either version 3 of the License, or
 8      (at your option) any later version.
 9  
10      This program is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13      GNU General Public License for more details.
14  
15      You should have received a copy of the GNU General Public License
16      along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  '''
18  
19  from PyQt6.QtWidgets import QPushButton, QVBoxLayout, QLabel, QGraphicsDropShadowEffect, QSizePolicy
20  from PyQt6.QtGui import QPixmap, QColor
21  from PyQt6.QtCore import Qt
22  
23  # Personalized cards
24  class CardWidget(QPushButton):
25      # Builder
26      def __init__(self, title: str, description: str, image_path: str = None):
27          super().__init__()
28          # Identifier in the qss
29          self.setObjectName("CardWidget")
30          
31          self.setCursor(Qt.CursorShape.PointingHandCursor)
32          self.setFlat(True)
33          
34          # Adaptative size
35          self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)
36  
37          # Shadow
38          shadow = QGraphicsDropShadowEffect(self)
39          shadow.setBlurRadius(20)
40          shadow.setOffset(0, 4)
41          shadow.setColor(QColor("#9b59b6"))  # Neon purple
42          self.setGraphicsEffect(shadow)
43  
44          layout = QVBoxLayout()
45          layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
46          layout.setContentsMargins(15, 15, 15, 15)
47          layout.setSpacing(10)
48  
49          # Image path
50          if image_path:
51              image_label = QLabel()
52              pixmap = QPixmap(image_path)
53              if not pixmap.isNull(): # 200, 120
54                  image_label.setPixmap(pixmap.scaled(70, 150, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation))
55                  layout.addWidget(image_label)
56                  # Center the images
57                  image_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
58  
59          # Title
60          title_label = QLabel(title)
61          title_label.setStyleSheet("font-size: 16px; font-weight: bold;")
62          title_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
63          layout.addWidget(title_label)
64  
65          # Description
66          desc_label = QLabel(description)
67          desc_label.setWordWrap(True)
68          desc_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
69          layout.addWidget(desc_label)
70  
71          self.setLayout(layout)
72          self.setCursor(Qt.CursorShape.PointingHandCursor)  # Hover efect