aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2022-01-02 14:22:35 -0800
committerA Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org>2022-01-03 19:03:46 +0000
commit6d319297ae06f560be8130e51540231d2200e429 (patch)
tree7bff80f169cf67b2122474fb07f366d8fb86c6f8 /ui
parentce43234c5a3840602b4a2ae05e82d1d04d17f313 (diff)
Qt: Add a common hover color.
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/packet_list.cpp10
-rw-r--r--ui/qt/proto_tree.cpp10
-rw-r--r--ui/qt/utils/color_utils.cpp11
-rw-r--r--ui/qt/utils/color_utils.h6
-rw-r--r--ui/qt/welcome_page.cpp4
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
@@ -71,6 +71,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);