Truly independent web browser
UI/Qt: Give hovered tabs the selected tab's shape
Andreas Klingb09701515847
diff --git a/Documentation/UI/QuietDesign.md b/Documentation/UI/QuietDesign.mdindex 52716f10cf6..06887ab7ae0 100644--- a/Documentation/UI/QuietDesign.md+++ b/Documentation/UI/QuietDesign.md@@ -92,7 +92,8 @@ All sizes are in logical pixels.| Element | Size | Notes ||---|---|---|-| Inactive tab | 28 px tall | 6 px radius, 3 px inset on each side |+| Inactive tab | No fill at rest | Content laid out in the same 30 px row as the active tab |+| Hovered tab | 30 px tall | The active tab's exact outline (full slot width, 8 px top radius, flush with the toolbar) in the `hover` fill, without the feet. Hover previews the shape the tab takes when selected; nothing inside it moves. Drawn under the active tab, so a neighboring foot overlaps it cleanly. || Active tab | 30 px tall | 8 px top radius plus an 8 px inverted "foot" on each side where it joins the toolbar. 5 px of strip shows above it. Its contents are vertically centered in it, which puts them on the shared center line. || End insets | Favicon 7 px from the left edge; × glyph 11 px from the right edge | Rule: each end item is as far from the tab's side as it is from the tab's top (the 16 px favicon sits 7 px down, the 8 px × glyph 11 px down). Padding: active 0 6 px 0 7 px; inactive 3 px inset + 0 3 px 0 4 px, so favicons and × never move when a tab becomes active. || Favicon to title | 8 px | |@@ -426,7 +427,7 @@ Don't invent new shadows. Pick a level.| State | Look ||---|---|| Default | Favicon and title; the close slot is reserved but empty |-| Hover | `hover` fill; the × fades into its slot |+| Hover | The active tab's shape in `hover` fill, no feet; the × fades into its slot || Active | Joins the toolbar; title in full `text` color, weight 400 || Dragging | Stays in the strip with a Lift shadow, flat (no tilt), slides sideways only || Loading | Accent ring (24 px) around the favicon. The favicon shrinks to 10 px inside the ring so square icons never touch it. |diff --git a/UI/Qt/TabBar.cpp b/UI/Qt/TabBar.cppindex 4b8adc156d7..a5be9254522 100644--- a/UI/Qt/TabBar.cpp+++ b/UI/Qt/TabBar.cpp@@ -138,13 +138,11 @@ static constexpr int TAB_CARD_SHAPE_TOP_INSET = 0;static constexpr int TAB_CARD_SHAPE_BOTTOM_INSET = 1;// The sidebar's tab bar leaves this much room above its first tab and below its last.static constexpr int VERTICAL_TAB_BAR_END_ROOM = 2;-// A horizontal tab's card holds its contents, and is what lights up when the tab is hovered. It is inset from the tab on-// every side.+// A horizontal tab's card holds its contents. It is inset from the tab on every side.static constexpr qreal HORIZONTAL_TAB_CARD_SHAPE_HORIZONTAL_INSET = 3;// NB: The card is as low in the tab as the selected tab's body is, so the contents of both share the strip's line.static constexpr int HORIZONTAL_TAB_CARD_SHAPE_TOP_INSET = 5;static constexpr int HORIZONTAL_TAB_CARD_SHAPE_BOTTOM_INSET = 1;-static constexpr qreal HORIZONTAL_TAB_CARD_RADIUS = 6;// The selected tab fills its whole tab, with rounded top corners, and joins the toolbar with an inverted curve at the// foot of each side.static constexpr qreal HORIZONTAL_SELECTED_TAB_RADIUS = 8;@@ -355,6 +353,24 @@ static QPainterPath horizontal_selected_tab_path(QRectF const& body)return path;}+// The hovered horizontal tab's outline: the selected tab's body, with its rounded top corners but without its feet.+static QPainterPath horizontal_hovered_tab_path(QRectF const& body)+{+ auto top_radius = HORIZONTAL_SELECTED_TAB_RADIUS;+ auto left = body.left();+ auto right = body.right();++ QPainterPath path;+ path.moveTo(left, body.bottom());+ path.lineTo(left, body.top() + top_radius);+ path.arcTo(QRectF(left, body.top(), 2 * top_radius, 2 * top_radius), 180, -90);+ path.lineTo(right - top_radius, body.top());+ path.arcTo(QRectF(right - (2 * top_radius), body.top(), 2 * top_radius, 2 * top_radius), 90, -90);+ path.lineTo(right, body.bottom());+ path.closeSubpath();+ return path;+}+// The selected horizontal tab's body: the whole width of the tab, from just below its top down to the toolbar.static QRectF horizontal_selected_tab_body_rect(QRectF const& tab_rect, HorizontalTabEndRoom end_room){@@ -1162,6 +1178,30 @@ void TabBar::paintEvent(QPaintEvent*)painter.restore();}+ if (!is_vertical) {+ // NB: The hovered tabs are filled before any tab is painted, so a selected tab's foot is drawn over the hovered+ // tab beside it.+ auto paint_hover_shape = [&](int index) {+ if (index < 0 || index >= count() || index == dragged_index)+ return;+ auto hover_progress = hover_progress_of(index);+ if (hover_progress <= 0.0 || selection_of(index) >= 1.0)+ return;+ auto tab_rect = shifted_tab_rect(index);+ if (!tab_rect.isValid() || tab_rect.right() < 0 || tab_rect.left() > width())+ return;+ auto body_rect = horizontal_selected_tab_body_rect(QRectF(tab_rect), horizontal_tab_end_room(index));+ if (body_rect.width() < 2 * HORIZONTAL_SELECTED_TAB_RADIUS)+ return;+ painter.setBrush(tab_hover_surface(Theme::chrome_palette(*this), hover_progress));+ painter.setPen(Qt::NoPen);+ painter.drawPath(horizontal_hovered_tab_path(body_rect));+ };+ paint_hover_shape(m_hover_animation_tab_index);+ if (m_hovered_tab_index != m_hover_animation_tab_index)+ paint_hover_shape(m_hovered_tab_index);+ }+auto previously_selected_index = m_previously_selected_tab && m_tab_widget ? m_tab_widget->index_of(m_previously_selected_tab) : -1;for (int index = 0; index < count(); ++index) {// The tab being dragged follows the cursor as the drag's image, leaving a gap where it would be dropped.@@ -1210,8 +1250,6 @@ void TabBar::paintEvent(QPaintEvent*)selection = 0.0;if (!is_vertical && selection > 0.0)tab_path = horizontal_selected_tab_path(horizontal_body_rect);- else if (!is_vertical)- tab_path.addRoundedRect(shape_rect, HORIZONTAL_TAB_CARD_RADIUS, HORIZONTAL_TAB_CARD_RADIUS);auto vertical_tab_radius = is_collapsed_vertical ? COLLAPSED_VERTICAL_TAB_RADIUS : VERTICAL_TAB_RADIUS;if (is_vertical)tab_path.addRoundedRect(shape_rect, vertical_tab_radius, vertical_tab_radius);@@ -1238,15 +1276,11 @@ void TabBar::paintEvent(QPaintEvent*)}}- if (selection < 1.0 && is_hovered) {- QPainterPath hover_path;- if (!is_vertical)- hover_path.addRoundedRect(shape_rect, HORIZONTAL_TAB_CARD_RADIUS, HORIZONTAL_TAB_CARD_RADIUS);- else- hover_path = tab_path;+ // NB: The hovered horizontal tabs were filled before any tab was painted.+ if (selection < 1.0 && is_hovered && is_vertical) {painter.setBrush(tab_hover_surface(Theme::chrome_palette(*this), hover_progress));painter.setPen(Qt::NoPen);- painter.drawPath(hover_path);+ painter.drawPath(tab_path);} else if (selection < 1.0 && is_vertical && !is_collapsed_vertical && is_pinned_tile) {// The pinned tiles at the top of the sidebar are always filled, so they read as a grid of buttons.painter.setBrush(tab_hover_surface(Theme::chrome_palette(*this), 1.0));