mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
sound plugin add slider
Change-Id: I41bc596be98d8f0a668e11bdf245d93af29fbb04
This commit is contained in:
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
@ -38,7 +38,7 @@ void DatetimePlugin::init(PluginProxyInterface *proxyInter)
|
|||||||
m_proxyInter->itemAdded(this, QString());
|
m_proxyInter->itemAdded(this, QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
int DatetimePlugin::itemSortKey(const QString &itemKey) const
|
int DatetimePlugin::itemSortKey(const QString &itemKey)
|
||||||
{
|
{
|
||||||
Q_UNUSED(itemKey);
|
Q_UNUSED(itemKey);
|
||||||
|
|
||||||
|
@ -17,15 +17,15 @@ public:
|
|||||||
explicit DatetimePlugin(QObject *parent = 0);
|
explicit DatetimePlugin(QObject *parent = 0);
|
||||||
~DatetimePlugin();
|
~DatetimePlugin();
|
||||||
|
|
||||||
const QString pluginName() const;
|
const QString pluginName() const override;
|
||||||
void init(PluginProxyInterface *proxyInter);
|
void init(PluginProxyInterface *proxyInter) override;
|
||||||
|
|
||||||
int itemSortKey(const QString &itemKey) const;
|
int itemSortKey(const QString &itemKey) override;
|
||||||
|
|
||||||
QWidget *itemWidget(const QString &itemKey);
|
QWidget *itemWidget(const QString &itemKey) override;
|
||||||
QWidget *itemTipsWidget(const QString &itemKey);
|
QWidget *itemTipsWidget(const QString &itemKey) override;
|
||||||
|
|
||||||
const QString itemCommand(const QString &itemKey);
|
const QString itemCommand(const QString &itemKey) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateCurrentTimeString();
|
void updateCurrentTimeString();
|
||||||
|
50
plugins/sound/componments/volumeslider.cpp
Normal file
50
plugins/sound/componments/volumeslider.cpp
Normal 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;});
|
||||||
|
}
|
24
plugins/sound/componments/volumeslider.h
Normal file
24
plugins/sound/componments/volumeslider.h
Normal 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
|
@ -16,7 +16,8 @@ HEADERS += \
|
|||||||
soundapplet.h \
|
soundapplet.h \
|
||||||
dbus/dbusaudio.h \
|
dbus/dbusaudio.h \
|
||||||
dbus/dbussink.h \
|
dbus/dbussink.h \
|
||||||
horizontalseparator.h
|
componments/horizontalseparator.h \
|
||||||
|
componments/volumeslider.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
soundplugin.cpp \
|
soundplugin.cpp \
|
||||||
@ -24,7 +25,8 @@ SOURCES += \
|
|||||||
soundapplet.cpp \
|
soundapplet.cpp \
|
||||||
dbus/dbusaudio.cpp \
|
dbus/dbusaudio.cpp \
|
||||||
dbus/dbussink.cpp \
|
dbus/dbussink.cpp \
|
||||||
horizontalseparator.cpp
|
componments/horizontalseparator.cpp \
|
||||||
|
componments/volumeslider.cpp
|
||||||
|
|
||||||
target.path = $${PREFIX}/lib/dde-dock/plugins/
|
target.path = $${PREFIX}/lib/dde-dock/plugins/
|
||||||
INSTALLS += target
|
INSTALLS += target
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include "soundapplet.h"
|
#include "soundapplet.h"
|
||||||
#include "horizontalseparator.h"
|
#include "componments/horizontalseparator.h"
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
@ -13,7 +13,7 @@ SoundApplet::SoundApplet(QWidget *parent)
|
|||||||
m_centeralWidget(new QWidget),
|
m_centeralWidget(new QWidget),
|
||||||
m_appControlWidget(new QWidget),
|
m_appControlWidget(new QWidget),
|
||||||
m_volumeIcon(new QLabel),
|
m_volumeIcon(new QLabel),
|
||||||
m_volumeSlider(new QSlider(Qt::Horizontal)),
|
m_volumeSlider(new VolumeSlider),
|
||||||
|
|
||||||
m_audioInter(new DBusAudio(this)),
|
m_audioInter(new DBusAudio(this)),
|
||||||
m_defSinkInter(nullptr)
|
m_defSinkInter(nullptr)
|
||||||
@ -53,7 +53,7 @@ SoundApplet::SoundApplet(QWidget *parent)
|
|||||||
|
|
||||||
m_volumeIcon->setFixedSize(ICON_SIZE, ICON_SIZE);
|
m_volumeIcon->setFixedSize(ICON_SIZE, ICON_SIZE);
|
||||||
m_volumeSlider->setMinimum(0);
|
m_volumeSlider->setMinimum(0);
|
||||||
m_volumeSlider->setMaximum(100);
|
m_volumeSlider->setMaximum(1000);
|
||||||
|
|
||||||
m_appControlWidget->setLayout(appLayout);
|
m_appControlWidget->setLayout(appLayout);
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ SoundApplet::SoundApplet(QWidget *parent)
|
|||||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
setStyleSheet("background-color:transparent;");
|
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);
|
connect(this, static_cast<void (SoundApplet::*)(DBusSink*) const>(&SoundApplet::defaultSinkChanged), this, &SoundApplet::onVolumeChanged);
|
||||||
|
|
||||||
QMetaObject::invokeMethod(this, "defaultSinkChanged", Qt::QueuedConnection);
|
QMetaObject::invokeMethod(this, "defaultSinkChanged", Qt::QueuedConnection);
|
||||||
@ -93,12 +93,10 @@ void SoundApplet::defaultSinkChanged()
|
|||||||
|
|
||||||
void SoundApplet::onVolumeChanged()
|
void SoundApplet::onVolumeChanged()
|
||||||
{
|
{
|
||||||
const bool mute = m_defSinkInter->mute();
|
|
||||||
const double volmue = m_defSinkInter->volume();
|
const double volmue = m_defSinkInter->volume();
|
||||||
|
const bool mute = m_defSinkInter->mute() || volmue < 0.001;
|
||||||
|
|
||||||
m_volumeSlider->blockSignals(true);
|
m_volumeSlider->setValue(std::min(1000.0, volmue * 1000));
|
||||||
m_volumeSlider->setValue(std::min(100.0, volmue * 100));
|
|
||||||
m_volumeSlider->blockSignals(false);
|
|
||||||
|
|
||||||
QString volumeString;
|
QString volumeString;
|
||||||
if (mute)
|
if (mute)
|
||||||
@ -116,5 +114,5 @@ void SoundApplet::onVolumeChanged()
|
|||||||
|
|
||||||
void SoundApplet::volumeSliderValueChanged()
|
void SoundApplet::volumeSliderValueChanged()
|
||||||
{
|
{
|
||||||
m_defSinkInter->SetVolume(double(m_volumeSlider->value()) / 100 + 0.5, false);
|
m_defSinkInter->SetVolume(double(m_volumeSlider->value()) / 1000, false);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef SOUNDAPPLET_H
|
#ifndef SOUNDAPPLET_H
|
||||||
#define SOUNDAPPLET_H
|
#define SOUNDAPPLET_H
|
||||||
|
|
||||||
|
#include "componments/volumeslider.h"
|
||||||
#include "dbus/dbusaudio.h"
|
#include "dbus/dbusaudio.h"
|
||||||
#include "dbus/dbussink.h"
|
#include "dbus/dbussink.h"
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ private:
|
|||||||
QWidget *m_centeralWidget;
|
QWidget *m_centeralWidget;
|
||||||
QWidget *m_appControlWidget;
|
QWidget *m_appControlWidget;
|
||||||
QLabel *m_volumeIcon;
|
QLabel *m_volumeIcon;
|
||||||
QSlider *m_volumeSlider;
|
VolumeSlider *m_volumeSlider;
|
||||||
QVBoxLayout *m_centeralLayout;
|
QVBoxLayout *m_centeralLayout;
|
||||||
|
|
||||||
DBusAudio *m_audioInter;
|
DBusAudio *m_audioInter;
|
||||||
|
@ -48,16 +48,15 @@ void SoundItem::refershIcon()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const double volmue = m_sinkInter->volume();
|
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>();
|
const Dock::DisplayMode displayMode = qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>();
|
||||||
|
|
||||||
|
|
||||||
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 = "010";
|
volumeString = "100";
|
||||||
else
|
else
|
||||||
volumeString = QString("0") + ('0' + int(volmue * 10)) + "0";
|
volumeString = QString("0") + ('0' + int(volmue * 10)) + "0";
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ void PopupControlWidget::clearTrashFloder()
|
|||||||
if (item.isFile())
|
if (item.isFile())
|
||||||
QFile(item.fileName()).remove();
|
QFile(item.fileName()).remove();
|
||||||
else if (item.isDir())
|
else if (item.isDir())
|
||||||
QDir(item.path()).removeRecursively();
|
QDir(item.absoluteFilePath()).removeRecursively();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user