2017-05-22 15:25: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.
|
2017-05-22 15:25: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
|
2017-05-22 15:25:49 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
#include "ui/rp_widget.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "ui/rect_part.h"
|
2019-04-02 09:13:30 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "base/object_ptr.h"
|
2017-10-05 15:35:52 +00:00
|
|
|
|
2018-01-21 14:49:42 +00:00
|
|
|
namespace Window {
|
2019-06-06 10:21:40 +00:00
|
|
|
class SessionController;
|
2018-11-05 11:16:09 +00:00
|
|
|
class AbstractSectionWidget;
|
|
|
|
enum class Column;
|
2018-01-21 14:49:42 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
2017-05-22 15:25:49 +00:00
|
|
|
namespace Media {
|
2019-02-27 11:36:19 +00:00
|
|
|
namespace View {
|
|
|
|
class PlaybackProgress;
|
|
|
|
} // namespace View
|
2019-03-26 08:54:51 +00:00
|
|
|
} // namespace Media
|
2017-05-22 15:25:49 +00:00
|
|
|
|
2019-03-26 08:54:51 +00:00
|
|
|
namespace Media {
|
|
|
|
namespace Streaming {
|
2019-12-11 10:15:48 +00:00
|
|
|
class Document;
|
2019-03-26 08:54:51 +00:00
|
|
|
class Player;
|
|
|
|
} // namespace Streaming
|
|
|
|
} // namespace Media
|
|
|
|
|
|
|
|
namespace Media {
|
2017-05-22 15:25:49 +00:00
|
|
|
namespace Player {
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
class Float : public Ui::RpWidget, private base::Subscriber {
|
2017-05-22 15:25:49 +00:00
|
|
|
public:
|
2018-01-21 14:49:42 +00:00
|
|
|
Float(
|
|
|
|
QWidget *parent,
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2018-01-21 14:49:42 +00:00
|
|
|
not_null<HistoryItem*> item,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(bool visible)> toggleCallback,
|
|
|
|
Fn<void(bool closed)> draggedCallback);
|
2017-05-22 15:25:49 +00:00
|
|
|
|
2019-12-11 10:15:48 +00:00
|
|
|
[[nodiscard]] HistoryItem *item() const {
|
2017-05-23 14:04:59 +00:00
|
|
|
return _item;
|
2017-05-22 15:25:49 +00:00
|
|
|
}
|
|
|
|
void setOpacity(float64 opacity) {
|
2017-05-23 18:00:57 +00:00
|
|
|
if (_opacity != opacity) {
|
|
|
|
_opacity = opacity;
|
|
|
|
update();
|
|
|
|
}
|
2017-05-22 15:25:49 +00:00
|
|
|
}
|
2019-12-11 10:15:48 +00:00
|
|
|
[[nodiscard]] float64 countOpacityByParent() const {
|
2017-05-24 12:07:58 +00:00
|
|
|
return outRatio();
|
|
|
|
}
|
2019-12-11 10:15:48 +00:00
|
|
|
[[nodiscard]] bool isReady() const {
|
2019-03-26 08:54:51 +00:00
|
|
|
return (getPlayer() != nullptr);
|
2017-08-01 17:59:43 +00:00
|
|
|
}
|
2017-05-22 15:25:49 +00:00
|
|
|
void detach();
|
2019-12-11 10:15:48 +00:00
|
|
|
[[nodiscard]] bool detached() const {
|
2017-05-22 15:25:49 +00:00
|
|
|
return !_item;
|
|
|
|
}
|
2019-12-11 10:15:48 +00:00
|
|
|
[[nodiscard]] bool dragged() const {
|
2017-05-23 18:00:57 +00:00
|
|
|
return _drag;
|
|
|
|
}
|
2017-05-23 14:40:25 +00:00
|
|
|
void resetMouseState() {
|
|
|
|
_down = false;
|
2017-05-23 18:00:57 +00:00
|
|
|
if (_drag) {
|
|
|
|
finishDrag(false);
|
|
|
|
}
|
2017-05-23 14:40:25 +00:00
|
|
|
}
|
2017-05-22 15:25:49 +00:00
|
|
|
|
|
|
|
protected:
|
2017-05-23 14:40:25 +00:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2017-05-23 18:00:57 +00:00
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
2017-05-23 14:40:25 +00:00
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void mouseDoubleClickEvent(QMouseEvent *e) override;
|
2017-05-22 15:25:49 +00:00
|
|
|
|
|
|
|
private:
|
2019-12-11 10:15:48 +00:00
|
|
|
[[nodiscard]] float64 outRatio() const;
|
|
|
|
[[nodiscard]] Streaming::Document *getStreamed() const;
|
|
|
|
[[nodiscard]] const Streaming::Player *getPlayer() const;
|
|
|
|
[[nodiscard]] View::PlaybackProgress *getPlayback() const;
|
2017-05-22 15:25:49 +00:00
|
|
|
void repaintItem();
|
|
|
|
void prepareShadow();
|
|
|
|
bool hasFrame() const;
|
|
|
|
bool fillFrame();
|
2019-12-11 10:15:48 +00:00
|
|
|
[[nodiscard]] QRect getInnerRect() const;
|
2017-05-23 18:00:57 +00:00
|
|
|
void finishDrag(bool closed);
|
2019-03-26 08:54:51 +00:00
|
|
|
void pauseResume();
|
2017-05-22 15:25:49 +00:00
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> _controller;
|
2017-05-22 15:25:49 +00:00
|
|
|
HistoryItem *_item = nullptr;
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(bool visible)> _toggleCallback;
|
2017-05-22 15:25:49 +00:00
|
|
|
|
|
|
|
float64 _opacity = 1.;
|
|
|
|
|
|
|
|
QPixmap _shadow;
|
|
|
|
QImage _frame;
|
2017-05-23 14:40:25 +00:00
|
|
|
bool _down = false;
|
2017-05-23 18:00:57 +00:00
|
|
|
QPoint _downPoint;
|
|
|
|
|
|
|
|
bool _drag = false;
|
|
|
|
QPoint _dragLocalPoint;
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(bool closed)> _draggedCallback;
|
2017-05-22 15:25:49 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-11-05 11:16:09 +00:00
|
|
|
class FloatDelegate {
|
|
|
|
public:
|
|
|
|
virtual not_null<Ui::RpWidget*> floatPlayerWidget() = 0;
|
2019-06-06 10:21:40 +00:00
|
|
|
virtual not_null<Window::SessionController*> floatPlayerController() = 0;
|
2018-11-05 11:16:09 +00:00
|
|
|
virtual not_null<Window::AbstractSectionWidget*> floatPlayerGetSection(
|
|
|
|
Window::Column column) = 0;
|
|
|
|
virtual void floatPlayerEnumerateSections(Fn<void(
|
|
|
|
not_null<Window::AbstractSectionWidget*> widget,
|
|
|
|
Window::Column widgetColumn)> callback) = 0;
|
2018-11-05 13:18:54 +00:00
|
|
|
virtual bool floatPlayerIsVisible(not_null<HistoryItem*> item) = 0;
|
|
|
|
|
|
|
|
virtual rpl::producer<> floatPlayerCheckVisibilityRequests() {
|
|
|
|
return _checkVisibility.events();
|
|
|
|
}
|
|
|
|
virtual rpl::producer<> floatPlayerHideAllRequests() {
|
|
|
|
return _hideAll.events();
|
|
|
|
}
|
|
|
|
virtual rpl::producer<> floatPlayerShowVisibleRequests() {
|
|
|
|
return _showVisible.events();
|
|
|
|
}
|
|
|
|
virtual rpl::producer<> floatPlayerRaiseAllRequests() {
|
|
|
|
return _raiseAll.events();
|
|
|
|
}
|
|
|
|
virtual rpl::producer<> floatPlayerUpdatePositionsRequests() {
|
|
|
|
return _updatePositions.events();;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct FloatPlayerFilterWheelEventRequest {
|
|
|
|
not_null<QObject*> object;
|
|
|
|
not_null<QEvent*> event;
|
|
|
|
not_null<std::optional<bool>*> result;
|
|
|
|
};
|
|
|
|
virtual auto floatPlayerFilterWheelEventRequests()
|
|
|
|
-> rpl::producer<FloatPlayerFilterWheelEventRequest> {
|
|
|
|
return _filterWheelEvent.events();
|
|
|
|
}
|
|
|
|
|
2019-02-15 11:24:58 +00:00
|
|
|
virtual ~FloatDelegate() = default;
|
|
|
|
|
2018-11-05 13:18:54 +00:00
|
|
|
protected:
|
|
|
|
void floatPlayerCheckVisibility() {
|
|
|
|
_checkVisibility.fire({});
|
|
|
|
}
|
|
|
|
void floatPlayerHideAll() {
|
|
|
|
_hideAll.fire({});
|
|
|
|
}
|
|
|
|
void floatPlayerShowVisible() {
|
|
|
|
_showVisible.fire({});
|
|
|
|
}
|
|
|
|
void floatPlayerRaiseAll() {
|
|
|
|
_raiseAll.fire({});
|
|
|
|
}
|
|
|
|
void floatPlayerUpdatePositions() {
|
|
|
|
_updatePositions.fire({});
|
|
|
|
}
|
|
|
|
std::optional<bool> floatPlayerFilterWheelEvent(
|
|
|
|
not_null<QObject*> object,
|
|
|
|
not_null<QEvent*> event) {
|
|
|
|
auto result = std::optional<bool>();
|
|
|
|
_filterWheelEvent.fire({ object, event, &result });
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
rpl::event_stream<> _checkVisibility;
|
|
|
|
rpl::event_stream<> _hideAll;
|
|
|
|
rpl::event_stream<> _showVisible;
|
|
|
|
rpl::event_stream<> _raiseAll;
|
|
|
|
rpl::event_stream<> _updatePositions;
|
|
|
|
rpl::event_stream<FloatPlayerFilterWheelEventRequest> _filterWheelEvent;
|
2018-11-05 11:16:09 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class FloatController : private base::Subscriber {
|
|
|
|
public:
|
|
|
|
explicit FloatController(not_null<FloatDelegate*> delegate);
|
|
|
|
|
2018-11-05 13:18:54 +00:00
|
|
|
void replaceDelegate(not_null<FloatDelegate*> delegate);
|
|
|
|
rpl::producer<FullMsgId> closeEvents() const {
|
|
|
|
return _closeEvents.events();
|
|
|
|
}
|
2018-11-05 11:16:09 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct Item {
|
|
|
|
template <typename ToggleCallback, typename DraggedCallback>
|
|
|
|
Item(
|
|
|
|
not_null<QWidget*> parent,
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2018-11-05 11:16:09 +00:00
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
ToggleCallback toggle,
|
|
|
|
DraggedCallback dragged);
|
|
|
|
|
|
|
|
bool hiddenByWidget = false;
|
|
|
|
bool hiddenByHistory = false;
|
|
|
|
bool visible = false;
|
|
|
|
RectPart animationSide;
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple visibleAnimation;
|
2018-11-05 11:16:09 +00:00
|
|
|
Window::Column column;
|
|
|
|
RectPart corner;
|
|
|
|
QPoint dragFrom;
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple draggedAnimation;
|
2018-11-05 11:16:09 +00:00
|
|
|
bool hiddenByDrag = false;
|
|
|
|
object_ptr<Float> widget;
|
|
|
|
};
|
|
|
|
|
|
|
|
void checkCurrent();
|
|
|
|
void create(not_null<HistoryItem*> item);
|
|
|
|
void toggle(not_null<Item*> instance);
|
|
|
|
void updatePosition(not_null<Item*> instance);
|
|
|
|
void remove(not_null<Item*> instance);
|
|
|
|
Item *current() const {
|
|
|
|
return _items.empty() ? nullptr : _items.back().get();
|
|
|
|
}
|
|
|
|
void finishDrag(
|
|
|
|
not_null<Item*> instance,
|
|
|
|
bool closed);
|
|
|
|
void updateColumnCorner(QPoint center);
|
|
|
|
QPoint getPosition(not_null<Item*> instance) const;
|
|
|
|
QPoint getHiddenPosition(
|
|
|
|
QPoint position,
|
|
|
|
QSize size,
|
|
|
|
RectPart side) const;
|
|
|
|
RectPart getSide(QPoint center) const;
|
|
|
|
|
2018-11-05 13:18:54 +00:00
|
|
|
void startDelegateHandling();
|
|
|
|
void checkVisibility();
|
|
|
|
void hideAll();
|
|
|
|
void showVisible();
|
|
|
|
void raiseAll();
|
|
|
|
void updatePositions();
|
|
|
|
std::optional<bool> filterWheelEvent(
|
|
|
|
not_null<QObject*> object,
|
|
|
|
not_null<QEvent*> event);
|
|
|
|
|
2018-11-05 11:16:09 +00:00
|
|
|
not_null<FloatDelegate*> _delegate;
|
|
|
|
not_null<Ui::RpWidget*> _parent;
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> _controller;
|
2018-11-05 11:16:09 +00:00
|
|
|
std::vector<std::unique_ptr<Item>> _items;
|
|
|
|
|
2018-11-05 13:18:54 +00:00
|
|
|
rpl::event_stream<FullMsgId> _closeEvents;
|
|
|
|
rpl::lifetime _delegateLifetime;
|
|
|
|
|
2018-11-05 11:16:09 +00:00
|
|
|
};
|
|
|
|
|
2017-05-22 15:25:49 +00:00
|
|
|
} // namespace Player
|
|
|
|
} // namespace Media
|