Cockatrice 2025-11-30-Development-2.11.0-beta.38
A cross-platform virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
ColorBar Class Reference

A widget for visualizing proportional color distributions as a horizontal bar. More...

#include <color_bar.h>

Inheritance diagram for ColorBar:
[legend]
Collaboration diagram for ColorBar:
[legend]

Public Member Functions

 ColorBar (const QMap< QString, int > &colors, QWidget *parent=nullptr)
 Constructs a ColorBar widget.
void setColors (const QMap< QString, int > &colors)
 Updates the color distribution map.
void setMinPercentThreshold (double treshold)
 Sets a minimum percentage threshold below which segments are not drawn.
QSize minimumSizeHint () const override
 Returns the recommended minimum size.

Protected Member Functions

void paintEvent (QPaintEvent *event) override
 Paints the color distribution bar.
void enterEvent (QEnterEvent *event) override
 Handles mouse hover entering (Qt6 version).
void leaveEvent (QEvent *event) override
 Handles mouse hover leaving.
void mouseMoveEvent (QMouseEvent *event) override
 Handles mouse movement to update contextual tooltips.

Private Member Functions

QColor colorFromName (const QString &name) const
 Converts a color name into a display QColor.
QString tooltipForPosition (int x) const
 Returns tooltip text for a given x-coordinate in the bar.

Private Attributes

QMap< QString, int > colors
 Map of color keys to counts used for rendering.
bool isHovered = false
 True if the mouse is currently inside the widget.
double minRatioThreshold = 0.0
 Minimum ratio a segment must exceed to be drawn.

Detailed Description

A widget for visualizing proportional color distributions as a horizontal bar.

This widget renders a horizontal bar divided into colored segments whose widths reflect the relative values associated with each color key in a QMap<QString, int>. The class is designed as a small, lightweight, and self-contained visualization component suitable for representing distributions such as color counts, mana statistics, categorical frequencies, and similar data sets.

Key features:

  • Filled segments for better visual clarity.
  • Deterministic alphabetical ordering of color keys.
  • Optional minimum percentage threshold for filtering out insignificant segments.
  • Mouse-hover tooltips showing each segment’s key, count, and percentage of total.

Default color mappings exist for "R", "G", "U", "W", and "B", using named colors, but any string recognized by QColor may be used. If an unknown name is provided, the segment will fall back to gray.

This component is display-only and does not interpret or mutate domain-level data.

Constructor & Destructor Documentation

◆ ColorBar()

ColorBar::ColorBar ( const QMap< QString, int > & colors,
QWidget * parent = nullptr )
explicit

Constructs a ColorBar widget.

Parameters
colorsMap of color identifiers to integer counts.
parentOptional parent widget.

Member Function Documentation

◆ colorFromName()

QColor ColorBar::colorFromName ( const QString & name) const
private

Converts a color name into a display QColor.

Recognized special keys: "R", "G", "U", "W", "B". Other strings are treated as QColor names or fall back to gray.

Here is the caller graph for this function:

◆ enterEvent()

void ColorBar::enterEvent ( QEnterEvent * event)
overrideprotected

Handles mouse hover entering (Qt6 version).

◆ leaveEvent()

void ColorBar::leaveEvent ( QEvent * event)
overrideprotected

Handles mouse hover leaving.

◆ minimumSizeHint()

QSize ColorBar::minimumSizeHint ( ) const
override

Returns the recommended minimum size.

◆ mouseMoveEvent()

void ColorBar::mouseMoveEvent ( QMouseEvent * event)
overrideprotected

Handles mouse movement to update contextual tooltips.

Here is the call graph for this function:

◆ paintEvent()

void ColorBar::paintEvent ( QPaintEvent * event)
overrideprotected

Paints the color distribution bar.

Draws:

  • A rounded border
  • Filled segments for each color
  • Only segments above the minimum ratio threshold
Here is the call graph for this function:

◆ setColors()

void ColorBar::setColors ( const QMap< QString, int > & colors)

Updates the color distribution map.

Parameters
colorsNew color → count mapping.

Triggers an immediate repaint.

◆ setMinPercentThreshold()

void ColorBar::setMinPercentThreshold ( double treshold)
inline

Sets a minimum percentage threshold below which segments are not drawn.

Parameters
tresholdPercentage from 0 to 100.

Internally converted into a ratio (0.05 = 5%).

Here is the caller graph for this function:

◆ tooltipForPosition()

QString ColorBar::tooltipForPosition ( int x) const
private

Returns tooltip text for a given x-coordinate in the bar.

Parameters
xHorizontal coordinate relative to widget.
Returns
Tooltip text or empty string if no segment applies.
Here is the caller graph for this function:

Member Data Documentation

◆ colors

QMap<QString, int> ColorBar::colors
private

Map of color keys to counts used for rendering.

◆ isHovered

bool ColorBar::isHovered = false
private

True if the mouse is currently inside the widget.

◆ minRatioThreshold

double ColorBar::minRatioThreshold = 0.0
private

Minimum ratio a segment must exceed to be drawn.


The documentation for this class was generated from the following files:
  • cockatrice/src/interface/widgets/general/display/color_bar.h
  • cockatrice/src/interface/widgets/general/display/color_bar.cpp