#include "Wifi.h"
#include "../Global.h"
#include <QPainter>
#include <QDebug>

Wifi::Wifi(QWidget *parent) : QWidget(parent) {
}




void Wifi::paintEvent(QPaintEvent *event) {
    QPainter painter(this);
//    painter.fillRect(rect(), Qt::red);
    QRect window(0, 0, 20, 10);
    painter.setWindow(window);
    double w = window.width(), h = window.height();
    QRect drawRect = get_max_rect(rect(), w / h);
    painter.setViewport(drawRect);
    double rate = 1.5;  // wife宽度 : 间隙宽度
    double base_height_rate = 0.2;
    double space_width = w/(1.0 * 4 + rate * 5);
    double strip_width = space_width * rate;
    double base_height = h * base_height_rate;
    double raise_height = h * (1.0 - base_height_rate)/4.0;
    double raise_width = space_width + strip_width;
    QRect text_rect = QRect(0, 0, (int)(raise_width * 2), (int)(base_height * 2));
    QFont font;
    font.setPixelSize(5);
    font.setBold(true);
    painter.setFont(font);
    QPen pen;
    pen.setColor(Qt::white);
    painter.setPen(pen);
    painter.drawText(text_rect, Qt::AlignJustify | Qt::AlignVCenter, "4G");
    for(int i = 0; i < 5; ++i){
        double cur_height = base_height + i * raise_height;
        double cur_x = 0 + raise_width * i;
        QColor color = i < value ? Qt::white : QColor(0, 0, 0, 50);
        painter.fillRect(QRectF(cur_x, h - cur_height, strip_width, cur_height), color);
    }
    painter.end();
}
