Exemplo n.º 1
0
Float::Float(QWidget *parent, HistoryItem *item, base::lambda<void(bool visible)> toggleCallback, base::lambda<void(bool closed)> draggedCallback) : TWidget(parent)
, _item(item)
, _toggleCallback(std::move(toggleCallback))
, _draggedCallback(std::move(draggedCallback)) {
	auto media = _item->getMedia();
	t_assert(media != nullptr);

	auto document = media->getDocument();
	t_assert(document != nullptr);
	t_assert(document->isRoundVideo());

	auto margin = st::mediaPlayerFloatMargin;
	auto size = 2 * margin + st::mediaPlayerFloatSize;
	resize(size, size);

	prepareShadow();

	subscribe(Global::RefItemRemoved(), [this](HistoryItem *item) {
		if (_item == item) {
			detach();
		}
	});

	setCursor(style::cur_pointer);
}
Float::Float(
	QWidget *parent,
	not_null<Window::Controller*> controller,
	not_null<HistoryItem*> item,
	Fn<void(bool visible)> toggleCallback,
	Fn<void(bool closed)> draggedCallback)
: RpWidget(parent)
, _controller(controller)
, _item(item)
, _toggleCallback(std::move(toggleCallback))
, _draggedCallback(std::move(draggedCallback)) {
	auto media = _item->media();
	Assert(media != nullptr);

	auto document = media->document();
	Assert(document != nullptr);
	Assert(document->isVideoMessage());

	auto margin = st::mediaPlayerFloatMargin;
	auto size = 2 * margin + st::mediaPlayerFloatSize;
	resize(size, size);

	prepareShadow();

	Auth().data().itemRepaintRequest(
	) | rpl::start_with_next([this](auto item) {
		if (_item == item) {
			repaintItem();
		}
	}, lifetime());
	Auth().data().itemRemoved(
	) | rpl::start_with_next([this](auto item) {
		if (_item == item) {
			detach();
		}
	}, lifetime());

	setCursor(style::cur_pointer);
}