Optimize code.

This commit is contained in:
jinxujie 2021-08-27 11:39:36 +08:00
parent e54c6465cc
commit d98122b677
3 changed files with 58 additions and 9 deletions

View File

@ -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 <<Q_FUNC_INFO << __LINE__;
@ -283,8 +284,10 @@ void WlanListItem::onSecurityChanged(QString interface, QString ssid, QString se
void WlanListItem::onPwdEditorTextChanged()
{
if (!m_pwdLineEdit || !m_connectButton) { return; }
if (m_pwdLineEdit->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;
}

View File

@ -13,7 +13,7 @@
#define NORMAL_HEIGHT 48
#define EXPANDED_HEIGHT 120
#define PWD_LENGTH_LIMIT 8
class WlanListItem : public ListItem
{

View File

@ -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();
}