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"
|
|
|
|
|
2018-01-21 14:49:42 +00:00
|
|
|
namespace Window {
|
|
|
|
class Controller;
|
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 {
|
|
|
|
namespace Clip {
|
|
|
|
class Playback;
|
|
|
|
} // namespace Clip
|
|
|
|
|
|
|
|
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,
|
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
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
|
|
|
|
2017-05-23 14:04:59 +00:00
|
|
|
HistoryItem *item() const {
|
|
|
|
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
|
|
|
}
|
2017-05-24 12:07:58 +00:00
|
|
|
float64 countOpacityByParent() const {
|
|
|
|
return outRatio();
|
|
|
|
}
|
2017-08-01 17:59:43 +00:00
|
|
|
bool isReady() const {
|
|
|
|
return (getReader() != nullptr);
|
|
|
|
}
|
2017-05-22 15:25:49 +00:00
|
|
|
void detach();
|
|
|
|
bool detached() const {
|
|
|
|
return !_item;
|
|
|
|
}
|
2017-05-23 18:00:57 +00:00
|
|
|
bool dragged() const {
|
|
|
|
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:
|
2017-05-23 18:00:57 +00:00
|
|
|
float64 outRatio() const;
|
2017-05-22 15:25:49 +00:00
|
|
|
Clip::Reader *getReader() const;
|
2018-01-21 14:49:42 +00:00
|
|
|
Clip::Playback *getPlayback() const;
|
2017-05-22 15:25:49 +00:00
|
|
|
void repaintItem();
|
|
|
|
void prepareShadow();
|
|
|
|
bool hasFrame() const;
|
|
|
|
bool fillFrame();
|
|
|
|
QRect getInnerRect() const;
|
2017-05-23 18:00:57 +00:00
|
|
|
void finishDrag(bool closed);
|
2017-05-22 15:25:49 +00:00
|
|
|
|
2018-01-21 14:49:42 +00:00
|
|
|
not_null<Window::Controller*> _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;
|
|
|
|
virtual not_null<Window::Controller*> floatPlayerController() = 0;
|
|
|
|
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;
|
|
|
|
virtual void floatPlayerCloseHook(FullMsgId itemId) = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class FloatController : private base::Subscriber {
|
|
|
|
public:
|
|
|
|
explicit FloatController(not_null<FloatDelegate*> delegate);
|
|
|
|
|
|
|
|
void checkVisibility();
|
|
|
|
void hideAll();
|
|
|
|
void showVisible();
|
|
|
|
void raiseAll();
|
|
|
|
void updatePositions();
|
|
|
|
std::optional<bool> filterWheelEvent(
|
|
|
|
QObject *object,
|
|
|
|
QEvent *event);
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Item {
|
|
|
|
template <typename ToggleCallback, typename DraggedCallback>
|
|
|
|
Item(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
ToggleCallback toggle,
|
|
|
|
DraggedCallback dragged);
|
|
|
|
|
|
|
|
bool hiddenByWidget = false;
|
|
|
|
bool hiddenByHistory = false;
|
|
|
|
bool visible = false;
|
|
|
|
RectPart animationSide;
|
|
|
|
Animation visibleAnimation;
|
|
|
|
Window::Column column;
|
|
|
|
RectPart corner;
|
|
|
|
QPoint dragFrom;
|
|
|
|
Animation draggedAnimation;
|
|
|
|
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;
|
|
|
|
|
|
|
|
not_null<FloatDelegate*> _delegate;
|
|
|
|
not_null<Ui::RpWidget*> _parent;
|
|
|
|
not_null<Window::Controller*> _controller;
|
|
|
|
std::vector<std::unique_ptr<Item>> _items;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-05-22 15:25:49 +00:00
|
|
|
} // namespace Player
|
|
|
|
} // namespace Media
|