From d98122b67713f3f8895ab3549c44456298813ea5 Mon Sep 17 00:00:00 2001 From: jinxujie Date: Fri, 27 Aug 2021 11:39:36 +0800 Subject: [PATCH] Optimize code. --- src/frontend/list-items/wlanlistitem.cpp | 23 +++++++++---- src/frontend/list-items/wlanlistitem.h | 2 +- src/frontend/tools/radioitembutton.cpp | 42 +++++++++++++++++++++++- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/frontend/list-items/wlanlistitem.cpp b/src/frontend/list-items/wlanlistitem.cpp index d6842262..2d5585c5 100644 --- a/src/frontend/list-items/wlanlistitem.cpp +++ b/src/frontend/list-items/wlanlistitem.cpp @@ -222,8 +222,9 @@ void WlanListItem::onNetButtonClicked() while (iter != actMap.end()) { if (iter.key() == m_wlanDevice && !iter.value().isEmpty()) { activedssid = iter.value().at(0); + break; } - break; + iter ++; } qDebug()<<"Get activated wlan succeed! ssid = " << activedssid <text().length() < 6) { + if (!m_pwdLineEdit || !m_connectButton) { + return; + } + if (m_pwdLineEdit->text().length() < PWD_LENGTH_LIMIT) { m_connectButton->setEnabled(false); } else { m_connectButton->setEnabled(true); @@ -308,7 +311,9 @@ void WlanListItem::onShowPwdButtonClicked() void WlanListItem::onConnectButtonClicked() { - if (!m_connectButton->isEnabled() || !m_data) { return; } + if (!m_connectButton->isEnabled() || !m_data) { + return; + } KyWirelessConnectSetting settings; settings.m_connectName = m_data->m_NetSsid; settings.m_ssid = m_data->m_NetSsid; @@ -319,7 +324,7 @@ void WlanListItem::onConnectButtonClicked() } else if (m_data->m_secuType.contains("WPA1") || m_data->m_secuType.contains("WPA2")) { settings.m_type = WpaPsk; } else if (m_data->m_secuType.contains("WPA3")) { - settings.m_type = WpaEap; + settings.m_type = SAE; } qDebug() << "On button connect clicked, will connect wlan. ssid = " << m_data->m_NetSsid << Q_FUNC_INFO <<__LINE__; @@ -328,7 +333,9 @@ void WlanListItem::onConnectButtonClicked() void WlanListItem::onConnectionAdd(QString deviceName, QString ssid) { - if (!m_data) { return; } + if (!m_data) { + return; + } if (ssid == m_data->m_NetSsid) { m_data->m_isConfigured = true; } @@ -336,7 +343,9 @@ void WlanListItem::onConnectionAdd(QString deviceName, QString ssid) void WlanListItem::onConnectionRemove(QString deviceName, QString ssid) { - if (!m_data) { return; } + if (!m_data) { + return; + } if (ssid == m_data->m_NetSsid) { m_data->m_isConfigured = false; } diff --git a/src/frontend/list-items/wlanlistitem.h b/src/frontend/list-items/wlanlistitem.h index ddb74c43..5556cc83 100644 --- a/src/frontend/list-items/wlanlistitem.h +++ b/src/frontend/list-items/wlanlistitem.h @@ -13,7 +13,7 @@ #define NORMAL_HEIGHT 48 #define EXPANDED_HEIGHT 120 - +#define PWD_LENGTH_LIMIT 8 class WlanListItem : public ListItem { diff --git a/src/frontend/tools/radioitembutton.cpp b/src/frontend/tools/radioitembutton.cpp index 3c3dddf5..a46f4522 100644 --- a/src/frontend/tools/radioitembutton.cpp +++ b/src/frontend/tools/radioitembutton.cpp @@ -1,6 +1,9 @@ #include "radioitembutton.h" #define BUTTON_SIZE 32,32 +#define FRAMESPEED 60 //帧与帧之间的间隔时间(ms) +#define ALLTIME 40*1000 //等待动画持续总时间 + RadioItemButton::RadioItemButton(bool isActivated, QWidget *parent) : QPushButton(parent) { connect(this, &RadioItemButton::requestStartLoading, this, &RadioItemButton::onLoadingStarted); @@ -10,6 +13,32 @@ RadioItemButton::RadioItemButton(bool isActivated, QWidget *parent) : QPushButto m_iconLabel = new QLabel(this); m_iconLabel->setScaledContents(true); this->setFixedSize(BUTTON_SIZE); + + this->switchTimer = new QTimer(this); //QTimer对象,控制等待动画播放 + + this->raise(); + this->hide(); +} + +void RadioItemButton::switchAnimStep() +{ + //另外一种加载方法 + QString qpmQss = ":/res/s/conning-b/"; + qpmQss.append(QString::number(this->currentPage)); + qpmQss.append(".png"); + m_iconLabel->setPixmap(QPixmap(qpmQss)); + m_iconLabel->setProperty("useIconHighlightEffect", true); + m_iconLabel->setProperty("iconHighlightEffectMode", true); + + this->currentPage --; + + if (this->currentPage < 1) { + this->currentPage = 12; //循环播放 + } + this->countCurrentTime += FRAMESPEED; + if (this->countCurrentTime >= ALLTIME) { + emit this->toStopLoading(); //发出信号停止主界面和托盘区的等待动画 + } } void RadioItemButton::startLoading() @@ -40,7 +69,9 @@ void RadioItemButton::setReleased() void RadioItemButton::setButtonIcon(QIcon *icon) { - if (!icon) { return; } + if (!icon) { + return; + } //ZJP_TODO 绘制圆形按钮 m_iconLabel->setPixmap(icon->pixmap(this->size())); } @@ -48,9 +79,18 @@ void RadioItemButton::setButtonIcon(QIcon *icon) void RadioItemButton::onLoadingStarted() { //ZJP_TODO 开始播放转圈动画 + this->currentPage = 12; + this->countCurrentTime = 0; + this->switchTimer->start(FRAMESPEED); + this->show(); + if (this->countCurrentTime >= ALLTIME) { + emit this->requestStopLoading(); //发出信号停止主界面和托盘区的等待动画 + } } void RadioItemButton::onLoadingStopped() { //ZJP_TODO 停止播放转圈动画 + this->switchTimer->stop(); + this->hide(); }