diff --git a/frame/window/quickpluginwindow.cpp b/frame/window/quickpluginwindow.cpp index bf0b58212..3262feccd 100644 --- a/frame/window/quickpluginwindow.cpp +++ b/frame/window/quickpluginwindow.cpp @@ -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 { int pixmapSize = static_cast(ICONHEIGHT * qApp->devicePixelRatio()); @@ -749,6 +757,8 @@ void QuickDockItem::initAttribute() Qt::WindowFlags flags = m_popupWindow->windowFlags() | Qt::FramelessWindowHint; m_popupWindow->setWindowFlags(flags); } + + this->installEventFilter(this); } void QuickDockItem::initConnection() diff --git a/frame/window/quickpluginwindow.h b/frame/window/quickpluginwindow.h index 7cf39a454..149db0be3 100644 --- a/frame/window/quickpluginwindow.h +++ b/frame/window/quickpluginwindow.h @@ -109,6 +109,7 @@ protected: void leaveEvent(QEvent *event) override; void showEvent(QShowEvent *event) override; void hideEvent(QHideEvent *event) override; + bool eventFilter(QObject *watched, QEvent *event) override; private: QPoint topleftPoint() const; diff --git a/plugins/sound/soundplugin.cpp b/plugins/sound/soundplugin.cpp index 62775c9ff..7b8e9f17b 100644 --- a/plugins/sound/soundplugin.cpp +++ b/plugins/sound/soundplugin.cpp @@ -24,6 +24,8 @@ #include "soundwidget.h" #include "sounddeviceswidget.h" +#include + #include #include @@ -164,6 +166,46 @@ PluginFlags SoundPlugin::flags() const | 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 path = defaultSinkCall.reply(); + const QString defaultSinkPath = path.value().value().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 volumePath = volumeCall.reply(); + double volume = volumePath.value().value(); + + // 根据滚轮的动作来增加音量或者减小音量 + QWheelEvent *wheelEvent = static_cast(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() { if (pluginIsDisable()) diff --git a/plugins/sound/soundplugin.h b/plugins/sound/soundplugin.h index 7b9a2be42..ad638fbbb 100644 --- a/plugins/sound/soundplugin.h +++ b/plugins/sound/soundplugin.h @@ -54,6 +54,7 @@ public: QIcon icon(const DockPart &dockPart, DGuiApplicationHelper::ColorType themeType) override; PluginMode status() const override; PluginFlags flags() const override; + bool eventHandler(QEvent *event) override; private: void refreshPluginItemsVisible();