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

160 lines
4.4 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 Main {
class Session;
} // namespace Main
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<Main::Session*> session);
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 showShadow();
void hideShadow();
2016-09-17 19:28:33 +00:00
[[nodiscard]] QPoint getPositionForVolumeWidget() const;
void volumeWidgetCreated(Dropdown *widget);
2016-09-17 19:28:33 +00:00
[[nodiscard]] QPoint getPositionForRepeatWidget() const;
void repeatWidgetCreated(Dropdown *widget);
[[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
bool eventFilter(QObject *o, QEvent *e) override;
2016-09-17 19:28:33 +00:00
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 updatePlayPrevNextPositions();
void updateLabelsGeometry();
void updateRepeatToggleIcon();
2021-11-24 12:23:10 +00:00
void updateOrderToggleIcon();
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<Main::Session*> _session;
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;
class PlayButton;
class SpeedButton;
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<SpeedButton> _playbackSpeed;
object_ptr<Ui::IconButton> _close;
object_ptr<Ui::PlainShadow> _shadow = { nullptr };
object_ptr<Ui::FilledSlider> _playbackSlider;
2019-02-27 11:36:19 +00:00
std::unique_ptr<View::PlaybackProgress> _playbackProgress;
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