2016-09-15 16:32:49 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-09-15 16:32:49 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-09-15 16:32:49 +00:00
|
|
|
*/
|
|
|
|
#include "media/player/media_player_volume_controller.h"
|
|
|
|
|
2019-02-13 12:36:59 +00:00
|
|
|
#include "media/audio/media_audio.h"
|
2021-11-18 17:02:12 +00:00
|
|
|
#include "media/player/media_player_dropdown.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-12-13 17:07:56 +00:00
|
|
|
#include "ui/widgets/shadow.h"
|
2016-11-22 09:48:13 +00:00
|
|
|
#include "ui/widgets/continuous_sliders.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2020-10-13 15:11:53 +00:00
|
|
|
#include "ui/cached_round_corners.h"
|
2016-10-12 19:34:25 +00:00
|
|
|
#include "mainwindow.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2020-06-08 15:17:33 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2020-06-18 18:04:16 +00:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/core_settings.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "styles/style_media_player.h"
|
|
|
|
#include "styles/style_widgets.h"
|
2016-09-17 19:28:33 +00:00
|
|
|
|
2022-01-24 16:33:30 +00:00
|
|
|
#include <QtGui/QGuiApplication>
|
|
|
|
|
2021-11-18 17:02:12 +00:00
|
|
|
namespace Media::Player {
|
2016-09-15 16:32:49 +00:00
|
|
|
|
2020-06-08 15:17:33 +00:00
|
|
|
VolumeController::VolumeController(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller)
|
2020-06-18 18:04:16 +00:00
|
|
|
: RpWidget(parent)
|
2016-10-12 19:34:25 +00:00
|
|
|
, _slider(this, st::mediaPlayerPanelPlayback) {
|
2016-10-13 08:33:12 +00:00
|
|
|
_slider->setMoveByWheel(true);
|
2019-08-06 16:40:08 +00:00
|
|
|
_slider->setChangeProgressCallback([=](float64 volume) {
|
2016-09-23 16:04:26 +00:00
|
|
|
applyVolumeChange(volume);
|
|
|
|
});
|
2019-08-06 16:40:08 +00:00
|
|
|
_slider->setChangeFinishedCallback([=](float64 volume) {
|
2016-09-23 16:04:26 +00:00
|
|
|
if (volume > 0) {
|
2020-06-18 18:04:16 +00:00
|
|
|
Core::App().settings().setRememberedSongVolume(volume);
|
2016-09-23 16:04:26 +00:00
|
|
|
}
|
|
|
|
applyVolumeChange(volume);
|
2020-06-30 09:49:22 +00:00
|
|
|
Core::App().saveSettingsDelayed();
|
2016-09-23 16:04:26 +00:00
|
|
|
});
|
2020-06-18 18:04:16 +00:00
|
|
|
Core::App().settings().songVolumeChanges(
|
|
|
|
) | rpl::start_with_next([=](float64 volume) {
|
2016-10-12 19:34:25 +00:00
|
|
|
if (!_slider->isChanging()) {
|
2020-06-18 18:04:16 +00:00
|
|
|
_slider->setValue(volume);
|
2016-10-12 19:34:25 +00:00
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
}, lifetime());
|
|
|
|
setVolume(Core::App().settings().songVolume());
|
2016-09-17 19:28:33 +00:00
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
resize(st::mediaPlayerPanelVolumeWidth, 2 * st::mediaPlayerPanelPlaybackPadding + st::mediaPlayerPanelPlayback.width);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VolumeController::setIsVertical(bool vertical) {
|
|
|
|
using Direction = Ui::MediaSlider::Direction;
|
|
|
|
_slider->setDirection(vertical ? Direction::Vertical : Direction::Horizontal);
|
|
|
|
_slider->setAlwaysDisplayMarker(vertical);
|
2016-09-17 19:28:33 +00:00
|
|
|
}
|
|
|
|
|
2021-11-29 07:11:16 +00:00
|
|
|
void VolumeController::outerWheelEvent(not_null<QWheelEvent*> e) {
|
|
|
|
QGuiApplication::sendEvent(_slider.data(), e);
|
|
|
|
}
|
|
|
|
|
2016-09-23 16:04:26 +00:00
|
|
|
void VolumeController::resizeEvent(QResizeEvent *e) {
|
2016-10-12 19:34:25 +00:00
|
|
|
_slider->setGeometry(rect());
|
2016-09-17 19:28:33 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 16:10:39 +00:00
|
|
|
void VolumeController::setVolume(float64 volume) {
|
|
|
|
_slider->setValue(volume);
|
2016-09-23 16:04:26 +00:00
|
|
|
if (volume > 0) {
|
2020-06-18 18:04:16 +00:00
|
|
|
Core::App().settings().setRememberedSongVolume(volume);
|
2016-09-23 16:04:26 +00:00
|
|
|
}
|
|
|
|
applyVolumeChange(volume);
|
2016-09-17 19:28:33 +00:00
|
|
|
}
|
|
|
|
|
2016-09-23 16:04:26 +00:00
|
|
|
void VolumeController::applyVolumeChange(float64 volume) {
|
2020-06-18 18:04:16 +00:00
|
|
|
if (volume != Core::App().settings().songVolume()) {
|
2021-09-05 20:46:34 +00:00
|
|
|
mixer()->setSongVolume(volume);
|
2020-06-18 18:04:16 +00:00
|
|
|
Core::App().settings().setSongVolume(volume);
|
2016-10-12 19:34:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-18 17:02:12 +00:00
|
|
|
void PrepareVolumeDropdown(
|
|
|
|
not_null<Dropdown*> dropdown,
|
2021-11-29 07:11:16 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
rpl::producer<not_null<QWheelEvent*>> outerWheelEvents) {
|
2021-11-18 17:02:12 +00:00
|
|
|
const auto volume = Ui::CreateChild<VolumeController>(
|
|
|
|
dropdown.get(),
|
|
|
|
controller);
|
|
|
|
volume->show();
|
|
|
|
volume->setIsVertical(true);
|
|
|
|
|
|
|
|
dropdown->sizeValue(
|
|
|
|
) | rpl::start_with_next([=](QSize size) {
|
|
|
|
const auto rect = QRect(QPoint(), size);
|
|
|
|
const auto inner = rect.marginsRemoved(dropdown->getMargin());
|
|
|
|
volume->setGeometry(
|
|
|
|
inner.x(),
|
|
|
|
inner.y() - st::lineWidth,
|
|
|
|
inner.width(),
|
|
|
|
(inner.height()
|
|
|
|
+ st::lineWidth
|
|
|
|
- ((st::mediaPlayerVolumeSize.width()
|
|
|
|
- st::mediaPlayerPanelPlayback.width) / 2)));
|
|
|
|
}, volume->lifetime());
|
2021-11-29 07:11:16 +00:00
|
|
|
|
|
|
|
std::move(
|
|
|
|
outerWheelEvents
|
|
|
|
) | rpl::start_with_next([=](not_null<QWheelEvent*> e) {
|
|
|
|
volume->outerWheelEvent(e);
|
|
|
|
}, volume->lifetime());
|
2021-11-18 17:02:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Media::Player
|