From 0db854c785e6ae5233b4d6f4c4e668f9977e2887 Mon Sep 17 00:00:00 2001 From: FanPengCheng Date: Thu, 10 Jun 2021 18:11:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=93=9D=E7=89=99?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E9=AB=98=E5=BA=A6=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 高度计算错误导致 Log: Change-Id: Ic168a905ef568560bfd9b065787a06b2c31ff700 --- frame/util/horizontalseperator.cpp | 5 ++++ frame/util/horizontalseperator.h | 4 +++- .../componments/bluetoothadapteritem.cpp | 12 +++++----- .../componments/bluetoothadapteritem.h | 3 ++- .../bluetooth/componments/bluetoothapplet.cpp | 24 ++++++++++--------- .../bluetooth/componments/bluetoothapplet.h | 2 ++ 6 files changed, 31 insertions(+), 19 deletions(-) diff --git a/frame/util/horizontalseperator.cpp b/frame/util/horizontalseperator.cpp index 66d0531ed..ca151e467 100644 --- a/frame/util/horizontalseperator.cpp +++ b/frame/util/horizontalseperator.cpp @@ -36,6 +36,11 @@ HorizontalSeperator::HorizontalSeperator(QWidget *parent) setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); } +QSize HorizontalSeperator::sizeHint() const +{ + return QSize(QWidget::sizeHint().width(), 2); +} + void HorizontalSeperator::paintEvent(QPaintEvent *e) { Q_UNUSED(e) diff --git a/frame/util/horizontalseperator.h b/frame/util/horizontalseperator.h index ace6c5e97..17f41010a 100644 --- a/frame/util/horizontalseperator.h +++ b/frame/util/horizontalseperator.h @@ -31,8 +31,10 @@ class HorizontalSeperator : public QWidget public: explicit HorizontalSeperator(QWidget *parent = nullptr); + QSize sizeHint() const override; + protected: - void paintEvent(QPaintEvent *e); + void paintEvent(QPaintEvent *e) override; }; #endif // HORIZONTALSEPERATOR_H diff --git a/plugins/bluetooth/componments/bluetoothadapteritem.cpp b/plugins/bluetooth/componments/bluetoothadapteritem.cpp index 76231cb66..6ddaa4043 100644 --- a/plugins/bluetooth/componments/bluetoothadapteritem.cpp +++ b/plugins/bluetooth/componments/bluetoothadapteritem.cpp @@ -131,7 +131,6 @@ BluetoothAdapterItem::BluetoothAdapterItem(Adapter *adapter, QWidget *parent) , m_bluetoothInter(new DBusBluetooth("com.deepin.daemon.Bluetooth", "/com/deepin/daemon/Bluetooth", QDBusConnection::sessionBus(), this)) , m_showUnnamedDevices(false) , m_seperator(new HorizontalSeperator(this)) - , m_bottomSeperator(new HorizontalSeperator(this)) { initData(); initUi(); @@ -181,6 +180,12 @@ void BluetoothAdapterItem::updateIconTheme(DGuiApplicationHelper::ColorType type m_refreshBtn->setRotateIcon(":/wireless/resources/wireless/refresh.svg"); } +QSize BluetoothAdapterItem::sizeHint() const +{ + return QSize(ItemWidth, m_deviceListview->model()->rowCount() * DeviceItemHeight + + (m_deviceListview->model()->rowCount() > 0 ? m_seperator->sizeHint().height() : 0));// 加上割线的高度 +} + int BluetoothAdapterItem::currentDeviceCount() { return m_deviceItems.size(); @@ -292,13 +297,10 @@ void BluetoothAdapterItem::initUi() mainLayout->addWidget(m_adapterLabel); mainLayout->addWidget(m_seperator); mainLayout->addWidget(m_deviceListview); - mainLayout->addWidget(m_bottomSeperator); m_seperator->setVisible(m_deviceListview->count() != 0); - m_bottomSeperator->setVisible(m_deviceListview->count() != 0); connect(m_deviceListview, &DListView::rowCountChanged, this, [ = ] { m_seperator->setVisible(m_deviceListview->count() != 0); - m_bottomSeperator->setVisible(m_deviceListview->count() != 0); }); m_deviceListview->setItemDelegate(m_itemDelegate); @@ -334,7 +336,6 @@ void BluetoothAdapterItem::initConnect() m_refreshBtn->setVisible(state); m_deviceListview->setVisible(state); m_seperator->setVisible(state); - m_bottomSeperator->setVisible(state); m_adapterStateBtn->setChecked(state); m_adapterStateBtn->setEnabled(true); emit adapterPowerChanged(); @@ -345,7 +346,6 @@ void BluetoothAdapterItem::initConnect() m_deviceModel->clear(); m_deviceListview->setVisible(false); m_seperator->setVisible(false); - m_bottomSeperator->setVisible(false); m_adapterStateBtn->setEnabled(false); m_refreshBtn->setVisible(state); emit requestSetAdapterPower(m_adapter, state); diff --git a/plugins/bluetooth/componments/bluetoothadapteritem.h b/plugins/bluetooth/componments/bluetoothadapteritem.h index b7f230e30..3fd098ad4 100644 --- a/plugins/bluetooth/componments/bluetoothadapteritem.h +++ b/plugins/bluetooth/componments/bluetoothadapteritem.h @@ -113,6 +113,8 @@ public slots: void onAdapterNameChanged(const QString name); void updateIconTheme(DGuiApplicationHelper::ColorType type); + QSize sizeHint() const override; + signals: void adapterPowerChanged(); void requestSetAdapterPower(Adapter *adapter, bool state); @@ -140,7 +142,6 @@ private: QMap m_deviceItems; HorizontalSeperator *m_seperator; - HorizontalSeperator *m_bottomSeperator; }; #endif // BLUETOOTHADAPTERITEM_H diff --git a/plugins/bluetooth/componments/bluetoothapplet.cpp b/plugins/bluetooth/componments/bluetoothapplet.cpp index 8c6ebb3fc..940a2989b 100644 --- a/plugins/bluetooth/componments/bluetoothapplet.cpp +++ b/plugins/bluetooth/componments/bluetoothapplet.cpp @@ -26,6 +26,7 @@ #include "adaptersmanager.h" #include "adapter.h" #include "bluetoothadapteritem.h" +#include "util/horizontalseperator.h" #include #include @@ -98,6 +99,7 @@ BluetoothApplet::BluetoothApplet(QWidget *parent) , m_settingLabel(new SettingLabel(tr("Bluetooth settings"), this)) , m_mainLayout(new QVBoxLayout(this)) , m_contentLayout(new QVBoxLayout(m_contentWidget)) + , m_seperator(new HorizontalSeperator(this)) { initUi(); initConnect(); @@ -213,6 +215,7 @@ void BluetoothApplet::initUi() m_contentWidget->setContentsMargins(0, 0, 0, 0); m_contentLayout->setMargin(0); m_contentLayout->setSpacing(0); + m_contentLayout->addWidget(m_seperator); m_contentLayout->addWidget(m_settingLabel, 0, Qt::AlignBottom | Qt::AlignVCenter); m_scroarea = new QScrollArea(this); @@ -271,19 +274,18 @@ void BluetoothApplet::updateIconTheme() void BluetoothApplet::updateSize() { - int hetght = 0; - int count = 0; + int height = 0; + height += TitleSpace; foreach (const auto item, m_adapterItems) { - hetght += TitleHeight + TitleSpace; - if (item->adapter()->powered()) { - count += item->currentDeviceCount(); - hetght += count * DeviceItemHeight; - } + height += TitleHeight; + height += item->sizeHint().height(); } - hetght += DeviceItemHeight; - int maxHeight = (TitleHeight + TitleSpace) + MaxDeviceCount * DeviceItemHeight; - hetght = hetght > maxHeight ? maxHeight : hetght; - setFixedSize(ItemWidth, hetght); + // 加上蓝牙设置选项的高度 + height += DeviceItemHeight; + + static const int maxHeight = (TitleHeight + TitleSpace) + MaxDeviceCount * DeviceItemHeight; + + setFixedSize(ItemWidth, qMin(maxHeight, height)); } diff --git a/plugins/bluetooth/componments/bluetoothapplet.h b/plugins/bluetooth/componments/bluetoothapplet.h index 7bd79dff7..a988ccb7c 100644 --- a/plugins/bluetooth/componments/bluetoothapplet.h +++ b/plugins/bluetooth/componments/bluetoothapplet.h @@ -36,6 +36,7 @@ class Device; class Adapter; class BluetoothAdapterItem; class AdaptersManager; +class HorizontalSeperator; DWIDGET_BEGIN_NAMESPACE class DLabel; @@ -111,6 +112,7 @@ private: SettingLabel *m_settingLabel; QVBoxLayout *m_mainLayout; QVBoxLayout *m_contentLayout; + HorizontalSeperator *m_seperator; QStringList m_connectDeviceName; QMap m_adapterItems; // 所有蓝牙适配器