mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
fix(bluetooth):popups display truncated
task20793 【TR4】【桌面专业版】【SP1】【华为】【Kunpeng920】【uos-20-pangu-daliy-20200424-build46】【任务栏】任务栏蓝牙显示截断 (cherry picked from commit 619ba29a258a215868a05e83f543f8a030f08d1d)
This commit is contained in:
parent
1b6db122f3
commit
4303f90d75
@ -30,6 +30,7 @@
|
|||||||
#include "componments/bluetoothconstants.h"
|
#include "componments/bluetoothconstants.h"
|
||||||
|
|
||||||
#include <DApplicationHelper>
|
#include <DApplicationHelper>
|
||||||
|
#include <DDBusSender>
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
@ -60,6 +61,7 @@ BluetoothApplet::BluetoothApplet(QWidget *parent)
|
|||||||
, m_appletName(new QLabel(this))
|
, m_appletName(new QLabel(this))
|
||||||
, m_centralWidget(new QWidget)
|
, m_centralWidget(new QWidget)
|
||||||
, m_centrealLayout(new QVBoxLayout)
|
, m_centrealLayout(new QVBoxLayout)
|
||||||
|
, m_openControlCenter(new MenueItem(this))
|
||||||
, m_adaptersManager(new AdaptersManager(this))
|
, m_adaptersManager(new AdaptersManager(this))
|
||||||
{
|
{
|
||||||
m_line->setVisible(false);
|
m_line->setVisible(false);
|
||||||
@ -72,6 +74,11 @@ BluetoothApplet::BluetoothApplet(QWidget *parent)
|
|||||||
initFontColor(m_appletName);
|
initFontColor(m_appletName);
|
||||||
m_appletName->setVisible(false);
|
m_appletName->setVisible(false);
|
||||||
|
|
||||||
|
m_openControlCenter->setText(tr("Bluetooth settings"));
|
||||||
|
initFontColor(m_openControlCenter);
|
||||||
|
m_openControlCenter->setFixedHeight(ITEMHEIGHT);
|
||||||
|
m_openControlCenter->setVisible(false);
|
||||||
|
|
||||||
auto appletNameLayout = new QHBoxLayout;
|
auto appletNameLayout = new QHBoxLayout;
|
||||||
appletNameLayout->setMargin(0);
|
appletNameLayout->setMargin(0);
|
||||||
appletNameLayout->setSpacing(0);
|
appletNameLayout->setSpacing(0);
|
||||||
@ -79,10 +86,19 @@ BluetoothApplet::BluetoothApplet(QWidget *parent)
|
|||||||
appletNameLayout->addWidget(m_appletName);
|
appletNameLayout->addWidget(m_appletName);
|
||||||
appletNameLayout->addStretch();
|
appletNameLayout->addStretch();
|
||||||
|
|
||||||
|
m_menueLayout = new QHBoxLayout;
|
||||||
|
m_menueLayout->setMargin(0);
|
||||||
|
m_menueLayout->setSpacing(0);
|
||||||
|
m_menueLayout->addSpacing(MARGIN);
|
||||||
|
|
||||||
|
m_adapterLayout = new QVBoxLayout;
|
||||||
|
|
||||||
m_centrealLayout->setMargin(0);
|
m_centrealLayout->setMargin(0);
|
||||||
m_centrealLayout->setSpacing(0);
|
m_centrealLayout->setSpacing(0);
|
||||||
m_centrealLayout->addLayout(appletNameLayout);
|
m_centrealLayout->addLayout(appletNameLayout);
|
||||||
m_centrealLayout->addWidget(m_line);
|
m_centrealLayout->addWidget(m_line);
|
||||||
|
m_centrealLayout->addLayout(m_adapterLayout);
|
||||||
|
m_centrealLayout->addLayout(m_menueLayout);
|
||||||
m_centralWidget->setLayout(m_centrealLayout);
|
m_centralWidget->setLayout(m_centrealLayout);
|
||||||
m_centralWidget->setFixedWidth(POPUPWIDTH);
|
m_centralWidget->setFixedWidth(POPUPWIDTH);
|
||||||
m_centralWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
m_centralWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||||
@ -97,6 +113,15 @@ BluetoothApplet::BluetoothApplet(QWidget *parent)
|
|||||||
|
|
||||||
connect(m_adaptersManager, &AdaptersManager::adapterIncreased, this, &BluetoothApplet::addAdapter);
|
connect(m_adaptersManager, &AdaptersManager::adapterIncreased, this, &BluetoothApplet::addAdapter);
|
||||||
connect(m_adaptersManager, &AdaptersManager::adapterDecreased, this, &BluetoothApplet::removeAdapter);
|
connect(m_adaptersManager, &AdaptersManager::adapterDecreased, this, &BluetoothApplet::removeAdapter);
|
||||||
|
connect(m_openControlCenter, &MenueItem::clicked, []{
|
||||||
|
DDBusSender()
|
||||||
|
.service("com.deepin.dde.ControlCenter")
|
||||||
|
.interface("com.deepin.dde.ControlCenter")
|
||||||
|
.path("/com/deepin/dde/ControlCenter")
|
||||||
|
.method(QString("ShowModule"))
|
||||||
|
.arg(QString("bluetooth"))
|
||||||
|
.call();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void BluetoothApplet::setAdapterPowered(bool powered)
|
void BluetoothApplet::setAdapterPowered(bool powered)
|
||||||
@ -155,6 +180,7 @@ void BluetoothApplet::onDeviceStateChanged()
|
|||||||
}
|
}
|
||||||
|
|
||||||
emit deviceStateChanged(deviceState);
|
emit deviceStateChanged(deviceState);
|
||||||
|
updateView();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BluetoothApplet::addAdapter(Adapter *adapter)
|
void BluetoothApplet::addAdapter(Adapter *adapter)
|
||||||
@ -169,7 +195,7 @@ void BluetoothApplet::addAdapter(Adapter *adapter)
|
|||||||
QString adapterId = adapter->id();
|
QString adapterId = adapter->id();
|
||||||
auto adatpterItem = new AdapterItem(m_adaptersManager, adapter, this);
|
auto adatpterItem = new AdapterItem(m_adaptersManager, adapter, this);
|
||||||
m_adapterItems[adapterId] = adatpterItem;
|
m_adapterItems[adapterId] = adatpterItem;
|
||||||
m_centrealLayout->addWidget(adatpterItem);
|
m_adapterLayout->addWidget(adatpterItem);
|
||||||
getDevieInitState(adatpterItem);
|
getDevieInitState(adatpterItem);
|
||||||
|
|
||||||
connect(adatpterItem, &AdapterItem::deviceStateChanged, this, &BluetoothApplet::onDeviceStateChanged);
|
connect(adatpterItem, &AdapterItem::deviceStateChanged, this, &BluetoothApplet::onDeviceStateChanged);
|
||||||
@ -185,7 +211,7 @@ void BluetoothApplet::removeAdapter(Adapter *adapter)
|
|||||||
QString adapterId = adapter->id();
|
QString adapterId = adapter->id();
|
||||||
AdapterItem *adapterItem = m_adapterItems.value(adapterId);
|
AdapterItem *adapterItem = m_adapterItems.value(adapterId);
|
||||||
if (adapterItem) {
|
if (adapterItem) {
|
||||||
m_centrealLayout->removeWidget(adapterItem);
|
m_adapterLayout->removeWidget(adapterItem);
|
||||||
delete adapterItem;
|
delete adapterItem;
|
||||||
m_adapterItems.remove(adapterId);
|
m_adapterItems.remove(adapterId);
|
||||||
updateView();
|
updateView();
|
||||||
@ -199,14 +225,24 @@ void BluetoothApplet::updateView()
|
|||||||
{
|
{
|
||||||
int contentHeight = 0;
|
int contentHeight = 0;
|
||||||
int itemCount = 0;
|
int itemCount = 0;
|
||||||
|
bool isAdapterConnected = true;
|
||||||
for (AdapterItem *adapterItem : m_adapterItems) {
|
for (AdapterItem *adapterItem : m_adapterItems) {
|
||||||
if (adapterItem) {
|
if (adapterItem) {
|
||||||
contentHeight += adapterItem->viewHeight();
|
contentHeight += CONTROLHEIGHT;
|
||||||
if (adapterItem->isPowered())
|
if (adapterItem->isPowered())
|
||||||
itemCount += adapterItem->deviceCount();
|
itemCount += adapterItem->deviceCount();
|
||||||
|
if (adapterItem->connectedDevsName().size())
|
||||||
|
isAdapterConnected = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_openControlCenter->setVisible(isAdapterConnected);
|
||||||
|
if (isAdapterConnected) {
|
||||||
|
m_menueLayout->addWidget(m_openControlCenter);
|
||||||
|
contentHeight += ITEMHEIGHT;
|
||||||
|
} else
|
||||||
|
m_menueLayout->removeWidget(m_openControlCenter);
|
||||||
|
|
||||||
int adaptersCnt = m_adapterItems.size();
|
int adaptersCnt = m_adapterItems.size();
|
||||||
if (adaptersCnt > 1) {
|
if (adaptersCnt > 1) {
|
||||||
m_line->setVisible(true);
|
m_line->setVisible(true);
|
||||||
|
@ -29,9 +29,11 @@
|
|||||||
|
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
|
class QHBoxLayout;
|
||||||
class Adapter;
|
class Adapter;
|
||||||
class AdapterItem;
|
class AdapterItem;
|
||||||
class HorizontalSeparator;
|
class HorizontalSeparator;
|
||||||
|
class MenueItem;
|
||||||
class AdaptersManager;
|
class AdaptersManager;
|
||||||
class BluetoothApplet : public QScrollArea
|
class BluetoothApplet : public QScrollArea
|
||||||
{
|
{
|
||||||
@ -66,6 +68,9 @@ private:
|
|||||||
QLabel *m_appletName;
|
QLabel *m_appletName;
|
||||||
QWidget *m_centralWidget;
|
QWidget *m_centralWidget;
|
||||||
QVBoxLayout *m_centrealLayout;
|
QVBoxLayout *m_centrealLayout;
|
||||||
|
QVBoxLayout *m_adapterLayout;
|
||||||
|
QHBoxLayout *m_menueLayout;
|
||||||
|
MenueItem *m_openControlCenter;
|
||||||
|
|
||||||
AdaptersManager *m_adaptersManager;
|
AdaptersManager *m_adaptersManager;
|
||||||
|
|
||||||
|
@ -187,11 +187,12 @@ void BluetoothItem::refreshTips()
|
|||||||
}
|
}
|
||||||
case Device::StateAvailable: {
|
case Device::StateAvailable: {
|
||||||
tipsText = tr("Connecting...");
|
tipsText = tr("Connecting...");
|
||||||
return ;
|
|
||||||
}
|
}
|
||||||
|
break ;
|
||||||
case Device::StateUnavailable: {
|
case Device::StateUnavailable: {
|
||||||
tipsText = tr("Bluetooth");
|
tipsText = tr("Bluetooth");
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tipsText = tr("Bluetooth");
|
tipsText = tr("Bluetooth");
|
||||||
|
@ -27,8 +27,6 @@
|
|||||||
#include "adaptersmanager.h"
|
#include "adaptersmanager.h"
|
||||||
#include "bluetoothconstants.h"
|
#include "bluetoothconstants.h"
|
||||||
|
|
||||||
#include <DDBusSender>
|
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
@ -39,7 +37,6 @@ AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWid
|
|||||||
, m_centralWidget(new QWidget(this))
|
, m_centralWidget(new QWidget(this))
|
||||||
, m_line(new HorizontalSeparator(this))
|
, m_line(new HorizontalSeparator(this))
|
||||||
, m_deviceLayout(new QVBoxLayout)
|
, m_deviceLayout(new QVBoxLayout)
|
||||||
, m_openControlCenter(new MenueItem(this))
|
|
||||||
, m_adaptersManager(adapterManager)
|
, m_adaptersManager(adapterManager)
|
||||||
, m_adapter(adapter)
|
, m_adapter(adapter)
|
||||||
, m_switchItem(new SwitchItem(this))
|
, m_switchItem(new SwitchItem(this))
|
||||||
@ -48,16 +45,12 @@ 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(tr("Bluetooth settings"));
|
|
||||||
initFontColor(m_openControlCenter);
|
|
||||||
m_openControlCenter->setFixedHeight(ITEMHEIGHT);
|
|
||||||
m_openControlCenter->setVisible(false);
|
|
||||||
m_switchItem->setTitle(adapter->name());
|
m_switchItem->setTitle(adapter->name());
|
||||||
m_switchItem->setChecked(adapter->powered(),false);
|
m_switchItem->setChecked(adapter->powered(),false);
|
||||||
|
|
||||||
m_deviceLayout->addWidget(m_switchItem);
|
m_deviceLayout->addWidget(m_switchItem);
|
||||||
m_deviceLayout->addWidget(m_line);
|
m_deviceLayout->addWidget(m_line);
|
||||||
m_deviceLayout->addWidget(m_openControlCenter);
|
|
||||||
m_centralWidget->setFixedWidth(POPUPWIDTH);
|
m_centralWidget->setFixedWidth(POPUPWIDTH);
|
||||||
m_centralWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
m_centralWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||||
m_centralWidget->setLayout(m_deviceLayout);
|
m_centralWidget->setLayout(m_deviceLayout);
|
||||||
@ -103,15 +96,6 @@ AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWid
|
|||||||
connect(adapter, &Adapter::poweredChanged, m_switchItem, [=](const bool powered){
|
connect(adapter, &Adapter::poweredChanged, m_switchItem, [=](const bool powered){
|
||||||
m_switchItem->setChecked(powered, false);
|
m_switchItem->setChecked(powered, false);
|
||||||
});
|
});
|
||||||
connect(m_openControlCenter, &MenueItem::clicked, []{
|
|
||||||
DDBusSender()
|
|
||||||
.service("com.deepin.dde.ControlCenter")
|
|
||||||
.interface("com.deepin.dde.ControlCenter")
|
|
||||||
.path("/com/deepin/dde/ControlCenter")
|
|
||||||
.method(QString("ShowModule"))
|
|
||||||
.arg(QString("bluetooth"))
|
|
||||||
.call();
|
|
||||||
});
|
|
||||||
|
|
||||||
showDevices(adapter->powered());
|
showDevices(adapter->powered());
|
||||||
}
|
}
|
||||||
@ -131,11 +115,6 @@ bool AdapterItem::isPowered()
|
|||||||
return m_switchItem->checkState();
|
return m_switchItem->checkState();
|
||||||
}
|
}
|
||||||
|
|
||||||
int AdapterItem::viewHeight()
|
|
||||||
{
|
|
||||||
return m_openControlCenter->isVisible() ? CONTROLHEIGHT + ITEMHEIGHT : CONTROLHEIGHT;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList AdapterItem::connectedDevsName()
|
QStringList AdapterItem::connectedDevsName()
|
||||||
{
|
{
|
||||||
QStringList devsName;
|
QStringList devsName;
|
||||||
@ -293,7 +272,7 @@ void AdapterItem::createDeviceItem(Device *device)
|
|||||||
void AdapterItem::updateView()
|
void AdapterItem::updateView()
|
||||||
{
|
{
|
||||||
int contentHeight = m_switchItem->height();
|
int contentHeight = m_switchItem->height();
|
||||||
contentHeight += (m_deviceLayout->count() - 3) * ITEMHEIGHT;
|
contentHeight += (m_deviceLayout->count() - 2) * ITEMHEIGHT;
|
||||||
m_centralWidget->setFixedHeight(contentHeight);
|
m_centralWidget->setFixedHeight(contentHeight);
|
||||||
setFixedHeight(contentHeight);
|
setFixedHeight(contentHeight);
|
||||||
emit sizeChange();
|
emit sizeChange();
|
||||||
@ -317,8 +296,6 @@ void AdapterItem::showDevices(bool powered)
|
|||||||
deviceItem->setVisible(powered);
|
deviceItem->setVisible(powered);
|
||||||
}
|
}
|
||||||
|
|
||||||
int itemCount = m_deviceItems.size();
|
|
||||||
m_line->setVisible(powered);
|
m_line->setVisible(powered);
|
||||||
m_openControlCenter->setVisible(!itemCount);
|
|
||||||
updateView();
|
updateView();
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,6 @@ public:
|
|||||||
int deviceCount();
|
int deviceCount();
|
||||||
void setPowered(bool powered);
|
void setPowered(bool powered);
|
||||||
bool isPowered();
|
bool isPowered();
|
||||||
int viewHeight();
|
|
||||||
inline Device::State initDeviceState() { return m_initDeviceState; }
|
inline Device::State initDeviceState() { return m_initDeviceState; }
|
||||||
inline Device::State currentDeviceState() { return m_currentDeviceState; }
|
inline Device::State currentDeviceState() { return m_currentDeviceState; }
|
||||||
QStringList connectedDevsName();
|
QStringList connectedDevsName();
|
||||||
@ -71,7 +70,6 @@ private:
|
|||||||
QWidget *m_centralWidget;
|
QWidget *m_centralWidget;
|
||||||
HorizontalSeparator *m_line;
|
HorizontalSeparator *m_line;
|
||||||
QVBoxLayout *m_deviceLayout;
|
QVBoxLayout *m_deviceLayout;
|
||||||
MenueItem *m_openControlCenter;
|
|
||||||
|
|
||||||
AdaptersManager *m_adaptersManager;
|
AdaptersManager *m_adaptersManager;
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ TipsWidget::TipsWidget(QWidget *parent) : QFrame(parent)
|
|||||||
|
|
||||||
void TipsWidget::setText(const QString &text)
|
void TipsWidget::setText(const QString &text)
|
||||||
{
|
{
|
||||||
|
m_type = TipsWidget::SingleLine;
|
||||||
m_text = text;
|
m_text = text;
|
||||||
|
|
||||||
setFixedSize(fontMetrics().width(text) + 6, fontMetrics().height());
|
setFixedSize(fontMetrics().width(text) + 6, fontMetrics().height());
|
||||||
@ -18,6 +19,7 @@ void TipsWidget::setText(const QString &text)
|
|||||||
|
|
||||||
void TipsWidget::setTextList(const QStringList &textList)
|
void TipsWidget::setTextList(const QStringList &textList)
|
||||||
{
|
{
|
||||||
|
m_type = TipsWidget::MultiLine;
|
||||||
m_textList = textList;
|
m_textList = textList;
|
||||||
|
|
||||||
int maxLength = 0;
|
int maxLength = 0;
|
||||||
@ -43,12 +45,13 @@ void TipsWidget::paintEvent(QPaintEvent *event)
|
|||||||
int fontHeight = fontMetrics().height();
|
int fontHeight = fontMetrics().height();
|
||||||
option.setAlignment(Qt::AlignCenter);
|
option.setAlignment(Qt::AlignCenter);
|
||||||
|
|
||||||
if (!m_text.isEmpty() && m_textList.isEmpty()) {
|
switch (m_type) {
|
||||||
|
case SingleLine: {
|
||||||
painter.drawText(rect(), m_text, option);
|
painter.drawText(rect(), m_text, option);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
int y = 0;
|
case MultiLine: {
|
||||||
if (m_text.isEmpty() && !m_textList.isEmpty()) {
|
int y = 0;
|
||||||
if (m_textList.size() != 1)
|
if (m_textList.size() != 1)
|
||||||
option.setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
option.setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||||
for (QString text : m_textList) {
|
for (QString text : m_textList) {
|
||||||
@ -56,5 +59,6 @@ void TipsWidget::paintEvent(QPaintEvent *event)
|
|||||||
y += fontHeight;
|
y += fontHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,11 @@
|
|||||||
class TipsWidget : public QFrame
|
class TipsWidget : public QFrame
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
enum ShowType
|
||||||
|
{
|
||||||
|
SingleLine,
|
||||||
|
MultiLine
|
||||||
|
};
|
||||||
public:
|
public:
|
||||||
explicit TipsWidget(QWidget *parent = nullptr);
|
explicit TipsWidget(QWidget *parent = nullptr);
|
||||||
|
|
||||||
@ -21,6 +26,7 @@ private:
|
|||||||
QString m_text;
|
QString m_text;
|
||||||
QStringList m_textList;
|
QStringList m_textList;
|
||||||
int m_width;
|
int m_width;
|
||||||
|
ShowType m_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TIPSWIDGET_H
|
#endif // TIPSWIDGET_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user