mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
fix: 任务栏音量拖到最右边概率性显示不是100%
refreshTips更新音量的时候也会调用DBus里的当前音量,这里直接修改为显示从后端volumeChanged信号传过来的音量值.优化一部分函数 Log: 任务栏音量拖到最右边概率性显示不是100% Bug: https://pms.uniontech.com/zentao/bug-view-52597.html Change-Id: I7267de814acd3e18e0df6526afadae1f34cbb47c
This commit is contained in:
parent
c699611d45
commit
cb26ec23bf
@ -257,7 +257,9 @@ void SoundApplet::defaultSinkChanged()
|
||||
m_defSinkInter = new DBusSink("com.deepin.daemon.Audio", defSinkPath.path(), QDBusConnection::sessionBus(), this);
|
||||
|
||||
connect(m_defSinkInter, &DBusSink::VolumeChanged, this, &SoundApplet::onVolumeChanged);
|
||||
connect(m_defSinkInter, &DBusSink::MuteChanged, this, &SoundApplet::onVolumeChanged);
|
||||
connect(m_defSinkInter, &DBusSink::MuteChanged, this, [ = ] {
|
||||
onVolumeChanged(m_defSinkInter->volume());
|
||||
});
|
||||
|
||||
QString portId = m_defSinkInter->activePort().name;
|
||||
uint cardId = m_defSinkInter->card();
|
||||
|
@ -56,7 +56,7 @@ SoundItem::SoundItem(QWidget *parent)
|
||||
m_applet->setVisible(false);
|
||||
|
||||
connect(m_applet, static_cast<void (SoundApplet::*)(DBusSink *) const>(&SoundApplet::defaultSinkChanged), this, &SoundItem::sinkChanged);
|
||||
connect(m_applet, &SoundApplet::volumeChanged, this, &SoundItem::refreshTips, Qt::QueuedConnection);
|
||||
connect(m_applet, &SoundApplet::volumeChanged, this, &SoundItem::refresh, Qt::QueuedConnection);
|
||||
|
||||
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [ = ] {
|
||||
refreshIcon();
|
||||
@ -65,7 +65,7 @@ SoundItem::SoundItem(QWidget *parent)
|
||||
|
||||
QWidget *SoundItem::tipsWidget()
|
||||
{
|
||||
refreshTips(true);
|
||||
refreshTips(m_applet->volumeValue(), true);
|
||||
|
||||
m_tipsLabel->resize(m_tipsLabel->sizeHint().width() + 10,
|
||||
m_tipsLabel->sizeHint().height());
|
||||
@ -163,6 +163,12 @@ void SoundItem::paintEvent(QPaintEvent *e)
|
||||
painter.drawPixmap(rf.center() - rfp.center() / m_iconPixmap.devicePixelRatioF(), m_iconPixmap);
|
||||
}
|
||||
|
||||
void SoundItem::refresh(const int volume)
|
||||
{
|
||||
refreshIcon();
|
||||
refreshTips(volume, false);
|
||||
}
|
||||
|
||||
void SoundItem::refreshIcon()
|
||||
{
|
||||
if (!m_sinkInter)
|
||||
@ -211,31 +217,21 @@ void SoundItem::refreshIcon()
|
||||
update();
|
||||
}
|
||||
|
||||
void SoundItem::refreshTips(const bool force)
|
||||
void SoundItem::refreshTips(const int volume, const bool force)
|
||||
{
|
||||
if (!force && !m_tipsLabel->isVisible())
|
||||
return;
|
||||
|
||||
if (!m_sinkInter)
|
||||
return;
|
||||
|
||||
QString value;
|
||||
if (m_sinkInter->mute()) {
|
||||
m_tipsLabel->setText(QString(tr("Mute")));
|
||||
} else {
|
||||
if (m_sinkInter->volume() * 1000 < m_applet->volumeValue())
|
||||
value = QString::number(m_applet->volumeValue() / 10) + '%';
|
||||
else
|
||||
value = QString::number(m_sinkInter->volume() * 100) + '%';
|
||||
m_tipsLabel->setText(QString(tr("Volume %1").arg(value)));
|
||||
m_tipsLabel->setText(QString(tr("Volume %1").arg(QString::number(volume) + '%')));
|
||||
}
|
||||
}
|
||||
|
||||
void SoundItem::sinkChanged(DBusSink *sink)
|
||||
{
|
||||
m_sinkInter = sink;
|
||||
|
||||
connect(m_sinkInter, &DBusSink::MuteChanged, this, &SoundItem::refreshIcon);
|
||||
connect(m_sinkInter, &DBusSink::VolumeChanged, this, &SoundItem::refreshIcon);
|
||||
refreshIcon();
|
||||
refresh(m_applet->volumeValue());
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ public:
|
||||
void invokeMenuItem(const QString menuId, const bool checked);
|
||||
|
||||
void refreshIcon();
|
||||
void refreshTips(const int volume, const bool force = false);
|
||||
|
||||
signals:
|
||||
void requestContextMenu() const;
|
||||
@ -59,8 +60,8 @@ protected:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
|
||||
private slots:
|
||||
void refreshTips(const bool force = false);
|
||||
void sinkChanged(DBusSink *sink);
|
||||
void refresh(const int volume);
|
||||
|
||||
private:
|
||||
Dock::TipsWidget *m_tipsLabel;
|
||||
|
Loading…
x
Reference in New Issue
Block a user