mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-11 04:43:56 -07:00
Min treshold for nicer display.
This commit is contained in:
parent
8cd5552d65
commit
6425238670
3 changed files with 11 additions and 0 deletions
|
|
@ -62,6 +62,11 @@ void ColorBar::paintEvent(QPaintEvent *)
|
||||||
for (const QString &key : sortedKeys) {
|
for (const QString &key : sortedKeys) {
|
||||||
int value = colors[key];
|
int value = colors[key];
|
||||||
double ratio = double(value) / total;
|
double ratio = double(value) / total;
|
||||||
|
|
||||||
|
if (ratio <= minRatioThreshold) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
int segmentWidth = int(ratio * w);
|
int segmentWidth = int(ratio * w);
|
||||||
|
|
||||||
// Ensure the segment width is at least 1 to avoid degenerate rectangles
|
// Ensure the segment width is at least 1 to avoid degenerate rectangles
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,10 @@ public:
|
||||||
explicit ColorBar(const QMap<QString, int> &colors, QWidget *parent = nullptr);
|
explicit ColorBar(const QMap<QString, int> &colors, QWidget *parent = nullptr);
|
||||||
|
|
||||||
void setColors(const QMap<QString, int> &colors);
|
void setColors(const QMap<QString, int> &colors);
|
||||||
|
void setMinPercentThreshold(double treshold)
|
||||||
|
{
|
||||||
|
minRatioThreshold = treshold / 100.0; // store as ratio
|
||||||
|
}
|
||||||
QSize minimumSizeHint() const override;
|
QSize minimumSizeHint() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -29,6 +33,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
QMap<QString, int> colors;
|
QMap<QString, int> colors;
|
||||||
bool isHovered = false;
|
bool isHovered = false;
|
||||||
|
double minRatioThreshold = 0.0; // 0.05 means 5%
|
||||||
|
|
||||||
QColor colorFromName(const QString &name) const;
|
QColor colorFromName(const QString &name) const;
|
||||||
QString tooltipForPosition(int x) const;
|
QString tooltipForPosition(int x) const;
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,7 @@ ArchidektApiResponseDeckEntryDisplayWidget::ArchidektApiResponseDeckEntryDisplay
|
||||||
auto colors = response.getColors();
|
auto colors = response.getColors();
|
||||||
|
|
||||||
ColorBar *colorBar = new ColorBar(colors, this);
|
ColorBar *colorBar = new ColorBar(colors, this);
|
||||||
|
colorBar->setMinPercentThreshold(3);
|
||||||
colorBar->setFixedHeight(22);
|
colorBar->setFixedHeight(22);
|
||||||
|
|
||||||
headerLayout->addWidget(colorBar);
|
headerLayout->addWidget(colorBar);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue