mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
feat: 声音插件滚轮调节音量
适配插件接口的eventHandler事件,响应对滚轮的处理,让其来调节音量 Log: Influence: 将鼠标放在任务栏声音图标上,滚动滚轮,观察音量大小是否调节 Bug: https://pms.uniontech.com/bug-view-172417.html Change-Id: I82cf58f652568f4152083973ba8328a39f496656
This commit is contained in:
parent
c35bee0c65
commit
13988c0b2a
@ -711,6 +711,14 @@ void QuickDockItem::hideEvent(QHideEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QuickDockItem::eventFilter(QObject *watched, QEvent *event)
|
||||||
|
{
|
||||||
|
if (watched == this)
|
||||||
|
return m_pluginItem->eventHandler(event);
|
||||||
|
|
||||||
|
return QWidget::eventFilter(watched, event);
|
||||||
|
}
|
||||||
|
|
||||||
QPixmap QuickDockItem::iconPixmap() const
|
QPixmap QuickDockItem::iconPixmap() const
|
||||||
{
|
{
|
||||||
int pixmapSize = static_cast<int>(ICONHEIGHT * qApp->devicePixelRatio());
|
int pixmapSize = static_cast<int>(ICONHEIGHT * qApp->devicePixelRatio());
|
||||||
@ -749,6 +757,8 @@ void QuickDockItem::initAttribute()
|
|||||||
Qt::WindowFlags flags = m_popupWindow->windowFlags() | Qt::FramelessWindowHint;
|
Qt::WindowFlags flags = m_popupWindow->windowFlags() | Qt::FramelessWindowHint;
|
||||||
m_popupWindow->setWindowFlags(flags);
|
m_popupWindow->setWindowFlags(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuickDockItem::initConnection()
|
void QuickDockItem::initConnection()
|
||||||
|
@ -109,6 +109,7 @@ protected:
|
|||||||
void leaveEvent(QEvent *event) override;
|
void leaveEvent(QEvent *event) override;
|
||||||
void showEvent(QShowEvent *event) override;
|
void showEvent(QShowEvent *event) override;
|
||||||
void hideEvent(QHideEvent *event) override;
|
void hideEvent(QHideEvent *event) override;
|
||||||
|
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPoint topleftPoint() const;
|
QPoint topleftPoint() const;
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#include "soundwidget.h"
|
#include "soundwidget.h"
|
||||||
#include "sounddeviceswidget.h"
|
#include "sounddeviceswidget.h"
|
||||||
|
|
||||||
|
#include <DDBusSender>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QAccessible>
|
#include <QAccessible>
|
||||||
|
|
||||||
@ -164,6 +166,46 @@ PluginFlags SoundPlugin::flags() const
|
|||||||
| PluginFlag::Attribute_CanSetting;
|
| PluginFlag::Attribute_CanSetting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SoundPlugin::eventHandler(QEvent *event)
|
||||||
|
{
|
||||||
|
// 当前只处理鼠标滚轮事件
|
||||||
|
if (event->type() != QEvent::Wheel)
|
||||||
|
return PluginsItemInterface::eventHandler(event);
|
||||||
|
|
||||||
|
// 获取当前默认的声音设备
|
||||||
|
QDBusPendingCall defaultSinkCall = DDBusSender().service("org.deepin.daemon.Audio1")
|
||||||
|
.path("/org/deepin/daemon/Audio1")
|
||||||
|
.interface("org.deepin.daemon.Audio1")
|
||||||
|
.property("DefaultSink").get();
|
||||||
|
defaultSinkCall.waitForFinished();
|
||||||
|
QDBusReply<QVariant> path = defaultSinkCall.reply();
|
||||||
|
const QString defaultSinkPath = path.value().value<QDBusObjectPath>().path();
|
||||||
|
if (defaultSinkPath.isNull())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// 获取当前默认声音设备的音量
|
||||||
|
DDBusSender sinkDBus = DDBusSender().service("org.deepin.daemon.Audio1")
|
||||||
|
.path(defaultSinkPath).interface("org.deepin.daemon.Audio1.Sink");
|
||||||
|
QDBusPendingCall volumeCall = sinkDBus.property("Volume").get();
|
||||||
|
volumeCall.waitForFinished();
|
||||||
|
QDBusReply<QVariant> volumePath = volumeCall.reply();
|
||||||
|
double volume = volumePath.value().value<double>();
|
||||||
|
|
||||||
|
// 根据滚轮的动作来增加音量或者减小音量
|
||||||
|
QWheelEvent *wheelEvent = static_cast<QWheelEvent *>(event);
|
||||||
|
if (wheelEvent->angleDelta().y() > 0) {
|
||||||
|
// 向上滚动,增大音量
|
||||||
|
if (volume < 1)
|
||||||
|
sinkDBus.method("SetVolume").arg(volume + 0.02).arg(true).call();
|
||||||
|
} else {
|
||||||
|
// 向下滚动,调小音量
|
||||||
|
if (volume > 0)
|
||||||
|
sinkDBus.method("SetVolume").arg(volume - 0.02).arg(true).call();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void SoundPlugin::refreshPluginItemsVisible()
|
void SoundPlugin::refreshPluginItemsVisible()
|
||||||
{
|
{
|
||||||
if (pluginIsDisable())
|
if (pluginIsDisable())
|
||||||
|
@ -54,6 +54,7 @@ public:
|
|||||||
QIcon icon(const DockPart &dockPart, DGuiApplicationHelper::ColorType themeType) override;
|
QIcon icon(const DockPart &dockPart, DGuiApplicationHelper::ColorType themeType) override;
|
||||||
PluginMode status() const override;
|
PluginMode status() const override;
|
||||||
PluginFlags flags() const override;
|
PluginFlags flags() const override;
|
||||||
|
bool eventHandler(QEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void refreshPluginItemsVisible();
|
void refreshPluginItemsVisible();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user