2020-01-03 11:18:38 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "media/streaming/media_streaming_instance.h"
|
2020-01-03 13:22:59 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2020-02-03 11:38:42 +00:00
|
|
|
#include "ui/round_rect.h"
|
2020-01-03 11:18:38 +00:00
|
|
|
#include "ui/rp_widget.h"
|
|
|
|
|
2020-01-06 17:54:11 +00:00
|
|
|
#include <QtCore/QPointer>
|
|
|
|
|
2020-03-27 11:40:50 +00:00
|
|
|
namespace Data {
|
|
|
|
class DocumentMedia;
|
|
|
|
} // namespace Data
|
|
|
|
|
2020-01-28 11:48:29 +00:00
|
|
|
namespace Ui {
|
|
|
|
class IconButton;
|
|
|
|
template <typename Widget>
|
|
|
|
class FadeWrap;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2020-01-03 11:18:38 +00:00
|
|
|
namespace Media {
|
2020-01-28 11:48:29 +00:00
|
|
|
namespace Player {
|
|
|
|
struct TrackState;
|
|
|
|
} // namespace Player
|
|
|
|
|
2020-01-03 11:18:38 +00:00
|
|
|
namespace View {
|
|
|
|
|
2020-02-03 14:19:58 +00:00
|
|
|
class PlaybackProgress;
|
|
|
|
|
2020-02-05 16:04:33 +00:00
|
|
|
[[nodiscard]] QRect RotatedRect(QRect rect, int rotation);
|
|
|
|
[[nodiscard]] bool UsePainterRotation(int rotation);
|
|
|
|
[[nodiscard]] QSize FlipSizeByRotation(QSize size, int rotation);
|
|
|
|
[[nodiscard]] QImage RotateFrameImage(QImage image, int rotation);
|
|
|
|
|
2020-01-03 11:18:38 +00:00
|
|
|
#if defined Q_OS_MAC && !defined OS_MAC_OLD
|
|
|
|
#define USE_OPENGL_OVERLAY_WIDGET
|
|
|
|
#endif // Q_OS_MAC && !OS_MAC_OLD
|
|
|
|
|
|
|
|
#ifdef USE_OPENGL_OVERLAY_WIDGET
|
|
|
|
using PipParent = Ui::RpWidgetWrap<QOpenGLWidget>;
|
|
|
|
#else // USE_OPENGL_OVERLAY_WIDGET
|
|
|
|
using PipParent = Ui::RpWidget;
|
|
|
|
#endif // USE_OPENGL_OVERLAY_WIDGET
|
|
|
|
|
2020-01-06 17:54:11 +00:00
|
|
|
class PipPanel final : public PipParent {
|
2020-01-03 11:18:38 +00:00
|
|
|
public:
|
2020-01-06 17:54:11 +00:00
|
|
|
struct Position {
|
|
|
|
RectParts attached = RectPart(0);
|
|
|
|
RectParts snapped = RectPart(0);
|
|
|
|
QRect geometry;
|
|
|
|
QRect screen;
|
|
|
|
};
|
|
|
|
using FrameRequest = Streaming::FrameRequest;
|
|
|
|
|
|
|
|
PipPanel(
|
|
|
|
QWidget *parent,
|
2020-01-06 19:50:03 +00:00
|
|
|
Fn<void(QPainter&, FrameRequest)> paint);
|
2020-01-06 17:54:11 +00:00
|
|
|
|
|
|
|
void setAspectRatio(QSize ratio);
|
|
|
|
[[nodiscard]] Position countPosition() const;
|
|
|
|
void setPosition(Position position);
|
2020-01-31 09:54:57 +00:00
|
|
|
[[nodiscard]] QRect inner() const;
|
2020-02-03 11:38:42 +00:00
|
|
|
[[nodiscard]] RectParts attached() const;
|
2020-02-03 15:48:25 +00:00
|
|
|
void setDragDisabled(bool disabled);
|
2020-01-31 09:54:57 +00:00
|
|
|
[[nodiscard]] bool dragging() const;
|
2020-01-03 11:18:38 +00:00
|
|
|
|
2020-01-29 13:16:22 +00:00
|
|
|
[[nodiscard]] rpl::producer<> saveGeometryRequests() const;
|
|
|
|
|
2020-01-03 11:18:38 +00:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
2020-01-06 17:54:11 +00:00
|
|
|
void setPositionDefault();
|
|
|
|
void setPositionOnScreen(Position position, QRect available);
|
|
|
|
|
2020-01-06 19:50:03 +00:00
|
|
|
QScreen *myScreen() const;
|
2020-10-19 01:23:30 +00:00
|
|
|
void startSystemDrag();
|
2020-01-29 13:16:22 +00:00
|
|
|
void processDrag(QPoint point);
|
2020-01-03 13:22:59 +00:00
|
|
|
void finishDrag(QPoint point);
|
|
|
|
void updatePositionAnimated();
|
2020-01-06 19:50:03 +00:00
|
|
|
void updateOverState(QPoint point);
|
2020-01-03 13:22:59 +00:00
|
|
|
void moveAnimated(QPoint to);
|
2020-01-29 13:16:22 +00:00
|
|
|
void updateDecorations();
|
2020-01-03 11:18:38 +00:00
|
|
|
|
2020-01-06 17:54:11 +00:00
|
|
|
QPointer<QWidget> _parent;
|
2020-01-06 19:50:03 +00:00
|
|
|
Fn<void(QPainter&, FrameRequest)> _paint;
|
2020-01-06 17:54:11 +00:00
|
|
|
RectParts _attached = RectParts();
|
2020-01-29 13:16:22 +00:00
|
|
|
RectParts _snapped = RectParts();
|
2020-01-06 17:54:11 +00:00
|
|
|
QSize _ratio;
|
2020-01-03 11:18:38 +00:00
|
|
|
|
2020-01-29 08:58:07 +00:00
|
|
|
bool _useTransparency = true;
|
2020-02-03 15:48:25 +00:00
|
|
|
bool _dragDisabled = false;
|
2020-01-29 08:58:07 +00:00
|
|
|
style::margins _padding;
|
|
|
|
|
2020-01-06 19:50:03 +00:00
|
|
|
RectPart _overState = RectPart();
|
|
|
|
std::optional<RectPart> _pressState;
|
|
|
|
QPoint _pressPoint;
|
2020-01-29 13:16:22 +00:00
|
|
|
QRect _dragStartGeometry;
|
|
|
|
std::optional<RectPart> _dragState;
|
|
|
|
rpl::event_stream<> _saveGeometryRequests;
|
2020-01-03 11:18:38 +00:00
|
|
|
|
2020-01-03 13:22:59 +00:00
|
|
|
QPoint _positionAnimationFrom;
|
|
|
|
QPoint _positionAnimationTo;
|
|
|
|
Ui::Animations::Simple _positionAnimation;
|
|
|
|
|
2020-01-03 11:18:38 +00:00
|
|
|
};
|
|
|
|
|
2020-01-06 17:54:11 +00:00
|
|
|
class Pip final {
|
|
|
|
public:
|
2020-01-29 08:58:07 +00:00
|
|
|
class Delegate {
|
|
|
|
public:
|
|
|
|
virtual void pipSaveGeometry(QByteArray geometry) = 0;
|
|
|
|
[[nodiscard]] virtual QByteArray pipLoadGeometry() = 0;
|
|
|
|
[[nodiscard]] virtual float64 pipPlaybackSpeed() = 0;
|
|
|
|
[[nodiscard]] virtual QWidget *pipParentWidget() = 0;
|
|
|
|
};
|
|
|
|
|
2020-01-06 17:54:11 +00:00
|
|
|
Pip(
|
2020-01-29 08:58:07 +00:00
|
|
|
not_null<Delegate*> delegate,
|
2020-03-27 11:40:50 +00:00
|
|
|
not_null<DocumentData*> data,
|
2020-02-03 13:44:12 +00:00
|
|
|
FullMsgId contextId,
|
|
|
|
std::shared_ptr<Streaming::Document> shared,
|
2020-01-06 17:54:11 +00:00
|
|
|
FnMut<void()> closeAndContinue,
|
|
|
|
FnMut<void()> destroy);
|
2020-02-03 14:19:58 +00:00
|
|
|
~Pip();
|
2020-01-06 17:54:11 +00:00
|
|
|
|
|
|
|
private:
|
2020-01-31 09:54:57 +00:00
|
|
|
enum class OverState {
|
|
|
|
None,
|
|
|
|
Close,
|
|
|
|
Enlarge,
|
|
|
|
Playback,
|
|
|
|
Other,
|
|
|
|
};
|
2020-02-03 13:44:12 +00:00
|
|
|
enum class ThumbState {
|
|
|
|
Empty,
|
|
|
|
Inline,
|
|
|
|
Thumb,
|
|
|
|
Good,
|
|
|
|
Cover,
|
|
|
|
};
|
2020-01-31 09:54:57 +00:00
|
|
|
struct Button {
|
|
|
|
QRect area;
|
|
|
|
QRect icon;
|
|
|
|
OverState state = OverState::None;
|
|
|
|
Ui::Animations::Simple active;
|
|
|
|
};
|
2020-01-06 17:54:11 +00:00
|
|
|
using FrameRequest = Streaming::FrameRequest;
|
|
|
|
|
|
|
|
void setupPanel();
|
2020-01-29 08:58:07 +00:00
|
|
|
void setupButtons();
|
2020-01-06 17:54:11 +00:00
|
|
|
void setupStreaming();
|
2020-01-06 19:50:03 +00:00
|
|
|
void paint(QPainter &p, FrameRequest request);
|
2020-01-06 17:54:11 +00:00
|
|
|
void playbackPauseResume();
|
|
|
|
void waitingAnimationCallback();
|
|
|
|
void handleStreamingUpdate(Streaming::Update &&update);
|
|
|
|
void handleStreamingError(Streaming::Error &&error);
|
2020-01-29 08:58:07 +00:00
|
|
|
void saveGeometry();
|
2020-01-06 17:54:11 +00:00
|
|
|
|
2020-01-28 11:48:29 +00:00
|
|
|
void updatePlaybackState();
|
|
|
|
void updatePlayPauseResumeState(const Player::TrackState &state);
|
|
|
|
void restartAtSeekPosition(crl::time position);
|
|
|
|
|
2020-06-05 10:26:42 +00:00
|
|
|
[[nodiscard]] bool canUseVideoFrame() const;
|
2020-01-06 17:54:11 +00:00
|
|
|
[[nodiscard]] QImage videoFrame(const FrameRequest &request) const;
|
|
|
|
[[nodiscard]] QImage videoFrameForDirectPaint(
|
|
|
|
const FrameRequest &request) const;
|
2020-01-31 09:54:57 +00:00
|
|
|
[[nodiscard]] OverState computeState(QPoint position) const;
|
|
|
|
void setOverState(OverState state);
|
2020-02-03 15:48:25 +00:00
|
|
|
void setPressedState(std::optional<OverState> state);
|
|
|
|
[[nodiscard]] OverState activeState() const;
|
|
|
|
[[nodiscard]] float64 activeValue(const Button &button) const;
|
|
|
|
void updateActiveState(OverState was);
|
2020-02-03 17:24:45 +00:00
|
|
|
void updatePlaybackTexts(int64 position, int64 length, int64 frequency);
|
2020-01-31 09:54:57 +00:00
|
|
|
|
|
|
|
void handleMouseMove(QPoint position);
|
2020-02-03 15:48:25 +00:00
|
|
|
void handleMousePress(QPoint position, Qt::MouseButton button);
|
|
|
|
void handleMouseRelease(QPoint position, Qt::MouseButton button);
|
2020-02-03 09:50:26 +00:00
|
|
|
void handleDoubleClick(Qt::MouseButton button);
|
2020-01-31 09:54:57 +00:00
|
|
|
void handleLeave();
|
|
|
|
void handleClose();
|
|
|
|
|
2020-02-03 14:19:58 +00:00
|
|
|
void paintControls(QPainter &p) const;
|
|
|
|
void paintFade(QPainter &p) const;
|
|
|
|
void paintButtons(QPainter &p) const;
|
|
|
|
void paintPlayback(QPainter &p) const;
|
2020-02-03 17:24:45 +00:00
|
|
|
void paintPlaybackTexts(QPainter &p) const;
|
2020-02-03 12:38:00 +00:00
|
|
|
void paintRadialLoading(QPainter &p) const;
|
|
|
|
void paintRadialLoadingContent(QPainter &p, const QRect &inner) const;
|
|
|
|
[[nodiscard]] QRect countRadialRect() const;
|
2020-01-06 17:54:11 +00:00
|
|
|
|
2020-02-03 15:48:25 +00:00
|
|
|
void seekUpdate(QPoint position);
|
|
|
|
void seekProgress(float64 value);
|
|
|
|
void seekFinish(float64 value);
|
|
|
|
|
2020-01-29 08:58:07 +00:00
|
|
|
const not_null<Delegate*> _delegate;
|
2020-03-27 11:40:50 +00:00
|
|
|
not_null<DocumentData*> _data;
|
2020-02-03 13:44:12 +00:00
|
|
|
FullMsgId _contextId;
|
2020-01-06 17:54:11 +00:00
|
|
|
Streaming::Instance _instance;
|
|
|
|
PipPanel _panel;
|
|
|
|
QSize _size;
|
2020-02-03 14:19:58 +00:00
|
|
|
std::unique_ptr<PlaybackProgress> _playbackProgress;
|
2020-03-27 11:40:50 +00:00
|
|
|
std::shared_ptr<Data::DocumentMedia> _dataMedia;
|
2020-01-07 14:30:49 +00:00
|
|
|
|
2020-01-28 11:48:29 +00:00
|
|
|
bool _showPause = false;
|
2020-02-03 15:48:25 +00:00
|
|
|
bool _startPaused = false;
|
|
|
|
bool _pausedBySeek = false;
|
2020-02-03 17:24:45 +00:00
|
|
|
QString _timeAlready, _timeLeft;
|
|
|
|
int _timeLeftWidth = 0;
|
2020-02-05 16:04:33 +00:00
|
|
|
int _rotation = 0;
|
2020-02-03 15:48:25 +00:00
|
|
|
crl::time _seekPositionMs = -1;
|
|
|
|
crl::time _lastDurationMs = 0;
|
2020-01-31 09:54:57 +00:00
|
|
|
OverState _over = OverState::None;
|
|
|
|
std::optional<OverState> _pressed;
|
2020-02-03 09:50:26 +00:00
|
|
|
std::optional<OverState> _lastHandledPress;
|
2020-01-31 09:54:57 +00:00
|
|
|
Button _close;
|
|
|
|
Button _enlarge;
|
|
|
|
Button _playback;
|
|
|
|
Button _play;
|
|
|
|
Ui::Animations::Simple _controlsShown;
|
2020-02-03 11:38:42 +00:00
|
|
|
Ui::RoundRect _roundRect;
|
2020-01-28 11:48:29 +00:00
|
|
|
|
2020-01-06 17:54:11 +00:00
|
|
|
FnMut<void()> _closeAndContinue;
|
|
|
|
FnMut<void()> _destroy;
|
|
|
|
|
2020-01-07 14:30:49 +00:00
|
|
|
#ifdef USE_OPENGL_OVERLAY_WIDGET
|
|
|
|
mutable QImage _frameForDirectPaint;
|
2020-02-03 12:38:00 +00:00
|
|
|
mutable QImage _radialCache;
|
2020-01-07 14:30:49 +00:00
|
|
|
#endif // USE_OPENGL_OVERLAY_WIDGET
|
|
|
|
|
2020-01-06 17:54:11 +00:00
|
|
|
mutable QImage _preparedCoverStorage;
|
|
|
|
mutable FrameRequest _preparedCoverRequest;
|
2020-02-03 13:44:12 +00:00
|
|
|
mutable ThumbState _preparedCoverState;
|
2020-01-06 17:54:11 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-01-03 11:18:38 +00:00
|
|
|
} // namespace View
|
|
|
|
} // namespace Media
|