Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
ColorUtils Class Reference

Utility class providing color conversion, blending, and theme-aware UI color definitions. More...

#include <color_utils.h>

Inheritance diagram for ColorUtils:

Public Member Functions

 ColorUtils (QObject *parent=0)
 Constructs a new ColorUtils object.

Static Public Member Functions

static QColor fromColorT (const color_t *color)
 Converts a core color_t pointer to a QColor.
static QColor fromColorT (color_t color)
 Converts a core color_t value to a QColor.
static const color_t toColorT (const QColor color)
 Converts a QColor to a core color_t.
static QRgb alphaBlend (const QColor &color1, const QColor &color2, qreal alpha)
 Blends two colors together using the specified alpha factor.
static QRgb alphaBlend (const QBrush &brush1, const QBrush &brush2, qreal alpha)
 Blends the colors of two brushes together using the specified alpha factor.
static QBrush themeLinkBrush ()
 Returns an appropriate link color for the current mode.
static QString themeLinkStyle ()
 Returns an appropriate HTML+CSS link style for the current mode.
static QString itemHoverStyleSheet (const QString &selector)
 Stylesheet rule for the hover state of an item view's items.
static void paintFlatCell (QPainter *painter, const QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index, const QColor &bg, const QColor &fg)
 Paints a single cell with a flat background/text color, ignoring any Qt::BackgroundRole/Qt::ForegroundRole (coloring rule, marked, ignored) the model would otherwise contribute – used for PacketList's and its pinned overlay panes' manually-driven hover highlight (see PacketList::drawRow()), where hovering needs to show the flat hover fill regardless of the row's own coloring.
static const QColor warningBackground ()
 Returns the warning background color for the current theme. Taken from the FilterDeprecated theme token, the same tint used for deprecated display filter text.
static QColor rowSeparatorColor (const QPalette &palette)
 Color of the 1px separator line between packet list rows. Equal to Base when Base is light; on a dark Base it is a mid gray halfway to Text so the line stays visible over light coloring rules.
static const QColor disabledForeground ()
 Returns an appropriate foreground color for disabled text.

Detailed Description

Utility class providing color conversion, blending, and theme-aware UI color definitions.

Constructor & Destructor Documentation

◆ ColorUtils()

ColorUtils::ColorUtils ( QObject * parent = 0)
explicit

Constructs a new ColorUtils object.

Parameters
parentThe parent QObject, defaults to 0.

Member Function Documentation

◆ alphaBlend() [1/2]

QRgb ColorUtils::alphaBlend ( const QBrush & brush1,
const QBrush & brush2,
qreal alpha )
static

Blends the colors of two brushes together using the specified alpha factor.

Parameters
brush1The first brush.
brush2The second brush.
alphaThe alpha blending factor.
Returns
The blended color as a QRgb value.

◆ alphaBlend() [2/2]

QRgb ColorUtils::alphaBlend ( const QColor & color1,
const QColor & color2,
qreal alpha )
static

Blends two colors together using the specified alpha factor.

Parameters
color1The first color.
color2The second color.
alphaThe alpha blending factor.
Returns
The blended color as a QRgb value.

◆ disabledForeground()

const QColor ColorUtils::disabledForeground ( )
static

Returns an appropriate foreground color for disabled text.

Returns
The foreground color.

◆ fromColorT() [1/2]

QColor ColorUtils::fromColorT ( color_t color)
static

Converts a core color_t value to a QColor.

Parameters
colorThe core color_t structure.
Returns
The corresponding QColor.

◆ fromColorT() [2/2]

QColor ColorUtils::fromColorT ( const color_t * color)
static

Converts a core color_t pointer to a QColor.

Parameters
colorPointer to the core color_t structure.
Returns
The corresponding QColor.

◆ itemHoverStyleSheet()

QString ColorUtils::itemHoverStyleSheet ( const QString & selector)
static

Stylesheet rule for the hover state of an item view's items.

The fill is ColorMath::selectionHoverFill() of the application palette's Base and Highlight, the text ColorMath::readableText() of its Text on that fill, so hover is a tint of the view's own selection color.

Parameters
selectorType selector of the view, e.g. "QTreeView".
Returns
"<selector>:item:hover { background-color: ...; color: ...; }"

◆ paintFlatCell()

void ColorUtils::paintFlatCell ( QPainter * painter,
const QAbstractItemView * view,
const QStyleOptionViewItem & option,
const QModelIndex & index,
const QColor & bg,
const QColor & fg )
static

Paints a single cell with a flat background/text color, ignoring any Qt::BackgroundRole/Qt::ForegroundRole (coloring rule, marked, ignored) the model would otherwise contribute – used for PacketList's and its pinned overlay panes' manually-driven hover highlight (see PacketList::drawRow()), where hovering needs to show the flat hover fill regardless of the row's own coloring.

QStyledItemDelegate::paint() can't be reused for this directly: its own initStyleOption() re-fetches Qt::BackgroundRole from the model and would silently overwrite a caller-supplied override, so this fills the background and draws the item's content (text, icons) itself instead of delegating to it.

Parameters
painterThe active painter (mid-paintEvent).
viewThe view the cell belongs to (for style/font lookups).
optionThe cell's style option; its rect is used as-is.
indexThe cell's model index (for its display content).
bgThe flat background color to fill.
fgThe flat text color to draw with.

◆ rowSeparatorColor()

QColor ColorUtils::rowSeparatorColor ( const QPalette & palette)
static

Color of the 1px separator line between packet list rows. Equal to Base when Base is light; on a dark Base it is a mid gray halfway to Text so the line stays visible over light coloring rules.

Parameters
paletteThe palette of the view that paints the rows.
Returns
The separator color.

◆ themeLinkBrush()

QBrush ColorUtils::themeLinkBrush ( )
static

Returns an appropriate link color for the current mode.

Returns
A brush suitable for setting a text color.

◆ themeLinkStyle()

QString ColorUtils::themeLinkStyle ( )
static

Returns an appropriate HTML+CSS link style for the current mode.

Returns
A "<style>a:link { color: ... ; }</style>" string

◆ toColorT()

const color_t ColorUtils::toColorT ( const QColor color)
static

Converts a QColor to a core color_t.

Parameters
colorThe QColor to convert.
Returns
The corresponding core color_t structure.

◆ warningBackground()

const QColor ColorUtils::warningBackground ( )
static

Returns the warning background color for the current theme. Taken from the FilterDeprecated theme token, the same tint used for deprecated display filter text.

Returns
The background color.

The documentation for this class was generated from the following files: