mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
refactor(bluetooth):adjust poupop window view
调整弹窗外观主要是字号,字体颜色,对齐等 task:20299 (cherry picked from commit e294281bef7a8e4d8960604965cad20e0be852c1)
This commit is contained in:
parent
5a4a76bd0c
commit
028ee46568
@ -28,10 +28,31 @@
|
|||||||
#include "componments/adaptersmanager.h"
|
#include "componments/adaptersmanager.h"
|
||||||
#include "componments/adapteritem.h"
|
#include "componments/adapteritem.h"
|
||||||
|
|
||||||
|
#include <DApplicationHelper>
|
||||||
|
DGUI_USE_NAMESPACE
|
||||||
|
|
||||||
extern int ControlHeight;
|
extern int ControlHeight;
|
||||||
extern int ItemHeight;
|
extern int ItemHeight;
|
||||||
const int Width = 200;
|
const int Width = 200;
|
||||||
|
|
||||||
|
extern void initFontColor(QWidget *widget)
|
||||||
|
{
|
||||||
|
if (!widget)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto fontChange = [&](QWidget *widget){
|
||||||
|
QPalette defaultPalette = widget->palette();
|
||||||
|
defaultPalette.setBrush(QPalette::WindowText, defaultPalette.brightText());
|
||||||
|
widget->setPalette(defaultPalette);
|
||||||
|
};
|
||||||
|
|
||||||
|
fontChange(widget);
|
||||||
|
|
||||||
|
QObject::connect(DApplicationHelper::instance(), &DApplicationHelper::themeTypeChanged, widget, [=]{
|
||||||
|
fontChange(widget);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
BluetoothApplet::BluetoothApplet(QWidget *parent)
|
BluetoothApplet::BluetoothApplet(QWidget *parent)
|
||||||
: QScrollArea(parent)
|
: QScrollArea(parent)
|
||||||
, m_line(new HorizontalSeparator(this))
|
, m_line(new HorizontalSeparator(this))
|
||||||
@ -42,7 +63,12 @@ BluetoothApplet::BluetoothApplet(QWidget *parent)
|
|||||||
{
|
{
|
||||||
m_line->setVisible(false);
|
m_line->setVisible(false);
|
||||||
|
|
||||||
|
auto defaultFont = font();
|
||||||
|
auto titlefont = QFont(defaultFont.family(), defaultFont.pointSize() + 2);
|
||||||
|
|
||||||
m_appletName->setText(tr("Bluetooth"));
|
m_appletName->setText(tr("Bluetooth"));
|
||||||
|
m_appletName->setFont(titlefont);
|
||||||
|
initFontColor(m_appletName);
|
||||||
m_appletName->setVisible(false);
|
m_appletName->setVisible(false);
|
||||||
|
|
||||||
auto appletNameLayout = new QHBoxLayout;
|
auto appletNameLayout = new QHBoxLayout;
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
DWIDGET_USE_NAMESPACE
|
DWIDGET_USE_NAMESPACE
|
||||||
DGUI_USE_NAMESPACE
|
DGUI_USE_NAMESPACE
|
||||||
|
|
||||||
|
|
||||||
BluetoothItem::BluetoothItem(QWidget *parent)
|
BluetoothItem::BluetoothItem(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, m_applet(new BluetoothApplet(this))
|
, m_applet(new BluetoothApplet(this))
|
||||||
@ -59,6 +58,7 @@ BluetoothItem::BluetoothItem(QWidget *parent)
|
|||||||
m_devState = state;
|
m_devState = state;
|
||||||
refreshIcon();
|
refreshIcon();
|
||||||
});
|
});
|
||||||
|
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &BluetoothItem::refreshIcon);
|
||||||
connect(m_applet, SIGNAL(noAdapter()), this, SIGNAL(noAdapter()));
|
connect(m_applet, SIGNAL(noAdapter()), this, SIGNAL(noAdapter()));
|
||||||
connect(m_applet, SIGNAL(justHasAdapter()), this, SIGNAL(justHasAdapter()));
|
connect(m_applet, SIGNAL(justHasAdapter()), this, SIGNAL(justHasAdapter()));
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ void Adapter::addDevice(const QJsonObject &deviceObj)
|
|||||||
const QString id = deviceObj["Path"].toString();
|
const QString id = deviceObj["Path"].toString();
|
||||||
const QString name = deviceObj["Alias"].toString();
|
const QString name = deviceObj["Alias"].toString();
|
||||||
const bool paired = deviceObj["Paired"].toBool();
|
const bool paired = deviceObj["Paired"].toBool();
|
||||||
|
const int rssi = deviceObj["RSSI"].toInt();
|
||||||
const Device::State state = Device::State(deviceObj["State"].toInt());
|
const Device::State state = Device::State(deviceObj["State"].toInt());
|
||||||
|
|
||||||
removeDevice(id);
|
removeDevice(id);
|
||||||
@ -60,6 +61,7 @@ void Adapter::addDevice(const QJsonObject &deviceObj)
|
|||||||
device->setName(name);
|
device->setName(name);
|
||||||
device->setPaired(paired);
|
device->setPaired(paired);
|
||||||
device->setState(state);
|
device->setState(state);
|
||||||
|
device->setRssi(rssi);
|
||||||
device->setAdapterId(m_id);
|
device->setAdapterId(m_id);
|
||||||
|
|
||||||
m_devices[id] = device;
|
m_devices[id] = device;
|
||||||
@ -85,6 +87,7 @@ void Adapter::updateDevice(const QJsonObject &json)
|
|||||||
const QString id = json["Path"].toString();
|
const QString id = json["Path"].toString();
|
||||||
const QString name = json["Alias"].toString();
|
const QString name = json["Alias"].toString();
|
||||||
const bool paired = json["Paired"].toBool();
|
const bool paired = json["Paired"].toBool();
|
||||||
|
const int rssi = json["RSSI"].toInt();
|
||||||
const Device::State state = Device::State(json["State"].toInt());
|
const Device::State state = Device::State(json["State"].toInt());
|
||||||
|
|
||||||
auto constdevice = m_devices.value(id);
|
auto constdevice = m_devices.value(id);
|
||||||
@ -93,6 +96,7 @@ void Adapter::updateDevice(const QJsonObject &json)
|
|||||||
device->setId(id);
|
device->setId(id);
|
||||||
device->setName(name);
|
device->setName(name);
|
||||||
device->setPaired(paired);
|
device->setPaired(paired);
|
||||||
|
device->setRssi(rssi);
|
||||||
device->setState(state);
|
device->setState(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,6 +149,7 @@ void Adapter::initDevicesList(const QJsonDocument &doc)
|
|||||||
const QString id = deviceObj["Path"].toString();
|
const QString id = deviceObj["Path"].toString();
|
||||||
const QString name = deviceObj["Alias"].toString();
|
const QString name = deviceObj["Alias"].toString();
|
||||||
const bool paired = deviceObj["Paired"].toBool();
|
const bool paired = deviceObj["Paired"].toBool();
|
||||||
|
const int rssi = deviceObj["RSSI"].toInt();
|
||||||
const Device::State state = Device::State(deviceObj["State"].toInt());
|
const Device::State state = Device::State(deviceObj["State"].toInt());
|
||||||
|
|
||||||
auto device = new Device(this);
|
auto device = new Device(this);
|
||||||
@ -152,6 +157,7 @@ void Adapter::initDevicesList(const QJsonDocument &doc)
|
|||||||
device->setName(name);
|
device->setName(name);
|
||||||
device->setPaired(paired);
|
device->setPaired(paired);
|
||||||
device->setState(state);
|
device->setState(state);
|
||||||
|
device->setRssi(rssi);
|
||||||
device->setAdapterId(adapterId);
|
device->setAdapterId(adapterId);
|
||||||
|
|
||||||
m_devices[id] = device;
|
m_devices[id] = device;
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
extern const int ItemHeight;
|
extern const int ItemHeight;
|
||||||
extern const int ControlHeight;
|
extern const int ControlHeight;
|
||||||
const int Width = 200;
|
const int Width = 200;
|
||||||
|
extern void initFontColor(QWidget *widget);
|
||||||
|
|
||||||
AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWidget *parent)
|
AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWidget *parent)
|
||||||
: QScrollArea(parent)
|
: QScrollArea(parent)
|
||||||
@ -46,7 +47,8 @@ AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWid
|
|||||||
m_line->setVisible(true);
|
m_line->setVisible(true);
|
||||||
m_deviceLayout->setMargin(0);
|
m_deviceLayout->setMargin(0);
|
||||||
m_deviceLayout->setSpacing(0);
|
m_deviceLayout->setSpacing(0);
|
||||||
m_openControlCenter->setText("Bluetooth settings");
|
m_openControlCenter->setText(tr("Bluetooth settings"));
|
||||||
|
initFontColor(m_openControlCenter);
|
||||||
m_openControlCenter->setFixedHeight(ItemHeight);
|
m_openControlCenter->setFixedHeight(ItemHeight);
|
||||||
m_openControlCenter->setVisible(false);
|
m_openControlCenter->setVisible(false);
|
||||||
m_switchItem->setTitle(adapter->name());
|
m_switchItem->setTitle(adapter->name());
|
||||||
@ -71,7 +73,11 @@ AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWid
|
|||||||
for (auto constDevice : myDevices) {
|
for (auto constDevice : myDevices) {
|
||||||
auto device = const_cast<Device *>(constDevice);
|
auto device = const_cast<Device *>(constDevice);
|
||||||
if (device) {
|
if (device) {
|
||||||
createDeviceItem(device);
|
DeviceItem *deviceItem = createDeviceItem(device);
|
||||||
|
if (device->state() == Device::StateConnected)
|
||||||
|
m_sortConnected << deviceItem;
|
||||||
|
else
|
||||||
|
m_sortUnConnect << deviceItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,6 +163,8 @@ void AdapterItem::removeDeviceItem(const Device *device)
|
|||||||
auto deviceItem = m_deviceItems.value(device->id());
|
auto deviceItem = m_deviceItems.value(device->id());
|
||||||
if (deviceItem) {
|
if (deviceItem) {
|
||||||
m_deviceItems.remove(device->id());
|
m_deviceItems.remove(device->id());
|
||||||
|
m_sortConnected.removeOne(deviceItem);
|
||||||
|
m_sortUnConnect.removeOne(deviceItem);
|
||||||
if (device->paired()) {
|
if (device->paired()) {
|
||||||
// m_pairedDeviceItems.remove(device->id());
|
// m_pairedDeviceItems.remove(device->id());
|
||||||
}
|
}
|
||||||
@ -192,11 +200,26 @@ void AdapterItem::deviceChangeState(const Device::State state)
|
|||||||
auto device = qobject_cast<Device *>(sender());
|
auto device = qobject_cast<Device *>(sender());
|
||||||
if (device) {
|
if (device) {
|
||||||
auto deviceItem = m_deviceItems.value(device->id());
|
auto deviceItem = m_deviceItems.value(device->id());
|
||||||
if (deviceItem && Device::StateConnected == state) {
|
if (deviceItem) {
|
||||||
auto fromWidget = m_deviceLayout->itemAt(2)->widget();
|
switch (state) {
|
||||||
if (fromWidget) {
|
case Device::StateUnavailable:
|
||||||
m_deviceLayout->replaceWidget(fromWidget, deviceItem);
|
case Device::StateAvailable: {
|
||||||
m_deviceLayout->addWidget(fromWidget);
|
int index = m_sortConnected.indexOf(deviceItem);
|
||||||
|
if (index < 0) {
|
||||||
|
m_sortConnected.removeOne(deviceItem);
|
||||||
|
m_sortUnConnect << deviceItem;
|
||||||
|
qSort(m_sortUnConnect);
|
||||||
|
moveDeviceItem(state, deviceItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Device::StateConnected: {
|
||||||
|
m_sortUnConnect.removeOne(deviceItem);
|
||||||
|
m_sortConnected << deviceItem;
|
||||||
|
qSort(m_sortConnected);
|
||||||
|
moveDeviceItem(state, deviceItem);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,10 +228,31 @@ void AdapterItem::deviceChangeState(const Device::State state)
|
|||||||
emit deviceStateChanged(state);
|
emit deviceStateChanged(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdapterItem::createDeviceItem(Device *device)
|
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;
|
||||||
|
}
|
||||||
|
index += 2;
|
||||||
|
m_deviceLayout->removeWidget(item);
|
||||||
|
m_deviceLayout->insertWidget(index, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceItem *AdapterItem::createDeviceItem(Device *device)
|
||||||
{
|
{
|
||||||
if (!device)
|
if (!device)
|
||||||
return;
|
return nullptr;
|
||||||
|
|
||||||
// auto paired = device->paired();
|
// auto paired = device->paired();
|
||||||
auto deviceId = device->id();
|
auto deviceId = device->id();
|
||||||
@ -223,11 +267,25 @@ void AdapterItem::createDeviceItem(Device *device)
|
|||||||
connect(device, &Device::nameChanged, deviceItem, &DeviceItem::setTitle);
|
connect(device, &Device::nameChanged, deviceItem, &DeviceItem::setTitle);
|
||||||
connect(device, &Device::stateChanged, deviceItem, &DeviceItem::changeState);
|
connect(device, &Device::stateChanged, deviceItem, &DeviceItem::changeState);
|
||||||
connect(device, &Device::stateChanged, this, &AdapterItem::deviceChangeState);
|
connect(device, &Device::stateChanged, this, &AdapterItem::deviceChangeState);
|
||||||
|
connect(device, &Device::rssiChanged, [&]{
|
||||||
|
auto device = qobject_cast<Device *>(sender());
|
||||||
|
if (device) {
|
||||||
|
auto deviceItem = m_deviceItems.value(device->id());
|
||||||
|
auto state = device->state();
|
||||||
|
if (deviceItem && Device::StateConnected == state)
|
||||||
|
qSort(m_sortConnected);
|
||||||
|
else
|
||||||
|
qSort(m_sortUnConnect);
|
||||||
|
moveDeviceItem(state, deviceItem);
|
||||||
|
}
|
||||||
|
});
|
||||||
connect(deviceItem, &DeviceItem::clicked, m_adaptersManager, &AdaptersManager::connectDevice);
|
connect(deviceItem, &DeviceItem::clicked, m_adaptersManager, &AdaptersManager::connectDevice);
|
||||||
|
|
||||||
|
return deviceItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdapterItem::updateView()
|
void AdapterItem::updateView()
|
||||||
{
|
{
|
||||||
auto contentHeight = m_switchItem->height();
|
auto contentHeight = m_switchItem->height();
|
||||||
contentHeight += (m_deviceLayout->count() - 3) * ItemHeight;
|
contentHeight += (m_deviceLayout->count() - 3) * ItemHeight;
|
||||||
m_centralWidget->setFixedHeight(contentHeight);
|
m_centralWidget->setFixedHeight(contentHeight);
|
||||||
@ -237,16 +295,22 @@ void AdapterItem::updateView()
|
|||||||
|
|
||||||
void AdapterItem::showDevices(bool change)
|
void AdapterItem::showDevices(bool change)
|
||||||
{
|
{
|
||||||
// for (auto deviceItem : m_pairedDeviceItems) {
|
if (m_sortConnected.size())
|
||||||
for (auto deviceItem : m_deviceItems) {
|
qSort(m_sortConnected);
|
||||||
|
if (m_sortUnConnect.size())
|
||||||
|
qSort(m_sortUnConnect);
|
||||||
|
|
||||||
|
QList<DeviceItem *> deviceItems;
|
||||||
|
deviceItems << m_sortConnected << m_sortUnConnect;
|
||||||
|
|
||||||
|
for (DeviceItem *deviceItem : deviceItems) {
|
||||||
if (change)
|
if (change)
|
||||||
m_deviceLayout->addWidget(deviceItem);
|
m_deviceLayout->addWidget(deviceItem);
|
||||||
else {
|
else
|
||||||
m_deviceLayout->removeWidget(deviceItem);
|
m_deviceLayout->removeWidget(deviceItem);
|
||||||
}
|
|
||||||
deviceItem->setVisible(change);
|
deviceItem->setVisible(change);
|
||||||
}
|
}
|
||||||
// auto itemCount = m_pairedDeviceItems.size();
|
|
||||||
auto itemCount = m_deviceItems.size();
|
auto itemCount = m_deviceItems.size();
|
||||||
m_line->setVisible(change);
|
m_line->setVisible(change);
|
||||||
m_openControlCenter->setVisible(!itemCount);
|
m_openControlCenter->setVisible(!itemCount);
|
||||||
|
@ -60,9 +60,10 @@ private slots:
|
|||||||
void showAndConnect(bool change);
|
void showAndConnect(bool change);
|
||||||
void addDeviceItem(const Device *constDevice);
|
void addDeviceItem(const Device *constDevice);
|
||||||
void deviceChangeState(const Device::State state);
|
void deviceChangeState(const Device::State state);
|
||||||
|
void moveDeviceItem(Device::State state, DeviceItem *item);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createDeviceItem(Device *device);
|
DeviceItem *createDeviceItem(Device *device);
|
||||||
void updateView();
|
void updateView();
|
||||||
void showDevices(bool change);
|
void showDevices(bool change);
|
||||||
|
|
||||||
@ -79,6 +80,8 @@ private:
|
|||||||
QMap<QString, DeviceItem*> m_deviceItems;
|
QMap<QString, DeviceItem*> m_deviceItems;
|
||||||
Device::State m_initDeviceState;
|
Device::State m_initDeviceState;
|
||||||
Device::State m_currentDeviceState;
|
Device::State m_currentDeviceState;
|
||||||
|
QList<DeviceItem *> m_sortConnected;
|
||||||
|
QList<DeviceItem *> m_sortUnConnect;
|
||||||
// QMap<QString, DeviceItem*> m_pairedDeviceItems;
|
// QMap<QString, DeviceItem*> m_pairedDeviceItems;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ Device::Device(QObject *parent) :
|
|||||||
m_paired(false),
|
m_paired(false),
|
||||||
m_trusted(false),
|
m_trusted(false),
|
||||||
m_connecting(false),
|
m_connecting(false),
|
||||||
|
m_rssi(0),
|
||||||
m_state(StateUnavailable),
|
m_state(StateUnavailable),
|
||||||
m_adapterId(QString())
|
m_adapterId(QString())
|
||||||
{
|
{
|
||||||
@ -79,6 +80,14 @@ void Device::setConnecting(bool connecting)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Device::setRssi(int rssi)
|
||||||
|
{
|
||||||
|
if (m_rssi != rssi) {
|
||||||
|
m_rssi = rssi;
|
||||||
|
Q_EMIT rssiChanged(rssi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QDebug &operator<<(QDebug &stream, const Device *device)
|
QDebug &operator<<(QDebug &stream, const Device *device)
|
||||||
{
|
{
|
||||||
stream << "Device name:" << device->name()
|
stream << "Device name:" << device->name()
|
||||||
|
@ -59,6 +59,9 @@ public:
|
|||||||
inline bool connecting() const { return m_connecting; }
|
inline bool connecting() const { return m_connecting; }
|
||||||
void setConnecting(bool connecting);
|
void setConnecting(bool connecting);
|
||||||
|
|
||||||
|
inline int rssi() const { return m_rssi; }
|
||||||
|
void setRssi(int rssi);
|
||||||
|
|
||||||
inline void setAdapterId(const QString &id) { m_adapterId = id; }
|
inline void setAdapterId(const QString &id) { m_adapterId = id; }
|
||||||
inline const QString &getAdapterId() const { return m_adapterId; }
|
inline const QString &getAdapterId() const { return m_adapterId; }
|
||||||
|
|
||||||
@ -68,6 +71,7 @@ Q_SIGNALS:
|
|||||||
void stateChanged(const State state) const;
|
void stateChanged(const State state) const;
|
||||||
void trustedChanged(const bool trusted) const;
|
void trustedChanged(const bool trusted) const;
|
||||||
void connectingChanged(const bool &connecting) const;
|
void connectingChanged(const bool &connecting) const;
|
||||||
|
void rssiChanged(const int rssi) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_id;
|
QString m_id;
|
||||||
@ -75,6 +79,7 @@ private:
|
|||||||
bool m_paired;
|
bool m_paired;
|
||||||
bool m_trusted;
|
bool m_trusted;
|
||||||
bool m_connecting;
|
bool m_connecting;
|
||||||
|
int m_rssi;
|
||||||
State m_state;
|
State m_state;
|
||||||
QString m_adapterId;
|
QString m_adapterId;
|
||||||
};
|
};
|
||||||
|
@ -22,12 +22,18 @@
|
|||||||
|
|
||||||
#include "deviceitem.h"
|
#include "deviceitem.h"
|
||||||
|
|
||||||
|
#include <DApplicationHelper>
|
||||||
#include <DStyle>
|
#include <DStyle>
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
|
DGUI_USE_NAMESPACE
|
||||||
|
|
||||||
extern const int ItemHeight = 30;
|
extern const int ItemHeight = 30;
|
||||||
|
const QString LightSuffix = "_dark.svg";
|
||||||
|
const QString DarkSuffix = ".svg";
|
||||||
|
extern void initFontColor(QWidget *widget);
|
||||||
|
|
||||||
DeviceItem::DeviceItem(const QString &title, QWidget *parent)
|
DeviceItem::DeviceItem(const QString &title, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
@ -37,8 +43,16 @@ DeviceItem::DeviceItem(const QString &title, QWidget *parent)
|
|||||||
, m_line(new HorizontalSeparator(this))
|
, m_line(new HorizontalSeparator(this))
|
||||||
{
|
{
|
||||||
setFixedHeight(ItemHeight);
|
setFixedHeight(ItemHeight);
|
||||||
// m_state->setPixmap(QPixmap(":/list_select@2x.png"));
|
auto themeChanged = [&](DApplicationHelper::ColorType themeType){
|
||||||
m_state->setPixmap(QPixmap(":/select_dark.svg"));
|
switch (themeType) {
|
||||||
|
case DApplicationHelper::UnknownType:
|
||||||
|
case DApplicationHelper::LightType: m_statSuffix = LightSuffix; break;
|
||||||
|
case DApplicationHelper::DarkType: m_statSuffix = DarkSuffix; break;
|
||||||
|
}
|
||||||
|
m_state->setPixmap(QPixmap(":/select" + m_statSuffix));
|
||||||
|
};
|
||||||
|
|
||||||
|
themeChanged(DApplicationHelper::instance()->themeType());
|
||||||
|
|
||||||
auto strTitle = title;
|
auto strTitle = title;
|
||||||
m_title->setText(strTitle);
|
m_title->setText(strTitle);
|
||||||
@ -48,6 +62,7 @@ DeviceItem::DeviceItem(const QString &title, QWidget *parent)
|
|||||||
strTitle = QFontMetrics(m_title->font()).elidedText(strTitle, Qt::ElideRight, m_title->width());
|
strTitle = QFontMetrics(m_title->font()).elidedText(strTitle, Qt::ElideRight, m_title->width());
|
||||||
}
|
}
|
||||||
m_title->setText(strTitle);
|
m_title->setText(strTitle);
|
||||||
|
initFontColor(m_title);
|
||||||
|
|
||||||
m_line->setVisible(true);
|
m_line->setVisible(true);
|
||||||
m_state->setVisible(false);
|
m_state->setVisible(false);
|
||||||
@ -69,6 +84,21 @@ DeviceItem::DeviceItem(const QString &title, QWidget *parent)
|
|||||||
itemLayout->addSpacing(12);
|
itemLayout->addSpacing(12);
|
||||||
deviceLayout->addLayout(itemLayout);
|
deviceLayout->addLayout(itemLayout);
|
||||||
setLayout(deviceLayout);
|
setLayout(deviceLayout);
|
||||||
|
|
||||||
|
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, themeChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeviceItem::operator <(const DeviceItem &item)
|
||||||
|
{
|
||||||
|
return this->device()->rssi() < item.device()->rssi();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceItem::setDevice(Device *d)
|
||||||
|
{
|
||||||
|
if (d) {
|
||||||
|
m_device = d;
|
||||||
|
changeState(d->state());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceItem::mousePressEvent(QMouseEvent *event)
|
void DeviceItem::mousePressEvent(QMouseEvent *event)
|
||||||
@ -83,7 +113,7 @@ void DeviceItem::enterEvent(QEvent *event)
|
|||||||
if (m_device) {
|
if (m_device) {
|
||||||
if (Device::StateConnected == m_device->state()) {
|
if (Device::StateConnected == m_device->state()) {
|
||||||
// m_state->setPixmap(QPixmap(":/notify_close_press@2x.png"));
|
// m_state->setPixmap(QPixmap(":/notify_close_press@2x.png"));
|
||||||
m_state->setPixmap(QPixmap(":/disconnect_dark.svg"));
|
m_state->setPixmap(QPixmap(":/disconnect" + m_statSuffix));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,7 +124,7 @@ void DeviceItem::leaveEvent(QEvent *event)
|
|||||||
if (m_device) {
|
if (m_device) {
|
||||||
if (Device::StateConnected == m_device->state()) {
|
if (Device::StateConnected == m_device->state()) {
|
||||||
// m_state->setPixmap(QPixmap(":/list_select@2x.png"));
|
// m_state->setPixmap(QPixmap(":/list_select@2x.png"));
|
||||||
m_state->setPixmap(QPixmap(":/select_dark.svg"));
|
m_state->setPixmap(QPixmap(":/select" + m_statSuffix));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,11 +37,13 @@ class DeviceItem : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit DeviceItem(const QString &title, QWidget *parent = nullptr);
|
explicit DeviceItem(const QString &title, QWidget *parent = nullptr);
|
||||||
|
bool operator <(const DeviceItem &item);
|
||||||
|
|
||||||
inline void setTitle(const QString &name) { m_title->setText(name); }
|
inline void setTitle(const QString &name) { m_title->setText(name); }
|
||||||
|
|
||||||
inline void setDevice(Device *d) { m_device = d; }
|
void setDevice(Device *d);
|
||||||
inline Device *device() { return m_device; }
|
inline Device *device() { return m_device; }
|
||||||
|
inline const Device *device() const { return m_device; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
@ -60,6 +62,7 @@ private:
|
|||||||
DSpinner *m_loadingStat;
|
DSpinner *m_loadingStat;
|
||||||
Device *m_device = nullptr;
|
Device *m_device = nullptr;
|
||||||
HorizontalSeparator *m_line;
|
HorizontalSeparator *m_line;
|
||||||
|
QString m_statSuffix;
|
||||||
};
|
};
|
||||||
|
|
||||||
class HorizontalSeparator : public QWidget
|
class HorizontalSeparator : public QWidget
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "QHBoxLayout"
|
#include "QHBoxLayout"
|
||||||
|
|
||||||
extern const int ControlHeight = 35;
|
extern const int ControlHeight = 35;
|
||||||
|
extern void initFontColor(QWidget *widget);
|
||||||
|
|
||||||
SwitchItem::SwitchItem(QWidget *parent)
|
SwitchItem::SwitchItem(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
@ -32,6 +33,8 @@ SwitchItem::SwitchItem(QWidget *parent)
|
|||||||
, m_switchBtn(new DSwitchButton(this))
|
, m_switchBtn(new DSwitchButton(this))
|
||||||
, m_default(false)
|
, m_default(false)
|
||||||
{
|
{
|
||||||
|
initFontColor(m_title);
|
||||||
|
|
||||||
setFixedHeight(ControlHeight);
|
setFixedHeight(ControlHeight);
|
||||||
auto switchLayout = new QHBoxLayout(this);
|
auto switchLayout = new QHBoxLayout(this);
|
||||||
switchLayout->setSpacing(0);
|
switchLayout->setSpacing(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user