2021-10-27 12:28:16 +08:00
|
|
|
#include "lanitem.h"
|
|
|
|
#define FRAME_SPEED 150
|
|
|
|
#define LIMIT_TIME 60*1000
|
|
|
|
#define TOTAL_PAGE 8
|
|
|
|
|
|
|
|
#define THEME_QT_SCHEMA "org.ukui.style"
|
|
|
|
#define MODE_QT_KEY "style-name"
|
|
|
|
|
|
|
|
LanItem::LanItem(bool isAcitve, QWidget *parent)
|
|
|
|
: QPushButton(parent),isAcitve(isAcitve)
|
|
|
|
{
|
|
|
|
this->setMinimumSize(550, 58);
|
|
|
|
this->setProperty("useButtonPalette", true);
|
|
|
|
setStyleSheet("QPushButton:!checked{background-color: palette(base)}");
|
|
|
|
QHBoxLayout *mLanLyt = new QHBoxLayout(this);
|
|
|
|
mLanLyt->setContentsMargins(16,0,16,0);
|
|
|
|
mLanLyt->setSpacing(16);
|
|
|
|
iconLabel = new QLabel(this);
|
2021-11-09 15:46:47 +08:00
|
|
|
iconLabel->setProperty("useIconHighlightEffect", 0x2);
|
2021-10-27 12:28:16 +08:00
|
|
|
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);
|
|
|
|
waitTimer = new QTimer(this);
|
|
|
|
connect(waitTimer, &QTimer::timeout, this, &LanItem::waitAnimStep);
|
|
|
|
}
|
|
|
|
|
|
|
|
LanItem::~LanItem()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void LanItem::setWaitPage(int waitPage)
|
|
|
|
{
|
|
|
|
this->waitPage = waitPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LanItem::setCountCurrentTime(int countCurrentTime)
|
|
|
|
{
|
|
|
|
this->countCurrentTime = countCurrentTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LanItem::startLoading()
|
|
|
|
{
|
|
|
|
waitTimer->start(FRAME_SPEED);
|
|
|
|
loading = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LanItem::stopLoading(){
|
|
|
|
waitTimer->stop();
|
|
|
|
loading = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LanItem::waitAnimStep()
|
|
|
|
{
|
|
|
|
QString qpmQss = "QLabel{background-image:url(':/img/plugins/netconnect/";
|
|
|
|
qpmQss.append(QString::number(this->waitPage));
|
|
|
|
QString imgPath = ":/img/plugins/netconnect/";
|
|
|
|
imgPath.append(QString::number(this->waitPage));
|
|
|
|
|
|
|
|
const QByteArray id(THEME_QT_SCHEMA);
|
|
|
|
themeGsettings = new QGSettings(id, QByteArray(), this);
|
|
|
|
if (themeGsettings->get(MODE_QT_KEY).toString() == "ukui-default") {
|
|
|
|
qpmQss.append("-black.png');}");
|
|
|
|
imgPath.append("-black.png");
|
|
|
|
} else {
|
|
|
|
qpmQss.append(".png');}");
|
|
|
|
imgPath.append(".png");
|
|
|
|
|
|
|
|
}
|
|
|
|
QImage img;
|
|
|
|
img.load(imgPath);
|
|
|
|
statusLabel->setText("");
|
|
|
|
statusLabel->setFixedSize(img.size());
|
|
|
|
statusLabel->setProperty("useIconHighlightEffect", 0x10);
|
|
|
|
|
|
|
|
statusLabel->setStyleSheet(qpmQss);
|
|
|
|
this->waitPage ++;
|
|
|
|
if (this->waitPage > TOTAL_PAGE) {
|
|
|
|
this->waitPage = 1; //循环播放8张图片
|
|
|
|
}
|
|
|
|
this->countCurrentTime += FRAME_SPEED;
|
|
|
|
if (this->countCurrentTime >= LIMIT_TIME) {
|
|
|
|
this->stopLoading(); //动画超出时间限制,强制停止动画
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-01 11:07:21 +08:00
|
|
|
void LanItem::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();
|
|
|
|
|
|
|
|
painter.drawRect(rect);
|
|
|
|
QPushButton::paintEvent(event);
|
|
|
|
}
|
|
|
|
|