mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 17:14:52 -07:00
[EDHRec] Display name above card, add bars for inclusion and synergy instead of coloring the whole label, card size slider (#5851)
* Display name above card, add bars for inclusion and synergy instead of coloring the whole label. * Re-add commander label. * Add a card size slider. * Lint. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
2fe639676b
commit
3b1d6e394d
12 changed files with 252 additions and 25 deletions
|
|
@ -0,0 +1,46 @@
|
|||
#include "percent_bar_widget.h"
|
||||
|
||||
PercentBarWidget::PercentBarWidget(QWidget *parent, double initialValue) : QWidget(parent), valueToDisplay(initialValue)
|
||||
{
|
||||
setMinimumSize(50, 10);
|
||||
}
|
||||
|
||||
void PercentBarWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
QPainter painter(this);
|
||||
QRect rect = this->rect();
|
||||
|
||||
const int midX = rect.width() / 2;
|
||||
const int height = rect.height();
|
||||
|
||||
// Draw background border (no fill)
|
||||
painter.setPen(QPen(Qt::black, 1));
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
painter.drawRect(rect.adjusted(0, 0, -1, -1)); // Avoid right/bottom overflow
|
||||
|
||||
const double halfWidth = rect.width() / 2.0;
|
||||
|
||||
const int barLength = static_cast<int>((qAbs(valueToDisplay) / 100.0) * halfWidth);
|
||||
|
||||
QRect fillRect;
|
||||
if (valueToDisplay > 0.0) {
|
||||
fillRect = QRect(midX, 0, barLength, height);
|
||||
painter.fillRect(fillRect, Qt::green);
|
||||
} else if (valueToDisplay < 0.0) {
|
||||
fillRect = QRect(midX - barLength, 0, barLength, height);
|
||||
painter.fillRect(fillRect, Qt::red);
|
||||
}
|
||||
|
||||
// Draw center line at 0
|
||||
painter.fillRect(midX - 1, 0, 3, height, Qt::white);
|
||||
|
||||
// Draw tick marks every 10%
|
||||
const int tickHeight = 4;
|
||||
|
||||
for (int percent = -100; percent <= 100; percent += 10) {
|
||||
int x = midX + static_cast<int>((percent / 100.0) * halfWidth);
|
||||
painter.drawLine(x, height - tickHeight, x, height);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef PERCENT_BAR_WIDGET_H
|
||||
#define PERCENT_BAR_WIDGET_H
|
||||
|
||||
#include <QColor>
|
||||
#include <QPainter>
|
||||
#include <QWidget>
|
||||
|
||||
class PercentBarWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PercentBarWidget(QWidget *parent, double initialValue);
|
||||
|
||||
void setValue(double newValue)
|
||||
{
|
||||
valueToDisplay = qBound(-100.0, newValue, 100.0); // Clamp to [-100, 100]
|
||||
update(); // Trigger repaint
|
||||
}
|
||||
|
||||
double value() const
|
||||
{
|
||||
return valueToDisplay;
|
||||
}
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
private:
|
||||
double valueToDisplay; // Ranges from -100 to 100
|
||||
};
|
||||
|
||||
#endif // PERCENT_BAR_WIDGET_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue