194 lines
6.1 KiB
Python
194 lines
6.1 KiB
Python
# coding: gb2312
|
|
import sys
|
|
|
|
from PyQt5.QtCore import Qt
|
|
from PyQt5.QtGui import QPainter, QColor, QFont, QPen
|
|
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout
|
|
|
|
from LSZXPagesLibrary.tool import format_time
|
|
|
|
|
|
class CircularProgress(QWidget):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.percentage = 100
|
|
self.rank = 0
|
|
self.timer_second = 0
|
|
self.state = "<状态>"
|
|
self.name = "<姓名>"
|
|
self.hr = 0
|
|
self.bo = 0
|
|
self.round = 0
|
|
self.normal = True
|
|
|
|
def set_data(self, second=None, state=None, name=None, hr=None, bo=None, rank=None, round=None, normal=True):
|
|
if second:
|
|
self.timer_second = second
|
|
if state:
|
|
self.state = state
|
|
if name:
|
|
self.name = name
|
|
if hr:
|
|
self.hr = hr
|
|
if bo:
|
|
self.bo = bo
|
|
if rank:
|
|
self.rank = rank
|
|
if round:
|
|
self.round = round
|
|
|
|
self.normal = normal
|
|
|
|
def paintEvent(self, event):
|
|
width, height = 180, 180
|
|
self.setMinimumSize(width, height)
|
|
size = min(width, height)
|
|
margin = 10
|
|
bar_width = 3
|
|
|
|
painter = QPainter(self)
|
|
painter.setRenderHint(QPainter.Antialiasing)
|
|
|
|
# 绘制圆形
|
|
if self.normal:
|
|
pen = QPen(QColor(14, 90, 244))
|
|
else:
|
|
pen = QPen(QColor(255, 85, 91))
|
|
pen.setWidth(bar_width)
|
|
painter.setPen(pen)
|
|
painter.drawArc(
|
|
margin,
|
|
margin,
|
|
size - 2 * margin,
|
|
size - 2 * margin,
|
|
0,
|
|
360 * 16,
|
|
)
|
|
|
|
# 绘制进度
|
|
if self.normal:
|
|
pen.setColor(QColor(14, 90, 244))
|
|
else:
|
|
pen.setColor(QColor(255, 85, 91))
|
|
painter.setPen(pen)
|
|
# 将百分比转换为角度,并确保结果为整数
|
|
angle = int(-self.percentage * 16 * 3.6)
|
|
painter.drawArc(
|
|
margin,
|
|
margin,
|
|
size - 2 * margin,
|
|
size - 2 * margin,
|
|
90 * 16,
|
|
angle,
|
|
)
|
|
|
|
# 绘制文字
|
|
painter.setFont(QFont('\"Microsoft YaHei UI\"', 20, 600)) # 设置姓名的字体大小为 20px
|
|
if self.normal:
|
|
painter.setPen(QPen(QColor(8, 164, 255))) # 设置姓名的颜色为蓝色
|
|
else:
|
|
painter.setPen(QPen(QColor(255, 85, 91))) # 设置姓名的颜色为红色
|
|
painter.drawText(
|
|
int(width / 2) - 100,
|
|
int(height / 2) - 50,
|
|
200,
|
|
30,
|
|
Qt.AlignCenter,
|
|
self.name
|
|
)
|
|
|
|
painter.setFont(QFont('\"Microsoft YaHei UI\"', 16)) # 恢复默认的字体大小
|
|
painter.setPen(QPen(QColor(255, 255, 255))) # 设置编号和心率血氧的颜色为蓝色
|
|
painter.drawText(
|
|
int(width / 2) - 100,
|
|
int(height / 2) - 12,
|
|
200,
|
|
20,
|
|
Qt.AlignCenter,
|
|
self.state
|
|
)
|
|
|
|
painter.setFont(QFont('\"Microsoft YaHei UI\"', 13)) # 恢复默认的字体大小
|
|
painter.setPen(QPen(QColor(255, 255, 255))) # 设置编号和心率血氧的颜色为蓝色
|
|
painter.drawText(
|
|
int(width / 2) - 100,
|
|
int(height / 2) + 15,
|
|
200,
|
|
20,
|
|
Qt.AlignCenter,
|
|
f"心率: {self.hr}次/分钟"
|
|
)
|
|
|
|
painter.setFont(QFont('\"Microsoft YaHei UI\"', 13)) # 恢复默认的字体大小
|
|
painter.setPen(QPen(QColor(255, 255, 255))) # 设置编号和心率血氧的颜色为蓝色
|
|
painter.drawText(
|
|
int(width / 2) - 100,
|
|
int(height / 2) + 40,
|
|
200,
|
|
20,
|
|
Qt.AlignCenter,
|
|
f"血氧: {self.bo}%"
|
|
)
|
|
|
|
# 绘制顶部框
|
|
pen_top = QPen()
|
|
pen_top.setColor(QColor(187, 187, 187))
|
|
painter.setPen(pen_top)
|
|
top_box_width = int((size - 2 * margin) * 0.6) # 宽度占环形的 50%
|
|
top_box_height = 30
|
|
|
|
# 绘制背景矩形
|
|
if self.normal:
|
|
painter.setBrush(QColor(14, 95, 255))
|
|
else:
|
|
painter.setBrush(QColor(255, 85, 91))
|
|
painter.drawRect(int(top_box_width * 0.3), 0, int(top_box_width + 25), top_box_height)
|
|
|
|
# 绘制圆和文字
|
|
painter.drawEllipse(int(top_box_width * 0.3), -top_box_height, int(top_box_width + 25), top_box_height) # 绘制圆
|
|
|
|
radius_rank = 13 # 小圆的半径
|
|
|
|
if self.normal:
|
|
painter.setBrush(QColor(14, 95, 255))
|
|
else:
|
|
painter.setBrush(QColor(255, 85, 91))
|
|
painter.drawEllipse(int(top_box_width * 0.38), 2, radius_rank * 2, radius_rank * 2) # 绘制小圆
|
|
|
|
painter.setFont(QFont('Arial', 13, QFont.Bold)) # 设置字体大小和加粗
|
|
painter.setPen(QPen(Qt.white)) # 设置文字颜色为白色
|
|
painter.drawText(
|
|
int(top_box_width * 0.27),
|
|
0,
|
|
int(top_box_width / 2),
|
|
top_box_height,
|
|
Qt.AlignCenter,
|
|
str(self.rank)
|
|
) # 绘制文字
|
|
|
|
# 显示计时
|
|
time_str = format_time(int(self.timer_second))
|
|
painter.setFont(QFont('Arial', 13, QFont.Bold)) # 设置字体大小
|
|
pen_time = QPen()
|
|
pen_time.setColor(QColor(255, 255, 255))
|
|
painter.setPen(pen_time) # 设置颜色
|
|
painter.drawText(int(top_box_width * 0.56), 0, top_box_width, top_box_height, Qt.AlignCenter, time_str)
|
|
|
|
# 计算小圆的坐标
|
|
radius = 15 # 小圆的半径
|
|
|
|
# 绘制 45 度角位置的小圆
|
|
pen_circle = QPen(Qt.NoPen) # 设置小圆无边框
|
|
painter.setPen(pen_circle)
|
|
if self.normal:
|
|
painter.setBrush(QColor(14, 90, 244)) # 设置小圆的背景颜色为红色
|
|
else:
|
|
painter.setBrush(QColor(255, 85, 91)) # 设置小圆的背景颜色为红色
|
|
painter.drawEllipse(int(size - 2 * margin - 20), int(size - 2 * margin - 35), radius * 2, radius * 2) # 绘制小圆
|
|
|
|
# 在小圆内显示圈数
|
|
painter.setFont(QFont('Arial', 14, QFont.Bold)) # 设置字体大小
|
|
painter.setPen(QPen(Qt.white)) # 设置文字颜色为蓝色
|
|
painter.drawText(int(size - 2 * margin - 20), int(size - 2 * margin - 35), radius * 2, radius * 2,
|
|
Qt.AlignCenter, str(self.round)) # 绘制文字
|