fileprocessgauge.cpp 1.58 KB
#include "fileprocessgauge.h"
#include <QPainter>
#include <QDebug>

FileProcessGauge::FileProcessGauge(QWidget *parent) : PreheatTempGauge(parent)
{
    border.load(":/images/gauge/103_usb_graph_01.png");
    indicator.load(":/images/gauge/103_usb_graph_02.png");
    body.load(":/images/gauge/103_usb_graph_03.png");
    min = 0;
    max = 100;
    val = 30;
}

void FileProcessGauge::paintEvent(QPaintEvent */*event*/){
    QPainter painter(this);
    painter.setBrush(Qt::NoBrush);
    painter.setPen(Qt::NoPen);
    QRect textRect(0,0,72,40);

    qreal percentage = (qreal) (val - min) / qMax(max - min, 1);
    percentage = qBound((qreal) 0.0, percentage, (qreal) 1.0);

    QRect targetRect(
                (border.size().width() - body.size().width()) / 2 + textRect.width()/2,
                (border.size().height() - body.size().height()) / 2 + indicator.size().height()+textRect.height(),
                body.size().width() * percentage, body.height());

    QRect sourceRect(0, 0, body.size().width() * percentage, body.height());
    QFont font;
    font.setFamily("나눔맑은고딕");
    font.setPixelSize(30);
    painter.setFont(font);
    painter.setPen(Qt::white);
    painter.drawPixmap(targetRect, body, sourceRect);
    painter.drawPixmap(textRect.width()/ 2, textRect.height()+indicator.size().height(), border);
    painter.drawPixmap(targetRect.right() - indicator.size().width() / 2, textRect.height(), indicator);
    textRect.setRect(targetRect.right() - textRect.size().width()/2, textRect.top(),72,40);
    painter.drawText(textRect,Qt::AlignCenter, QString("%1%").arg(val));
}