summaryrefslogtreecommitdiff
path: root/src/study/NumberFrame.cpp
blob: 1d2a2e11a963a0801852dbcff358ea25904f1a19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "NumberFrame.h"

NumberFrame::NumberFrame(QWidget* parent):
    QLabel(parent)
{
    init();
}

void NumberFrame::init()
{
    setMinimumSize(MinWidth, MinHeight);
    setAlignment(Qt::AlignCenter);
    setFrameShape(QFrame::NoFrame);
}

void NumberFrame::setColor(const QColor& color)
{
    setPalette(QPalette(color));
}

void NumberFrame::setValue(int value)
{
    setMinimumWidth(value >= 100? MinWidth100: MinWidth);
    setVisible(value > 0);
    setText(QString::number(value));
}

void NumberFrame::paintEvent(QPaintEvent* event)
{
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);

    QPen pen("#7c7c7c");
    pen.setWidthF(0.5);
    painter.setPen(pen);
    painter.setBrush(QBrush(palette().color(QPalette::Button)));
    painter.drawRoundedRect(rect().adjusted(1, 1, -1, -1), Radius, Radius);

    QLabel::paintEvent(event);
}