mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
fix(bluetooth):Interface display adjustment
调整设备项显示高度,去掉“我的设备”标题,设备连接时状态指示图标,隐藏分割线,截取过长设备名,及设备显示规则 bug:9218 (cherry picked from commit 2abeb9ff28a9831b7c02deba04c73f337ec4c7a2) (cherry picked from commit c3f56c565966621e49a8696d755702fdd624b07b)
This commit is contained in:
parent
0668bf206e
commit
e11a0be387
@ -118,7 +118,7 @@ void BluetoothApplet::updateView()
|
||||
int itemCount = 0;
|
||||
for (auto adapterItem : m_adapterItems) {
|
||||
if (adapterItem)
|
||||
itemCount += adapterItem->pairedDeviceCount();
|
||||
itemCount += adapterItem->deviceCount();
|
||||
}
|
||||
|
||||
if (m_adapterItems.size() > 1) {
|
||||
|
@ -34,7 +34,6 @@ AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWid
|
||||
: QScrollArea(parent)
|
||||
, m_centralWidget(new QWidget(this))
|
||||
, m_line(new HorizontalSeparator(this))
|
||||
, m_devGoupName(new QLabel(this))
|
||||
, m_deviceLayout(new QVBoxLayout)
|
||||
, m_openControlCenter(new MenueItem(this))
|
||||
, m_adaptersManager(adapterManager)
|
||||
@ -43,8 +42,6 @@ AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWid
|
||||
{
|
||||
m_centralWidget->setFixedWidth(Width);
|
||||
m_line->setVisible(true);
|
||||
m_devGoupName->setText(tr("My Device"));
|
||||
m_devGoupName->setVisible(false);
|
||||
m_deviceLayout->setMargin(0);
|
||||
m_deviceLayout->setSpacing(0);
|
||||
m_openControlCenter->setText("Bluetooth settings");
|
||||
@ -54,7 +51,6 @@ AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWid
|
||||
|
||||
m_deviceLayout->addWidget(m_switchItem);
|
||||
m_deviceLayout->addWidget(m_line);
|
||||
m_deviceLayout->addWidget(m_devGoupName);
|
||||
m_deviceLayout->addWidget(m_openControlCenter);
|
||||
m_centralWidget->setFixedWidth(Width);
|
||||
m_centralWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
@ -94,10 +90,10 @@ AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWid
|
||||
showDevices(adapter->powered());
|
||||
}
|
||||
|
||||
int AdapterItem::pairedDeviceCount()
|
||||
{
|
||||
return m_pairedDeviceItems.size();
|
||||
}
|
||||
//int AdapterItem::pairedDeviceCount()
|
||||
//{
|
||||
// return m_pairedDeviceItems.size();
|
||||
//}
|
||||
|
||||
int AdapterItem::deviceCount()
|
||||
{
|
||||
@ -111,18 +107,18 @@ void AdapterItem::setPowered(bool powered)
|
||||
|
||||
void AdapterItem::deviceItemPaired(const bool paired)
|
||||
{
|
||||
auto device = qobject_cast<Device *>(sender());
|
||||
if (device) {
|
||||
auto deviceId = device->id();
|
||||
auto deviceItem = m_deviceItems.value(deviceId);
|
||||
if (deviceItem) {
|
||||
if (paired)
|
||||
m_pairedDeviceItems[deviceId] = deviceItem;
|
||||
else
|
||||
m_pairedDeviceItems.remove(deviceId);
|
||||
}
|
||||
showDevices(m_adapter->powered());
|
||||
}
|
||||
// auto device = qobject_cast<Device *>(sender());
|
||||
// if (device) {
|
||||
// auto deviceId = device->id();
|
||||
// auto deviceItem = m_deviceItems.value(deviceId);
|
||||
// if (deviceItem) {
|
||||
// if (paired)
|
||||
// m_pairedDeviceItems[deviceId] = deviceItem;
|
||||
// else
|
||||
// m_pairedDeviceItems.remove(deviceId);
|
||||
// }
|
||||
// showDevices(m_adapter->powered());
|
||||
// }
|
||||
}
|
||||
|
||||
void AdapterItem::removeDeviceItem(const Device *device)
|
||||
@ -134,7 +130,7 @@ void AdapterItem::removeDeviceItem(const Device *device)
|
||||
if (deviceItem) {
|
||||
m_deviceItems.remove(device->id());
|
||||
if (device->paired()) {
|
||||
m_pairedDeviceItems.remove(device->id());
|
||||
// m_pairedDeviceItems.remove(device->id());
|
||||
m_deviceLayout->removeWidget(deviceItem);
|
||||
}
|
||||
delete deviceItem;
|
||||
@ -163,24 +159,41 @@ void AdapterItem::addDeviceItem(const Device *constDevice)
|
||||
showDevices(m_adapter->powered());
|
||||
}
|
||||
|
||||
void AdapterItem::deviceChangeState(const Device::State state)
|
||||
{
|
||||
auto device = qobject_cast<Device *>(sender());
|
||||
if (device) {
|
||||
auto deviceItem = m_deviceItems.value(device->id());
|
||||
if (deviceItem && Device::StateConnected == state) {
|
||||
auto fromWidget = m_deviceLayout->itemAt(2)->widget();
|
||||
if (fromWidget) {
|
||||
m_deviceLayout->replaceWidget(fromWidget, deviceItem);
|
||||
m_deviceLayout->addWidget(fromWidget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
emit deviceStateChanged(state);
|
||||
}
|
||||
|
||||
void AdapterItem::createDeviceItem(Device *device)
|
||||
{
|
||||
if (!device)
|
||||
return;
|
||||
|
||||
auto paired = device->paired();
|
||||
// auto paired = device->paired();
|
||||
auto deviceId = device->id();
|
||||
auto deviceItem = new DeviceItem(device->name(), this);
|
||||
deviceItem->setDevice(device);
|
||||
m_deviceItems[deviceId] = deviceItem;
|
||||
if (paired)
|
||||
m_pairedDeviceItems[deviceId] = deviceItem;
|
||||
deviceItem->setVisible(paired);
|
||||
// if (paired)
|
||||
// m_pairedDeviceItems[deviceId] = deviceItem;
|
||||
// deviceItem->setVisible(paired);
|
||||
|
||||
connect(device, &Device::pairedChanged, this, &AdapterItem::deviceItemPaired);
|
||||
// connect(device, &Device::pairedChanged, this, &AdapterItem::deviceItemPaired);
|
||||
connect(device, &Device::nameChanged, deviceItem, &DeviceItem::setTitle);
|
||||
connect(device, &Device::stateChanged, deviceItem, &DeviceItem::chaneState);
|
||||
connect(device, &Device::stateChanged, this, &AdapterItem::deviceStateChanged);
|
||||
connect(device, &Device::stateChanged, deviceItem, &DeviceItem::changeState);
|
||||
connect(device, &Device::stateChanged, this, &AdapterItem::deviceChangeState);
|
||||
connect(deviceItem, &DeviceItem::clicked, m_adaptersManager, &AdaptersManager::connectDevice);
|
||||
}
|
||||
|
||||
@ -194,7 +207,8 @@ void AdapterItem::updateView()
|
||||
|
||||
void AdapterItem::showDevices(bool change)
|
||||
{
|
||||
for (auto deviceItem : m_pairedDeviceItems) {
|
||||
// for (auto deviceItem : m_pairedDeviceItems) {
|
||||
for (auto deviceItem : m_deviceItems) {
|
||||
if (change)
|
||||
m_deviceLayout->addWidget(deviceItem);
|
||||
else {
|
||||
@ -202,9 +216,9 @@ void AdapterItem::showDevices(bool change)
|
||||
}
|
||||
deviceItem->setVisible(change);
|
||||
}
|
||||
auto itemCount = m_pairedDeviceItems.size();
|
||||
// auto itemCount = m_pairedDeviceItems.size();
|
||||
auto itemCount = m_deviceItems.size();
|
||||
m_line->setVisible(change);
|
||||
m_devGoupName->setVisible(itemCount && change);
|
||||
m_openControlCenter->setVisible(!itemCount);
|
||||
updateView();
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class AdapterItem : public QScrollArea
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AdapterItem(AdaptersManager *a, Adapter *adapter, QWidget *parent = nullptr);
|
||||
int pairedDeviceCount();
|
||||
// int pairedDeviceCount();
|
||||
int deviceCount();
|
||||
void setPowered(bool powered);
|
||||
|
||||
@ -55,6 +55,7 @@ private slots:
|
||||
void removeDeviceItem(const Device *device);
|
||||
void showAndConnect(bool change);
|
||||
void addDeviceItem(const Device *constDevice);
|
||||
void deviceChangeState(const Device::State state);
|
||||
|
||||
private:
|
||||
void createDeviceItem(Device *device);
|
||||
@ -64,7 +65,6 @@ private:
|
||||
private:
|
||||
QWidget *m_centralWidget;
|
||||
HorizontalSeparator *m_line;
|
||||
QLabel *m_devGoupName;
|
||||
QVBoxLayout *m_deviceLayout;
|
||||
MenueItem *m_openControlCenter;
|
||||
|
||||
@ -73,7 +73,7 @@ private:
|
||||
Adapter *m_adapter;
|
||||
SwitchItem *m_switchItem;
|
||||
QMap<QString, DeviceItem*> m_deviceItems;
|
||||
QMap<QString, DeviceItem*> m_pairedDeviceItems;
|
||||
// QMap<QString, DeviceItem*> m_pairedDeviceItems;
|
||||
};
|
||||
|
||||
#endif // ADAPTERITEM_H
|
||||
|
@ -27,14 +27,27 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QPainter>
|
||||
|
||||
const int ItemHeight = 30;
|
||||
|
||||
DeviceItem::DeviceItem(const QString &title, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_title(new QLabel(title, this))
|
||||
, m_title(new QLabel(this))
|
||||
, m_state(new QLabel(this))
|
||||
, m_loadingStat(new DSpinner)
|
||||
, m_line(new HorizontalSeparator(this))
|
||||
{
|
||||
m_state->setPixmap(QPixmap(":/list_select@2x.png"));
|
||||
setFixedHeight(ItemHeight);
|
||||
// m_state->setPixmap(QPixmap(":/list_select@2x.png"));
|
||||
m_state->setPixmap(QPixmap(":/select_dark.svg"));
|
||||
|
||||
auto strTitle = title;
|
||||
m_title->setText(strTitle);
|
||||
QFontMetrics fontMetrics(m_title->font());
|
||||
if(fontMetrics.width(strTitle) > m_title->width())
|
||||
{
|
||||
strTitle = QFontMetrics(m_title->font()).elidedText(strTitle, Qt::ElideRight, m_title->width());
|
||||
}
|
||||
m_title->setText(strTitle);
|
||||
|
||||
m_line->setVisible(true);
|
||||
m_state->setVisible(false);
|
||||
@ -69,7 +82,8 @@ void DeviceItem::enterEvent(QEvent *event)
|
||||
QWidget::enterEvent(event);
|
||||
if (m_device) {
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -79,12 +93,13 @@ void DeviceItem::leaveEvent(QEvent *event)
|
||||
QWidget::enterEvent(event);
|
||||
if (m_device) {
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceItem::chaneState(const Device::State state)
|
||||
void DeviceItem::changeState(const Device::State state)
|
||||
{
|
||||
switch (state) {
|
||||
case Device::StateUnavailable: {
|
||||
@ -123,7 +138,7 @@ void HorizontalSeparator::paintEvent(QPaintEvent *e)
|
||||
QWidget::paintEvent(e);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.fillRect(rect(), QColor(0, 0, 0, 125));
|
||||
painter.fillRect(rect(), QColor(0, 0, 0, 0));
|
||||
}
|
||||
|
||||
MenueItem::MenueItem(QWidget *parent)
|
||||
|
@ -52,7 +52,7 @@ signals:
|
||||
void clicked(Device *);
|
||||
|
||||
public slots:
|
||||
void chaneState(const Device::State state);
|
||||
void changeState(const Device::State state);
|
||||
|
||||
private:
|
||||
QLabel *m_title;
|
||||
|
@ -30,11 +30,15 @@ SwitchItem::SwitchItem(QWidget *parent)
|
||||
, m_switchBtn(new DSwitchButton(this))
|
||||
, m_default(false)
|
||||
{
|
||||
setFixedHeight(35);
|
||||
auto switchLayout = new QHBoxLayout(this);
|
||||
switchLayout->setMargin(2);
|
||||
switchLayout->setSpacing(0);
|
||||
switchLayout->setMargin(0);
|
||||
switchLayout->addSpacing(5);
|
||||
switchLayout->addWidget(m_title);
|
||||
switchLayout->addStretch();
|
||||
switchLayout->addWidget(m_switchBtn);
|
||||
switchLayout->addSpacing(5);
|
||||
setLayout(switchLayout);
|
||||
|
||||
connect(m_switchBtn, &DSwitchButton::toggled, [&](bool change) {
|
||||
|
@ -10,5 +10,11 @@
|
||||
<file>list_select@2x.png</file>
|
||||
<file>notify_close_press.png</file>
|
||||
<file>notify_close_press@2x.png</file>
|
||||
<file>refresh_dark.svg</file>
|
||||
<file>refresh.svg</file>
|
||||
<file>select_dark.svg</file>
|
||||
<file>select.svg</file>
|
||||
<file>disconnect.svg</file>
|
||||
<file>disconnect_dark.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
3
plugins/bluetooth/resources/disconnect.svg
Normal file
3
plugins/bluetooth/resources/disconnect.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
|
||||
<path fill="#FFF" fill-rule="evenodd" d="M10.0000013,1.27118983e-06 C15.5228488,1.27118983e-06 20.0000013,4.47715377 20.0000013,10.0000013 C20.0000013,15.5228488 15.5228488,20.0000013 10.0000013,20.0000013 C4.47715377,20.0000013 1.27118983e-06,15.5228488 1.27118983e-06,10.0000013 C1.27118983e-06,4.47715377 4.47715377,1.27118983e-06 10.0000013,1.27118983e-06 Z M7.2843055,6.58858366 C7.08943736,6.45358761 6.82001296,6.47287276 6.64644661,6.64643911 L6.64644661,6.64643911 L6.58859116,6.715687 C6.45359511,6.91055514 6.47288026,7.17997954 6.64644661,7.35354589 L6.64644661,7.35354589 L9.293,9.9999925 L6.64644661,12.6464391 L6.58859116,12.715687 C6.45359511,12.9105551 6.47288026,13.1799795 6.64644661,13.3535459 L6.64644661,13.3535459 L6.7156945,13.4114013 C6.91056264,13.5463974 7.17998704,13.5271122 7.35355339,13.3535459 L7.35355339,13.3535459 L10,10.7069925 L12.6464466,13.3535459 L12.7156945,13.4114013 C12.9105626,13.5463974 13.179987,13.5271122 13.3535534,13.3535459 L13.3535534,13.3535459 L13.4114088,13.284298 C13.5464049,13.0894299 13.5271197,12.8200055 13.3535534,12.6464391 L13.3535534,12.6464391 L10.707,9.9999925 L13.3535534,7.35354589 L13.4114088,7.284298 C13.5464049,7.08942986 13.5271197,6.82000546 13.3535534,6.64643911 L13.3535534,6.64643911 L13.2843055,6.58858366 C13.0894374,6.45358761 12.820013,6.47287276 12.6464466,6.64643911 L12.6464466,6.64643911 L10,9.2929925 L7.35355339,6.64643911 Z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 1.5 KiB |
3
plugins/bluetooth/resources/disconnect_dark.svg
Normal file
3
plugins/bluetooth/resources/disconnect_dark.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M10.0000013,1.27118983e-06 C15.5228488,1.27118983e-06 20.0000013,4.47715377 20.0000013,10.0000013 C20.0000013,15.5228488 15.5228488,20.0000013 10.0000013,20.0000013 C4.47715377,20.0000013 1.27118983e-06,15.5228488 1.27118983e-06,10.0000013 C1.27118983e-06,4.47715377 4.47715377,1.27118983e-06 10.0000013,1.27118983e-06 Z M7.2843055,6.58858366 C7.08943736,6.45358761 6.82001296,6.47287276 6.64644661,6.64643911 L6.64644661,6.64643911 L6.58859116,6.715687 C6.45359511,6.91055514 6.47288026,7.17997954 6.64644661,7.35354589 L6.64644661,7.35354589 L9.293,9.9999925 L6.64644661,12.6464391 L6.58859116,12.715687 C6.45359511,12.9105551 6.47288026,13.1799795 6.64644661,13.3535459 L6.64644661,13.3535459 L6.7156945,13.4114013 C6.91056264,13.5463974 7.17998704,13.5271122 7.35355339,13.3535459 L7.35355339,13.3535459 L10,10.7069925 L12.6464466,13.3535459 L12.7156945,13.4114013 C12.9105626,13.5463974 13.179987,13.5271122 13.3535534,13.3535459 L13.3535534,13.3535459 L13.4114088,13.284298 C13.5464049,13.0894299 13.5271197,12.8200055 13.3535534,12.6464391 L13.3535534,12.6464391 L10.707,9.9999925 L13.3535534,7.35354589 L13.4114088,7.284298 C13.5464049,7.08942986 13.5271197,6.82000546 13.3535534,6.64643911 L13.3535534,6.64643911 L13.2843055,6.58858366 C13.0894374,6.45358761 12.820013,6.47287276 12.6464466,6.64643911 L12.6464466,6.64643911 L10,9.2929925 L7.35355339,6.64643911 Z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 1.5 KiB |
3
plugins/bluetooth/resources/refresh.svg
Normal file
3
plugins/bluetooth/resources/refresh.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
|
||||
<path fill="#FFF" d="M17,2 L17,8 L11,8 L14.0692732,4.93027904 C12.9431015,4.02647545 11.5199506,3.5 10,3.5 C6.41014912,3.5 3.5,6.41014912 3.5,10 C3.5,13.5898508 6.41014914,16.5 10,16.5 C12.6572393,16.5 15.0163846,14.8908134 16.012065,12.4756735 L16.012065,12.4756735 L16.9365798,12.8568197 C15.7878061,15.6433054 13.0658021,17.5 10,17.5 C5.85786439,17.5 2.5,14.1421356 2.5,10 C2.5,5.85786438 5.85786438,2.5 10,2.5 C11.7921585,2.5 13.4677532,3.13445568 14.7801646,4.21961165 L17,2 Z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 578 B |
3
plugins/bluetooth/resources/refresh_dark.svg
Normal file
3
plugins/bluetooth/resources/refresh_dark.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M17,2 L17,8 L11,8 L14.0692732,4.93027904 C12.9431015,4.02647545 11.5199506,3.5 10,3.5 C6.41014912,3.5 3.5,6.41014912 3.5,10 C3.5,13.5898508 6.41014914,16.5 10,16.5 C12.6572393,16.5 15.0163846,14.8908134 16.012065,12.4756735 L16.012065,12.4756735 L16.9365798,12.8568197 C15.7878061,15.6433054 13.0658021,17.5 10,17.5 C5.85786439,17.5 2.5,14.1421356 2.5,10 C2.5,5.85786438 5.85786438,2.5 10,2.5 C11.7921585,2.5 13.4677532,3.13445568 14.7801646,4.21961165 L17,2 Z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 586 B |
3
plugins/bluetooth/resources/select.svg
Normal file
3
plugins/bluetooth/resources/select.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
|
||||
<path fill="#FFF" fill-rule="evenodd" d="M10,0 C15.5,0 20,4.5 20,10 C20,15.5 15.5,20 10,20 C4.5,20 0,15.5 0,10 C0,4.5 4.5,0 10,0 Z M14.1636213,5.63070157 L9.2152245,11.9670795 L7.038112,9.65378951 L6.16425285,10.4762068 L9.30003171,13.8081274 L15.109388,6.36929843 L14.1636213,5.63070157 Z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 386 B |
3
plugins/bluetooth/resources/select_dark.svg
Normal file
3
plugins/bluetooth/resources/select_dark.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M10,0 C15.5,0 20,4.5 20,10 C20,15.5 15.5,20 10,20 C4.5,20 0,15.5 0,10 C0,4.5 4.5,0 10,0 Z M14.1636213,5.63070157 L9.2152245,11.9670795 L7.038112,9.65378951 L6.16425285,10.4762068 L9.30003171,13.8081274 L15.109388,6.36929843 L14.1636213,5.63070157 Z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 374 B |
Loading…
x
Reference in New Issue
Block a user