mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
fix: 状态图标颜色变化
将状态图标由SVG图标换为自定义绘制控件,该控件可随系统活动主题色变化而变化 Log: 修复网络,蓝牙插件设备状态图标颜色不会随系统活动色变化而变化的问题 Bug: https://pms.uniontech.com/zentao/bug-view-31253.html
This commit is contained in:
parent
25745c873d
commit
b04b9bb6d2
@ -22,6 +22,7 @@
|
||||
#ifndef IMAGEUTIL_H
|
||||
#define IMAGEUTIL_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPixmap>
|
||||
#include <QSvgRenderer>
|
||||
|
||||
|
86
frame/util/statebutton.cpp
Normal file
86
frame/util/statebutton.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
#include "statebutton.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QPainter>
|
||||
#include <QtMath>
|
||||
|
||||
StateButton::StateButton(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
}
|
||||
|
||||
void StateButton::setType(StateButton::Type type)
|
||||
{
|
||||
m_type = type;
|
||||
update();
|
||||
}
|
||||
|
||||
void StateButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QWidget::paintEvent(event);
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
|
||||
int radius = qMin(width(), height());
|
||||
painter.setPen(QPen(Qt::NoPen));
|
||||
painter.setBrush(palette().color(QPalette::Highlight));
|
||||
painter.drawPie(rect(), 0, 360 * 16);
|
||||
|
||||
QPen pen(palette().color(QPalette::Text), radius / 100.0 * 6.20, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
|
||||
switch (m_type) {
|
||||
case Check: drawCheck(painter, pen, radius); break;
|
||||
case Fork: drawFork(painter, pen, radius); break;
|
||||
}
|
||||
}
|
||||
|
||||
void StateButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
QWidget::mousePressEvent(event);
|
||||
emit click();
|
||||
}
|
||||
|
||||
void StateButton::enterEvent(QEvent *event)
|
||||
{
|
||||
QWidget::enterEvent(event);
|
||||
setType(Fork);
|
||||
}
|
||||
|
||||
void StateButton::leaveEvent(QEvent *event)
|
||||
{
|
||||
QWidget::leaveEvent(event);
|
||||
setType(Check);
|
||||
}
|
||||
|
||||
void StateButton::drawCheck(QPainter &painter, QPen &pen, int radius)
|
||||
{
|
||||
painter.setPen(pen);
|
||||
|
||||
QPointF points[3] = {
|
||||
QPointF(radius / 100.0 * 32, radius / 100.0 * 57),
|
||||
QPointF(radius / 100.0 * 45, radius / 100.0 * 70),
|
||||
QPointF(radius / 100.0 * 75, radius / 100.0 * 35)
|
||||
};
|
||||
|
||||
painter.drawPolyline(points, 3);
|
||||
}
|
||||
|
||||
void StateButton::drawFork(QPainter &painter, QPen &pen, int radius)
|
||||
{
|
||||
pen.setCapStyle(Qt::RoundCap);
|
||||
painter.setPen(pen);
|
||||
|
||||
QPointF pointsl[2] = {
|
||||
QPointF(radius / 100.0 * 35, radius / 100.0 * 35),
|
||||
QPointF(radius / 100.0 * 65, radius / 100.0 * 65)
|
||||
};
|
||||
|
||||
painter.drawPolyline(pointsl, 2);
|
||||
|
||||
QPointF pointsr[2] = {
|
||||
QPointF(radius / 100.0 * 65, radius / 100.0 * 35),
|
||||
QPointF(radius / 100.0 * 35, radius / 100.0 * 65)
|
||||
};
|
||||
|
||||
painter.drawPolyline(pointsr, 2);
|
||||
}
|
37
frame/util/statebutton.h
Normal file
37
frame/util/statebutton.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef STATEBUTTON_H
|
||||
#define STATEBUTTON_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class StateButton : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Type {
|
||||
Check,
|
||||
Fork
|
||||
};
|
||||
|
||||
public:
|
||||
explicit StateButton(QWidget *parent = nullptr);
|
||||
void setType(Type type);
|
||||
|
||||
signals:
|
||||
void click();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void enterEvent(QEvent *event) override;
|
||||
void leaveEvent(QEvent *event) override;
|
||||
|
||||
private:
|
||||
void drawCheck(QPainter &painter, QPen &pen, int radius);
|
||||
void drawFork(QPainter &painter, QPen &pen, int radius);
|
||||
|
||||
private:
|
||||
Type m_type;
|
||||
};
|
||||
|
||||
#endif // STATEBUTTON_H
|
@ -4,7 +4,9 @@ set(PLUGIN_NAME "bluetooth")
|
||||
project(${PLUGIN_NAME})
|
||||
|
||||
# Sources files
|
||||
file(GLOB_RECURSE SRCS "*.h" "*.cpp" "../../widgets/*.h" "../../widgets/*.cpp" "../../frame/util/imageutil.h" "../../frame/util/imageutil.cpp")
|
||||
file(GLOB_RECURSE SRCS "*.h" "*.cpp" "../../widgets/*.h" "../../widgets/*.cpp"
|
||||
"../../frame/util/imageutil.h" "../../frame/util/imageutil.cpp"
|
||||
"../../frame/util/statebutton.h" "../../frame/util/statebutton.cpp")
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(Qt5Widgets REQUIRED)
|
||||
|
@ -292,18 +292,18 @@ void BluetoothApplet::getDevieInitStatus(AdapterItem *item)
|
||||
}
|
||||
|
||||
switch (deviceState) {
|
||||
case Device::StateConnected:
|
||||
emit deviceStateChanged(deviceState);
|
||||
break;
|
||||
case Device::StateUnavailable:
|
||||
emit deviceStateChanged(otherDeviceState);
|
||||
break;
|
||||
case Device::StateAvailable: {
|
||||
if (otherDeviceState != Device::StateConnected)
|
||||
case Device::StateConnected:
|
||||
emit deviceStateChanged(deviceState);
|
||||
else
|
||||
break;
|
||||
case Device::StateUnavailable:
|
||||
emit deviceStateChanged(otherDeviceState);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case Device::StateAvailable: {
|
||||
if (otherDeviceState != Device::StateConnected)
|
||||
emit deviceStateChanged(deviceState);
|
||||
else
|
||||
emit deviceStateChanged(otherDeviceState);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -128,15 +128,15 @@ void BluetoothItem::refreshIcon()
|
||||
|
||||
if (m_adapterPowered) {
|
||||
switch (m_devState) {
|
||||
case Device::StateConnected:
|
||||
stateString = "active";
|
||||
break;
|
||||
case Device::StateAvailable: {
|
||||
return ;
|
||||
}
|
||||
case Device::StateUnavailable: {
|
||||
stateString = "disable";
|
||||
} break;
|
||||
case Device::StateConnected:
|
||||
stateString = "active";
|
||||
break;
|
||||
case Device::StateAvailable: {
|
||||
return ;
|
||||
}
|
||||
case Device::StateUnavailable: {
|
||||
stateString = "disable";
|
||||
} break;
|
||||
}
|
||||
} else {
|
||||
stateString = "disable";
|
||||
|
@ -212,34 +212,34 @@ void AdapterItem::deviceChangeState(const Device::State state)
|
||||
DeviceItem *deviceItem = m_deviceItems.value(device->id());
|
||||
if (deviceItem) {
|
||||
switch (state) {
|
||||
case Device::StateUnavailable: {
|
||||
int index = m_sortUnConnect.indexOf(deviceItem);
|
||||
if (index < 0) {
|
||||
m_sortConnected.removeOne(deviceItem);
|
||||
m_sortUnConnect << deviceItem;
|
||||
qSort(m_sortUnConnect);
|
||||
moveDeviceItem(state, deviceItem);
|
||||
case Device::StateUnavailable: {
|
||||
int index = m_sortUnConnect.indexOf(deviceItem);
|
||||
if (index < 0) {
|
||||
m_sortConnected.removeOne(deviceItem);
|
||||
m_sortUnConnect << deviceItem;
|
||||
qSort(m_sortUnConnect);
|
||||
moveDeviceItem(state, deviceItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Device::StateAvailable: {
|
||||
int index = m_sortUnConnect.indexOf(deviceItem);
|
||||
if (index < 0)
|
||||
m_sortConnected.removeOne(deviceItem);
|
||||
else
|
||||
m_sortUnConnect.removeOne(deviceItem);
|
||||
}
|
||||
break;
|
||||
case Device::StateConnected: {
|
||||
int index = m_sortConnected.indexOf(deviceItem);
|
||||
if (index < 0) {
|
||||
m_sortUnConnect.removeOne(deviceItem);
|
||||
m_sortConnected << deviceItem;
|
||||
qSort(m_sortConnected);
|
||||
moveDeviceItem(state, deviceItem);
|
||||
break;
|
||||
case Device::StateAvailable: {
|
||||
int index = m_sortUnConnect.indexOf(deviceItem);
|
||||
if (index < 0)
|
||||
m_sortConnected.removeOne(deviceItem);
|
||||
else
|
||||
m_sortUnConnect.removeOne(deviceItem);
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case Device::StateConnected: {
|
||||
int index = m_sortConnected.indexOf(deviceItem);
|
||||
if (index < 0) {
|
||||
m_sortUnConnect.removeOne(deviceItem);
|
||||
m_sortConnected << deviceItem;
|
||||
qSort(m_sortConnected);
|
||||
moveDeviceItem(state, deviceItem);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -259,16 +259,16 @@ void AdapterItem::moveDeviceItem(Device::State state, DeviceItem *item)
|
||||
int size = m_sortConnected.size();
|
||||
int index = 0;
|
||||
switch (state) {
|
||||
case Device::StateUnavailable:
|
||||
case Device::StateAvailable: {
|
||||
index = m_sortUnConnect.indexOf(item);
|
||||
index += size;
|
||||
}
|
||||
break;
|
||||
case Device::StateConnected: {
|
||||
index = m_sortUnConnect.indexOf(item);
|
||||
}
|
||||
break;
|
||||
case Device::StateUnavailable:
|
||||
case Device::StateAvailable: {
|
||||
index = m_sortUnConnect.indexOf(item);
|
||||
index += size;
|
||||
}
|
||||
break;
|
||||
case Device::StateConnected: {
|
||||
index = m_sortUnConnect.indexOf(item);
|
||||
}
|
||||
break;
|
||||
}
|
||||
index += 2;
|
||||
m_deviceLayout->removeWidget(item);
|
||||
|
@ -131,18 +131,18 @@ void AdaptersManager::connectDevice(Device *device)
|
||||
if (device) {
|
||||
QDBusObjectPath path(device->id());
|
||||
switch (device->state()) {
|
||||
case Device::StateUnavailable: {
|
||||
m_bluetoothInter->ConnectDevice(path);
|
||||
qDebug() << "connect to device: " << device->name();
|
||||
}
|
||||
break;
|
||||
case Device::StateAvailable:
|
||||
break;
|
||||
case Device::StateConnected: {
|
||||
m_bluetoothInter->DisconnectDevice(path);
|
||||
qDebug() << "disconnect device: " << device->name();
|
||||
}
|
||||
break;
|
||||
case Device::StateUnavailable: {
|
||||
m_bluetoothInter->ConnectDevice(path);
|
||||
qDebug() << "connect to device: " << device->name();
|
||||
}
|
||||
break;
|
||||
case Device::StateAvailable:
|
||||
break;
|
||||
case Device::StateConnected: {
|
||||
m_bluetoothInter->DisconnectDevice(path);
|
||||
qDebug() << "disconnect device: " << device->name();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,8 @@
|
||||
#include "deviceitem.h"
|
||||
#include "constants.h"
|
||||
#include "bluetoothconstants.h"
|
||||
#include "../frame/util/imageutil.h"
|
||||
#include "util/imageutil.h"
|
||||
#include "util/statebutton.h"
|
||||
|
||||
#include <DApplicationHelper>
|
||||
#include <DStyle>
|
||||
@ -38,7 +39,7 @@ extern void initFontColor(QWidget *widget);
|
||||
DeviceItem::DeviceItem(Device *d, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_title(new QLabel(this))
|
||||
, m_state(new QLabel(this))
|
||||
, m_state(new StateButton(this))
|
||||
, m_loadingStat(new DSpinner)
|
||||
, m_line(new HorizontalSeparator(this))
|
||||
, m_typeIcon(new QLabel(this))
|
||||
@ -50,21 +51,17 @@ DeviceItem::DeviceItem(Device *d, QWidget *parent)
|
||||
QString iconPrefix;
|
||||
QString iconSuffix;
|
||||
switch (themeType) {
|
||||
case DApplicationHelper::UnknownType:
|
||||
case DApplicationHelper::LightType: {
|
||||
iconPrefix = LIGHTICON;
|
||||
iconSuffix = LIGHTICONSUFFIX;
|
||||
m_stateSuffix = LIGHTSUFFIX;
|
||||
case DApplicationHelper::UnknownType:
|
||||
case DApplicationHelper::LightType: {
|
||||
iconPrefix = LIGHTICON;
|
||||
iconSuffix = LIGHTICONSUFFIX;
|
||||
}
|
||||
break;
|
||||
case DApplicationHelper::DarkType: {
|
||||
iconPrefix = DARKICON;
|
||||
iconSuffix = DARKICONSUFFIX;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DApplicationHelper::DarkType: {
|
||||
iconPrefix = DARKICON;
|
||||
m_stateSuffix = DARKSUFFIX;
|
||||
iconSuffix = DARKICONSUFFIX;
|
||||
}
|
||||
}
|
||||
|
||||
m_state->setPixmap(QPixmap(":/select" + m_stateSuffix));
|
||||
|
||||
QString iconString;
|
||||
if (!m_device->deviceType().isEmpty())
|
||||
@ -76,11 +73,14 @@ DeviceItem::DeviceItem(Device *d, QWidget *parent)
|
||||
|
||||
themeChanged(DApplicationHelper::instance()->themeType());
|
||||
|
||||
m_state->setType(StateButton::Check);
|
||||
m_state->setFixedSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE);
|
||||
m_state->setVisible(false);
|
||||
|
||||
m_title->setText(nameDecorated(m_device->name()));
|
||||
initFontColor(m_title);
|
||||
|
||||
m_line->setVisible(true);
|
||||
m_state->setVisible(false);
|
||||
m_loadingStat->setFixedSize(20, 20);
|
||||
m_loadingStat->setVisible(false);
|
||||
|
||||
@ -123,52 +123,30 @@ void DeviceItem::mousePressEvent(QMouseEvent *event)
|
||||
QWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void DeviceItem::enterEvent(QEvent *event)
|
||||
{
|
||||
QWidget::enterEvent(event);
|
||||
if (m_device) {
|
||||
if (Device::StateConnected == m_device->state()) {
|
||||
m_state->setPixmap(QPixmap(":/disconnect" + m_stateSuffix));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceItem::leaveEvent(QEvent *event)
|
||||
{
|
||||
QWidget::enterEvent(event);
|
||||
if (m_device) {
|
||||
if (Device::StateConnected == m_device->state()) {
|
||||
m_state->setPixmap(QPixmap(":/select" + m_stateSuffix));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceItem::changeState(const Device::State state)
|
||||
{
|
||||
switch (state) {
|
||||
case Device::StateUnavailable: {
|
||||
m_state->setPixmap(QPixmap(":/disconnect" + m_stateSuffix));
|
||||
m_state->setVisible(false);
|
||||
m_loadingStat->stop();
|
||||
m_loadingStat->hide();
|
||||
m_loadingStat->setVisible(false);
|
||||
}
|
||||
break;
|
||||
case Device::StateAvailable: {
|
||||
m_state->setVisible(false);
|
||||
m_loadingStat->start();
|
||||
m_loadingStat->show();
|
||||
m_loadingStat->setVisible(true);
|
||||
}
|
||||
break;
|
||||
case Device::StateConnected: {
|
||||
m_state->setPixmap(QPixmap(":/select" + m_stateSuffix));
|
||||
m_loadingStat->stop();
|
||||
m_loadingStat->hide();
|
||||
m_loadingStat->setVisible(false);
|
||||
m_state->setVisible(true);
|
||||
}
|
||||
break;
|
||||
case Device::StateUnavailable: {
|
||||
m_state->setVisible(false);
|
||||
m_loadingStat->stop();
|
||||
m_loadingStat->hide();
|
||||
m_loadingStat->setVisible(false);
|
||||
}
|
||||
break;
|
||||
case Device::StateAvailable: {
|
||||
m_state->setVisible(false);
|
||||
m_loadingStat->start();
|
||||
m_loadingStat->show();
|
||||
m_loadingStat->setVisible(true);
|
||||
}
|
||||
break;
|
||||
case Device::StateConnected: {
|
||||
m_loadingStat->stop();
|
||||
m_loadingStat->hide();
|
||||
m_loadingStat->setVisible(false);
|
||||
m_state->setVisible(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
class StateButton;
|
||||
class HorizontalSeparator;
|
||||
class DeviceItem : public QWidget
|
||||
{
|
||||
@ -47,8 +48,6 @@ public:
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void enterEvent(QEvent *event) override;
|
||||
void leaveEvent(QEvent *event) override;
|
||||
|
||||
signals:
|
||||
void clicked(Device *);
|
||||
@ -61,11 +60,10 @@ private:
|
||||
|
||||
private:
|
||||
QLabel *m_title;
|
||||
QLabel *m_state;
|
||||
StateButton *m_state;
|
||||
DSpinner *m_loadingStat;
|
||||
Device *m_device;
|
||||
HorizontalSeparator *m_line;
|
||||
QString m_stateSuffix;
|
||||
QLabel *m_typeIcon;
|
||||
};
|
||||
|
||||
|
@ -4,7 +4,9 @@ set(PLUGIN_NAME "network")
|
||||
project(${PLUGIN_NAME})
|
||||
|
||||
# Sources files
|
||||
file(GLOB_RECURSE SRCS "*.h" "*.cpp" "../../widgets/*.h" "../../widgets/*.cpp" "../../frame/util/imageutil.h" "../../frame/util/imageutil.cpp")
|
||||
file(GLOB_RECURSE SRCS "*.h" "*.cpp" "../../widgets/*.h" "../../widgets/*.cpp"
|
||||
"../../frame/util/imageutil.h" "../../frame/util/imageutil.cpp"
|
||||
"../../frame/util/statebutton.h" "../../frame/util/statebutton.cpp")
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(Qt5Widgets REQUIRED)
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "../frame/util/imageutil.h"
|
||||
#include "../wireditem.h"
|
||||
#include "constants.h"
|
||||
#include "util/statebutton.h"
|
||||
|
||||
#include <DGuiApplicationHelper>
|
||||
#include <DApplication>
|
||||
@ -49,7 +50,7 @@ AccessPointWidget::AccessPointWidget()
|
||||
, m_ssidBtn(new SsidButton(this))
|
||||
, m_securityLabel(new QLabel)
|
||||
, m_strengthLabel(new QLabel)
|
||||
, m_stateButton(new StateLabel(this))
|
||||
, m_stateButton(new StateButton(this))
|
||||
{
|
||||
m_ssidBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
|
||||
@ -58,13 +59,11 @@ AccessPointWidget::AccessPointWidget()
|
||||
|
||||
bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType);
|
||||
|
||||
auto pixpath = QString(":/wireless/resources/wireless/select");
|
||||
pixpath = isLight ? pixpath + DarkType : pixpath + LightType;
|
||||
auto iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF());
|
||||
m_stateButton->setPixmap(iconPix);
|
||||
m_stateButton->setFixedSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE);
|
||||
m_stateButton->setType(StateButton::Check);
|
||||
m_stateButton->setVisible(false);
|
||||
|
||||
pixpath = QString(":/wireless/resources/wireless/security");
|
||||
auto pixpath = QString(":/wireless/resources/wireless/security");
|
||||
pixpath = isLight ? pixpath + DarkType : pixpath + LightType;
|
||||
m_securityPixmap = Utils::renderSVG(pixpath, QSize(16, 16), devicePixelRatioF());
|
||||
m_securityIconSize = m_securityPixmap.size();
|
||||
@ -100,9 +99,7 @@ AccessPointWidget::AccessPointWidget()
|
||||
setStrengthIcon(m_ap.strength());
|
||||
});
|
||||
|
||||
connect(m_stateButton, &StateLabel::click, this, &AccessPointWidget::disconnectBtnClicked);
|
||||
connect(m_stateButton, &StateLabel::enter, this , &AccessPointWidget::buttonEnter);
|
||||
connect(m_stateButton, &StateLabel::leave, this , &AccessPointWidget::buttonLeave);
|
||||
connect(m_stateButton, &StateButton::click, this, &AccessPointWidget::disconnectBtnClicked);
|
||||
|
||||
setStrengthIcon(m_ap.strength());
|
||||
}
|
||||
@ -190,13 +187,6 @@ void AccessPointWidget::setStrengthIcon(const int strength)
|
||||
m_securityPixmap = QIcon::fromTheme(isLight ? ":/wireless/resources/wireless/security_dark.svg" : ":/wireless/resources/wireless/security.svg").pixmap(s * devicePixelRatioF());
|
||||
m_securityPixmap.setDevicePixelRatio(devicePixelRatioF());
|
||||
m_securityLabel->setPixmap(m_securityPixmap);
|
||||
|
||||
if (NetworkDevice::Activated == m_activeState) {
|
||||
auto pixpath = QString(":/wireless/resources/wireless/select");
|
||||
pixpath = isLight ? pixpath + DarkType : pixpath + LightType;
|
||||
auto iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF());
|
||||
m_stateButton->setPixmap(iconPix);
|
||||
}
|
||||
}
|
||||
|
||||
void AccessPointWidget::ssidClicked()
|
||||
@ -213,25 +203,3 @@ void AccessPointWidget::disconnectBtnClicked()
|
||||
setActiveState(NetworkDevice::Unknow);
|
||||
emit requestDeactiveAP(m_ap);
|
||||
}
|
||||
|
||||
void AccessPointWidget::buttonEnter()
|
||||
{
|
||||
bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType);
|
||||
if (NetworkDevice::Activated == m_activeState) {
|
||||
auto pixpath = QString(":/wireless/resources/wireless/disconnect");
|
||||
pixpath = isLight ? pixpath + DarkType : pixpath + LightType;
|
||||
auto iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF());
|
||||
m_stateButton->setPixmap(iconPix);
|
||||
}
|
||||
}
|
||||
|
||||
void AccessPointWidget::buttonLeave()
|
||||
{
|
||||
bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType);
|
||||
if (NetworkDevice::Activated == m_activeState) {
|
||||
auto pixpath = QString(":/wireless/resources/wireless/select");
|
||||
pixpath = isLight ? pixpath + DarkType : pixpath + LightType;
|
||||
auto iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF());
|
||||
m_stateButton->setPixmap(iconPix);
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <QLabel>
|
||||
#include <QDBusObjectPath>
|
||||
|
||||
class StateLabel;
|
||||
class StateButton;
|
||||
class SsidButton : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -77,9 +77,6 @@ private:
|
||||
private slots:
|
||||
void ssidClicked();
|
||||
void disconnectBtnClicked();
|
||||
void buttonEnter();
|
||||
void buttonLeave();
|
||||
|
||||
|
||||
private:
|
||||
dde::network::NetworkDevice::DeviceStatus m_activeState;
|
||||
@ -88,7 +85,7 @@ private:
|
||||
SsidButton *m_ssidBtn;
|
||||
QLabel *m_securityLabel;
|
||||
QLabel *m_strengthLabel;
|
||||
StateLabel *m_stateButton;
|
||||
StateButton *m_stateButton;
|
||||
|
||||
QPixmap m_securityPixmap;
|
||||
QSize m_securityIconSize;
|
||||
|
@ -25,11 +25,15 @@
|
||||
#include "applet/horizontalseperator.h"
|
||||
#include "../widgets/tipswidget.h"
|
||||
#include "util/utils.h"
|
||||
#include "util/statebutton.h"
|
||||
|
||||
#include <DGuiApplicationHelper>
|
||||
#include <NetworkModel>
|
||||
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <NetworkModel>
|
||||
|
||||
DGUI_USE_NAMESPACE
|
||||
|
||||
const int ItemHeight = 30;
|
||||
@ -42,7 +46,7 @@ WiredItem::WiredItem(WiredDevice *device, const QString &deviceName, QWidget *pa
|
||||
, m_deviceName(deviceName)
|
||||
, m_connectedName(new QLabel(this))
|
||||
, m_wiredIcon(new QLabel(this))
|
||||
, m_stateButton(new StateLabel(this))
|
||||
, m_stateButton(new StateButton(this))
|
||||
, m_loadingStat(new DSpinner(this))
|
||||
{
|
||||
setFixedHeight(ItemHeight);
|
||||
@ -56,11 +60,8 @@ WiredItem::WiredItem(WiredDevice *device, const QString &deviceName, QWidget *pa
|
||||
m_wiredIcon->setPixmap(iconPix);
|
||||
m_wiredIcon->setVisible(false);
|
||||
|
||||
pixpath = QString(":/wireless/resources/wireless/select");
|
||||
pixpath = isLight ? pixpath + DarkType : pixpath + LightType;
|
||||
iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF());
|
||||
m_stateButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
m_stateButton->setPixmap(iconPix);
|
||||
m_stateButton->setFixedSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE);
|
||||
m_stateButton->setType(StateButton::Check);
|
||||
m_stateButton->setVisible(false);
|
||||
m_loadingStat->setFixedSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE);
|
||||
m_loadingStat->setVisible(false);
|
||||
@ -93,12 +94,10 @@ WiredItem::WiredItem(WiredDevice *device, const QString &deviceName, QWidget *pa
|
||||
connect(static_cast<WiredDevice *>(m_device.data()), &WiredDevice::activeWiredConnectionInfoChanged,
|
||||
this, &WiredItem::changedActiveWiredConnectionInfo);
|
||||
|
||||
connect(m_stateButton, &StateLabel::click, this, [&] {
|
||||
connect(m_stateButton, &StateButton::click, this, [&] {
|
||||
auto enableState = m_device->enabled();
|
||||
emit requestSetDeviceEnable(path(), !enableState);
|
||||
});
|
||||
connect(m_stateButton, &StateLabel::enter, this, &WiredItem::buttonEnter);
|
||||
connect(m_stateButton, &StateLabel::leave, this, &WiredItem::buttonLeave);
|
||||
|
||||
deviceStateChanged(m_device->status());
|
||||
}
|
||||
@ -134,19 +133,19 @@ WiredItem::WiredStatus WiredItem::getDeviceState()
|
||||
}
|
||||
|
||||
switch (m_device->status()) {
|
||||
case NetworkDevice::Unknow: return Unknow;
|
||||
case NetworkDevice::Unmanaged:
|
||||
case NetworkDevice::Unavailable: return Nocable;
|
||||
case NetworkDevice::Disconnected: return Disconnected;
|
||||
case NetworkDevice::Prepare:
|
||||
case NetworkDevice::Config: return Connecting;
|
||||
case NetworkDevice::NeedAuth: return Authenticating;
|
||||
case NetworkDevice::IpConfig:
|
||||
case NetworkDevice::IpCheck:
|
||||
case NetworkDevice::Secondaries: return ObtainingIP;
|
||||
case NetworkDevice::Activated: return Connected;
|
||||
case NetworkDevice::Deactivation:
|
||||
case NetworkDevice::Failed: return Failed;
|
||||
case NetworkDevice::Unknow: return Unknow;
|
||||
case NetworkDevice::Unmanaged:
|
||||
case NetworkDevice::Unavailable: return Nocable;
|
||||
case NetworkDevice::Disconnected: return Disconnected;
|
||||
case NetworkDevice::Prepare:
|
||||
case NetworkDevice::Config: return Connecting;
|
||||
case NetworkDevice::NeedAuth: return Authenticating;
|
||||
case NetworkDevice::IpConfig:
|
||||
case NetworkDevice::IpCheck:
|
||||
case NetworkDevice::Secondaries: return ObtainingIP;
|
||||
case NetworkDevice::Activated: return Connected;
|
||||
case NetworkDevice::Deactivation:
|
||||
case NetworkDevice::Failed: return Failed;
|
||||
}
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
@ -164,53 +163,44 @@ void WiredItem::setThemeType(DGuiApplicationHelper::ColorType themeType)
|
||||
pixpath = isLight ? pixpath + "-dark.svg" : pixpath + LightType;
|
||||
auto iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF());
|
||||
m_wiredIcon->setPixmap(iconPix);
|
||||
|
||||
if (m_device) {
|
||||
if (NetworkDevice::Activated == m_device->status()) {
|
||||
pixpath = QString(":/wireless/resources/wireless/select");
|
||||
pixpath = isLight ? pixpath + DarkType : pixpath + LightType;
|
||||
auto iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF());
|
||||
m_stateButton->setPixmap(iconPix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WiredItem::deviceStateChanged(NetworkDevice::DeviceStatus state)
|
||||
{
|
||||
QPixmap iconPix;
|
||||
switch (state) {
|
||||
case NetworkDevice::Unknow:
|
||||
case NetworkDevice::Unmanaged:
|
||||
case NetworkDevice::Unavailable:
|
||||
case NetworkDevice::Disconnected:
|
||||
case NetworkDevice::Deactivation:
|
||||
case NetworkDevice::Failed: {
|
||||
m_loadingStat->stop();
|
||||
m_loadingStat->hide();
|
||||
m_loadingStat->setVisible(false);
|
||||
if (!m_device->enabled())
|
||||
case NetworkDevice::Unknow:
|
||||
case NetworkDevice::Unmanaged:
|
||||
case NetworkDevice::Unavailable:
|
||||
case NetworkDevice::Disconnected:
|
||||
case NetworkDevice::Deactivation:
|
||||
case NetworkDevice::Failed: {
|
||||
m_loadingStat->stop();
|
||||
m_loadingStat->hide();
|
||||
m_loadingStat->setVisible(false);
|
||||
if (!m_device->enabled())
|
||||
m_stateButton->setVisible(false);
|
||||
}
|
||||
break;
|
||||
case NetworkDevice::Prepare:
|
||||
case NetworkDevice::Config:
|
||||
case NetworkDevice::NeedAuth:
|
||||
case NetworkDevice::IpConfig:
|
||||
case NetworkDevice::IpCheck:
|
||||
case NetworkDevice::Secondaries: {
|
||||
m_stateButton->setVisible(false);
|
||||
}
|
||||
break;
|
||||
case NetworkDevice::Prepare:
|
||||
case NetworkDevice::Config:
|
||||
case NetworkDevice::NeedAuth:
|
||||
case NetworkDevice::IpConfig:
|
||||
case NetworkDevice::IpCheck:
|
||||
case NetworkDevice::Secondaries: {
|
||||
m_stateButton->setVisible(false);
|
||||
m_loadingStat->setVisible(true);
|
||||
m_loadingStat->start();
|
||||
m_loadingStat->show();
|
||||
}
|
||||
break;
|
||||
case NetworkDevice::Activated: {
|
||||
m_loadingStat->stop();
|
||||
m_loadingStat->hide();
|
||||
m_loadingStat->setVisible(false);
|
||||
m_stateButton->setVisible(true);
|
||||
}
|
||||
break;
|
||||
m_loadingStat->setVisible(true);
|
||||
m_loadingStat->start();
|
||||
m_loadingStat->show();
|
||||
}
|
||||
break;
|
||||
case NetworkDevice::Activated: {
|
||||
m_loadingStat->stop();
|
||||
m_loadingStat->hide();
|
||||
m_loadingStat->setVisible(false);
|
||||
m_stateButton->setVisible(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
emit wiredStateChanged();
|
||||
@ -235,29 +225,3 @@ void WiredItem::changedActiveWiredConnectionInfo(const QJsonObject &connInfo)
|
||||
|
||||
emit activeConnectionChanged();
|
||||
}
|
||||
|
||||
void WiredItem::buttonEnter()
|
||||
{
|
||||
if (m_device) {
|
||||
bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType);
|
||||
if (NetworkDevice::Activated == m_device->status()) {
|
||||
auto pixpath = QString(":/wireless/resources/wireless/disconnect");
|
||||
pixpath = isLight ? pixpath + DarkType : pixpath + LightType;
|
||||
auto iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF());
|
||||
m_stateButton->setPixmap(iconPix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WiredItem::buttonLeave()
|
||||
{
|
||||
if (m_device) {
|
||||
bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType);
|
||||
if (NetworkDevice::Activated == m_device->status()) {
|
||||
auto pixpath = QString(":/wireless/resources/wireless/select");
|
||||
pixpath = isLight ? pixpath + DarkType : pixpath + LightType;
|
||||
auto iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF());
|
||||
m_stateButton->setPixmap(iconPix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,15 +29,14 @@
|
||||
#include <DGuiApplicationHelper>
|
||||
#include <DSpinner>
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
using namespace dde::network;
|
||||
DGUI_USE_NAMESPACE
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
class QLabel;
|
||||
class TipsWidget;
|
||||
class HorizontalSeperator;
|
||||
class StateLabel;
|
||||
class StateButton;
|
||||
class WiredItem : public DeviceItem
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -78,47 +77,15 @@ signals:
|
||||
private slots:
|
||||
void deviceStateChanged(NetworkDevice::DeviceStatus state);
|
||||
void changedActiveWiredConnectionInfo(const QJsonObject &connInfo);
|
||||
void buttonEnter();
|
||||
void buttonLeave();
|
||||
|
||||
private:
|
||||
QString m_deviceName;
|
||||
QLabel *m_connectedName;
|
||||
QLabel *m_wiredIcon;
|
||||
StateLabel *m_stateButton;
|
||||
StateButton *m_stateButton;
|
||||
DSpinner *m_loadingStat;
|
||||
|
||||
HorizontalSeperator *m_line;
|
||||
};
|
||||
|
||||
class StateLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit StateLabel(QWidget *parent = nullptr)
|
||||
: QLabel(parent) {}
|
||||
|
||||
signals:
|
||||
void enter();
|
||||
void leave();
|
||||
void click();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event) override
|
||||
{
|
||||
QLabel::mousePressEvent(event);
|
||||
emit click();
|
||||
}
|
||||
void enterEvent(QEvent *event) override
|
||||
{
|
||||
QLabel::enterEvent(event);
|
||||
emit enter();
|
||||
}
|
||||
void leaveEvent(QEvent *event) override
|
||||
{
|
||||
QLabel::leaveEvent(event);
|
||||
emit leave();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // WIREDITEM_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user