/* 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 "base/unique_qptr.h" #include "ui/ui_integration.h" #include template class object_ptr; namespace Ui { namespace details { struct ForwardTag { }; struct InPlaceTag { }; template class AttachmentOwner : public QObject { public: template AttachmentOwner(QObject *parent, const ForwardTag&, OtherValue &&value) : QObject(parent) , _value(std::forward(value)) { } template AttachmentOwner(QObject *parent, const InPlaceTag&, Args &&...args) : QObject(parent) , _value(std::forward(args)...) { } not_null value() { return &_value; } private: Value _value; }; } // namespace details template inline base::unique_qptr CreateObject(Args &&...args) { return base::make_unique_q( nullptr, std::forward(args)...); } template inline Value *CreateChild( Parent *parent, Args &&...args) { Expects(parent != nullptr); if constexpr (std::is_base_of_v) { return new Value(parent, std::forward(args)...); } else { return CreateChild>( parent, details::InPlaceTag{}, std::forward(args)...)->value(); } } inline void DestroyChild(QWidget *child) { delete child; } template inline auto Connect(Args &&...args) { return QObject::connect(std::forward(args)...); } template inline not_null*> AttachAsChild( not_null parent, Value &&value) { return CreateChild>>( parent.get(), details::ForwardTag{}, std::forward(value))->value(); } [[nodiscard]] inline bool InFocusChain(not_null widget) { if (const auto top = widget->window()) { if (auto focused = top->focusWidget()) { return !widget->isHidden() && (focused == widget || widget->isAncestorOf(focused)); } } return false; } template inline ChildWidget *AttachParentChild( not_null parent, const object_ptr &child) { if (const auto raw = child.data()) { raw->setParent(parent); raw->show(); return raw; } return nullptr; } void SendPendingMoveResizeEvents(not_null target); [[nodiscard]] QPixmap GrabWidget( not_null target, QRect rect = QRect(), QColor bg = QColor(255, 255, 255, 0)); [[nodiscard]] QImage GrabWidgetToImage( not_null target, QRect rect = QRect(), QColor bg = QColor(255, 255, 255, 0)); void RenderWidget( QPainter &painter, not_null source, const QPoint &targetOffset = QPoint(), const QRegion &sourceRegion = QRegion(), QWidget::RenderFlags renderFlags = QWidget::DrawChildren | QWidget::IgnoreMask); void ForceFullRepaint(not_null widget); template < typename Guard, typename Callable, typename GuardTraits = crl::guard_traits>, typename = std::enable_if_t< sizeof(GuardTraits) != crl::details::dependent_zero>> inline void PostponeCall(Guard && object, Callable && callable) { return PostponeCall(crl::guard( std::forward(object), std::forward(callable))); } void SendSynteticMouseEvent( QWidget *widget, QEvent::Type type, Qt::MouseButton button, const QPoint &globalPoint); inline void SendSynteticMouseEvent( QWidget *widget, QEvent::Type type, Qt::MouseButton button) { return SendSynteticMouseEvent(widget, type, button, QCursor::pos()); } template QPointer MakeWeak(Widget *object) { return QPointer(object); } template QPointer MakeWeak(const Widget *object) { return QPointer(object); } template QPointer MakeWeak(not_null object) { return QPointer(object.get()); } template QPointer MakeWeak(not_null object) { return QPointer(object.get()); } } // namespace Ui