Change volume by wheel events on volume icon.
This commit is contained in:
parent
07dfe88d62
commit
c153cdc70e
|
@ -57,6 +57,10 @@ void VolumeController::setIsVertical(bool vertical) {
|
||||||
_slider->setAlwaysDisplayMarker(vertical);
|
_slider->setAlwaysDisplayMarker(vertical);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VolumeController::outerWheelEvent(not_null<QWheelEvent*> e) {
|
||||||
|
QGuiApplication::sendEvent(_slider.data(), e);
|
||||||
|
}
|
||||||
|
|
||||||
void VolumeController::resizeEvent(QResizeEvent *e) {
|
void VolumeController::resizeEvent(QResizeEvent *e) {
|
||||||
_slider->setGeometry(rect());
|
_slider->setGeometry(rect());
|
||||||
}
|
}
|
||||||
|
@ -78,7 +82,8 @@ void VolumeController::applyVolumeChange(float64 volume) {
|
||||||
|
|
||||||
void PrepareVolumeDropdown(
|
void PrepareVolumeDropdown(
|
||||||
not_null<Dropdown*> dropdown,
|
not_null<Dropdown*> dropdown,
|
||||||
not_null<Window::SessionController*> controller) {
|
not_null<Window::SessionController*> controller,
|
||||||
|
rpl::producer<not_null<QWheelEvent*>> outerWheelEvents) {
|
||||||
const auto volume = Ui::CreateChild<VolumeController>(
|
const auto volume = Ui::CreateChild<VolumeController>(
|
||||||
dropdown.get(),
|
dropdown.get(),
|
||||||
controller);
|
controller);
|
||||||
|
@ -98,6 +103,12 @@ void PrepareVolumeDropdown(
|
||||||
- ((st::mediaPlayerVolumeSize.width()
|
- ((st::mediaPlayerVolumeSize.width()
|
||||||
- st::mediaPlayerPanelPlayback.width) / 2)));
|
- st::mediaPlayerPanelPlayback.width) / 2)));
|
||||||
}, volume->lifetime());
|
}, volume->lifetime());
|
||||||
|
|
||||||
|
std::move(
|
||||||
|
outerWheelEvents
|
||||||
|
) | rpl::start_with_next([=](not_null<QWheelEvent*> e) {
|
||||||
|
volume->outerWheelEvent(e);
|
||||||
|
}, volume->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Media::Player
|
} // namespace Media::Player
|
||||||
|
|
|
@ -10,6 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/rp_widget.h"
|
#include "ui/rp_widget.h"
|
||||||
#include "base/object_ptr.h"
|
#include "base/object_ptr.h"
|
||||||
|
|
||||||
|
class QWheelEvent;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MediaSlider;
|
class MediaSlider;
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
@ -29,6 +31,7 @@ public:
|
||||||
not_null<Window::SessionController*> controller);
|
not_null<Window::SessionController*> controller);
|
||||||
|
|
||||||
void setIsVertical(bool vertical);
|
void setIsVertical(bool vertical);
|
||||||
|
void outerWheelEvent(not_null<QWheelEvent*> e);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *e) override;
|
void resizeEvent(QResizeEvent *e) override;
|
||||||
|
@ -43,6 +46,7 @@ private:
|
||||||
|
|
||||||
void PrepareVolumeDropdown(
|
void PrepareVolumeDropdown(
|
||||||
not_null<Dropdown*> dropdown,
|
not_null<Dropdown*> dropdown,
|
||||||
not_null<Window::SessionController*> controller);
|
not_null<Window::SessionController*> controller,
|
||||||
|
rpl::producer<not_null<QWheelEvent*>> outerWheelEvents);
|
||||||
|
|
||||||
} // namespace Media::Player
|
} // namespace Media::Player
|
||||||
|
|
|
@ -515,7 +515,12 @@ Widget::Widget(
|
||||||
handleSongUpdate(state);
|
handleSongUpdate(state);
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
PrepareVolumeDropdown(_volume.get(), controller);
|
PrepareVolumeDropdown(_volume.get(), controller, _volumeToggle->events(
|
||||||
|
) | rpl::filter([=](not_null<QEvent*> e) {
|
||||||
|
return (e->type() == QEvent::Wheel);
|
||||||
|
}) | rpl::map([=](not_null<QEvent*> e) {
|
||||||
|
return not_null{ static_cast<QWheelEvent*>(e.get()) };
|
||||||
|
}));
|
||||||
_volumeToggle->installEventFilter(_volume.get());
|
_volumeToggle->installEventFilter(_volume.get());
|
||||||
_volume->events(
|
_volume->events(
|
||||||
) | rpl::start_with_next([=](not_null<QEvent*> e) {
|
) | rpl::start_with_next([=](not_null<QEvent*> e) {
|
||||||
|
|
Loading…
Reference in New Issue