11import typing
22
33from PyQt6 import QtCore , QtGui , QtWidgets
4- from lib .utils .blocks_label import BlocksLabel
54from lib .utils .icon_button import IconButton
65
76
8- class OptionCard (QtWidgets .QFrame ):
9- continue_clicked : typing .ClassVar [QtCore .pyqtSignal ] = QtCore .pyqtSignal (
7+ class OptionCard (QtWidgets .QAbstractButton ):
8+ clicked : typing .ClassVar [QtCore .pyqtSignal ] = QtCore .pyqtSignal (
109 "PyQt_PyObject" , name = "continue_clicked"
1110 )
1211
@@ -25,8 +24,22 @@ def __init__(
2524 self .icon_background_color = QtGui .QColor (150 , 150 , 130 , 80 )
2625 self .name = name
2726 self .card_text = text
27+ self .doubleT : bool = False
2828 self ._setupUi (self )
29- self .continue_button .clicked .connect (lambda : self .continue_clicked .emit (self ))
29+ self .option_icon .setAttribute (
30+ QtCore .Qt .WidgetAttribute .WA_TransparentForMouseEvents
31+ )
32+ self .option_text .setAttribute (
33+ QtCore .Qt .WidgetAttribute .WA_TransparentForMouseEvents
34+ )
35+ self .secondtext .setAttribute (
36+ QtCore .Qt .WidgetAttribute .WA_TransparentForMouseEvents
37+ )
38+ self .line_separator .setAttribute (
39+ QtCore .Qt .WidgetAttribute .WA_TransparentForMouseEvents
40+ )
41+
42+ self .setMode (False )
3043 self .set_card_icon (icon )
3144 self .set_card_text (text )
3245
@@ -42,7 +55,13 @@ def enable_button(self) -> None:
4255
4356 def set_card_icon (self , pixmap : QtGui .QPixmap ) -> None :
4457 """Set widget icon"""
45- self .option_icon .setPixmap (pixmap )
58+ scaled = pixmap .scaled (
59+ 300 ,
60+ 300 ,
61+ QtCore .Qt .AspectRatioMode .IgnoreAspectRatio ,
62+ QtCore .Qt .TransformationMode .SmoothTransformation ,
63+ )
64+ self .option_icon .setPixmap (scaled )
4665 self .repaint ()
4766
4867 def set_card_text (self , text : str ) -> None :
@@ -79,14 +98,54 @@ def leaveEvent(self, a0: QtCore.QEvent) -> None:
7998
8099 def mousePressEvent (self , a0 : QtGui .QMouseEvent ) -> None :
81100 """Re-implemented method, handle mouse press event"""
101+ self .clicked .emit (self )
82102 self .update ()
83103 return super ().mousePressEvent (a0 )
84104
105+ def setMode (self , double_mode : bool = False ):
106+ """Set the mode of the layout: single or double text."""
107+ self .doubleT = double_mode
108+
109+ # Clear existing widgets from layout before adding new ones
110+ while self .verticalLayout .count ():
111+ item = self .verticalLayout .takeAt (0 )
112+ widget = item .widget ()
113+ if widget is not None :
114+ widget .setParent (None )
115+
116+ if self .doubleT :
117+ self .verticalLayout .addWidget (
118+ self .option_icon ,
119+ 0 ,
120+ QtCore .Qt .AlignmentFlag .AlignHCenter
121+ | QtCore .Qt .AlignmentFlag .AlignBottom ,
122+ )
123+ self .verticalLayout .addWidget (
124+ self .secondtext , 0 , QtCore .Qt .AlignmentFlag .AlignHCenter
125+ )
126+ self .verticalLayout .addWidget (
127+ self .line_separator , 0 , QtCore .Qt .AlignmentFlag .AlignCenter
128+ )
129+ self .verticalLayout .addWidget (self .option_text )
130+ self .verticalLayout .addItem (self .spacer )
131+ self .secondtext .show ()
132+ else :
133+ self .verticalLayout .addWidget (
134+ self .option_icon , 0 , QtCore .Qt .AlignmentFlag .AlignCenter
135+ )
136+ self .verticalLayout .addWidget (
137+ self .line_separator , 0 , QtCore .Qt .AlignmentFlag .AlignCenter
138+ )
139+ self .verticalLayout .addWidget (self .option_text )
140+ self .verticalLayout .addWidget (self .continue_button )
141+
142+ self .update ()
143+
85144 def paintEvent (self , a0 : QtGui .QPaintEvent ) -> None :
86145 """Re-implemented method, paint widget"""
87146 # Rounded background edges
88- self . background_path = QtGui .QPainterPath ()
89- self . background_path .addRoundedRect (
147+ background_path = QtGui .QPainterPath ()
148+ background_path .addRoundedRect (
90149 self .rect ().toRectF (), 20.0 , 20.0 , QtCore .Qt .SizeMode .AbsoluteSize
91150 )
92151
@@ -108,7 +167,7 @@ def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
108167 painter .setRenderHint (painter .RenderHint .Antialiasing )
109168 painter .setRenderHint (painter .RenderHint .SmoothPixmapTransform )
110169 painter .setRenderHint (painter .RenderHint .LosslessImageRendering )
111- painter .fillPath (self . background_path , bg_color )
170+ painter .fillPath (background_path , bg_color )
112171 if self .underMouse ():
113172 _pen = QtGui .QPen ()
114173 _pen .setStyle (QtCore .Qt .PenStyle .SolidLine )
@@ -134,7 +193,7 @@ def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
134193 _gradient .setColorAt (1 , _color3 )
135194 painter .setBrush (_gradient )
136195 painter .setPen (QtCore .Qt .PenStyle .NoPen )
137- painter .fillPath (self . background_path , painter .brush ())
196+ painter .fillPath (background_path , painter .brush ())
138197
139198 painter .end ()
140199
@@ -154,12 +213,21 @@ def _setupUi(self, option_card):
154213 self .verticalLayout = QtWidgets .QVBoxLayout (option_card )
155214 self .verticalLayout .setContentsMargins (0 , 0 , - 1 , - 1 )
156215 self .verticalLayout .setObjectName ("verticalLayout" )
157- self .option_icon = BlocksLabel (parent = option_card )
216+ self .option_icon = IconButton (parent = option_card )
158217 self .option_icon .setMinimumSize (QtCore .QSize (200 , 150 ))
159218 self .option_icon .setObjectName ("option_icon" )
160- self .verticalLayout .addWidget (
161- self .option_icon , 0 , QtCore .Qt .AlignmentFlag .AlignHCenter
162- )
219+ self .option_icon .setScaledContents (True )
220+ _button_font = QtGui .QFont ()
221+ _button_font .setBold (True )
222+ _button_font .setPointSize (20 )
223+ self .secondtext = QtWidgets .QLabel (parent = option_card )
224+ self .secondtext .setText ("%" )
225+ self .secondtext .setStyleSheet ("color:white" )
226+ self .secondtext .setFont (_button_font )
227+ self .secondtext .setObjectName ("option_text" )
228+ self .secondtext .setWordWrap (True )
229+ self .secondtext .setAlignment (QtCore .Qt .AlignmentFlag .AlignCenter )
230+ self .secondtext .hide ()
163231 self .line_separator = QtWidgets .QFrame (parent = option_card )
164232 self .line_separator .setFrameShape (QtWidgets .QFrame .Shape .HLine )
165233 self .line_separator .setFrameShadow (QtWidgets .QFrame .Shadow .Sunken )
@@ -174,21 +242,15 @@ def _setupUi(self, option_card):
174242 self .option_text = QtWidgets .QLabel (parent = option_card )
175243 self .option_text .setMinimumSize (QtCore .QSize (200 , 50 ))
176244 self .option_text .setObjectName ("option_text" )
177- self .verticalLayout .addWidget (
178- self .option_text ,
179- )
180- self .continue_button = IconButton (parent = option_card )
181- self .option_text .setAlignment (
182- QtCore .Qt .AlignmentFlag .AlignHCenter | QtCore .Qt .AlignmentFlag .AlignVCenter
183- )
184245 self .option_text .setWordWrap (True )
185- _button_font = QtGui . QFont ( )
186- _button_font . setBold ( True )
246+ self . option_text . setStyleSheet ( "color:white" )
247+ self . option_text . setAlignment ( QtCore . Qt . AlignmentFlag . AlignCenter )
187248 _palette = self .option_text .palette ()
188249 _palette .setColor (QtGui .QPalette .ColorRole .WindowText , self .text_color )
189250 self .option_text .setPalette (_palette )
190- _button_font . setPointSize ( 15 )
251+
191252 self .option_text .setFont (_button_font )
253+ self .continue_button = IconButton (parent = option_card )
192254 sizePolicy = QtWidgets .QSizePolicy (
193255 QtWidgets .QSizePolicy .Policy .MinimumExpanding ,
194256 QtWidgets .QSizePolicy .Policy .MinimumExpanding ,
@@ -207,8 +269,13 @@ def _setupUi(self, option_card):
207269 QtGui .QPixmap (":/arrow_icons/media/btn_icons/right_arrow.svg" ),
208270 )
209271 self .continue_button .setObjectName ("continue_button" )
210- self .verticalLayout .addWidget (self .continue_button )
211272
273+ self .spacer = QtWidgets .QSpacerItem (
274+ 20 ,
275+ 40 ,
276+ QtWidgets .QSizePolicy .Policy .Minimum ,
277+ QtWidgets .QSizePolicy .Policy .Expanding ,
278+ )
212279 self ._retranslateUi (option_card )
213280 QtCore .QMetaObject .connectSlotsByName (option_card )
214281
0 commit comments