A widget for visualizing proportional color distributions as a horizontal bar. More...
#include <color_bar.h>
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. | |
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:
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.
|
explicit |
Constructs a ColorBar widget.
| colors | Map of color identifiers to integer counts. |
| parent | Optional parent widget. |
|
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.
|
overrideprotected |
Handles mouse hover entering (Qt6 version).
|
overrideprotected |
Handles mouse hover leaving.
|
override |
Returns the recommended minimum size.
|
overrideprotected |
Handles mouse movement to update contextual tooltips.
|
overrideprotected |
Paints the color distribution bar.
Draws:
| void ColorBar::setColors | ( | const QMap< QString, int > & | colors | ) |
Updates the color distribution map.
| colors | New color → count mapping. |
Triggers an immediate repaint.
|
inline |
Sets a minimum percentage threshold below which segments are not drawn.
| treshold | Percentage from 0 to 100. |
Internally converted into a ratio (0.05 = 5%).
|
private |
Returns tooltip text for a given x-coordinate in the bar.
| x | Horizontal coordinate relative to widget. |
|
private |
Map of color keys to counts used for rendering.
|
private |
True if the mouse is currently inside the widget.
|
private |
Minimum ratio a segment must exceed to be drawn.