sound plugin add slider

Change-Id: I41bc596be98d8f0a668e11bdf245d93af29fbb04
This commit is contained in:
石博文 2016-08-02 20:14:45 +08:00
parent be48f09677
commit 05b2fc9c8b
Notes: Deepin Code Review 2016-08-02 12:18:13 +00:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: 石博文 <sbw@sbw.so>
Submitted-by: 石博文 <sbw@sbw.so>
Submitted-at: Tue, 02 Aug 2016 12:18:13 +0000
Reviewed-on: https://cr.deepin.io/14868
Project: dde/dde-dock
Branch: refs/heads/master
11 changed files with 97 additions and 23 deletions

View File

@ -38,7 +38,7 @@ void DatetimePlugin::init(PluginProxyInterface *proxyInter)
m_proxyInter->itemAdded(this, QString());
}
int DatetimePlugin::itemSortKey(const QString &itemKey) const
int DatetimePlugin::itemSortKey(const QString &itemKey)
{
Q_UNUSED(itemKey);

View File

@ -17,15 +17,15 @@ public:
explicit DatetimePlugin(QObject *parent = 0);
~DatetimePlugin();
const QString pluginName() const;
void init(PluginProxyInterface *proxyInter);
const QString pluginName() const override;
void init(PluginProxyInterface *proxyInter) override;
int itemSortKey(const QString &itemKey) const;
int itemSortKey(const QString &itemKey) override;
QWidget *itemWidget(const QString &itemKey);
QWidget *itemTipsWidget(const QString &itemKey);
QWidget *itemWidget(const QString &itemKey) override;
QWidget *itemTipsWidget(const QString &itemKey) override;
const QString itemCommand(const QString &itemKey);
const QString itemCommand(const QString &itemKey) override;
private slots:
void updateCurrentTimeString();

View File

@ -0,0 +1,50 @@
#include "volumeslider.h"
#include <QMouseEvent>
#include <QDebug>
#include <QTimer>
VolumeSlider::VolumeSlider(QWidget *parent)
: QSlider(Qt::Horizontal, parent),
m_pressed(false)
{
setTickInterval(50);
setPageStep(50);
setTickPosition(QSlider::NoTicks);
}
void VolumeSlider::setValue(const int value)
{
if (m_pressed)
return;
blockSignals(true);
QSlider::setValue(value);
blockSignals(false);
}
void VolumeSlider::mousePressEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton)
{
if (!rect().contains(e->pos()))
return;
m_pressed = true;
QSlider::setValue(minimum() + (double((maximum()) - minimum()) * e->x() / rect().width()));
}
}
void VolumeSlider::mouseMoveEvent(QMouseEvent *e)
{
const int value = minimum() + (double((maximum()) - minimum()) * e->x() / rect().width());
QSlider::setValue(std::max(std::min(1000, value), 0));
emit valueChanged(std::max(std::min(1000, value), 0));
}
void VolumeSlider::mouseReleaseEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton)
m_pressed = false;
// QTimer::singleShot(100, [this] {m_pressed = false;});
}

View File

@ -0,0 +1,24 @@
#ifndef VOLUMESLIDER_H
#define VOLUMESLIDER_H
#include <QSlider>
class VolumeSlider : public QSlider
{
Q_OBJECT
public:
explicit VolumeSlider(QWidget *parent = 0);
void setValue(const int value);
protected:
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
private:
bool m_pressed;
};
#endif // VOLUMESLIDER_H

View File

@ -16,7 +16,8 @@ HEADERS += \
soundapplet.h \
dbus/dbusaudio.h \
dbus/dbussink.h \
horizontalseparator.h
componments/horizontalseparator.h \
componments/volumeslider.h
SOURCES += \
soundplugin.cpp \
@ -24,7 +25,8 @@ SOURCES += \
soundapplet.cpp \
dbus/dbusaudio.cpp \
dbus/dbussink.cpp \
horizontalseparator.cpp
componments/horizontalseparator.cpp \
componments/volumeslider.cpp
target.path = $${PREFIX}/lib/dde-dock/plugins/
INSTALLS += target

View File

@ -1,5 +1,5 @@
#include "soundapplet.h"
#include "horizontalseparator.h"
#include "componments/horizontalseparator.h"
#include <QLabel>
#include <QIcon>
@ -13,7 +13,7 @@ SoundApplet::SoundApplet(QWidget *parent)
m_centeralWidget(new QWidget),
m_appControlWidget(new QWidget),
m_volumeIcon(new QLabel),
m_volumeSlider(new QSlider(Qt::Horizontal)),
m_volumeSlider(new VolumeSlider),
m_audioInter(new DBusAudio(this)),
m_defSinkInter(nullptr)
@ -53,7 +53,7 @@ SoundApplet::SoundApplet(QWidget *parent)
m_volumeIcon->setFixedSize(ICON_SIZE, ICON_SIZE);
m_volumeSlider->setMinimum(0);
m_volumeSlider->setMaximum(100);
m_volumeSlider->setMaximum(1000);
m_appControlWidget->setLayout(appLayout);
@ -72,7 +72,7 @@ SoundApplet::SoundApplet(QWidget *parent)
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setStyleSheet("background-color:transparent;");
connect(m_volumeSlider, &QSlider::valueChanged, this, &SoundApplet::volumeSliderValueChanged);
connect(m_volumeSlider, &VolumeSlider::valueChanged, this, &SoundApplet::volumeSliderValueChanged);
connect(this, static_cast<void (SoundApplet::*)(DBusSink*) const>(&SoundApplet::defaultSinkChanged), this, &SoundApplet::onVolumeChanged);
QMetaObject::invokeMethod(this, "defaultSinkChanged", Qt::QueuedConnection);
@ -93,12 +93,10 @@ void SoundApplet::defaultSinkChanged()
void SoundApplet::onVolumeChanged()
{
const bool mute = m_defSinkInter->mute();
const double volmue = m_defSinkInter->volume();
const bool mute = m_defSinkInter->mute() || volmue < 0.001;
m_volumeSlider->blockSignals(true);
m_volumeSlider->setValue(std::min(100.0, volmue * 100));
m_volumeSlider->blockSignals(false);
m_volumeSlider->setValue(std::min(1000.0, volmue * 1000));
QString volumeString;
if (mute)
@ -116,5 +114,5 @@ void SoundApplet::onVolumeChanged()
void SoundApplet::volumeSliderValueChanged()
{
m_defSinkInter->SetVolume(double(m_volumeSlider->value()) / 100 + 0.5, false);
m_defSinkInter->SetVolume(double(m_volumeSlider->value()) / 1000, false);
}

View File

@ -1,6 +1,7 @@
#ifndef SOUNDAPPLET_H
#define SOUNDAPPLET_H
#include "componments/volumeslider.h"
#include "dbus/dbusaudio.h"
#include "dbus/dbussink.h"
@ -28,7 +29,7 @@ private:
QWidget *m_centeralWidget;
QWidget *m_appControlWidget;
QLabel *m_volumeIcon;
QSlider *m_volumeSlider;
VolumeSlider *m_volumeSlider;
QVBoxLayout *m_centeralLayout;
DBusAudio *m_audioInter;

View File

@ -48,16 +48,15 @@ void SoundItem::refershIcon()
return;
const double volmue = m_sinkInter->volume();
const bool mute = m_sinkInter->mute();
const bool mute = m_sinkInter->mute() || volmue < 0.001;
const Dock::DisplayMode displayMode = qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>();
QString iconString;
if (displayMode == Dock::Fashion)
{
QString volumeString;
if (volmue >= 1.0)
volumeString = "010";
volumeString = "100";
else
volumeString = QString("0") + ('0' + int(volmue * 10)) + "0";

View File

@ -56,7 +56,7 @@ void PopupControlWidget::clearTrashFloder()
if (item.isFile())
QFile(item.fileName()).remove();
else if (item.isDir())
QDir(item.path()).removeRecursively();
QDir(item.absoluteFilePath()).removeRecursively();
}
}