3232#include < QResizeEvent>
3333#include < QSizePolicy>
3434#include < QTabBar>
35- #include < QTimer>
3635#include < QToolButton>
3736#include < QToolTip>
38- #include < QWindow>
3937
4038namespace {
4139
42- constexpr int kSpinIntervalMs = 66 ; // ~15 fps, one timer for the whole strip
43- constexpr int kSpinPeriodMs = 1000 ; // one turn of the arc
44- constexpr int kArcSpanDeg = 100 ;
40+ constexpr int kBusyFillAlpha = 110 ; // Highlight at ~43%: the digit stays readable
4541
46- // A session number that can wear a spinner. Painting only; the size never
47- // changes, so a busy session never relayouts the tab bar.
42+ // A session number that can wear a working fill and a waiting dot. Painting
43+ // only, and static: the size never changes (a busy session never relayouts the
44+ // tab bar) and nothing repaints on a timer.
4845class SessionNumberButton : public QToolButton
4946{
5047public:
@@ -64,31 +61,26 @@ class SessionNumberButton : public QToolButton
6461 m_waiting = waiting;
6562 update ();
6663 }
67- void setSpinAngle (int degrees)
68- {
69- m_angle = degrees;
70- if (m_busy)
71- update ();
72- }
7364
7465protected:
7566 void paintEvent (QPaintEvent *event) override
7667 {
77- QToolButton::paintEvent (event);
78- if (!m_busy && !m_waiting)
79- return ;
80- QPainter p (this );
81- p.setRenderHint (QPainter::Antialiasing);
68+ // One painter at a time on a widget: the base paint opens its own.
8269 if (m_busy) {
83- const int side = qMin (width (), height ()) - 2 ;
84- QRectF ring (0 , 0 , side, side);
85- ring.moveCenter (QRectF (rect ()).center ());
86- QPen pen (palette ().color (QPalette::Highlight), 1.5 );
87- pen.setCapStyle (Qt::RoundCap);
88- p.setPen (pen);
89- p.drawArc (ring, -m_angle * 16 , -kArcSpanDeg * 16 );
70+ // Under the stylesheet's transparent rest background, so the
71+ // digit, the current number's border and the hover fill draw on top.
72+ QPainter p (this );
73+ p.setRenderHint (QPainter::Antialiasing);
74+ QColor fill = palette ().color (QPalette::Highlight);
75+ fill.setAlpha (kBusyFillAlpha );
76+ p.setPen (Qt::NoPen);
77+ p.setBrush (fill);
78+ p.drawRoundedRect (QRectF (rect ()), kFillRadius , kFillRadius );
9079 }
80+ QToolButton::paintEvent (event);
9181 if (m_waiting) {
82+ QPainter p (this );
83+ p.setRenderHint (QPainter::Antialiasing);
9284 // A window-coloured rim keeps the dot apart from the digit.
9385 const QPointF center (width () - kDotRadius - 1 , kDotRadius + 1 );
9486 p.setPen (QPen (palette ().color (QPalette::Window), 1 ));
@@ -99,19 +91,16 @@ class SessionNumberButton : public QToolButton
9991
10092private:
10193 static constexpr qreal kDotRadius = 3.0 ; // ~6px dot, top-right corner
94+ static constexpr qreal kFillRadius = 4.0 ; // ui-dna status-surface radius
10295 bool m_busy = false ;
10396 bool m_waiting = false ;
104- int m_angle = 0 ;
10597};
10698
10799} // namespace
108100
109101AiDockSessionStrip::AiDockSessionStrip (QWidget *parent)
110102 : QWidget(parent)
111103{
112- m_spinTimer = new QTimer (this );
113- m_spinTimer->setInterval (kSpinIntervalMs );
114- connect (m_spinTimer, &QTimer::timeout, this , &AiDockSessionStrip::onSpinTick);
115104 m_layout = new QHBoxLayout (this );
116105 m_layout->setContentsMargins (0 , 0 , 0 , 0 );
117106 m_layout->setSpacing (kSpacingPx );
@@ -143,9 +132,9 @@ void AiDockSessionStrip::setSlots(int count, int current, const QVector<SlotSnap
143132 rebuildButtons ();
144133}
145134
146- bool AiDockSessionStrip::isSpinning ( ) const
135+ bool AiDockSessionStrip::busyAt ( int index ) const
147136{
148- return m_spinTimer-> isActive () ;
137+ return index >= 0 && index < m_snapshots. size () && m_snapshots. at (index). busy ;
149138}
150139
151140QColor AiDockSessionStrip::attentionColor ()
@@ -158,54 +147,10 @@ bool AiDockSessionStrip::waitingAt(int index) const
158147 return index >= 0 && index < m_snapshots.size () && m_snapshots.at (index).waiting ;
159148}
160149
161- void AiDockSessionStrip::updateSpinTimer ()
162- {
163- bool anyBusy = false ;
164- for (const SlotSnapshot &snap : std::as_const (m_snapshots)) {
165- if (snap.busy ) {
166- anyBusy = true ;
167- break ;
168- }
169- }
170- const QWidget *top = window ();
171- const bool want = anyBusy && isVisible () && top && !top->isMinimized ();
172- if (want == m_spinTimer->isActive ())
173- return ;
174- if (want) {
175- m_spinClock.start ();
176- m_spinTimer->start ();
177- } else {
178- m_spinTimer->stop ();
179- }
180- }
181-
182- void AiDockSessionStrip::onSpinTick ()
183- {
184- const int angle = static_cast <int >((m_spinClock.elapsed () % kSpinPeriodMs ) * 360 / kSpinPeriodMs );
185- for (QToolButton *btn : std::as_const (m_buttons))
186- static_cast <SessionNumberButton *>(btn)->setSpinAngle (angle);
187- }
188-
189- void AiDockSessionStrip::showEvent (QShowEvent *event)
190- {
191- QWidget::showEvent (event);
192- // Minimizing hides no widget: follow the window's own visibility.
193- if (QWindow *handle = window () ? window ()->windowHandle () : nullptr ; handle != m_trackedWindow) {
194- if (m_trackedWindow)
195- disconnect (m_trackedWindow, nullptr , this , nullptr );
196- m_trackedWindow = handle;
197- if (handle) {
198- connect (handle, &QWindow::visibilityChanged, this , [this ]() { updateSpinTimer (); });
199- }
200- }
201- updateSpinTimer ();
202- }
203-
204150void AiDockSessionStrip::hideEvent (QHideEvent *event)
205151{
206152 QWidget::hideEvent (event);
207153 endDrag ();
208- updateSpinTimer ();
209154}
210155
211156QSize AiDockSessionStrip::sizeHint () const
@@ -406,23 +351,27 @@ void AiDockSessionStrip::restyleButtons()
406351 for (int i = 0 ; i < m_buttons.size (); ++i) {
407352 QToolButton *btn = m_buttons.at (i);
408353 const bool current = (i == m_current);
354+ const bool busy = busyAt (i);
409355 auto *numberBtn = static_cast <SessionNumberButton *>(btn);
410- numberBtn->setBusy (i < m_snapshots. size () && m_snapshots. at (i). busy );
356+ numberBtn->setBusy (busy);
411357 numberBtn->setWaiting (waitingAt (i));
412358
413359 QFont font = btn->font ();
414360 font.setBold (current);
415361 btn->setFont (font);
416362
363+ // A muted digit on the working fill is too faint: busy numbers take the
364+ // full text colour (the current one still has the bold and the border).
365+ const bool strong = current || busy;
417366 QPalette pal = btn->palette ();
418- pal.setColor (QPalette::ButtonText, current ? currentColor : muted);
419- pal.setColor (QPalette::WindowText, current ? currentColor : muted);
367+ pal.setColor (QPalette::ButtonText, strong ? currentColor : muted);
368+ pal.setColor (QPalette::WindowText, strong ? currentColor : muted);
420369 btn->setPalette (pal);
421370 // Toolbar chrome (ui-dna): auto-raise + 1px mid border on hover.
422371 // Transparent rest border keeps size stable. Windows QStyle ignores
423372 // QToolButton palette colors, so paint via palette() roles.
424- const QString colorRole = current ? QStringLiteral (" palette(button-text)" )
425- : QStringLiteral (" palette(placeholder-text)" );
373+ const QString colorRole = strong ? QStringLiteral (" palette(button-text)" )
374+ : QStringLiteral (" palette(placeholder-text)" );
426375 const QString restBorder = current ? QStringLiteral (" 1px solid palette(mid)" )
427376 : QStringLiteral (" 1px solid transparent" );
428377 btn->setStyleSheet (
@@ -433,7 +382,6 @@ void AiDockSessionStrip::restyleButtons()
433382 .arg (colorRole, QString::number (kSpacingPx ), restBorder));
434383 btn->setMinimumSize (btn->sizeHint ());
435384 }
436- updateSpinTimer ();
437385 syncIntrinsicSize ();
438386 notifyHostTabBar ();
439387}
0 commit comments