Truly independent web browser
UI/Qt: Quiet the close buttons of the sidebar's other rows
Andreas Kling98009b6fad9b
diff --git a/UI/Qt/TabBar.cpp b/UI/Qt/TabBar.cppindex a64153a096b..47d293c3247 100644--- a/UI/Qt/TabBar.cpp+++ b/UI/Qt/TabBar.cpp@@ -228,6 +228,9 @@ static constexpr int TAB_TITLE_FADE_WIDTH = 24;static constexpr int SIDEBAR_ROW_AUDIO_BUTTON_SIZE = 22;static constexpr int SIDEBAR_ROW_AUDIO_ICON_SIZE = 16;static constexpr int SIDEBAR_ROW_BUTTON_GAP = 4;+// A sidebar row's close button is lighter than the muted color at rest.+static constexpr QRgb SIDEBAR_ROW_QUIET_CLOSE_ICON_LIGHT = 0x9C9CA3;+static constexpr QRgb SIDEBAR_ROW_QUIET_CLOSE_ICON_DARK = 0x7A7A81;// In the collapsed sidebar, the close button and the speaker are round badges on opposite corners of the favicon,// reaching a little past them.static constexpr int RAIL_BADGE_SIZE = 18;@@ -3038,6 +3041,8 @@ void TabBar::update_tab_button_geometry()if (!button)return;prepare_button(button, TabBarButton::Placement::SidebarRow);+ if (auto* tab_bar_button = qobject_cast<TabBarButton*>(button))+ tab_bar_button->set_row_emphasized(index == m_hovered_tab_index || index == currentIndex());auto button_size = button->size();if (button_size.isEmpty())@@ -5202,6 +5207,14 @@ void TabBarButton::set_revealed(bool revealed)m_reveal_animation->start();}+void TabBarButton::set_row_emphasized(bool emphasized)+{+ if (m_row_emphasized == emphasized)+ return;+ m_row_emphasized = emphasized;+ update();+}+bool TabBarButton::event(QEvent* event){if (event->type() == QEvent::Enter)@@ -5229,13 +5242,25 @@ void TabBarButton::paintEvent(QPaintEvent*)auto icon_pixmap = icon().pixmap(iconSize(), devicePixelRatioF(), icon_mode);option.icon = {};+ // A full sidebar would draw a dark stripe of close buttons down its side, so they are lighter but on the hovered and+ // the selected rows, and on the button under the pointer.+ auto is_hovered = isDown() || (underMouse() && rect().contains(mapFromGlobal(QCursor::pos())));+ if (m_placement == Placement::SidebarRow && m_role == Role::Close && !m_row_emphasized && !is_hovered && isEnabled() && !Theme::has_increased_contrast()) {+ auto dark = Theme::is_dark(*this);+ if (m_quiet_close_icon.isNull() || m_quiet_close_icon_is_dark != dark) {+ m_quiet_close_icon = create_chrome_icon(ChromeIcon::TabClose, QColor::fromRgb(dark ? SIDEBAR_ROW_QUIET_CLOSE_ICON_DARK : SIDEBAR_ROW_QUIET_CLOSE_ICON_LIGHT));+ m_quiet_close_icon_is_dark = dark;+ }+ icon_pixmap = m_quiet_close_icon.pixmap(iconSize(), devicePixelRatioF());+ }+QStylePainter painter(this);painter.setOpacity(m_opacity);if (m_placement == Placement::RailBadge) {ChromeStyle::paint_control_frame(painter, *this, ChromeStyle::ControlFrameStyle::ActiveTabOverlay);} else if (m_role == Role::Close) {- if (isDown() || (underMouse() && rect().contains(mapFromGlobal(QCursor::pos())))) {+ if (is_hovered) {// A tab's close button is a small rounded square that lights up over the tab's own fill.painter.setRenderHint(QPainter::Antialiasing, true);painter.setPen(Qt::NoPen);diff --git a/UI/Qt/TabBar.h b/UI/Qt/TabBar.hindex 395c0a45716..9a2a18a13c3 100644--- a/UI/Qt/TabBar.h+++ b/UI/Qt/TabBar.h@@ -509,6 +509,8 @@ public:void set_placement(Placement);// Shows the button by fading it in, or fades it out and hides it.void set_revealed(bool);+ // A sidebar row's close button is quieter, but on the hovered and the selected rows.+ void set_row_emphasized(bool);protected:virtual bool event(QEvent* event) override;@@ -520,6 +522,9 @@ private:Role m_role { Role::Close };Placement m_placement { Placement::Tab };bool m_revealed { false };+ bool m_row_emphasized { false };+ QIcon m_quiet_close_icon;+ bool m_quiet_close_icon_is_dark { false };qreal m_opacity { 1 };QVariantAnimation* m_reveal_animation { nullptr };};