2021-10-27 12:28:16 +08:00
|
|
|
|
#include "wlanitem.h"
|
2021-12-01 11:07:21 +08:00
|
|
|
|
#include <QPainter>
|
2021-10-27 12:28:16 +08:00
|
|
|
|
#define FRAME_SPEED 150
|
|
|
|
|
#define LIMIT_TIME 60*1000
|
|
|
|
|
#define TOTAL_PAGE 8
|
2021-12-01 11:07:21 +08:00
|
|
|
|
#define RADIUS 6.0
|
2021-10-27 12:28:16 +08:00
|
|
|
|
|
|
|
|
|
#define THEME_QT_SCHEMA "org.ukui.style"
|
|
|
|
|
#define MODE_QT_KEY "style-name"
|
|
|
|
|
|
|
|
|
|
WlanItem::WlanItem(bool bAcitve, bool isLock, QWidget *parent)
|
|
|
|
|
: isAcitve(bAcitve), isLock(isLock), QPushButton(parent)
|
|
|
|
|
{
|
|
|
|
|
this->setMinimumSize(550, 58);
|
|
|
|
|
this->setProperty("useButtonPalette", true);
|
2022-06-01 17:13:25 +08:00
|
|
|
|
this->setFlat(true);
|
2021-10-27 12:28:16 +08:00
|
|
|
|
QHBoxLayout *mLanLyt = new QHBoxLayout(this);
|
|
|
|
|
mLanLyt->setContentsMargins(16,0,16,0);
|
|
|
|
|
mLanLyt->setSpacing(16);
|
|
|
|
|
iconLabel = new QLabel(this);
|
|
|
|
|
titileLabel = new FixLabel(this);
|
|
|
|
|
statusLabel = new QLabel(this);
|
|
|
|
|
statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
|
|
|
// statusLabel->setMinimumSize(36,36);
|
|
|
|
|
infoLabel = new InfoButton(this);
|
|
|
|
|
mLanLyt->addWidget(iconLabel);
|
|
|
|
|
mLanLyt->addWidget(titileLabel,Qt::AlignLeft);
|
|
|
|
|
mLanLyt->addStretch();
|
|
|
|
|
mLanLyt->addWidget(statusLabel);
|
|
|
|
|
mLanLyt->addWidget(infoLabel);
|
2022-01-17 14:29:24 +08:00
|
|
|
|
|
|
|
|
|
loadIcons.append(QIcon::fromTheme("ukui-loading-1-symbolic"));
|
|
|
|
|
loadIcons.append(QIcon::fromTheme("ukui-loading-2-symbolic"));
|
|
|
|
|
loadIcons.append(QIcon::fromTheme("ukui-loading-3-symbolic"));
|
|
|
|
|
loadIcons.append(QIcon::fromTheme("ukui-loading-4-symbolic"));
|
|
|
|
|
loadIcons.append(QIcon::fromTheme("ukui-loading-5-symbolic"));
|
|
|
|
|
loadIcons.append(QIcon::fromTheme("ukui-loading-6-symbolic"));
|
|
|
|
|
loadIcons.append(QIcon::fromTheme("ukui-loading-7-symbolic"));
|
|
|
|
|
|
2021-10-27 12:28:16 +08:00
|
|
|
|
waitTimer = new QTimer(this);
|
2022-01-17 14:29:24 +08:00
|
|
|
|
connect(waitTimer, &QTimer::timeout, this, &WlanItem::updateIcon);
|
|
|
|
|
|
2021-10-27 12:28:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WlanItem::~WlanItem()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-17 14:29:24 +08:00
|
|
|
|
void WlanItem::updateIcon()
|
2021-10-27 12:28:16 +08:00
|
|
|
|
{
|
2022-01-17 14:29:24 +08:00
|
|
|
|
if (currentIconIndex > 6) {
|
|
|
|
|
currentIconIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
statusLabel->setPixmap(loadIcons.at(currentIconIndex).pixmap(16,16));
|
|
|
|
|
currentIconIndex ++;
|
2021-10-27 12:28:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WlanItem::startLoading()
|
|
|
|
|
{
|
|
|
|
|
waitTimer->start(FRAME_SPEED);
|
|
|
|
|
loading = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WlanItem::stopLoading(){
|
|
|
|
|
waitTimer->stop();
|
|
|
|
|
loading = false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 11:07:21 +08:00
|
|
|
|
void WlanItem::paintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
|
|
|
|
QPalette pal = this->palette();
|
|
|
|
|
|
|
|
|
|
QPainter painter(this);
|
|
|
|
|
painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿
|
|
|
|
|
painter.setPen(Qt::NoPen);
|
|
|
|
|
painter.setBrush(pal.color(QPalette::Base));
|
|
|
|
|
|
|
|
|
|
QRect rect = this->rect();
|
|
|
|
|
if (!useHalfFillet) {
|
|
|
|
|
painter.drawRect(rect);
|
|
|
|
|
} else {
|
|
|
|
|
QPainterPath path;
|
2022-06-01 17:13:25 +08:00
|
|
|
|
// path.addRoundedRect (rect, RADIUS, RADIUS);
|
|
|
|
|
// QRect temp_rect(rect.left(), rect.top(), rect.width(), rect.height()/2);
|
|
|
|
|
// path.addRect(temp_rect);
|
|
|
|
|
//设置起点
|
|
|
|
|
path.moveTo(rect.topLeft().x(), rect.topLeft().y());
|
|
|
|
|
path.lineTo(rect.bottomLeft().x(), rect.bottomLeft().y() - RADIUS);
|
|
|
|
|
//绘制圆角 圆弧以外切圆的270度位置为起点,逆时针画圆弧运行90度结束
|
|
|
|
|
path.arcTo(QRect(QPoint(rect.bottomLeft().x(), rect.bottomLeft().y() - (RADIUS * 2)), QSize(RADIUS * 2, RADIUS * 2)), 180, 90);
|
|
|
|
|
path.lineTo(rect.bottomRight().x() - RADIUS, rect.bottomRight().y());
|
|
|
|
|
//画圆弧
|
|
|
|
|
path.arcTo(QRect(QPoint(rect.bottomRight().x() - (RADIUS * 2), rect.bottomRight().y() - (RADIUS * 2)), QSize(RADIUS * 2, RADIUS * 2)), 270, 90);
|
|
|
|
|
path.lineTo(rect.topRight());
|
|
|
|
|
path.lineTo(rect.topLeft());
|
2021-12-01 11:07:21 +08:00
|
|
|
|
painter.drawPath(path);
|
|
|
|
|
}
|
|
|
|
|
QPushButton::paintEvent(event);
|
|
|
|
|
}
|