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
|
|
|
*/
|
|
|
|
#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
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
class AudioMsgId;
|
2016-09-17 19:28:33 +00:00
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
namespace Ui {
|
2016-11-16 10:44:06 +00:00
|
|
|
class FlatLabel;
|
2016-10-12 19:34:25 +00:00
|
|
|
class LabelSimple;
|
|
|
|
class IconButton;
|
|
|
|
class PlainShadow;
|
2017-05-18 16:10:39 +00:00
|
|
|
class FilledSlider;
|
2016-10-12 19:34:25 +00:00
|
|
|
} // 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;
|
2016-10-12 19:34:25 +00:00
|
|
|
} // namespace Clip
|
2019-02-27 11:36:19 +00:00
|
|
|
} // namespace Media
|
2016-10-12 19:34:25 +00:00
|
|
|
|
2020-06-09 16:57:05 +00:00
|
|
|
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 {
|
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
class PlayButton;
|
2021-08-30 23:31:34 +00:00
|
|
|
class SpeedButton;
|
2021-11-18 17:02:12 +00:00
|
|
|
class Dropdown;
|
2017-01-24 21:24:39 +00:00
|
|
|
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:
|
2020-06-09 16:57:05 +00:00
|
|
|
Widget(QWidget *parent, not_null<Main::Session*> session);
|
2016-09-17 19:28:33 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void setCloseCallback(Fn<void()> callback);
|
2021-06-15 23:06:22 +00:00
|
|
|
void setShowItemCallback(Fn<void(not_null<const HistoryItem*>)> callback);
|
2017-05-23 18:00:57 +00:00
|
|
|
void stopAndClose();
|
2016-10-12 19:34:25 +00:00
|
|
|
void setShadowGeometryToLeft(int x, int y, int w, int h);
|
|
|
|
void showShadow();
|
|
|
|
void hideShadow();
|
2016-09-17 19:28:33 +00:00
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
QPoint getPositionForVolumeWidget() const;
|
2021-11-18 17:02:12 +00:00
|
|
|
void volumeWidgetCreated(Dropdown *widget);
|
2016-09-17 19:28:33 +00:00
|
|
|
|
2021-11-18 17:02:39 +00:00
|
|
|
QPoint getPositionForRepeatWidget() const;
|
|
|
|
void repeatWidgetCreated(Dropdown *widget);
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
~Widget();
|
|
|
|
|
2016-09-17 19:28:33 +00:00
|
|
|
protected:
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
2017-02-11 11:24:37 +00:00
|
|
|
void leaveEventHook(QEvent *e) override;
|
2016-10-14 17:10:15 +00:00
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
2017-05-21 15:14:42 +00:00
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
2016-10-14 17:10:15 +00:00
|
|
|
|
2016-09-17 19:28:33 +00:00
|
|
|
private:
|
2016-10-12 19:34:25 +00:00
|
|
|
void handleSeekProgress(float64 progress);
|
|
|
|
void handleSeekFinished(float64 progress);
|
|
|
|
|
2016-10-14 17:10:15 +00:00
|
|
|
int getLabelsLeft() const;
|
|
|
|
int getLabelsRight() const;
|
|
|
|
void updateOverLabelsState(QPoint pos);
|
|
|
|
void updateOverLabelsState(bool over);
|
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
void updatePlayPrevNextPositions();
|
|
|
|
void updateLabelsGeometry();
|
|
|
|
void updateRepeatTrackIcon();
|
2021-08-31 16:11:37 +00:00
|
|
|
void updateControlsVisibility();
|
|
|
|
void updateControlsGeometry();
|
2016-10-12 19:34:25 +00:00
|
|
|
void createPrevNextButtons();
|
|
|
|
void destroyPrevNextButtons();
|
|
|
|
|
2018-11-09 12:28:15 +00:00
|
|
|
bool hasPlaybackSpeedControl() const;
|
2016-10-12 19:34:25 +00:00
|
|
|
void updateVolumeToggleIcon();
|
|
|
|
|
2017-05-21 13:16:39 +00:00
|
|
|
void checkForTypeChange();
|
|
|
|
void setType(AudioMsgId::Type type);
|
2017-01-24 21:24:39 +00:00
|
|
|
void handleSongUpdate(const TrackState &state);
|
2016-10-12 19:34:25 +00:00
|
|
|
void handleSongChange();
|
|
|
|
void handlePlaylistUpdate();
|
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
void updateTimeText(const TrackState &state);
|
2016-10-12 19:34:25 +00:00
|
|
|
void updateTimeLabel();
|
|
|
|
|
2020-06-09 16:57:05 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time _seekPositionMs = -1;
|
|
|
|
crl::time _lastDurationMs = 0;
|
2016-10-12 19:34:25 +00:00
|
|
|
QString _time;
|
|
|
|
|
2017-05-21 13:16:39 +00:00
|
|
|
// 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;
|
2019-03-11 14:35:11 +00:00
|
|
|
AudioMsgId _lastSongId;
|
2017-05-21 13:16:39 +00:00
|
|
|
bool _voiceIsActive = false;
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> _closeCallback;
|
2021-06-15 23:06:22 +00:00
|
|
|
Fn<void(not_null<const HistoryItem*>)> _showItemCallback;
|
2017-05-21 13:16:39 +00:00
|
|
|
|
2017-05-21 15:14:42 +00:00
|
|
|
bool _labelsOver = false;
|
|
|
|
bool _labelsDown = false;
|
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
class PlayButton;
|
2021-08-30 23:31:34 +00:00
|
|
|
class SpeedButton;
|
2016-12-13 17:07:56 +00:00
|
|
|
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;
|
2021-11-18 17:02:12 +00:00
|
|
|
object_ptr<Ui::IconButton> _repeatToggle;
|
2021-08-30 23:31:34 +00:00
|
|
|
object_ptr<SpeedButton> _playbackSpeed;
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::IconButton> _close;
|
|
|
|
object_ptr<Ui::PlainShadow> _shadow = { nullptr };
|
2017-05-18 16:10:39 +00:00
|
|
|
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
|