mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-10 20:33:58 -07:00
Increase font size, qt version guard.
This commit is contained in:
parent
25f7c75b15
commit
add93bf09a
3 changed files with 30 additions and 16 deletions
|
|
@ -6,14 +6,14 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QToolTip>
|
#include <QToolTip>
|
||||||
|
|
||||||
ColorBar::ColorBar(const QMap<QString, int> &colors, QWidget *parent) : QWidget(parent), m_colors(colors)
|
ColorBar::ColorBar(const QMap<QString, int> &_colors, QWidget *parent) : QWidget(parent), colors(_colors)
|
||||||
{
|
{
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorBar::setColors(const QMap<QString, int> &colors)
|
void ColorBar::setColors(const QMap<QString, int> &_colors)
|
||||||
{
|
{
|
||||||
m_colors = colors;
|
colors = _colors;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,11 +27,11 @@ QSize ColorBar::minimumSizeHint() const
|
||||||
//-------------------------------------------
|
//-------------------------------------------
|
||||||
void ColorBar::paintEvent(QPaintEvent *)
|
void ColorBar::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
if (m_colors.isEmpty())
|
if (colors.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for (int v : m_colors.values())
|
for (int v : colors.values())
|
||||||
total += v;
|
total += v;
|
||||||
|
|
||||||
// Prevent divide-by-zero
|
// Prevent divide-by-zero
|
||||||
|
|
@ -55,12 +55,12 @@ void ColorBar::paintEvent(QPaintEvent *)
|
||||||
p.setClipRect(bounds.adjusted(2, 2, -2, -2));
|
p.setClipRect(bounds.adjusted(2, 2, -2, -2));
|
||||||
|
|
||||||
// Sort colors by key (this ensures a predictable order)
|
// Sort colors by key (this ensures a predictable order)
|
||||||
QList<QString> sortedKeys = m_colors.keys();
|
QList<QString> sortedKeys = colors.keys();
|
||||||
std::sort(sortedKeys.begin(), sortedKeys.end()); // Sort alphabetically
|
std::sort(sortedKeys.begin(), sortedKeys.end()); // Sort alphabetically
|
||||||
|
|
||||||
// Draw each color segment in the sorted order
|
// Draw each color segment in the sorted order
|
||||||
for (const QString &key : sortedKeys) {
|
for (const QString &key : sortedKeys) {
|
||||||
int value = m_colors[key];
|
int value = colors[key];
|
||||||
double ratio = double(value) / total;
|
double ratio = double(value) / total;
|
||||||
int segmentWidth = int(ratio * w);
|
int segmentWidth = int(ratio * w);
|
||||||
|
|
||||||
|
|
@ -84,19 +84,28 @@ void ColorBar::paintEvent(QPaintEvent *)
|
||||||
//-------------------------------------------
|
//-------------------------------------------
|
||||||
// Hover + Tooltips
|
// Hover + Tooltips
|
||||||
//-------------------------------------------
|
//-------------------------------------------
|
||||||
void ColorBar::enterEvent(QEnterEvent *)
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
void ColorBar::enterEvent(QEnterEvent *event)
|
||||||
{
|
{
|
||||||
m_hover = true;
|
Q_UNUSED(event);
|
||||||
|
isHovered = true;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
void ColorBar::enterEvent(QEvent *event)
|
||||||
|
{
|
||||||
|
Q_UNUSED(event);
|
||||||
|
isHovered = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void ColorBar::leaveEvent(QEvent *)
|
void ColorBar::leaveEvent(QEvent *)
|
||||||
{
|
{
|
||||||
m_hover = false;
|
isHovered = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorBar::mouseMoveEvent(QMouseEvent *event)
|
void ColorBar::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (!m_hover || m_colors.isEmpty())
|
if (!isHovered || colors.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString text = tooltipForPosition(event->position().x());
|
QString text = tooltipForPosition(event->position().x());
|
||||||
|
|
@ -107,11 +116,11 @@ void ColorBar::mouseMoveEvent(QMouseEvent *event)
|
||||||
QString ColorBar::tooltipForPosition(int x) const
|
QString ColorBar::tooltipForPosition(int x) const
|
||||||
{
|
{
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for (int v : m_colors.values())
|
for (int v : colors.values())
|
||||||
total += v;
|
total += v;
|
||||||
|
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for (auto it = m_colors.begin(); it != m_colors.end(); ++it) {
|
for (auto it = colors.begin(); it != colors.end(); ++it) {
|
||||||
double ratio = double(it.value()) / total;
|
double ratio = double(it.value()) / total;
|
||||||
int segmentWidth = int(ratio * width());
|
int segmentWidth = int(ratio * width());
|
||||||
|
|
||||||
|
|
@ -127,7 +136,7 @@ QString ColorBar::tooltipForPosition(int x) const
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------
|
//-------------------------------------------
|
||||||
// Color name mapping (expandable)
|
// Color name mapping
|
||||||
//-------------------------------------------
|
//-------------------------------------------
|
||||||
QColor ColorBar::colorFromName(const QString &name) const
|
QColor ColorBar::colorFromName(const QString &name) const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,17 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
void enterEvent(QEnterEvent *event) override;
|
void enterEvent(QEnterEvent *event) override;
|
||||||
|
#else
|
||||||
|
void enterEvent(QEvent *event) override;
|
||||||
|
#endif
|
||||||
void leaveEvent(QEvent *event) override;
|
void leaveEvent(QEvent *event) override;
|
||||||
void mouseMoveEvent(QMouseEvent *event) override;
|
void mouseMoveEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<QString, int> m_colors;
|
QMap<QString, int> colors;
|
||||||
bool m_hover = false;
|
bool isHovered = false;
|
||||||
|
|
||||||
QColor colorFromName(const QString &name) const;
|
QColor colorFromName(const QString &name) const;
|
||||||
QString tooltipForPosition(int x) const;
|
QString tooltipForPosition(int x) const;
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ ArchidektDeckPreviewImageDisplayWidget::ArchidektDeckPreviewImageDisplayWidget(Q
|
||||||
|
|
||||||
QFont f;
|
QFont f;
|
||||||
f.setBold(true);
|
f.setBold(true);
|
||||||
|
f.setPointSize(16);
|
||||||
topLeftLabel->setFont(f);
|
topLeftLabel->setFont(f);
|
||||||
topRightLabel->setFont(f);
|
topRightLabel->setFont(f);
|
||||||
bottomLeftLabel->setFont(f);
|
bottomLeftLabel->setFont(f);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue