Feature:Add loading animation.
This commit is contained in:
parent
444d87029b
commit
63a55ddb92
|
@ -122,8 +122,8 @@ void WlanListItem::initWlanUI()
|
|||
#define CONNECT_BUTTON_WIDTH 96
|
||||
#define FRAME_CONTENT_MARGINS 56,4,16,4
|
||||
#define FRAME_SPACING 8
|
||||
#define PWD_CONTENT_MARGINS 8,0,32,0
|
||||
#define SHOW_PWD_BUTTON_SIZE 16,16
|
||||
#define PWD_CONTENT_MARGINS 8,0,34,0
|
||||
#define SHOW_PWD_BUTTON_SIZE 24,24
|
||||
#define PWD_LAYOUT_MARGINS 8,0,8,0
|
||||
//密码输入区域的UI
|
||||
m_pwdFrame = new QFrame(this);
|
||||
|
@ -136,11 +136,15 @@ void WlanListItem::initWlanUI()
|
|||
connect(m_pwdLineEdit, &QLineEdit::textChanged, this, &WlanListItem::onPwdEditorTextChanged);
|
||||
m_pwdLineEdit->setFixedHeight(PWD_AREA_HEIGHT);
|
||||
m_pwdLineEdit->setEchoMode(QLineEdit::EchoMode::Password);
|
||||
m_pwdLineEdit->setTextMargins(PWD_CONTENT_MARGINS);
|
||||
m_pwdLineEditLyt = new QHBoxLayout(m_pwdLineEdit);
|
||||
m_pwdLineEditLyt->setContentsMargins(PWD_LAYOUT_MARGINS);
|
||||
m_pwdLineEdit->setLayout(m_pwdLineEditLyt);
|
||||
m_showPwdButton = new QPushButton(m_pwdLineEdit);
|
||||
m_showPwdButton->setFixedSize(SHOW_PWD_BUTTON_SIZE);
|
||||
m_showPwdButton->setAutoFillBackground(false);
|
||||
m_showPwdButton->setIcon(QIcon(":/res/h/hide-pwd.png"));
|
||||
m_showPwdButton->setCursor(Qt::PointingHandCursor);
|
||||
connect(m_showPwdButton, &QPushButton::clicked, this, &WlanListItem::onShowPwdButtonClicked);
|
||||
m_pwdLineEditLyt->addStretch();
|
||||
m_pwdLineEditLyt->addWidget(m_showPwdButton);
|
||||
|
@ -329,11 +333,10 @@ void WlanListItem::onShowPwdButtonClicked()
|
|||
return;
|
||||
}
|
||||
if (m_pwdLineEdit->echoMode() == QLineEdit::EchoMode::Password) {
|
||||
//TODO 按钮图标要发生改变
|
||||
|
||||
m_showPwdButton->setIcon(QIcon(":/res/h/show-pwd.png"));
|
||||
m_pwdLineEdit->setEchoMode(QLineEdit::EchoMode::Normal);
|
||||
} else {
|
||||
//TODO 按钮图标要发生改变
|
||||
m_showPwdButton->setIcon(QIcon(":/res/h/hide-pwd.png"));
|
||||
m_pwdLineEdit->setEchoMode(QLineEdit::EchoMode::Password);
|
||||
}
|
||||
}
|
||||
|
@ -385,7 +388,7 @@ void WlanListItem::onWlanStatusChange(QString uuid, NetworkManager::ActiveConnec
|
|||
QString ssid;
|
||||
m_resource->getSsidByUuid(uuid,ssid);
|
||||
if (m_data->m_NetSsid == ssid) {
|
||||
qDebug() << "[WlanPage] State changed to :" << state << Q_FUNC_INFO <<__LINE__;
|
||||
qDebug() << ssid << " state changed to :" << state << Q_FUNC_INFO <<__LINE__;
|
||||
if (state == NetworkManager::ActiveConnection::State::Activating) {
|
||||
m_netButton->startLoading();
|
||||
} else {
|
||||
|
|
|
@ -93,13 +93,13 @@ void TabPage::initUI()
|
|||
void TabPage::updateDefaultDevice(QString &deviceName)
|
||||
{
|
||||
qDebug() << "updateDefaultDevice" << deviceName;
|
||||
defaultDevice = deviceName;
|
||||
m_defaultDevice = deviceName;
|
||||
}
|
||||
|
||||
QString TabPage::getDefaultDevice()
|
||||
{
|
||||
qDebug() << "getDefaultDevice" << defaultDevice;
|
||||
return defaultDevice;
|
||||
qDebug() << "getDefaultDevice" << m_defaultDevice;
|
||||
return m_defaultDevice;
|
||||
}
|
||||
|
||||
void setDefaultDevice(KyDeviceType deviceType, QString deviceName)
|
||||
|
|
|
@ -83,7 +83,7 @@ protected:
|
|||
QHBoxLayout * m_settingsLayout = nullptr;
|
||||
QLabel * m_settingsLabel = nullptr;
|
||||
|
||||
QString defaultDevice = "";
|
||||
QString m_defaultDevice = "";
|
||||
|
||||
//临时增加的下拉框选择网卡区域
|
||||
QFrame * m_deviceFrame = nullptr;
|
||||
|
|
|
@ -193,7 +193,7 @@ void WlanPage::getActiveWlan()
|
|||
QMap<QString,QStringList>::iterator iter = actMap.begin();
|
||||
int height = 0;
|
||||
while (iter != actMap.end()) {
|
||||
if (iter.key() == defaultDevice && !iter.value().isEmpty()) {
|
||||
if (iter.key() == m_defaultDevice && !iter.value().isEmpty()) {
|
||||
QString ssid = iter.value().at(0);
|
||||
appendActiveWlan(ssid, height);
|
||||
break;
|
||||
|
@ -220,11 +220,11 @@ void WlanPage::appendActiveWlan(const QString &ssid, int &height)
|
|||
m_activatedWlanSSid = ssid;
|
||||
|
||||
KyWirelessNetItem data;
|
||||
if (!m_resource->getWifiNetwork(defaultDevice, ssid, data)) {
|
||||
if (!m_resource->getWifiNetwork(m_defaultDevice, ssid, data)) {
|
||||
return;
|
||||
}
|
||||
KyWirelessNetItem *item_data = new KyWirelessNetItem(data);
|
||||
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, item_data, defaultDevice);
|
||||
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, item_data, m_defaultDevice);
|
||||
qDebug() << "Activated wlan: ssid = " << item_data->m_NetSsid;
|
||||
QListWidgetItem *wlanItem = new QListWidgetItem(m_activatedNetListWidget);
|
||||
wlanItem->setSizeHint(QSize(m_activatedNetListWidget->width(), wlanItemWidget->height()));
|
||||
|
@ -248,8 +248,7 @@ void WlanPage::getAllWlan()
|
|||
m_itemsMap.clear();
|
||||
QList<KyWirelessNetItem> wlanList;
|
||||
// if (!m_resource->getAllDeviceWifiNetwork(map))
|
||||
if (!m_resource->getDeviceWifiNetwork(defaultDevice, wlanList)) //ZJP_TODO 获取默认网卡并传入
|
||||
{
|
||||
if (!m_resource->getDeviceWifiNetwork(m_defaultDevice, wlanList)) { //ZJP_TODO 获取默认网卡并传入
|
||||
return;
|
||||
}
|
||||
int height = 0;
|
||||
|
@ -259,7 +258,7 @@ void WlanPage::getAllWlan()
|
|||
}
|
||||
|
||||
KyWirelessNetItem *data = new KyWirelessNetItem(itemData);
|
||||
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, defaultDevice);
|
||||
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, m_defaultDevice);
|
||||
QListWidgetItem *wlanItem = new QListWidgetItem(m_inactivatedNetListWidget);
|
||||
connect(wlanItemWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged);
|
||||
connect(wlanItemWidget, &WlanListItem::connectButtonClicked, this, &WlanPage::onConnectButtonClicked);
|
||||
|
@ -282,8 +281,9 @@ void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item)
|
|||
qDebug() << "A Wlan Added! interface = " << interface << "; ssid = " << item.m_NetSsid << Q_FUNC_INFO <<__LINE__;
|
||||
|
||||
KyWirelessNetItem *data = new KyWirelessNetItem(item);
|
||||
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, defaultDevice);
|
||||
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, m_defaultDevice);
|
||||
connect(wlanItemWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged);
|
||||
connect(wlanItemWidget, &WlanListItem::connectButtonClicked, this, &WlanPage::onConnectButtonClicked);
|
||||
QListWidgetItem *wlanItem = new QListWidgetItem(m_inactivatedNetListWidget);
|
||||
wlanItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), wlanItemWidget->height()));
|
||||
m_inactivatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget);
|
||||
|
@ -454,13 +454,26 @@ void WlanPage::onActivatedWlanChanged(QString uuid, NetworkManager::ActiveConnec
|
|||
m_activatedNetListWidget->clear();
|
||||
int height = 0;
|
||||
appendActiveWlan(ssid, height);
|
||||
onWlanRemoved(defaultDevice, ssid);
|
||||
onWlanRemoved(m_defaultDevice, ssid);
|
||||
// this->showDesktopNotify(tr("Connect WLAN succeed"));
|
||||
} else if (state == NetworkManager::ActiveConnection::State::Deactivated) {
|
||||
onWlanUpdated();
|
||||
QString oldActWlanSsid = m_activatedWlanSSid;
|
||||
getActiveWlan();
|
||||
QString newActWlanSsid = m_activatedWlanSSid;
|
||||
if (oldActWlanSsid != newActWlanSsid) {
|
||||
if (!oldActWlanSsid.isEmpty()) {
|
||||
KyWirelessNetItem item;
|
||||
if(m_resource->getWifiNetwork(m_defaultDevice, oldActWlanSsid, item)) {
|
||||
onWlanAdded(m_defaultDevice, item);
|
||||
}
|
||||
}
|
||||
if (!newActWlanSsid.isEmpty()) {
|
||||
onWlanRemoved(m_defaultDevice, newActWlanSsid);
|
||||
}
|
||||
}
|
||||
// this->showDesktopNotify(tr("Disconnect WLAN succeed"));
|
||||
} else {
|
||||
onWlanUpdated();
|
||||
qDebug() << "Unexpected wlan state, will do nothing." << Q_FUNC_INFO << __LINE__;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -488,7 +501,7 @@ void WlanPage::onItemHeightChanged(const QString &ssid)
|
|||
void WlanPage::onConnectButtonClicked(KyWirelessConnectSetting &connSettingInfo, const bool &isHidden)
|
||||
{
|
||||
qDebug() << "Received signal of connecting wlan, ssid = " << connSettingInfo.m_ssid << Q_FUNC_INFO << __LINE__;
|
||||
m_wirelessConnectOpreation->addAndActiveWirelessConnect(defaultDevice, connSettingInfo, isHidden);
|
||||
m_wirelessConnectOpreation->addAndActiveWirelessConnect(m_defaultDevice, connSettingInfo, isHidden);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -515,7 +528,7 @@ void WlanPage::onDeviceComboxIndexChanged(int currentIndex)
|
|||
//TODO 设备变更时更新设备和列表
|
||||
QString currentDevice = m_deviceComboBox->itemText(currentIndex);
|
||||
qDebug() << "Current device changed! device = " << currentDevice << Q_FUNC_INFO << __LINE__;
|
||||
defaultDevice = currentDevice;
|
||||
m_defaultDevice = currentDevice;
|
||||
getActiveWlan();
|
||||
getAllWlan();
|
||||
}
|
||||
|
|
|
@ -33,6 +33,11 @@ RadioItemButton::RadioItemButton(QWidget *parent) : QPushButton(parent)
|
|||
connect(qApp, &QApplication::paletteChanged, this, &RadioItemButton::onPaletteChanged);
|
||||
}
|
||||
|
||||
RadioItemButton::~RadioItemButton()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RadioItemButton::startLoading()
|
||||
{
|
||||
emit this->requestStartLoading();
|
||||
|
@ -72,50 +77,40 @@ void RadioItemButton::setActive(const bool &isActive)
|
|||
}
|
||||
void RadioItemButton::onLoadingStarted()
|
||||
{
|
||||
if (!m_loadingTimer) {
|
||||
m_loadingTimer = new QTimer();
|
||||
connect(m_loadingTimer, &QTimer::timeout, this, &RadioItemButton::onLoadingTimerTimeout);
|
||||
#define ANIMATION_SPEED 0.5*1000
|
||||
#define START_ROTATION 0
|
||||
#define END_ROTATION 360
|
||||
#define ANIMATION_LOOP -1 //无限旋转
|
||||
if (!m_iconLabel) {
|
||||
qWarning() << "Start loading failed, iconLabel is null pointer!" << Q_FUNC_INFO << __LINE__;
|
||||
}
|
||||
if (!m_timeoutTimer) {
|
||||
m_timeoutTimer = new QTimer();
|
||||
connect(m_timeoutTimer, &QTimer::timeout, this, &RadioItemButton::onLoadingStopped);
|
||||
if (!m_animation) {
|
||||
m_animation = new QVariantAnimation(m_iconLabel);
|
||||
}
|
||||
if (m_loadingTimer->isActive()) {
|
||||
return;
|
||||
}
|
||||
m_loadingTimer->start(FLASH_SPEED);
|
||||
m_timeoutTimer->stop();
|
||||
m_timeoutTimer->start(TIMEOUT_TIMER);
|
||||
m_animation->setDuration(ANIMATION_SPEED);
|
||||
m_animation->setStartValue(START_ROTATION);
|
||||
m_animation->setEndValue(END_ROTATION);
|
||||
m_animation->setLoopCount(ANIMATION_LOOP);
|
||||
connect(m_animation, &QVariantAnimation::valueChanged, this, &RadioItemButton::onAnimationValueChanged);
|
||||
m_animation->start();
|
||||
}
|
||||
|
||||
void RadioItemButton::onLoadingStopped()
|
||||
{
|
||||
//ZJP_TODO 停止播放转圈动画
|
||||
if (this->m_loadingTimer) {
|
||||
this->m_loadingTimer->stop();
|
||||
if (!m_animation) {
|
||||
qWarning() << "Stop loading failed, m_animation is null pointer!" << Q_FUNC_INFO << __LINE__;
|
||||
return;
|
||||
} else {
|
||||
qWarning() << "Stop loading failed, m_loadingTimer is nullptr." << Q_FUNC_INFO << __LINE__;
|
||||
m_animation->stop();
|
||||
}
|
||||
if (this->m_timeoutTimer) {
|
||||
this->m_timeoutTimer->stop();
|
||||
|
||||
if (!m_iconLabel) {
|
||||
qWarning() << "Stop loading failed, iconLabel is null pointer!" << Q_FUNC_INFO << __LINE__;
|
||||
return;
|
||||
} else {
|
||||
qWarning() << "Stop timeout_timer failed, m_timeoutTimer is nullptr." << Q_FUNC_INFO << __LINE__;
|
||||
}
|
||||
}
|
||||
|
||||
void RadioItemButton::onLoadingTimerTimeout()
|
||||
{
|
||||
QString qpmQss = ":/res/s/conning-a/";
|
||||
qpmQss.append(QString::number(this->currentPage));
|
||||
qpmQss.append(".png");
|
||||
qDebug()<<qpmQss;
|
||||
m_iconLabel->setPixmap(QPixmap(qpmQss));
|
||||
|
||||
this->currentPage --;
|
||||
|
||||
if (this->currentPage < 1) {
|
||||
this->currentPage = 8; //循环播放
|
||||
m_iconLabel->setPixmap(m_pixmap);
|
||||
}
|
||||
qDebug() << "Stop loading succeed!" << Q_FUNC_INFO << __LINE__;
|
||||
}
|
||||
|
||||
void RadioItemButton::onPaletteChanged()
|
||||
|
@ -129,6 +124,16 @@ void RadioItemButton::onPaletteChanged()
|
|||
}
|
||||
}
|
||||
|
||||
void RadioItemButton::onAnimationValueChanged(const QVariant& value)
|
||||
{
|
||||
if (!m_iconLabel) {
|
||||
return;
|
||||
}
|
||||
QTransform t;
|
||||
t.rotate(value.toReal());
|
||||
m_iconLabel->setPixmap(QIcon(":/res/s/conning-a/1.png").pixmap(ICON_SIZE).transformed(t));
|
||||
}
|
||||
|
||||
void RadioItemButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPalette pal = this->palette();
|
||||
|
|
|
@ -3,16 +3,18 @@
|
|||
#include <QPushButton>
|
||||
#include <QIcon>
|
||||
#include <QLabel>
|
||||
#include<QTimer>
|
||||
#include <QTimer>
|
||||
#include <QVariantAnimation>
|
||||
|
||||
#define MIDDLE_COLOR 178
|
||||
|
||||
class RadioItemButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RadioItemButton(QWidget * parent = nullptr);
|
||||
~RadioItemButton() = default;
|
||||
~RadioItemButton();
|
||||
void startLoading();
|
||||
void stopLoading();
|
||||
void setButtonIcon(const QIcon &icon);
|
||||
|
@ -37,18 +39,16 @@ protected:
|
|||
private:
|
||||
bool m_isActivated = false;
|
||||
QLabel * m_iconLabel = nullptr;
|
||||
QTimer * m_loadingTimer = nullptr;
|
||||
QTimer * m_timeoutTimer = nullptr;
|
||||
QColor m_backgroundColor;
|
||||
QVariantAnimation * m_animation = nullptr;
|
||||
|
||||
int currentPage = 8;
|
||||
QPixmap m_pixmap;
|
||||
|
||||
private slots:
|
||||
void onLoadingStarted();
|
||||
void onLoadingStopped();
|
||||
void onLoadingTimerTimeout();
|
||||
void onPaletteChanged();
|
||||
void onAnimationValueChanged(const QVariant& value);
|
||||
};
|
||||
|
||||
#endif // NETBUTTON_H
|
||||
|
|
Loading…
Reference in New Issue