From fa7fa1a37c248496f32dd3e41021e7ae20e7798e Mon Sep 17 00:00:00 2001 From: zhangyuanyuan1 Date: Fri, 27 May 2022 09:46:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A7=E5=88=B6=E9=9D=A2=E6=9D=BF=E6=9C=89?= =?UTF-8?q?=E7=BA=BF=E5=BC=80=E5=85=B3=E6=8D=A2=E7=94=A8KSwitchButton?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/netconnect/netconnect.cpp | 21 ++++++++++++--------- plugins/netconnect/netconnect.h | 7 +++++-- plugins/netconnect/netconnect.pro | 1 + plugins/wlanconnect/wlanconnect.cpp | 13 +------------ plugins/wlanconnect/wlanconnect.h | 1 - 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/plugins/netconnect/netconnect.cpp b/plugins/netconnect/netconnect.cpp index 16b50761..42f024e9 100644 --- a/plugins/netconnect/netconnect.cpp +++ b/plugins/netconnect/netconnect.cpp @@ -162,28 +162,31 @@ bool NetConnect::eventFilter(QObject *w, QEvent *e) { if (w->findChild()) w->findChild()->setStyleSheet("QWidget{background: palette(base);border-radius:4px;}"); } + if (w == wiredSwitch && e->type() == QMouseEvent::MouseButtonPress) { + if (!wiredSwitch->isCheckable()) { + showDesktopNotify(tr("No ethernet device avaliable")); + } + } return QObject::eventFilter(w,e); } void NetConnect::initComponent() { - wiredSwitch = new SwitchButton(pluginWidget); + wiredSwitch = new KSwitchButton(pluginWidget); ui->openWIifLayout->addWidget(wiredSwitch); ui->detailLayOut->setContentsMargins(MAIN_LAYOUT_MARGINS); ui->verticalLayout_3->setContentsMargins(NO_MARGINS); ui->availableLayout->setSpacing(SPACING); ui->horizontalLayout->setContentsMargins(TOP_MARGINS); - connect(wiredSwitch, &SwitchButton::disabledClick, this, [=]() { - showDesktopNotify(tr("No ethernet device avaliable")); - }); + wiredSwitch->installEventFilter(this); if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA); - connect(wiredSwitch, &SwitchButton::checkedChanged, this, [=] (bool checked) { + connect(wiredSwitch, &KSwitchButton::stateChanged, this, [=] (bool checked) { if (!m_interface->isValid()) { return; } - if (wiredSwitch->getDisabledFlag()) { + if (!wiredSwitch->isCheckable()) { return; } qDebug() << "[NetConnect]call setWiredSwitchEnable" << checked << __LINE__; @@ -206,7 +209,7 @@ void NetConnect::initComponent() { getDeviceStatusMap(deviceStatusMap); if (deviceStatusMap.isEmpty()) { qDebug() << "[Netconnect] no device exist when init, set switch disable"; - wiredSwitch->setDisabledFlag(true); + wiredSwitch->setCheckable(false); wiredSwitch->setChecked(false); } initNet(); @@ -592,10 +595,10 @@ void NetConnect::onDeviceStatusChanged() } deviceStatusMap = map; if (deviceStatusMap.isEmpty()) { - wiredSwitch->setDisabledFlag(true); + wiredSwitch->setCheckable(false); wiredSwitch->setChecked(false); } else { - wiredSwitch->setDisabledFlag(false); + wiredSwitch->setCheckable(true); setSwitchStatus(); } diff --git a/plugins/netconnect/netconnect.h b/plugins/netconnect/netconnect.h index 2126c399..f991540f 100644 --- a/plugins/netconnect/netconnect.h +++ b/plugins/netconnect/netconnect.h @@ -48,11 +48,14 @@ #include "interface.h" #include "addbtn.h" #include "fixlabel.h" -#include "switchbutton.h" #include "hoverbtn.h" #include "lanitem.h" #include "deviceframe.h" #include "itemframe.h" +#include "kwidget.h" +#include "kswitchbutton.h" + +using namespace kdk; enum { DISCONNECTED, @@ -131,7 +134,7 @@ private: QWidget *pluginWidget; QDBusInterface *m_interface = nullptr; - SwitchButton *wiredSwitch; + KSwitchButton *wiredSwitch; bool mFirstLoad; QGSettings *m_switchGsettings; diff --git a/plugins/netconnect/netconnect.pro b/plugins/netconnect/netconnect.pro index c6245ada..3a6954f8 100644 --- a/plugins/netconnect/netconnect.pro +++ b/plugins/netconnect/netconnect.pro @@ -22,6 +22,7 @@ CONFIG += c++11 \ link_pkgconfig \ PKGCONFIG += gsettings-qt \ + kysdk-qtwidgets \ #DEFINES += QT_DEPRECATED_WARNINGS diff --git a/plugins/wlanconnect/wlanconnect.cpp b/plugins/wlanconnect/wlanconnect.cpp index 168aa4ab..496d04c5 100644 --- a/plugins/wlanconnect/wlanconnect.cpp +++ b/plugins/wlanconnect/wlanconnect.cpp @@ -188,20 +188,12 @@ bool WlanConnect::eventFilter(QObject *w, QEvent *e) { void WlanConnect::initComponent() { 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, &KSwitchButton::isCheckable, this, [=]() { - if (!m_wifiSwitch->isCheckable()) { - showDesktopNotify(tr("No wireless network card detected")); - } - }); + m_wifiSwitch->installEventFilter(this); //开关 if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { @@ -235,7 +227,6 @@ void WlanConnect::initComponent() { getDeviceList(deviceList); if (deviceList.isEmpty()) { qDebug() << "[WlanConnect]no device exist when init, set switch disable"; -// m_wifiSwitch->setDisabledFlag(true); m_wifiSwitch->setCheckable(false); m_wifiSwitch->setChecked(false); } @@ -490,11 +481,9 @@ void WlanConnect::onDeviceStatusChanged() } deviceList = list; if (deviceList.isEmpty()) { -// m_wifiSwitch->setDisabledFlag(true); m_wifiSwitch->setCheckable(false); m_wifiSwitch->setChecked(false); } else { -// m_wifiSwitch->setDisabledFlag(false); m_wifiSwitch->setCheckable(true); setSwitchStatus(); } diff --git a/plugins/wlanconnect/wlanconnect.h b/plugins/wlanconnect/wlanconnect.h index 80349cc1..f5ffcb5e 100644 --- a/plugins/wlanconnect/wlanconnect.h +++ b/plugins/wlanconnect/wlanconnect.h @@ -42,7 +42,6 @@ #include #include -//#include "switchbutton.h" #include "hoverbtn.h" #include "itemframe.h" #include "wlanitem.h"