控制面板无线网络换用KSwitchButton

This commit is contained in:
zhangyuanyuan1 2022-05-27 09:01:18 +08:00
parent 82d68ac9cc
commit e435fb0918
3 changed files with 31 additions and 10 deletions

View File

@ -178,28 +178,40 @@ bool WlanConnect::eventFilter(QObject *w, QEvent *e) {
if (w->findChild<QWidget*>())
w->findChild<QWidget*>()->setStyleSheet("QWidget{background: palette(base);border-radius:4px;}");
}
if (w == m_wifiSwitch && e->type() == QMouseEvent::MouseButtonPress) {
if (!m_wifiSwitch->isCheckable()) {
showDesktopNotify(tr("No wireless network card detected"));
}
}
return QObject::eventFilter(w,e);
}
void WlanConnect::initComponent() {
m_wifiSwitch = new SwitchButton(pluginWidget);
m_wifiSwitch = new KSwitchButton(pluginWidget);
m_wifiSwitch->installEventFilter(this);
ui->openWIifLayout->addWidget(m_wifiSwitch);
ui->detailLayOut_3->setContentsMargins(MAIN_LAYOUT_MARGINS);
ui->verticalLayout_3->setContentsMargins(NO_MARGINS);
ui->availableLayout->setSpacing(SPACING);
connect(m_wifiSwitch, &SwitchButton::disabledClick, this, [=]() {
showDesktopNotify(tr("No wireless network card detected"));
// connect(m_wifiSwitch, &SwitchButton::disabledClick, this, [=]() {
// showDesktopNotify(tr("No wireless network card detected"));
// });
connect(m_wifiSwitch, &KSwitchButton::isCheckable, this, [=]() {
if (!m_wifiSwitch->isCheckable()) {
showDesktopNotify(tr("No wireless network card detected"));
}
});
//开关
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA);
connect(m_wifiSwitch, &SwitchButton::checkedChanged, this, [=] (bool checked) {
connect(m_wifiSwitch, &KSwitchButton::stateChanged, this, [=] (bool checked) {
if (!m_interface->isValid()) {
return;
}
if (m_wifiSwitch->getDisabledFlag()) {
if (!m_wifiSwitch->isCheckable()) {
return;
}
qDebug() << "[WlanConnect]call setWirelessSwitchEnable " << checked << __LINE__;
@ -223,7 +235,8 @@ void WlanConnect::initComponent() {
getDeviceList(deviceList);
if (deviceList.isEmpty()) {
qDebug() << "[WlanConnect]no device exist when init, set switch disable";
m_wifiSwitch->setDisabledFlag(true);
// m_wifiSwitch->setDisabledFlag(true);
m_wifiSwitch->setCheckable(false);
m_wifiSwitch->setChecked(false);
}
initNet();
@ -477,10 +490,12 @@ void WlanConnect::onDeviceStatusChanged()
}
deviceList = list;
if (deviceList.isEmpty()) {
m_wifiSwitch->setDisabledFlag(true);
// m_wifiSwitch->setDisabledFlag(true);
m_wifiSwitch->setCheckable(false);
m_wifiSwitch->setChecked(false);
} else {
m_wifiSwitch->setDisabledFlag(false);
// m_wifiSwitch->setDisabledFlag(false);
m_wifiSwitch->setCheckable(true);
setSwitchStatus();
}
}

View File

@ -42,10 +42,15 @@
#include <QDBusReply>
#include <interface.h>
#include "switchbutton.h"
//#include "switchbutton.h"
#include "hoverbtn.h"
#include "itemframe.h"
#include "wlanitem.h"
#include "kwidget.h"
#include "kswitchbutton.h"
using namespace kdk;
namespace Ui {
class WlanConnect;
}
@ -145,7 +150,7 @@ private:
QTimer * m_scanTimer = nullptr;
// QTimer * m_updateTimer = nullptr;
private:
SwitchButton *m_wifiSwitch;
KSwitchButton *m_wifiSwitch;
bool m_firstLoad;
private slots:

View File

@ -22,6 +22,7 @@ CONFIG += c++11 \
link_pkgconfig \
PKGCONFIG += gsettings-qt \
kysdk-qtwidgets \
#DEFINES += QT_DEPRECATED_WARNINGS