QRect PreviewContentWidget::updateWidgetSize()
    {
        auto imageRect = getPreviewScaledRect();

        imageRect = QRect(
            imageRect.left(),
            imageRect.top(),
            std::max(imageRect.width(), 2),
            std::max(imageRect.height(), 2)
        );

        auto widgetHeight = imageRect.height();

        if (TextControl_)
        {
            widgetHeight += getTextBubbleSize().height();
            widgetHeight += getTextBottomMargin();
        }

        const QSize widgetSize(
            width(),
            widgetHeight
        );

        if (LastSize_ != widgetSize)
        {
            prepareTextGeometry();
            MessageContentWidget::setFixedSize(widgetSize);
        }

        LastSize_ = widgetSize;

        return imageRect;
    }
    QPoint PreviewContentWidget::deliveryStatusOffsetHint(const int32_t statusLineWidth) const
    {
        if (TextControl_ && TextControl_->isVisible())
        {
            const auto textSize = getTextBubbleSize();
            return QPoint(
                textSize.width() - statusLineWidth,
                textSize.height()
            );
        }

        if (PreviewsEnabled_ && !isBlockElement())
        {
            return QPoint(
                getPreviewScaledRect().width() + getPreviewScaledRect().x(),
                0
            );
        }

        return MessageContentWidget::deliveryStatusOffsetHint(statusLineWidth);
    }
    void PreviewContentWidget::renderPreloaderBubble(QPainter &p)
    {
        p.save();

        auto bodyBrush = (
            isOutgoing() ?
                Ui::MessageStyle::getOutgoingBodyColorA(0.7) :
                Ui::MessageStyle::getIncomingBodyColorA(0.7)
        );

        p.setBrush(bodyBrush);

        p.drawRoundedRect(getPreviewScaledRect(), Ui::MessageStyle::getBorderRadius(), Ui::MessageStyle::getBorderRadius());

        p.restore();
    }
	const QRect& FileSharingWidget::getControlButtonPreviewRect() const
	{
		assert(isState(State::ImageFile_Downloading) ||
			   isState(State::ImageFile_Uploading));

		if (Private_.ControlButtonPreviewRect_.isEmpty())
		{
			const auto &btn = downloadCancelButton();

			auto buttonRect = btn.GetRect();

			buttonRect.moveCenter(getPreviewScaledRect().center());

			Private_.ControlButtonPreviewRect_ = buttonRect;
		}

		return Private_.ControlButtonPreviewRect_;
	}
 bool FileSharingWidget::isOverPreview(const QPoint &p) const
 {
     return getPreviewScaledRect().contains(p);
 }