fix sound tip

Change-Id: I25683d0866eaa6c38837ba53c7f49c5de44e451d
This commit is contained in:
kirigayakazushin 2016-11-04 17:34:48 +08:00
parent 14952c45ed
commit f2bc0f8868
Notes: Deepin Code Review 2016-11-08 11:16:11 +08:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: 石博文 <sbw@sbw.so>
Submitted-by: 石博文 <sbw@sbw.so>
Submitted-at: Tue, 08 Nov 2016 11:16:03 +0800
Reviewed-on: https://cr.deepin.io/17269
Project: dde/dde-dock
Branch: refs/heads/master

View File

@ -20,10 +20,11 @@ SoundItem::SoundItem(QWidget *parent)
m_tipsLabel->setObjectName("sound"); m_tipsLabel->setObjectName("sound");
m_tipsLabel->setVisible(false); m_tipsLabel->setVisible(false);
// m_tipsLabel->setFixedWidth(145); // m_tipsLabel->setFixedWidth(145);
m_tipsLabel->setAlignment(Qt::AlignCenter); m_tipsLabel->setAlignment(Qt::AlignCenter);
m_tipsLabel->setStyleSheet("color:white;" m_tipsLabel->setStyleSheet("color:white;"
"padding:5px 10px;"); "padding:5px 10px;"
"margin:0px 10px 0px");
m_applet->setVisible(false); m_applet->setVisible(false);
@ -35,7 +36,7 @@ QWidget *SoundItem::tipsWidget()
{ {
refershTips(true); refershTips(true);
m_tipsLabel->setFixedWidth(m_tipsLabel->sizeHint().width() + 10); m_tipsLabel->setFixedWidth(m_tipsLabel->sizeHint().width());
return m_tipsLabel; return m_tipsLabel;
} }
@ -137,33 +138,33 @@ void SoundItem::refershIcon()
QString iconString; QString iconString;
if (displayMode == Dock::Fashion) if (displayMode == Dock::Fashion)
{ {
QString volumeString; QString volumeString;
if (volmue >= 1.0) if (volmue >= 1.0)
volumeString = "100"; volumeString = "100";
else else
volumeString = QString("0") + ('0' + int(volmue * 10)) + "0"; volumeString = QString("0") + ('0' + int(volmue * 10)) + "0";
iconString = "audio-volume-" + volumeString + (mute ? "-muted" : ""); iconString = "audio-volume-" + volumeString + (mute ? "-muted" : "");
} else { } else {
QString volumeString; QString volumeString;
if (mute) if (mute)
volumeString = "muted"; volumeString = "muted";
else if (volmue >= double(2)/3) else if (volmue >= double(2)/3)
volumeString = "high"; volumeString = "high";
else if (volmue >= double(1)/3) else if (volmue >= double(1)/3)
volumeString = "medium"; volumeString = "medium";
else else
volumeString = "low"; volumeString = "low";
iconString = QString("audio-volume-%1-symbolic").arg(volumeString); iconString = QString("audio-volume-%1-symbolic").arg(volumeString);
} }
const int iconSize = displayMode == Dock::Fashion ? std::min(width(), height()) * 0.8 : 16; const int iconSize = displayMode == Dock::Fashion ? std::min(width(), height()) * 0.8 : 16;
const QIcon icon = QIcon::fromTheme(iconString); const QIcon icon = QIcon::fromTheme(iconString);
m_iconPixmap = icon.pixmap(iconSize, iconSize); m_iconPixmap = icon.pixmap(iconSize, iconSize);
update(); update();
} }
void SoundItem::refershTips(const bool force) void SoundItem::refershTips(const bool force)
@ -171,7 +172,15 @@ void SoundItem::refershTips(const bool force)
if (!force && !m_tipsLabel->isVisible()) if (!force && !m_tipsLabel->isVisible())
return; return;
const QString value = QString::number(m_applet->volumeValue() / 10) + '%'; if(!m_sinkInter)
return;
QString value;
if (m_sinkInter->mute()) {
value = QString("0") + '%';
} else {
value = QString::number(m_applet->volumeValue() / 10) + '%';
}
m_tipsLabel->setText(QString(tr("Current Volume %1").arg(value))); m_tipsLabel->setText(QString(tr("Current Volume %1").arg(value)));
} }