From 95aabc0a2f9db8181026f989bed1be7d0e89b383 Mon Sep 17 00:00:00 2001 From: FanPengCheng Date: Mon, 31 May 2021 19:33:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=9B=BE=E6=A0=87=E6=A8=A1=E7=B3=8A=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E7=95=8C=E9=9D=A2=E9=AB=98=E5=BA=A6=E4=B8=8D?= =?UTF-8?q?=E5=AF=B9=E5=B8=A6=E6=9D=A5=E7=9A=84=E4=BD=93=E9=AA=8C=E4=B8=8D?= =?UTF-8?q?=E5=8F=8B=E5=A5=BD=E7=AD=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 蓝牙刷新图标模糊问题 声音界面图标模糊问题 声音界面相关 网络界面相关 Log: Change-Id: Idfb343a2d3dc9fa98c45955637c0157a3a9957e6 --- .../bluetooth/componments/refreshbutton.cpp | 5 +-- .../network/item/applet/accesspointwidget.cpp | 2 +- plugins/network/networkitem.cpp | 24 ++++++-------- plugins/sound/soundapplet.cpp | 32 +++++++++++-------- plugins/sound/soundapplet.h | 7 ++-- 5 files changed, 37 insertions(+), 33 deletions(-) diff --git a/plugins/bluetooth/componments/refreshbutton.cpp b/plugins/bluetooth/componments/refreshbutton.cpp index b776e2598..31e166047 100644 --- a/plugins/bluetooth/componments/refreshbutton.cpp +++ b/plugins/bluetooth/componments/refreshbutton.cpp @@ -1,4 +1,5 @@ #include "refreshbutton.h" +#include "imageutil.h" #include #include @@ -19,7 +20,7 @@ RefreshButton::RefreshButton(QWidget *parent) void RefreshButton::setRotateIcon(QString path) { - m_pixmap = QIcon(path).pixmap(size()); + m_pixmap = ImageUtil::loadSvg(path, ":/", qMin(width(), height()), devicePixelRatio()); } void RefreshButton::startRotate() @@ -44,7 +45,7 @@ void RefreshButton::paintEvent(QPaintEvent *e) QPainter painter(this); painter.setPen(Qt::NoPen); painter.setBrush(Qt::NoBrush); - painter.setRenderHint(QPainter::SmoothPixmapTransform); + painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); painter.translate(this->width() / 2, this->height() / 2); painter.rotate(m_rotateAngle); diff --git a/plugins/network/item/applet/accesspointwidget.cpp b/plugins/network/item/applet/accesspointwidget.cpp index 4df148238..edc6c9bea 100644 --- a/plugins/network/item/applet/accesspointwidget.cpp +++ b/plugins/network/item/applet/accesspointwidget.cpp @@ -88,7 +88,7 @@ AccessPointWidget::AccessPointWidget(QWidget *parent) infoLayout->addSpacing(10); infoLayout->addWidget(m_ssidBtn); infoLayout->addWidget(m_stateButton); - infoLayout->addSpacing(3); + infoLayout->addSpacing(10); infoLayout->setSpacing(0); QVBoxLayout *centralLayout = new QVBoxLayout; diff --git a/plugins/network/networkitem.cpp b/plugins/network/networkitem.cpp index f87fa00f3..72293dff3 100644 --- a/plugins/network/networkitem.cpp +++ b/plugins/network/networkitem.cpp @@ -269,6 +269,10 @@ void NetworkItem::updateDeviceItems(QMap &wiredItems, QMap } } + m_wirelessControlPanel->setVisible(m_wirelessItems.count() > 0); + m_firstSeparator->setVisible(m_wirelessItems.count() > 0); + m_secondSeparator->setVisible(m_wirelessItems.count() > 0); + updateSelf(); } @@ -1134,22 +1138,14 @@ void NetworkItem::updateView() if (m_switchWiredBtnState) itemCount += wiredDeviceCnt; - // 分割线 都有设备时才有 - // auto hasDevice = wirelessDeviceCnt && wiredDeviceCnt; - // m_line->setVisible(hasDevice); - auto centralWidget = m_applet->widget(); if (itemCount <= constDisplayItemCnt) { - contentHeight += (itemCount - wiredDeviceCnt) * ITEM_HEIGHT; - contentHeight += wiredDeviceCnt * ITEM_HEIGHT; - centralWidget->setFixedHeight(contentHeight); - m_applet->setFixedHeight(contentHeight); - } else { - contentHeight += (itemCount - wiredDeviceCnt) * ITEM_HEIGHT; - contentHeight += wiredDeviceCnt * ITEM_HEIGHT; - //加上分割线占用的高度,否则显示界面高度不够显示,会造成无线网络列表item最后一项比其它项的高度小 - centralWidget->setFixedHeight(contentHeight + SeparatorItemHeight * 3); - m_applet->setFixedHeight(constDisplayItemCnt * ITEM_HEIGHT + SeparatorItemHeight * 3); + centralWidget->setFixedHeight(centralWidget->sizeHint().height()); + m_applet->setFixedHeight(centralWidget->sizeHint().height()); + } else {//最大大小 + contentHeight += itemCount * ITEM_HEIGHT; + centralWidget->setFixedHeight(centralWidget->sizeHint().height()); + m_applet->setFixedHeight(qMin(centralWidget->sizeHint().height(), 360)); } if (m_wirelessControlPanel->isVisible()) { diff --git a/plugins/sound/soundapplet.cpp b/plugins/sound/soundapplet.cpp index 5e769be7f..d74ef45a0 100644 --- a/plugins/sound/soundapplet.cpp +++ b/plugins/sound/soundapplet.cpp @@ -112,7 +112,7 @@ void Port::setCardId(const uint &cardId) SoundApplet::SoundApplet(QWidget *parent) : QScrollArea(parent) , m_centralWidget(new QWidget(this)) - , m_volumeIconMin(new DIconButton(this)) + , m_volumeIconMin(new QLabel(this)) , m_volumeIconMax(new QLabel(this)) , m_volumeSlider(new VolumeSlider(this)) , m_soundShow(new QLabel(this)) @@ -129,6 +129,8 @@ SoundApplet::SoundApplet(QWidget *parent) , m_gsettings(Utils::ModuleSettingsPtr("sound", QByteArray(), this)) { initUi(); + + m_volumeIconMin->installEventFilter(this); } void SoundApplet::initUi() @@ -152,14 +154,12 @@ void SoundApplet::initUi() verticalScrollBar()->setAccessibleName("volume-verticalscrollbar"); m_volumeIconMin->setFixedSize(ICON_SIZE, ICON_SIZE); - m_volumeIconMin->setIconSize(QSize(ICON_SIZE, ICON_SIZE)); - m_volumeIconMin->setFlat(true); m_volumeIconMax->setFixedSize(ICON_SIZE, ICON_SIZE); m_soundShow->setText(QString("%1%").arg(0)); m_soundShow->setFixedHeight(TITLE_HEIGHT); m_soundShow->setForegroundRole(QPalette::BrightText); - DFontSizeManager::instance()->bind(m_soundShow, DFontSizeManager::T4, QFont::Medium); + DFontSizeManager::instance()->bind(m_soundShow, DFontSizeManager::T8, QFont::Medium); m_deviceLabel->setText(tr("Device")); m_deviceLabel->setFixedHeight(TITLE_HEIGHT); @@ -204,6 +204,7 @@ void SoundApplet::initUi() setFixedWidth(WIDTH); setWidget(m_centralWidget); + setContentsMargins(0, 0, 0, 0); setFrameShape(QFrame::NoFrame); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -219,9 +220,6 @@ void SoundApplet::initUi() updateVolumeSliderStatus(m_gsettings->get(GSETTING_SOUND_OUTPUT_SLIDER).toString()); } }); - connect(m_volumeIconMin, &DIconButton::clicked, this, [ = ] { - m_defSinkInter->SetMuteQueued(!m_defSinkInter->mute()); - }); connect(qApp, &QGuiApplication::fontChanged, this, &SoundApplet::updateListHeight); connect(m_volumeSlider, &VolumeSlider::valueChanged, this, &SoundApplet::volumeSliderValueChanged); connect(m_audioInter, &DBusAudio::DefaultSinkChanged, this, &SoundApplet::onDefaultSinkChanged); @@ -409,20 +407,20 @@ void SoundApplet::refreshIcon() color = Qt::white; break; } - // setControlBackground(); + //主题改变时,同步修改item颜色 for (int i = 0; i < m_model->rowCount(); i++) { auto item = m_model->item(i); item->setForeground(color); item->setBackground(Qt::transparent); } - // setItemHoverColor(); + const auto ratio = devicePixelRatioF(); QPixmap ret = ImageUtil::loadSvg(iconRight, ":/", ICON_SIZE, ratio); m_volumeIconMax->setPixmap(ret); ret = ImageUtil::loadSvg(iconLeft, ":/", ICON_SIZE, ratio); - m_volumeIconMin->setIcon(ret); + m_volumeIconMin->setPixmap(ret); } /** @@ -620,6 +618,14 @@ void SoundApplet::updateVolumeSliderStatus(const QString &status) m_volumeIconMax->setVisible(flag); } +bool SoundApplet::eventFilter(QObject *watcher, QEvent *event) +{ + if (watcher == m_volumeIconMin && event->type() == QEvent::MouseButtonRelease) { + m_defSinkInter->SetMuteQueued(!m_defSinkInter->mute()); + } + return false; +} + void SoundApplet::haldleDbusSignal(const QDBusMessage &msg) { Q_UNUSED(msg) @@ -630,7 +636,7 @@ void SoundApplet::haldleDbusSignal(const QDBusMessage &msg) void SoundApplet::updateListHeight() { //设备数多于10个时显示滚动条,固定高度 - int count = m_model->rowCount(); + int count = m_model->rowCount() == 1 ? 0 : m_model->rowCount(); if (m_model->rowCount() > 10) { count = 10; @@ -640,7 +646,7 @@ void SoundApplet::updateListHeight() } int visualHeight = 0; - for (int i = 1; i < count; i++) + for (int i = 0; i < count; i++) visualHeight += m_listView->visualRect(m_model->index(i, 0)).height(); int listMargin = m_listView->contentsMargins().top() + m_listView->contentsMargins().bottom(); @@ -648,7 +654,7 @@ void SoundApplet::updateListHeight() int viewHeight = visualHeight + m_listView->spacing() * (count - 1) + listMargin; // 设备信息高度 = 设备标签 + 分隔线 + 滚动条 + 间隔 int labelHeight = m_deviceLabel->height() > m_soundShow->height() ? m_deviceLabel->height() : m_soundShow->height(); - int infoHeight = labelHeight + m_seperator->height() + m_volumeSlider->height() + m_centralLayout->spacing() * 3 + DEVICE_SPACING; + int infoHeight = labelHeight + m_seperator->height() * 2 + m_volumeSlider->height(); int margain = m_centralLayout->contentsMargins().top() + m_centralLayout->contentsMargins().bottom(); //整个界面高度 = 显示声音设备列表高度 + 设备信息高度 + 边距 int totalHeight = viewHeight + infoHeight + margain; diff --git a/plugins/sound/soundapplet.h b/plugins/sound/soundapplet.h index 98a78b4b0..890cbf55f 100644 --- a/plugins/sound/soundapplet.h +++ b/plugins/sound/soundapplet.h @@ -110,8 +110,6 @@ public: Port *findPort(const QString &portId, const uint &cardId) const; void setUnchecked(DStandardItem *pi); void initUi(); -// void setItemHoverColor(); -// void setControlBackground(); signals: void volumeChanged(const int value) const; @@ -139,9 +137,12 @@ private: void removeDisabledDevice(QString portId, unsigned int cardId); void updateVolumeSliderStatus(const QString &status); +protected: + bool eventFilter(QObject *watcher, QEvent *event) override; + private: QWidget *m_centralWidget; - DIconButton *m_volumeIconMin; + QLabel *m_volumeIconMin; QLabel *m_volumeIconMax; VolumeSlider *m_volumeSlider; QLabel *m_soundShow;