mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
add sound value tips
Change-Id: I085ae10f6c3fc85d032a89d5cef3e4caa7a36bb4
This commit is contained in:
parent
6c2734f62d
commit
2d0bae7b2c
Notes:
Deepin Code Review
2016-08-26 02:25:52 +00:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Fri, 26 Aug 2016 02:25:52 +0000 Reviewed-on: https://cr.deepin.io/15565 Project: dde/dde-dock Branch: refs/heads/master
@ -93,6 +93,11 @@ SoundApplet::SoundApplet(QWidget *parent)
|
||||
QMetaObject::invokeMethod(this, "sinkInputsChanged", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
int SoundApplet::volumeValue() const
|
||||
{
|
||||
return m_volumeSlider->value();
|
||||
}
|
||||
|
||||
void SoundApplet::defaultSinkChanged()
|
||||
{
|
||||
delete m_defSinkInter;
|
||||
@ -109,9 +114,10 @@ void SoundApplet::defaultSinkChanged()
|
||||
void SoundApplet::onVolumeChanged()
|
||||
{
|
||||
const double volmue = m_defSinkInter->volume();
|
||||
const bool mute = m_defSinkInter->mute() || volmue < 0.001;
|
||||
const bool mute = m_defSinkInter->mute();
|
||||
|
||||
m_volumeSlider->setValue(std::min(1000.0, volmue * 1000));
|
||||
emit volumeChanegd(m_volumeSlider->value());
|
||||
|
||||
QString volumeString;
|
||||
if (mute)
|
||||
@ -128,6 +134,7 @@ void SoundApplet::onVolumeChanged()
|
||||
|
||||
void SoundApplet::volumeSliderValueChanged()
|
||||
{
|
||||
m_defSinkInter->SetMute(false);
|
||||
m_defSinkInter->SetVolume(double(m_volumeSlider->value()) / 1000, false);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,10 @@ class SoundApplet : public QScrollArea
|
||||
public:
|
||||
explicit SoundApplet(QWidget *parent = 0);
|
||||
|
||||
int volumeValue() const;
|
||||
|
||||
signals:
|
||||
void volumeChanegd(const int value) const;
|
||||
void defaultSinkChanged(DBusSink *sink) const;
|
||||
|
||||
private slots:
|
||||
|
@ -8,14 +8,29 @@
|
||||
SoundItem::SoundItem(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
|
||||
m_tipsLabel(new QLabel(this)),
|
||||
m_applet(new SoundApplet(this)),
|
||||
m_sinkInter(nullptr)
|
||||
{
|
||||
QIcon::setThemeName("deepin");
|
||||
|
||||
m_tipsLabel->setVisible(false);
|
||||
m_tipsLabel->setFixedWidth(60);
|
||||
m_tipsLabel->setAlignment(Qt::AlignCenter);
|
||||
m_tipsLabel->setStyleSheet("color:white;"
|
||||
"padding:5px 10px;");
|
||||
|
||||
m_applet->setVisible(false);
|
||||
|
||||
connect(m_applet, static_cast<void (SoundApplet::*)(DBusSink*) const>(&SoundApplet::defaultSinkChanged), this, &SoundItem::sinkChanged);
|
||||
connect(m_applet, &SoundApplet::volumeChanegd, this, &SoundItem::refershTips);
|
||||
}
|
||||
|
||||
QWidget *SoundItem::tipsWidget()
|
||||
{
|
||||
refershTips(true);
|
||||
|
||||
return m_tipsLabel;
|
||||
}
|
||||
|
||||
QWidget *SoundItem::popupApplet()
|
||||
@ -61,7 +76,7 @@ void SoundItem::refershIcon()
|
||||
return;
|
||||
|
||||
const double volmue = m_sinkInter->volume();
|
||||
const bool mute = m_sinkInter->mute() || volmue < 0.001;
|
||||
const bool mute = m_sinkInter->mute();
|
||||
const Dock::DisplayMode displayMode = qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>();
|
||||
|
||||
QString iconString;
|
||||
@ -95,6 +110,14 @@ void SoundItem::refershIcon()
|
||||
update();
|
||||
}
|
||||
|
||||
void SoundItem::refershTips(const bool force)
|
||||
{
|
||||
if (!force && !m_tipsLabel->isVisible())
|
||||
return;
|
||||
|
||||
m_tipsLabel->setText(QString::number(m_applet->volumeValue() / 10) + '%');
|
||||
}
|
||||
|
||||
void SoundItem::sinkChanged(DBusSink *sink)
|
||||
{
|
||||
m_sinkInter = sink;
|
||||
|
@ -13,6 +13,7 @@ class SoundItem : public QWidget
|
||||
public:
|
||||
explicit SoundItem(QWidget *parent = 0);
|
||||
|
||||
QWidget *tipsWidget();
|
||||
QWidget *popupApplet();
|
||||
|
||||
protected:
|
||||
@ -23,9 +24,11 @@ protected:
|
||||
|
||||
private slots:
|
||||
void refershIcon();
|
||||
void refershTips(const bool force = false);
|
||||
void sinkChanged(DBusSink *sink);
|
||||
|
||||
private:
|
||||
QLabel *m_tipsLabel;
|
||||
SoundApplet *m_applet;
|
||||
DBusSink *m_sinkInter;
|
||||
QPixmap m_iconPixmap;
|
||||
|
@ -27,6 +27,13 @@ QWidget *SoundPlugin::itemWidget(const QString &itemKey)
|
||||
return m_soundItem;
|
||||
}
|
||||
|
||||
QWidget *SoundPlugin::itemTipsWidget(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return m_soundItem->tipsWidget();
|
||||
}
|
||||
|
||||
QWidget *SoundPlugin::itemPopupApplet(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
@ -19,6 +19,7 @@ public:
|
||||
void init(PluginProxyInterface *proxyInter);
|
||||
|
||||
QWidget *itemWidget(const QString &itemKey);
|
||||
QWidget *itemTipsWidget(const QString &itemKey);
|
||||
QWidget *itemPopupApplet(const QString &itemKey);
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user