mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
add volume slider
Change-Id: I555868d683b568e4ada83d9839ebfd2f7b01ad11
This commit is contained in:
parent
4944079076
commit
774c52c3f3
Notes:
Deepin Code Review
2016-08-02 09:44:05 +00:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Tue, 02 Aug 2016 09:44:05 +0000 Reviewed-on: https://cr.deepin.io/14864 Project: dde/dde-dock Branch: refs/heads/master
@ -126,10 +126,10 @@ public Q_SLOTS: // METHODS
|
||||
return asyncCallWithArgumentList(QStringLiteral("SetPort"), argumentList);
|
||||
}
|
||||
|
||||
inline QDBusPendingReply<> SetVolume(double in0, bool in1)
|
||||
inline QDBusPendingReply<> SetVolume(double volume, bool feedBack)
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
argumentList << QVariant::fromValue(in0) << QVariant::fromValue(in1);
|
||||
argumentList << QVariant::fromValue(volume) << QVariant::fromValue(feedBack);
|
||||
return asyncCallWithArgumentList(QStringLiteral("SetVolume"), argumentList);
|
||||
}
|
||||
|
||||
|
18
plugins/sound/horizontalseparator.cpp
Normal file
18
plugins/sound/horizontalseparator.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "horizontalseparator.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
HorizontalSeparator::HorizontalSeparator(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setFixedHeight(1);
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
}
|
||||
|
||||
void HorizontalSeparator::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QWidget::paintEvent(e);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.fillRect(rect(), QColor(255, 255, 255, 255 * 0.5));
|
||||
}
|
17
plugins/sound/horizontalseparator.h
Normal file
17
plugins/sound/horizontalseparator.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef HORIZONTALSEPARATOR_H
|
||||
#define HORIZONTALSEPARATOR_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class HorizontalSeparator : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit HorizontalSeparator(QWidget *parent = 0);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
};
|
||||
|
||||
#endif // HORIZONTALSEPARATOR_H
|
@ -15,14 +15,16 @@ HEADERS += \
|
||||
sounditem.h \
|
||||
soundapplet.h \
|
||||
dbus/dbusaudio.h \
|
||||
dbus/dbussink.h
|
||||
dbus/dbussink.h \
|
||||
horizontalseparator.h
|
||||
|
||||
SOURCES += \
|
||||
soundplugin.cpp \
|
||||
sounditem.cpp \
|
||||
soundapplet.cpp \
|
||||
dbus/dbusaudio.cpp \
|
||||
dbus/dbussink.cpp
|
||||
dbus/dbussink.cpp \
|
||||
horizontalseparator.cpp
|
||||
|
||||
target.path = $${PREFIX}/lib/dde-dock/plugins/
|
||||
INSTALLS += target
|
||||
|
@ -1,16 +1,67 @@
|
||||
#include "soundapplet.h"
|
||||
#include "horizontalseparator.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QIcon>
|
||||
|
||||
#define WIDTH 200
|
||||
#define ICON_SIZE 24
|
||||
|
||||
SoundApplet::SoundApplet(QWidget *parent)
|
||||
: QScrollArea(parent),
|
||||
|
||||
m_centeralWidget(new QWidget(this)),
|
||||
m_centeralWidget(new QWidget),
|
||||
m_appControlWidget(new QWidget),
|
||||
m_volumeIcon(new QLabel),
|
||||
m_volumeSlider(new QSlider(Qt::Horizontal)),
|
||||
|
||||
m_audioInter(new DBusAudio(this)),
|
||||
m_defSinkInter(nullptr)
|
||||
{
|
||||
QIcon::setThemeName("deepin");
|
||||
|
||||
QLabel *deviceLabel = new QLabel;
|
||||
deviceLabel->setText(tr("Device"));
|
||||
deviceLabel->setStyleSheet("color:white;");
|
||||
|
||||
QHBoxLayout *deviceLineLayout = new QHBoxLayout;
|
||||
deviceLineLayout->addWidget(deviceLabel);
|
||||
deviceLineLayout->addWidget(new HorizontalSeparator);
|
||||
deviceLineLayout->setMargin(0);
|
||||
deviceLineLayout->setSpacing(10);
|
||||
|
||||
QHBoxLayout *volumeCtrlLayout = new QHBoxLayout;
|
||||
volumeCtrlLayout->addWidget(m_volumeIcon);
|
||||
volumeCtrlLayout->addWidget(m_volumeSlider);
|
||||
volumeCtrlLayout->setSpacing(0);
|
||||
volumeCtrlLayout->setMargin(0);
|
||||
|
||||
QLabel *appLabel = new QLabel;
|
||||
appLabel->setText(tr("Application"));
|
||||
appLabel->setStyleSheet("color:white;");
|
||||
|
||||
QHBoxLayout *appLineLayout = new QHBoxLayout;
|
||||
appLineLayout->addWidget(appLabel);
|
||||
appLineLayout->addWidget(new HorizontalSeparator);
|
||||
appLineLayout->setMargin(0);
|
||||
appLineLayout->setSpacing(10);
|
||||
|
||||
QVBoxLayout *appLayout = new QVBoxLayout;
|
||||
appLayout->addLayout(appLineLayout);
|
||||
appLayout->setSpacing(0);
|
||||
appLayout->setMargin(0);
|
||||
|
||||
m_volumeIcon->setFixedSize(ICON_SIZE, ICON_SIZE);
|
||||
m_volumeSlider->setMinimum(0);
|
||||
m_volumeSlider->setMaximum(100);
|
||||
|
||||
m_appControlWidget->setLayout(appLayout);
|
||||
|
||||
m_centeralLayout = new QVBoxLayout;
|
||||
m_centeralLayout->addLayout(deviceLineLayout);
|
||||
m_centeralLayout->addLayout(volumeCtrlLayout);
|
||||
m_centeralLayout->addWidget(m_appControlWidget);
|
||||
|
||||
m_centeralWidget->setLayout(m_centeralLayout);
|
||||
m_centeralWidget->setFixedWidth(WIDTH);
|
||||
|
||||
@ -21,6 +72,9 @@ SoundApplet::SoundApplet(QWidget *parent)
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setStyleSheet("background-color:transparent;");
|
||||
|
||||
connect(m_volumeSlider, &QSlider::valueChanged, this, &SoundApplet::volumeSliderValueChanged);
|
||||
connect(this, static_cast<void (SoundApplet::*)(DBusSink*) const>(&SoundApplet::defaultSinkChanged), this, &SoundApplet::onVolumeChanged);
|
||||
|
||||
QMetaObject::invokeMethod(this, "defaultSinkChanged", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
@ -31,5 +85,36 @@ void SoundApplet::defaultSinkChanged()
|
||||
const QDBusObjectPath defSinkPath = m_audioInter->GetDefaultSink();
|
||||
m_defSinkInter = new DBusSink(defSinkPath.path(), this);
|
||||
|
||||
connect(m_defSinkInter, &DBusSink::VolumeChanged, this, &SoundApplet::onVolumeChanged);
|
||||
connect(m_defSinkInter, &DBusSink::MuteChanged, this, &SoundApplet::onVolumeChanged);
|
||||
|
||||
emit defaultSinkChanged(m_defSinkInter);
|
||||
}
|
||||
|
||||
void SoundApplet::onVolumeChanged()
|
||||
{
|
||||
const bool mute = m_defSinkInter->mute();
|
||||
const double volmue = m_defSinkInter->volume();
|
||||
|
||||
m_volumeSlider->blockSignals(true);
|
||||
m_volumeSlider->setValue(std::min(100.0, volmue * 100));
|
||||
m_volumeSlider->blockSignals(false);
|
||||
|
||||
QString volumeString;
|
||||
if (mute)
|
||||
volumeString = "muted";
|
||||
else if (volmue >= double(2)/3)
|
||||
volumeString = "high";
|
||||
else if (volmue >= double(1)/3)
|
||||
volumeString = "medium";
|
||||
else
|
||||
volumeString = "low";
|
||||
|
||||
const QString iconString = QString("audio-volume-%1-symbolic").arg(volumeString);
|
||||
m_volumeIcon->setPixmap(QIcon::fromTheme(iconString).pixmap(ICON_SIZE, ICON_SIZE));
|
||||
}
|
||||
|
||||
void SoundApplet::volumeSliderValueChanged()
|
||||
{
|
||||
m_defSinkInter->SetVolume(double(m_volumeSlider->value()) / 100 + 0.5, false);
|
||||
}
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
#include <QScrollArea>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QSlider>
|
||||
|
||||
class SoundApplet : public QScrollArea
|
||||
{
|
||||
@ -19,9 +21,14 @@ signals:
|
||||
|
||||
private slots:
|
||||
void defaultSinkChanged();
|
||||
void onVolumeChanged();
|
||||
void volumeSliderValueChanged();
|
||||
|
||||
private:
|
||||
QWidget *m_centeralWidget;
|
||||
QWidget *m_appControlWidget;
|
||||
QLabel *m_volumeIcon;
|
||||
QSlider *m_volumeSlider;
|
||||
QVBoxLayout *m_centeralLayout;
|
||||
|
||||
DBusAudio *m_audioInter;
|
||||
|
Loading…
x
Reference in New Issue
Block a user