From 6d319297ae06f560be8130e51540231d2200e429 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Sun, 2 Jan 2022 14:22:35 -0800 Subject: [PATCH] Qt: Add a common hover color. --- ui/qt/packet_list.cpp | 10 +--------- ui/qt/proto_tree.cpp | 10 +--------- ui/qt/utils/color_utils.cpp | 11 +++++++++++ ui/qt/utils/color_utils.h | 6 ++++++ ui/qt/welcome_page.cpp | 4 +--- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index 38998ca9f4..f3e35bddca 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -305,19 +305,11 @@ void PacketList::colorsChanged() QString hover_style; #if !defined(Q_OS_WIN) -#if defined(Q_OS_MAC) - QPalette default_pal = QApplication::palette(); - default_pal.setCurrentColorGroup(QPalette::Active); - QColor hover_color = default_pal.highlight().color(); -#else - QColor hover_color = ColorUtils::alphaBlend(palette().window(), palette().highlight(), 0.5); -#endif - hover_style = QString( "QTreeView:item:hover {" " background-color: %1;" " color: palette(text);" - "}").arg(hover_color.name(QColor::HexArgb)); + "}").arg(ColorUtils::hoverBackground().name(QColor::HexArgb)); #endif QString active_style = QString(); diff --git a/ui/qt/proto_tree.cpp b/ui/qt/proto_tree.cpp index 56373d354c..47ed67e280 100644 --- a/ui/qt/proto_tree.cpp +++ b/ui/qt/proto_tree.cpp @@ -62,19 +62,11 @@ ProtoTree::ProtoTree(QWidget *parent, epan_dissect_t *edt_fixed) : setHeaderHidden(true); #if !defined(Q_OS_WIN) -#if defined(Q_OS_MAC) - QPalette default_pal = QApplication::palette(); - default_pal.setCurrentColorGroup(QPalette::Active); - QColor hover_color = default_pal.highlight().color(); -#else - QColor hover_color = ColorUtils::alphaBlend(palette().window(), palette().highlight(), 0.5); -#endif - setStyleSheet(QString( "QTreeView:item:hover {" " background-color: %1;" " color: palette(text);" - "}").arg(hover_color.name(QColor::HexArgb))); + "}").arg(ColorUtils::hoverBackground().name(QColor::HexArgb))); #endif // Shrink down to a small but nonzero size in the main splitter. diff --git a/ui/qt/utils/color_utils.cpp b/ui/qt/utils/color_utils.cpp index 52304520f3..77197fefa4 100644 --- a/ui/qt/utils/color_utils.cpp +++ b/ui/qt/utils/color_utils.cpp @@ -188,6 +188,17 @@ const QColor ColorUtils::contrastingTextColor(const QColor color) return QApplication::palette().base().color(); } +const QColor ColorUtils::hoverBackground() +{ + QPalette hover_palette = QApplication::palette(); +#if defined(Q_OS_MAC) + hover_palette.setCurrentColorGroup(QPalette::Active); + return hover_palette.highlight().color(); +#else + return ColorUtils::alphaBlend(hover_palette.window(), hover_palette.highlight(), 0.5); +#endif +} + const QColor ColorUtils::warningBackground() { if (themeIsDark()) { diff --git a/ui/qt/utils/color_utils.h b/ui/qt/utils/color_utils.h index 7c235d5df4..a205cccc79 100644 --- a/ui/qt/utils/color_utils.h +++ b/ui/qt/utils/color_utils.h @@ -70,6 +70,12 @@ public: */ static const QColor contrastingTextColor(const QColor color); + /** + * Returns an appropriate background color for hovered abstract items. + * @return The background color. + */ + static const QColor hoverBackground(); + /** * Returns an appropriate warning background color for the current mode. * @return The background color. diff --git a/ui/qt/welcome_page.cpp b/ui/qt/welcome_page.cpp index 8631423ce4..8097c25455 100644 --- a/ui/qt/welcome_page.cpp +++ b/ui/qt/welcome_page.cpp @@ -427,8 +427,6 @@ void WelcomePage::on_helpLabel_clicked() void WelcomePage::updateStyleSheets() { - QColor hover_color = ColorUtils::alphaBlend(palette().window(), palette().highlight(), 0.5); - QString welcome_ss = QString( "WelcomePage {" " padding: 1em;" @@ -448,7 +446,7 @@ void WelcomePage::updateStyleSheets() " color: palette(text);" "}" ) - .arg(hover_color.name()); + .arg(ColorUtils::hoverBackground().name(QColor::HexArgb)); #endif setStyleSheet(welcome_ss);