控制面板有线开关换用KSwitchButton
This commit is contained in:
parent
e435fb0918
commit
fa7fa1a37c
|
@ -162,28 +162,31 @@ bool NetConnect::eventFilter(QObject *w, QEvent *e) {
|
||||||
if (w->findChild<QWidget*>())
|
if (w->findChild<QWidget*>())
|
||||||
w->findChild<QWidget*>()->setStyleSheet("QWidget{background: palette(base);border-radius:4px;}");
|
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);
|
return QObject::eventFilter(w,e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetConnect::initComponent() {
|
void NetConnect::initComponent() {
|
||||||
wiredSwitch = new SwitchButton(pluginWidget);
|
wiredSwitch = new KSwitchButton(pluginWidget);
|
||||||
ui->openWIifLayout->addWidget(wiredSwitch);
|
ui->openWIifLayout->addWidget(wiredSwitch);
|
||||||
ui->detailLayOut->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
ui->detailLayOut->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
||||||
ui->verticalLayout_3->setContentsMargins(NO_MARGINS);
|
ui->verticalLayout_3->setContentsMargins(NO_MARGINS);
|
||||||
ui->availableLayout->setSpacing(SPACING);
|
ui->availableLayout->setSpacing(SPACING);
|
||||||
ui->horizontalLayout->setContentsMargins(TOP_MARGINS);
|
ui->horizontalLayout->setContentsMargins(TOP_MARGINS);
|
||||||
|
|
||||||
connect(wiredSwitch, &SwitchButton::disabledClick, this, [=]() {
|
wiredSwitch->installEventFilter(this);
|
||||||
showDesktopNotify(tr("No ethernet device avaliable"));
|
|
||||||
});
|
|
||||||
|
|
||||||
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
|
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
|
||||||
m_switchGsettings = new QGSettings(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()) {
|
if (!m_interface->isValid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (wiredSwitch->getDisabledFlag()) {
|
if (!wiredSwitch->isCheckable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qDebug() << "[NetConnect]call setWiredSwitchEnable" << checked << __LINE__;
|
qDebug() << "[NetConnect]call setWiredSwitchEnable" << checked << __LINE__;
|
||||||
|
@ -206,7 +209,7 @@ void NetConnect::initComponent() {
|
||||||
getDeviceStatusMap(deviceStatusMap);
|
getDeviceStatusMap(deviceStatusMap);
|
||||||
if (deviceStatusMap.isEmpty()) {
|
if (deviceStatusMap.isEmpty()) {
|
||||||
qDebug() << "[Netconnect] no device exist when init, set switch disable";
|
qDebug() << "[Netconnect] no device exist when init, set switch disable";
|
||||||
wiredSwitch->setDisabledFlag(true);
|
wiredSwitch->setCheckable(false);
|
||||||
wiredSwitch->setChecked(false);
|
wiredSwitch->setChecked(false);
|
||||||
}
|
}
|
||||||
initNet();
|
initNet();
|
||||||
|
@ -592,10 +595,10 @@ void NetConnect::onDeviceStatusChanged()
|
||||||
}
|
}
|
||||||
deviceStatusMap = map;
|
deviceStatusMap = map;
|
||||||
if (deviceStatusMap.isEmpty()) {
|
if (deviceStatusMap.isEmpty()) {
|
||||||
wiredSwitch->setDisabledFlag(true);
|
wiredSwitch->setCheckable(false);
|
||||||
wiredSwitch->setChecked(false);
|
wiredSwitch->setChecked(false);
|
||||||
} else {
|
} else {
|
||||||
wiredSwitch->setDisabledFlag(false);
|
wiredSwitch->setCheckable(true);
|
||||||
setSwitchStatus();
|
setSwitchStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,11 +48,14 @@
|
||||||
#include "interface.h"
|
#include "interface.h"
|
||||||
#include "addbtn.h"
|
#include "addbtn.h"
|
||||||
#include "fixlabel.h"
|
#include "fixlabel.h"
|
||||||
#include "switchbutton.h"
|
|
||||||
#include "hoverbtn.h"
|
#include "hoverbtn.h"
|
||||||
#include "lanitem.h"
|
#include "lanitem.h"
|
||||||
#include "deviceframe.h"
|
#include "deviceframe.h"
|
||||||
#include "itemframe.h"
|
#include "itemframe.h"
|
||||||
|
#include "kwidget.h"
|
||||||
|
#include "kswitchbutton.h"
|
||||||
|
|
||||||
|
using namespace kdk;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
DISCONNECTED,
|
DISCONNECTED,
|
||||||
|
@ -131,7 +134,7 @@ private:
|
||||||
QWidget *pluginWidget;
|
QWidget *pluginWidget;
|
||||||
|
|
||||||
QDBusInterface *m_interface = nullptr;
|
QDBusInterface *m_interface = nullptr;
|
||||||
SwitchButton *wiredSwitch;
|
KSwitchButton *wiredSwitch;
|
||||||
|
|
||||||
bool mFirstLoad;
|
bool mFirstLoad;
|
||||||
QGSettings *m_switchGsettings;
|
QGSettings *m_switchGsettings;
|
||||||
|
|
|
@ -22,6 +22,7 @@ CONFIG += c++11 \
|
||||||
link_pkgconfig \
|
link_pkgconfig \
|
||||||
|
|
||||||
PKGCONFIG += gsettings-qt \
|
PKGCONFIG += gsettings-qt \
|
||||||
|
kysdk-qtwidgets \
|
||||||
|
|
||||||
#DEFINES += QT_DEPRECATED_WARNINGS
|
#DEFINES += QT_DEPRECATED_WARNINGS
|
||||||
|
|
||||||
|
|
|
@ -188,20 +188,12 @@ bool WlanConnect::eventFilter(QObject *w, QEvent *e) {
|
||||||
|
|
||||||
void WlanConnect::initComponent() {
|
void WlanConnect::initComponent() {
|
||||||
m_wifiSwitch = new KSwitchButton(pluginWidget);
|
m_wifiSwitch = new KSwitchButton(pluginWidget);
|
||||||
m_wifiSwitch->installEventFilter(this);
|
|
||||||
ui->openWIifLayout->addWidget(m_wifiSwitch);
|
ui->openWIifLayout->addWidget(m_wifiSwitch);
|
||||||
ui->detailLayOut_3->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
ui->detailLayOut_3->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
||||||
ui->verticalLayout_3->setContentsMargins(NO_MARGINS);
|
ui->verticalLayout_3->setContentsMargins(NO_MARGINS);
|
||||||
ui->availableLayout->setSpacing(SPACING);
|
ui->availableLayout->setSpacing(SPACING);
|
||||||
|
|
||||||
// connect(m_wifiSwitch, &SwitchButton::disabledClick, this, [=]() {
|
m_wifiSwitch->installEventFilter(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)) {
|
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
|
||||||
|
@ -235,7 +227,6 @@ void WlanConnect::initComponent() {
|
||||||
getDeviceList(deviceList);
|
getDeviceList(deviceList);
|
||||||
if (deviceList.isEmpty()) {
|
if (deviceList.isEmpty()) {
|
||||||
qDebug() << "[WlanConnect]no device exist when init, set switch disable";
|
qDebug() << "[WlanConnect]no device exist when init, set switch disable";
|
||||||
// m_wifiSwitch->setDisabledFlag(true);
|
|
||||||
m_wifiSwitch->setCheckable(false);
|
m_wifiSwitch->setCheckable(false);
|
||||||
m_wifiSwitch->setChecked(false);
|
m_wifiSwitch->setChecked(false);
|
||||||
}
|
}
|
||||||
|
@ -490,11 +481,9 @@ void WlanConnect::onDeviceStatusChanged()
|
||||||
}
|
}
|
||||||
deviceList = list;
|
deviceList = list;
|
||||||
if (deviceList.isEmpty()) {
|
if (deviceList.isEmpty()) {
|
||||||
// m_wifiSwitch->setDisabledFlag(true);
|
|
||||||
m_wifiSwitch->setCheckable(false);
|
m_wifiSwitch->setCheckable(false);
|
||||||
m_wifiSwitch->setChecked(false);
|
m_wifiSwitch->setChecked(false);
|
||||||
} else {
|
} else {
|
||||||
// m_wifiSwitch->setDisabledFlag(false);
|
|
||||||
m_wifiSwitch->setCheckable(true);
|
m_wifiSwitch->setCheckable(true);
|
||||||
setSwitchStatus();
|
setSwitchStatus();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,6 @@
|
||||||
#include <QDBusReply>
|
#include <QDBusReply>
|
||||||
|
|
||||||
#include <interface.h>
|
#include <interface.h>
|
||||||
//#include "switchbutton.h"
|
|
||||||
#include "hoverbtn.h"
|
#include "hoverbtn.h"
|
||||||
#include "itemframe.h"
|
#include "itemframe.h"
|
||||||
#include "wlanitem.h"
|
#include "wlanitem.h"
|
||||||
|
|
Loading…
Reference in New Issue