mirror of https://github.com/procxx/kepka.git
Support menu with playback speed.
This commit is contained in:
parent
e889a52f6f
commit
e13325ca22
|
@ -1579,6 +1579,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_mediaview_saved_to" = "Image was saved to your {downloads} folder";
|
"lng_mediaview_saved_to" = "Image was saved to your {downloads} folder";
|
||||||
"lng_mediaview_downloads" = "Downloads";
|
"lng_mediaview_downloads" = "Downloads";
|
||||||
"lng_mediaview_video_loading" = "Loading - {percent}";
|
"lng_mediaview_video_loading" = "Loading - {percent}";
|
||||||
|
"lng_mediaview_playback_speed" = "Playback speed";
|
||||||
|
"lng_mediaview_playback_speed_normal" = "Normal";
|
||||||
|
|
||||||
"lng_theme_preview_title" = "Theme Preview";
|
"lng_theme_preview_title" = "Theme Preview";
|
||||||
"lng_theme_preview_generating" = "Generating color theme preview...";
|
"lng_theme_preview_generating" = "Generating color theme preview...";
|
||||||
|
|
|
@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/widgets/continuous_sliders.h"
|
#include "ui/widgets/continuous_sliders.h"
|
||||||
#include "ui/effects/fade_animation.h"
|
#include "ui/effects/fade_animation.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
|
#include "ui/widgets/popup_menu.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
@ -36,6 +37,7 @@ PlaybackControls::PlaybackControls(
|
||||||
, _pictureInPicture(this, st::mediaviewPipButton)
|
, _pictureInPicture(this, st::mediaviewPipButton)
|
||||||
, _playedAlready(this, st::mediaviewPlayProgressLabel)
|
, _playedAlready(this, st::mediaviewPlayProgressLabel)
|
||||||
, _toPlayLeft(this, st::mediaviewPlayProgressLabel)
|
, _toPlayLeft(this, st::mediaviewPlayProgressLabel)
|
||||||
|
, _speedMenuStyle(st::mediaviewControlsPopupMenu)
|
||||||
, _fadeAnimation(std::make_unique<Ui::FadeAnimation>(this)) {
|
, _fadeAnimation(std::make_unique<Ui::FadeAnimation>(this)) {
|
||||||
_fadeAnimation->show();
|
_fadeAnimation->show();
|
||||||
_fadeAnimation->setFinishedCallback([=] {
|
_fadeAnimation->setFinishedCallback([=] {
|
||||||
|
@ -48,6 +50,9 @@ PlaybackControls::PlaybackControls(
|
||||||
_pictureInPicture->addClickHandler([=] {
|
_pictureInPicture->addClickHandler([=] {
|
||||||
_delegate->playbackControlsToPictureInPicture();
|
_delegate->playbackControlsToPictureInPicture();
|
||||||
});
|
});
|
||||||
|
_menuToggle->addClickHandler([=] {
|
||||||
|
showMenu();
|
||||||
|
});
|
||||||
|
|
||||||
_volumeController->setValue(_delegate->playbackControlsCurrentVolume());
|
_volumeController->setValue(_delegate->playbackControlsCurrentVolume());
|
||||||
_volumeController->setChangeProgressCallback([=](float64 value) {
|
_volumeController->setChangeProgressCallback([=](float64 value) {
|
||||||
|
@ -170,6 +175,61 @@ void PlaybackControls::fadeUpdated(float64 opacity) {
|
||||||
_volumeController->setFadeOpacity(opacity);
|
_volumeController->setFadeOpacity(opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlaybackControls::validateSpeedMenuStyle() {
|
||||||
|
auto &st = _speedMenuStyle.menu;
|
||||||
|
const auto &check = st::mediaviewMenuCheck;
|
||||||
|
const auto normal = tr::lng_mediaview_playback_speed_normal(tr::now);
|
||||||
|
const auto itemHeight = st.itemPadding.top()
|
||||||
|
+ st.itemStyle.font->height
|
||||||
|
+ st.itemPadding.bottom();
|
||||||
|
const auto itemWidth = st.itemPadding.left()
|
||||||
|
+ st.itemStyle.font->width(normal)
|
||||||
|
+ st.itemPadding.right();
|
||||||
|
if (itemWidth + st.itemPadding.right() + check.width() > st.widthMin) {
|
||||||
|
st.widthMin = itemWidth + st.itemPadding.right() + check.width();
|
||||||
|
}
|
||||||
|
const auto realWidth = std::clamp(itemWidth, st.widthMin, st.widthMax);
|
||||||
|
st.itemIconPosition = QPoint(
|
||||||
|
realWidth - st.itemPadding.right() - check.width(),
|
||||||
|
(itemHeight - check.height()) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlaybackControls::showMenu() {
|
||||||
|
if (_menu) {
|
||||||
|
_menu = nullptr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
validateSpeedMenuStyle();
|
||||||
|
|
||||||
|
auto submenu = std::make_unique<Ui::PopupMenu>(
|
||||||
|
this,
|
||||||
|
_speedMenuStyle);
|
||||||
|
const auto addSpeed = [&](float64 speed, QString text = QString()) {
|
||||||
|
if (text.isEmpty()) {
|
||||||
|
text = QString::number(speed);
|
||||||
|
}
|
||||||
|
const auto checked = (speed == _delegate->playbackControlsCurrentSpeed());
|
||||||
|
const auto action = submenu->addAction(
|
||||||
|
text,
|
||||||
|
[=] { updatePlaybackSpeed(speed); },
|
||||||
|
checked ? &st::mediaviewMenuCheck : nullptr);
|
||||||
|
};
|
||||||
|
addSpeed(0.5);
|
||||||
|
addSpeed(0.75);
|
||||||
|
addSpeed(1., tr::lng_mediaview_playback_speed_normal(tr::now));
|
||||||
|
addSpeed(1.25);
|
||||||
|
addSpeed(1.5);
|
||||||
|
addSpeed(1.75);
|
||||||
|
addSpeed(2.);
|
||||||
|
_menu.emplace(this, st::mediaviewControlsPopupMenu);
|
||||||
|
_menu->addAction(
|
||||||
|
tr::lng_mediaview_playback_speed(tr::now),
|
||||||
|
std::move(submenu));
|
||||||
|
_menu->setForcedOrigin(Ui::PanelAnimation::Origin::BottomLeft);
|
||||||
|
_menu->popup(mapToGlobal(_menuToggle->geometry().topLeft()));
|
||||||
|
}
|
||||||
|
|
||||||
void PlaybackControls::updatePlaybackSpeed(float64 speed) {
|
void PlaybackControls::updatePlaybackSpeed(float64 speed) {
|
||||||
_delegate->playbackControlsSpeedChanged(speed);
|
_delegate->playbackControlsSpeedChanged(speed);
|
||||||
resizeEvent(nullptr);
|
resizeEvent(nullptr);
|
||||||
|
|
|
@ -9,12 +9,15 @@ 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"
|
||||||
|
#include "base/unique_qptr.h"
|
||||||
|
#include "styles/style_widgets.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class LabelSimple;
|
class LabelSimple;
|
||||||
class FadeAnimation;
|
class FadeAnimation;
|
||||||
class IconButton;
|
class IconButton;
|
||||||
class MediaSlider;
|
class MediaSlider;
|
||||||
|
class PopupMenu;
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
||||||
namespace Media {
|
namespace Media {
|
||||||
|
@ -80,6 +83,8 @@ private:
|
||||||
void updatePlayPauseResumeState(const Player::TrackState &state);
|
void updatePlayPauseResumeState(const Player::TrackState &state);
|
||||||
void updateTimeTexts(const Player::TrackState &state);
|
void updateTimeTexts(const Player::TrackState &state);
|
||||||
void refreshTimeTexts();
|
void refreshTimeTexts();
|
||||||
|
void validateSpeedMenuStyle();
|
||||||
|
void showMenu();
|
||||||
|
|
||||||
not_null<Delegate*> _delegate;
|
not_null<Delegate*> _delegate;
|
||||||
|
|
||||||
|
@ -106,6 +111,8 @@ private:
|
||||||
object_ptr<Ui::LabelSimple> _toPlayLeft;
|
object_ptr<Ui::LabelSimple> _toPlayLeft;
|
||||||
object_ptr<Ui::LabelSimple> _downloadProgress = { nullptr };
|
object_ptr<Ui::LabelSimple> _downloadProgress = { nullptr };
|
||||||
|
|
||||||
|
style::PopupMenu _speedMenuStyle;
|
||||||
|
base::unique_qptr<Ui::PopupMenu> _menu;
|
||||||
std::unique_ptr<Ui::FadeAnimation> _fadeAnimation;
|
std::unique_ptr<Ui::FadeAnimation> _fadeAnimation;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -174,6 +174,38 @@ mediaviewDropdownMenu: DropdownMenu(defaultDropdownMenu) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mediaviewControlsMenu: Menu(defaultMenu) {
|
||||||
|
itemBg: mediaviewSaveMsgBg;
|
||||||
|
itemBgOver: mediaviewPlaybackIconRipple;
|
||||||
|
itemFg: mediaviewPlaybackProgressFg;
|
||||||
|
itemFgOver: mediaviewPlaybackProgressFg;
|
||||||
|
itemFgDisabled: mediaviewPlaybackProgressFg;
|
||||||
|
itemFgShortcut: mediaviewPlaybackProgressFg;
|
||||||
|
itemFgShortcutOver: mediaviewPlaybackProgressFg;
|
||||||
|
itemFgShortcutDisabled: mediaviewPlaybackProgressFg;
|
||||||
|
|
||||||
|
separatorFg: mediaviewPlaybackIconRipple;
|
||||||
|
|
||||||
|
arrow: icon {{ "dropdown_submenu_arrow", mediaviewPlaybackProgressFg }};
|
||||||
|
|
||||||
|
ripple: RippleAnimation(defaultRippleAnimation) {
|
||||||
|
color: mediaviewPlaybackIconRipple;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mediaviewControlsMenuShadow: Shadow(defaultEmptyShadow) {
|
||||||
|
fallback: mediaviewSaveMsgBg;
|
||||||
|
}
|
||||||
|
mediaviewControlsPanelAnimation: PanelAnimation(defaultPanelAnimation) {
|
||||||
|
fadeBg: mediaviewSaveMsgBg;
|
||||||
|
shadow: mediaviewControlsMenuShadow;
|
||||||
|
}
|
||||||
|
mediaviewControlsPopupMenu: PopupMenu(defaultPopupMenu) {
|
||||||
|
shadow: mediaviewControlsMenuShadow;
|
||||||
|
menu: mediaviewControlsMenu;
|
||||||
|
animation: mediaviewControlsPanelAnimation;
|
||||||
|
}
|
||||||
|
mediaviewMenuCheck: icon {{ "player_check", mediaviewPlaybackProgressFg }};
|
||||||
|
|
||||||
mediaviewSaveMsgCheck: icon {{ "mediaview_save_check", mediaviewSaveMsgFg }};
|
mediaviewSaveMsgCheck: icon {{ "mediaview_save_check", mediaviewSaveMsgFg }};
|
||||||
mediaviewSaveMsgPadding: margins(55px, 19px, 29px, 20px);
|
mediaviewSaveMsgPadding: margins(55px, 19px, 29px, 20px);
|
||||||
mediaviewSaveMsgCheckPos: point(23px, 21px);
|
mediaviewSaveMsgCheckPos: point(23px, 21px);
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 33ea14969edfbe2546726d82925a1a66ae49310e
|
Subproject commit 18ba60ec86f1494d994ce507bb3e43ebe1766c20
|
Loading…
Reference in New Issue