@@ -14,8 +14,11 @@ GlassButton::GlassButton(const QString& iconChar, const QString& title,
1414 , m_titleText(title)
1515 , m_descText(description)
1616 , m_accentColor(accentColor)
17+ , m_isActive(false )
1718{
18- setFixedHeight (80 );
19+ // Removed fixed height to allow dynamic sizing
20+ setMinimumHeight (40 );
21+ setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred);
1922 setCursor (Qt::PointingHandCursor);
2023
2124 m_opacityEffect = new QGraphicsOpacityEffect (this );
@@ -34,6 +37,12 @@ void GlassButton::setEnabled(bool enabled) {
3437 update ();
3538}
3639
40+ void GlassButton::setActive (bool active) {
41+ if (m_isActive == active) return ;
42+ m_isActive = active;
43+ update ();
44+ }
45+
3746void GlassButton::paintEvent (QPaintEvent* event) {
3847 Q_UNUSED (event);
3948
@@ -45,36 +54,51 @@ void GlassButton::paintEvent(QPaintEvent* event) {
4554 bool isPressed = isDown () && isEnabled ();
4655
4756 QRect rect = this ->rect ();
57+ int h = rect.height ();
58+ bool isCompact = (h < 60 ); // Compact mode for sidebar items
59+
4860 QRect bgRect = rect.adjusted (1 , 1 , -1 , -1 );
4961
5062 // 1. Background (Glass)
5163 QColor bgColor = Colors::toQColor (Colors::GLASS_BG);
52- if (isHover) {
64+
65+ if (m_isActive) {
66+ // Active state background (Accent tint)
67+ bgColor = QColor (m_accentColor);
68+ bgColor.setAlpha (30 );
69+ } else if (isHover) {
5370 bgColor = Colors::toQColor (Colors::GLASS_HOVER);
54- }
55- if (isPressed) {
71+ } else if (isPressed) {
5672 bgColor = QColor (m_accentColor);
5773 bgColor.setAlpha (40 );
5874 }
5975
6076 QPainterPath path;
61- path.addRoundedRect (bgRect, 16 , 16 );
77+ path.addRoundedRect (bgRect, 8 , 8 ); // Reduced radius for cleaner look
6278 painter.fillPath (path, bgColor);
6379
64- // 2. Border
65- QColor borderColor = Colors::toQColor (Colors::GLASS_BORDER);
66- if (isHover || isPressed) {
67- borderColor = QColor (m_accentColor);
68- borderColor.setAlpha (100 );
80+ // 2. Active Indicator (Left Border)
81+ if (m_isActive) {
82+ painter.fillRect (0 , 4 , 3 , h - 8 , QColor (m_accentColor));
83+ }
84+
85+ // 3. Border (Optional)
86+ if (!m_isActive) {
87+ QColor borderColor = Colors::toQColor (Colors::GLASS_BORDER);
88+ if (isHover || isPressed) {
89+ borderColor = QColor (m_accentColor);
90+ borderColor.setAlpha (80 );
91+ }
92+ QPen pen (borderColor, 1 );
93+ painter.setPen (pen);
94+ painter.drawPath (path);
6995 }
7096
71- QPen pen (borderColor, 1 );
72- painter. setPen (pen);
73- painter. drawPath (path) ;
97+ // 4. Icon Box (Left)
98+ int iconSize = isCompact ? 28 : 40 ; // Reduced from 48
99+ int padding = isCompact ? 8 : 16 ;
74100
75- // 3. Icon Box (Left)
76- int iconSize = 48 ;
77- QRect iconRect (20 , (rect.height () - iconSize) / 2 , iconSize, iconSize);
101+ QRect iconRect (padding, (h - iconSize) / 2 , iconSize, iconSize);
78102
79103 // Icon Background Gradient
80104 QLinearGradient grad (iconRect.topLeft (), iconRect.bottomRight ());
@@ -85,29 +109,38 @@ void GlassButton::paintEvent(QPaintEvent* event) {
85109
86110 painter.setPen (Qt::NoPen);
87111 painter.setBrush (QBrush (grad));
88- painter.drawRoundedRect (iconRect, 12 , 12 );
112+ painter.drawRoundedRect (iconRect, isCompact ? 8 : 10 , isCompact ? 8 : 10 );
89113
90114 // Icon Text
91115 painter.setPen (QColor (" #FFFFFF" ));
92- QFont iconFont (" Segoe UI Symbol" , 18 );
116+ QFont iconFont (" Segoe UI Symbol" , isCompact ? 12 : 16 ); // Reduced from 18
93117 painter.setFont (iconFont);
94118 painter.drawText (iconRect, Qt::AlignCenter, m_iconChar);
95119
96- // 4. Text Content
97- int textX = 20 + iconSize + 16 ;
98- int textW = rect.width () - textX - 10 ;
99-
100- // Title
101- QRect titleRect (textX, 18 , textW, 24 );
102- painter.setPen (Colors::toQColor (Colors::TEXT_PRIMARY));
103- QFont titleFont (" Segoe UI" , 11 , QFont::Bold);
104- painter.setFont (titleFont);
105- painter.drawText (titleRect, Qt::AlignLeft | Qt::AlignVCenter, m_titleText);
106-
107- // Description
108- QRect descRect (textX, 42 , textW, 20 );
109- painter.setPen (Colors::toQColor (Colors::TEXT_SECONDARY));
110- QFont descFont (" Segoe UI" , 9 );
111- painter.setFont (descFont);
112- painter.drawText (descRect, Qt::AlignLeft | Qt::AlignVCenter, m_descText);
120+ // 5. Text Content
121+ int textX = padding + iconSize + (isCompact ? 10 : 14 );
122+ int textW = rect.width () - textX - 5 ;
123+
124+ painter.setPen (m_isActive ? QColor (m_accentColor) : Colors::toQColor (Colors::TEXT_PRIMARY));
125+
126+ if (isCompact || m_descText.isEmpty ()) {
127+ // Center Title Only
128+ QRect titleRect (textX, 0 , textW, h);
129+ QFont titleFont (" Segoe UI" , isCompact ? 9 : 10 , QFont::Bold); // Reduced from 11
130+ painter.setFont (titleFont);
131+ painter.drawText (titleRect, Qt::AlignLeft | Qt::AlignVCenter, m_titleText.trimmed ());
132+ } else {
133+ // Title & Description
134+ int titleY = (h / 2 ) - 10 ;
135+ QRect titleRect (textX, titleY - 2 , textW, 20 );
136+ QFont titleFont (" Segoe UI" , 10 , QFont::Bold);
137+ painter.setFont (titleFont);
138+ painter.drawText (titleRect, Qt::AlignLeft | Qt::AlignVCenter, m_titleText);
139+
140+ QRect descRect (textX, titleY + 18 , textW, 16 );
141+ painter.setPen (Colors::toQColor (Colors::TEXT_SECONDARY));
142+ QFont descFont (" Segoe UI" , 8 ); // Reduced from 9
143+ painter.setFont (descFont);
144+ painter.drawText (descRect, Qt::AlignLeft | Qt::AlignVCenter, m_descText);
145+ }
113146}
0 commit comments