44 lines
1.4 KiB
C++
44 lines
1.4 KiB
C++
#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 = getMaxRect(rect(), w / h);
|
|
painter.setViewport(drawRect);
|
|
double rate = 1.5; // wife宽度 : 间隙宽度
|
|
double baseHeightRate = 0.2;
|
|
double spaceWidth = w/(1.0 * 4 + rate * 5);
|
|
double stripWidth = spaceWidth * rate;
|
|
double baseHeight = h * baseHeightRate;
|
|
double raiseHeight = h * (1.0 - baseHeightRate)/4.0;
|
|
double raiseWidth = spaceWidth + stripWidth;
|
|
QRect textRect = QRect(0, 0, (int)(raiseWidth * 2), (int)(baseHeight * 2));
|
|
QFont font;
|
|
font.setPixelSize(5);
|
|
font.setBold(true);
|
|
painter.setFont(font);
|
|
QPen pen;
|
|
pen.setColor(Qt::white);
|
|
painter.setPen(pen);
|
|
painter.drawText(textRect, Qt::AlignJustify | Qt::AlignVCenter, "4G");
|
|
for(int i = 0; i < 5; ++i){
|
|
double curHeight = baseHeight + i * raiseHeight;
|
|
double curX = 0 + raiseWidth * i;
|
|
QColor color = i < value ? Qt::white : QColor(0, 0, 0, 50);
|
|
painter.fillRect(QRectF(curX, h - curHeight, stripWidth, curHeight), color);
|
|
}
|
|
painter.end();
|
|
}
|