Merge branch '0916-new' into 'dbus-interface'
Feature:Add loading animation. See merge request kylin-desktop/kylin-nm!257
This commit is contained in:
commit
9b2cb3709f
|
@ -117,16 +117,17 @@ void KyWirelessNetResource::getWirelessActiveConnection(NetworkManager::ActiveCo
|
|||
continue;
|
||||
}
|
||||
|
||||
qDebug() << "getWirelessActiveConnection " << activeConnectionPtr->uuid();
|
||||
QString ssid;
|
||||
QString ifaceName = getDeviceIFace(activeConnectionPtr,ssid);
|
||||
if(ifaceName.isEmpty() || ssid.isNull()) {
|
||||
continue;
|
||||
}
|
||||
if (map.contains(ifaceName)) {
|
||||
map[ifaceName].append(ssid);
|
||||
map[ifaceName].append(activeConnectionPtr->uuid());
|
||||
} else {
|
||||
QStringList list;
|
||||
list.append(ssid);
|
||||
list.append(activeConnectionPtr->uuid());
|
||||
map.insert(ifaceName,list);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,6 +78,9 @@ void WlanListItem::resizeEvent(QResizeEvent *event)
|
|||
|
||||
void WlanListItem::onRightButtonClicked()
|
||||
{
|
||||
if (!m_menu) {
|
||||
return;
|
||||
}
|
||||
m_menu->clear();
|
||||
if (!this->m_data) {
|
||||
return;
|
||||
|
@ -122,8 +125,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 +139,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 +336,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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,14 +149,11 @@ void WlanPage::initDevice()
|
|||
QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat);
|
||||
m_settings->beginGroup("DEFAULTCARD");
|
||||
QString key("wireless");
|
||||
QString deviceName = m_settings->value(key, "").toString();
|
||||
QString deviceName;
|
||||
m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, m_devList);
|
||||
if (deviceName.isEmpty()) {
|
||||
qDebug() << "initDevice but defalut wireless card is null";
|
||||
if (!m_devList.isEmpty()) {
|
||||
deviceName = m_devList.at(0);
|
||||
m_settings->setValue(key, deviceName);
|
||||
}
|
||||
if (!m_devList.isEmpty()) {
|
||||
deviceName = m_devList.at(0);
|
||||
m_settings->setValue(key, deviceName);
|
||||
}
|
||||
updateDefaultDevice(deviceName);
|
||||
qDebug() << "[WlanPage] initDevice defaultDevice = " << deviceName;
|
||||
|
@ -203,8 +200,8 @@ void WlanPage::getActiveWlan()
|
|||
int height = 0;
|
||||
while (iter != actMap.end()) {
|
||||
if (iter.key() == m_defaultDevice && !iter.value().isEmpty()) {
|
||||
QString ssid = iter.value().at(0);
|
||||
appendActiveWlan(ssid, height);
|
||||
QString uuid = iter.value().at(0);
|
||||
appendActiveWlan(uuid, height);
|
||||
break;
|
||||
}
|
||||
iter ++;
|
||||
|
@ -214,6 +211,7 @@ void WlanPage::getActiveWlan()
|
|||
} else {
|
||||
//未连接任何WiFi的情况
|
||||
m_activatedWlanSSid.clear();
|
||||
m_activatedWlanUuid.clear();
|
||||
WlanListItem *wlanItemWidget = new WlanListItem();
|
||||
qDebug() << "There is no activated wlan." << Q_FUNC_INFO << __LINE__ ;
|
||||
QListWidgetItem *wlanItem = new QListWidgetItem(m_activatedNetListWidget);
|
||||
|
@ -224,12 +222,15 @@ void WlanPage::getActiveWlan()
|
|||
}
|
||||
}
|
||||
|
||||
void WlanPage::appendActiveWlan(const QString &ssid, int &height)
|
||||
void WlanPage::appendActiveWlan(const QString &uuid, int &height)
|
||||
{
|
||||
m_activatedWlanSSid = ssid;
|
||||
qDebug() << "appendActiveWlan" << uuid;
|
||||
m_activatedWlanUuid = uuid;
|
||||
m_resource->getSsidByUuid(uuid, m_activatedWlanSSid, m_defaultDevice);
|
||||
|
||||
KyWirelessNetItem data;
|
||||
if (!m_resource->getWifiNetwork(m_defaultDevice, ssid, data)) {
|
||||
if (!m_resource->getWifiNetwork(m_defaultDevice, m_activatedWlanSSid, data)) {
|
||||
qWarning() << "Get activated wlan failed! ssid = " << m_activatedWlanSSid <<"; device = " << m_defaultDevice << "; uuid = " << m_activatedWlanUuid;
|
||||
return;
|
||||
}
|
||||
KyWirelessNetItem *item_data = new KyWirelessNetItem(data);
|
||||
|
@ -257,8 +258,7 @@ void WlanPage::getAllWlan()
|
|||
m_itemsMap.clear();
|
||||
QList<KyWirelessNetItem> wlanList;
|
||||
// if (!m_resource->getAllDeviceWifiNetwork(map))
|
||||
if (!m_resource->getDeviceWifiNetwork(m_defaultDevice, wlanList)) //ZJP_TODO 获取默认网卡并传入
|
||||
{
|
||||
if (!m_resource->getDeviceWifiNetwork(m_defaultDevice, wlanList)) { //ZJP_TODO 获取默认网卡并传入
|
||||
return;
|
||||
}
|
||||
int height = 0;
|
||||
|
@ -302,6 +302,7 @@ void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item)
|
|||
KyWirelessNetItem *data = new KyWirelessNetItem(item);
|
||||
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);
|
||||
|
@ -467,14 +468,27 @@ void WlanPage::onActivatedWlanChanged(QString uuid, NetworkManager::ActiveConnec
|
|||
//onWlanRemoved(m_wlanDevice, ssid);
|
||||
m_activatedNetListWidget->clear();
|
||||
int height = 0;
|
||||
appendActiveWlan(ssid, height);
|
||||
appendActiveWlan(uuid, height);
|
||||
onWlanRemoved(m_defaultDevice, ssid);
|
||||
// this->showDesktopNotify(tr("Connect WLAN succeed"));
|
||||
} else if (state == NetworkManager::ActiveConnection::State::Deactivated) {
|
||||
onWlanUpdated();
|
||||
} else if (state == NetworkManager::ActiveConnection::State::Deactivated && (uuid.isEmpty() || (!uuid.isEmpty() && uuid == m_activatedWlanUuid))) {
|
||||
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__;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ private:
|
|||
void initDeviceCombox();
|
||||
|
||||
void getActiveWlan();
|
||||
void appendActiveWlan(const QString &ssid, int &height);
|
||||
void appendActiveWlan(const QString &uuid, int &height);
|
||||
void getAllWlan();
|
||||
QMap<QString, QListWidgetItem*> m_itemsMap;
|
||||
QListWidgetItem *m_expandedItem = nullptr;
|
||||
|
@ -75,6 +75,7 @@ private:
|
|||
QLabel * m_hiddenWlanLabel = nullptr;
|
||||
|
||||
QString m_activatedWlanSSid;
|
||||
QString m_activatedWlanUuid;
|
||||
QStringList m_devList;
|
||||
|
||||
KyWirelessNetResource *m_resource = nullptr;
|
||||
|
|
|
@ -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