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;
|
2021-11-24 12:23:10 +00:00
|
|
|
template <typename Widget>
|
|
|
|
class FadeWrap;
|
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
|
|
|
|
2021-11-24 14:26:39 +00:00
|
|
|
namespace Window {
|
|
|
|
class SessionController;
|
|
|
|
} // namespace Window
|
2020-06-09 16:57:05 +00:00
|
|
|
|
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
|
|
|
|
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:
|
2021-11-24 14:26:39 +00:00
|
|
|
Widget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Ui::RpWidget*> dropdownsParent,
|
|
|
|
not_null<Window::SessionController*> controller);
|
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);
|
2021-11-24 14:26:39 +00:00
|
|
|
void hideShadowAndDropdowns();
|
|
|
|
void showShadowAndDropdowns();
|
|
|
|
void updateDropdownsGeometry();
|
|
|
|
void raiseDropdowns();
|
2021-11-18 17:02:39 +00:00
|
|
|
|
2021-11-19 11:55:09 +00:00
|
|
|
[[nodiscard]] rpl::producer<bool> togglePlaylistRequests() const {
|
|
|
|
return _togglePlaylistRequests.events();
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
~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;
|
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
|
|
|
|
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
|
|
|
|
2016-10-12 19:34:25 +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;
|
2016-10-14 17:10:15 +00:00
|
|
|
void updateOverLabelsState(QPoint pos);
|
|
|
|
void updateOverLabelsState(bool over);
|
2021-11-25 11:41:18 +00:00
|
|
|
void hidePlaylistOn(const object_ptr<Ui::IconButton> &button);
|
2016-10-14 17:10:15 +00:00
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
void updatePlayPrevNextPositions();
|
|
|
|
void updateLabelsGeometry();
|
2021-11-19 11:09:44 +00:00
|
|
|
void updateRepeatToggleIcon();
|
2021-08-31 16:11:37 +00:00
|
|
|
void updateControlsVisibility();
|
|
|
|
void updateControlsGeometry();
|
2021-11-24 12:23:10 +00:00
|
|
|
void updateControlsWrapGeometry();
|
2021-11-24 13:44:47 +00:00
|
|
|
void updateControlsWrapVisibility();
|
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();
|
2021-11-24 13:44:47 +00:00
|
|
|
void markOver(bool over);
|
2016-10-12 19:34:25 +00:00
|
|
|
|
2021-11-24 14:26:39 +00:00
|
|
|
const not_null<Window::SessionController*> _controller;
|
2021-11-25 11:41:18 +00:00
|
|
|
const not_null<Ui::RpWidget*> _orderMenuParent;
|
2020-06-09 16:57:05 +00:00
|
|
|
|
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;
|
2021-11-19 11:55:09 +00:00
|
|
|
rpl::event_stream<bool> _togglePlaylistRequests;
|
2021-11-24 13:44:47 +00:00
|
|
|
bool _narrow = false;
|
|
|
|
bool _over = false;
|
|
|
|
bool _wontBeOver = false;
|
2021-11-24 14:26:39 +00:00
|
|
|
bool _volumeHidden = false;
|
2017-05-21 15:14:42 +00:00
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
class PlayButton;
|
2021-11-25 13:24:23 +00:00
|
|
|
class OrderController;
|
2021-11-24 14:02:27 +00:00
|
|
|
class SpeedController;
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::FlatLabel> _nameLabel;
|
2021-11-24 12:23:10 +00:00
|
|
|
object_ptr<Ui::FadeWrap<Ui::RpWidget>> _rightControls;
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::LabelSimple> _timeLabel;
|
|
|
|
object_ptr<Ui::IconButton> _previousTrack = { nullptr };
|
2021-11-24 12:23:10 +00:00
|
|
|
object_ptr<Ui::IconButton> _playPause;
|
2016-12-13 17:07:56 +00:00
|
|
|
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-11-24 12:23:10 +00:00
|
|
|
object_ptr<Ui::IconButton> _orderToggle;
|
2021-11-25 13:24:23 +00:00
|
|
|
object_ptr<Ui::IconButton> _speedToggle;
|
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;
|
2021-11-25 11:41:18 +00:00
|
|
|
base::unique_qptr<Dropdown> _volume;
|
2019-02-27 11:36:19 +00:00
|
|
|
std::unique_ptr<View::PlaybackProgress> _playbackProgress;
|
2021-11-25 13:24:23 +00:00
|
|
|
std::unique_ptr<OrderController> _orderController;
|
2021-11-24 14:02:27 +00:00
|
|
|
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
|