tdesktop/Telegram/SourceFiles/media/player/media_player_widget.h

164 lines
4.6 KiB
C
Raw Normal View History

2016-09-15 16:32:49 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
2016-09-15 16:32:49 +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
*/
#pragma once
2021-08-31 11:26:17 +00:00
#include "data/data_audio_msg_id.h"
2017-09-13 16:57:44 +00:00
#include "ui/rp_widget.h"
2019-09-13 12:22:54 +00:00
#include "base/object_ptr.h"
2017-09-13 16:57:44 +00:00
class AudioMsgId;
2016-09-17 19:28:33 +00:00
namespace Ui {
class FlatLabel;
class LabelSimple;
class IconButton;
class PlainShadow;
class FilledSlider;
2021-11-24 12:23:10 +00:00
template <typename Widget>
class FadeWrap;
} // namespace Ui
2016-09-17 19:28:33 +00:00
2016-09-15 16:32:49 +00:00
namespace Media {
2019-02-27 11:36:19 +00:00
namespace View {
class PlaybackProgress;
} // namespace Clip
2019-02-27 11:36:19 +00:00
} // namespace Media
namespace Window {
class SessionController;
} // namespace Window
2019-02-27 11:36:19 +00:00
namespace Media {
2016-09-15 16:32:49 +00:00
namespace Player {
class PlayButton;
class SpeedButton;
class Dropdown;
struct TrackState;
2016-09-17 19:28:33 +00:00
2021-11-24 13:44:47 +00:00
class Widget final : public Ui::RpWidget, private base::Subscriber {
2016-09-17 19:28:33 +00:00
public:
Widget(
QWidget *parent,
not_null<Ui::RpWidget*> dropdownsParent,
not_null<Window::SessionController*> controller);
2016-09-17 19:28:33 +00:00
void setCloseCallback(Fn<void()> callback);
void setShowItemCallback(Fn<void(not_null<const HistoryItem*>)> callback);
void stopAndClose();
void setShadowGeometryToLeft(int x, int y, int w, int h);
void hideShadowAndDropdowns();
void showShadowAndDropdowns();
void updateDropdownsGeometry();
void raiseDropdowns();
[[nodiscard]] rpl::producer<bool> togglePlaylistRequests() const {
return _togglePlaylistRequests.events();
}
~Widget();
2021-11-24 13:44:47 +00:00
private:
2016-09-17 19:28:33 +00:00
void resizeEvent(QResizeEvent *e) override;
void paintEvent(QPaintEvent *e) override;
2021-11-24 13:44:47 +00:00
void enterEventHook(QEnterEvent *e) override;
void leaveEventHook(QEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
2021-11-24 12:23:10 +00:00
[[nodiscard]] not_null<Ui::RpWidget*> rightControls();
2021-11-24 13:44:47 +00:00
void setupRightControls();
2021-11-24 12:23:10 +00:00
void handleSeekProgress(float64 progress);
void handleSeekFinished(float64 progress);
2021-11-24 12:23:10 +00:00
[[nodiscard]] int getNameLeft() const;
[[nodiscard]] int getNameRight() const;
[[nodiscard]] int getTimeRight() const;
void updateOverLabelsState(QPoint pos);
void updateOverLabelsState(bool over);
void hidePlaylistOn(not_null<Ui::RpWidget*> widget);
void updatePlayPrevNextPositions();
void updateLabelsGeometry();
void updateRepeatToggleIcon();
void updateControlsVisibility();
void updateControlsGeometry();
2021-11-24 12:23:10 +00:00
void updateControlsWrapGeometry();
2021-11-24 13:44:47 +00:00
void updateControlsWrapVisibility();
void createPrevNextButtons();
void destroyPrevNextButtons();
bool hasPlaybackSpeedControl() const;
void updateVolumeToggleIcon();
void checkForTypeChange();
void setType(AudioMsgId::Type type);
void handleSongUpdate(const TrackState &state);
void handleSongChange();
void handlePlaylistUpdate();
void updateTimeText(const TrackState &state);
void updateTimeLabel();
2021-11-24 13:44:47 +00:00
void markOver(bool over);
const not_null<Window::SessionController*> _controller;
const not_null<Ui::RpWidget*> _orderMenuParent;
crl::time _seekPositionMs = -1;
crl::time _lastDurationMs = 0;
QString _time;
// We display all the controls according to _type.
// We switch to Type::Voice if a voice/video message is played.
// We switch to Type::Song only if _voiceIsActive == false.
// We change _voiceIsActive to false only manually or from tracksFinished().
AudioMsgId::Type _type = AudioMsgId::Type::Unknown;
AudioMsgId _lastSongId;
bool _voiceIsActive = false;
Fn<void()> _closeCallback;
Fn<void(not_null<const HistoryItem*>)> _showItemCallback;
bool _labelsOver = false;
bool _labelsDown = false;
rpl::event_stream<bool> _togglePlaylistRequests;
2021-11-24 13:44:47 +00:00
bool _narrow = false;
bool _over = false;
bool _wontBeOver = false;
bool _volumeHidden = false;
class PlayButton;
class OrderController;
class SpeedController;
object_ptr<Ui::FlatLabel> _nameLabel;
2021-11-24 12:23:10 +00:00
object_ptr<Ui::FadeWrap<Ui::RpWidget>> _rightControls;
object_ptr<Ui::LabelSimple> _timeLabel;
object_ptr<Ui::IconButton> _previousTrack = { nullptr };
2021-11-24 12:23:10 +00:00
object_ptr<Ui::IconButton> _playPause;
object_ptr<Ui::IconButton> _nextTrack = { nullptr };
object_ptr<Ui::IconButton> _volumeToggle;
object_ptr<Ui::IconButton> _repeatToggle;
2021-11-24 12:23:10 +00:00
object_ptr<Ui::IconButton> _orderToggle;
object_ptr<Ui::IconButton> _speedToggle;
object_ptr<Ui::IconButton> _close;
object_ptr<Ui::PlainShadow> _shadow = { nullptr };
object_ptr<Ui::FilledSlider> _playbackSlider;
base::unique_qptr<Dropdown> _volume;
2019-02-27 11:36:19 +00:00
std::unique_ptr<View::PlaybackProgress> _playbackProgress;
std::unique_ptr<OrderController> _orderController;
std::unique_ptr<SpeedController> _speedController;
2016-09-17 19:28:33 +00:00
2017-12-08 18:27:28 +00:00
rpl::lifetime _playlistChangesLifetime;
2016-09-17 19:28:33 +00:00
};
2019-02-27 11:36:19 +00:00
} // namespace Player
2016-09-15 16:32:49 +00:00
} // namespace Media