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

130 lines
3.3 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
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;
} // 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 VolumeWidget;
struct TrackState;
2016-09-17 19:28:33 +00:00
2017-09-13 16:57:44 +00:00
class Widget : 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 stopAndClose();
void setShadowGeometryToLeft(int x, int y, int w, int h);
void showShadow();
void hideShadow();
2016-09-17 19:28:33 +00:00
QPoint getPositionForVolumeWidget() const;
void volumeWidgetCreated(VolumeWidget *widget);
2016-09-17 19:28:33 +00:00
~Widget();
2016-09-17 19:28:33 +00:00
protected:
void resizeEvent(QResizeEvent *e) override;
void paintEvent(QPaintEvent *e) override;
void leaveEventHook(QEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
2016-09-17 19:28:33 +00:00
private:
void handleSeekProgress(float64 progress);
void handleSeekFinished(float64 progress);
int getLabelsLeft() const;
int getLabelsRight() const;
void updateOverLabelsState(QPoint pos);
void updateOverLabelsState(bool over);
void updatePlayPrevNextPositions();
void updateLabelsGeometry();
void updateRepeatTrackIcon();
void updatePlaybackSpeedIcon();
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();
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;
bool _labelsOver = false;
bool _labelsDown = false;
class PlayButton;
object_ptr<Ui::FlatLabel> _nameLabel;
object_ptr<Ui::LabelSimple> _timeLabel;
object_ptr<Ui::IconButton> _previousTrack = { nullptr };
object_ptr<PlayButton> _playPause;
object_ptr<Ui::IconButton> _nextTrack = { nullptr };
object_ptr<Ui::IconButton> _volumeToggle;
object_ptr<Ui::IconButton> _repeatTrack;
object_ptr<Ui::IconButton> _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