Qt: Add a common hover color.

This commit is contained in:
Gerald Combs 2022-01-02 14:22:35 -08:00 committed by A Wireshark GitLab Utility
parent ce43234c5a
commit 6d319297ae
5 changed files with 20 additions and 21 deletions

View File

@ -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();

View File

@ -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.

View File

@ -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()) {

View File

@ -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.

View File

@ -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);