控制面板有线开关换用KSwitchButton

This commit is contained in:
zhangyuanyuan1 2022-05-27 09:46:05 +08:00
parent e435fb0918
commit fa7fa1a37c
5 changed files with 19 additions and 24 deletions

View File

@ -162,28 +162,31 @@ bool NetConnect::eventFilter(QObject *w, QEvent *e) {
if (w->findChild<QWidget*>())
w->findChild<QWidget*>()->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();
}

View File

@ -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;

View File

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

View File

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

View File

@ -42,7 +42,6 @@
#include <QDBusReply>
#include <interface.h>
//#include "switchbutton.h"
#include "hoverbtn.h"
#include "itemframe.h"
#include "wlanitem.h"