void PageGraphicsItem::paint (QPainter *painter,
			const QStyleOptionGraphicsItem *option, QWidget *w)
	{
		if (Invalid_ && IsDisplayed ())
		{
			auto backendObj = Doc_->GetBackendPlugin ();
			if (qobject_cast<IBackendPlugin*> (backendObj)->IsThreaded ())
			{
				if (!RenderFuture_)
					RequestThreadedRender ();

				auto size = Doc_->GetPageSize (PageNum_);
				size.rwidth () *= XScale_;
				size.rheight () *= YScale_;
				QPixmap px (size);
				px.fill ();
				setPixmap (px);
			}
			else
			{
				const auto& img = Doc_->RenderPage (PageNum_, XScale_, YScale_);
				setPixmap (QPixmap::fromImage (img));
			}
			Invalid_ = false;

			Core::Instance ().GetPixmapCacheManager ()->PixmapChanged (this);
		}

		QGraphicsPixmapItem::paint (painter, option, w);
		Core::Instance ().GetPixmapCacheManager ()->PixmapPainted (this);
	}
	void PageGraphicsItem::ClearPixmap ()
	{
		auto size = Doc_->GetPageSize (PageNum_);
		size.rwidth () *= XScale_;
		size.rheight () *= YScale_;
		setPixmap (QPixmap (size));

		Invalid_ = true;
	}
void ShareUserGroupWidget::slotAdjustScrollWidgetSize()
{
    QScrollArea *scrollArea = _ui->scrollArea;
    if (scrollArea->findChildren<ShareWidget*>().count() <= 3) {
        auto minimumSize = scrollArea->widget()->sizeHint();
        auto spacing = scrollArea->widget()->layout()->spacing();
        minimumSize.rwidth() += spacing;
        minimumSize.rheight() += spacing;
        scrollArea->setMinimumSize(minimumSize);
    }
}
    QSize PreviewContentWidget::getTextBubbleSize() const
    {
        auto bubbleSize = getTextSize();

        const auto textHeight = bubbleSize.height();

        bubbleSize.setHeight(
            std::max(
                Ui::MessageStyle::getBubbleHeight(),
                textHeight
            )
        );

        bubbleSize.setHeight(
            Utils::applyMultilineTextFix(textHeight, bubbleSize.height())
        );

        bubbleSize.rwidth() += Ui::MessageStyle::getBubbleHorPadding();
        bubbleSize.rwidth() += Ui::MessageStyle::getBubbleHorPadding();
        bubbleSize.rwidth() += Ui::MessageStatusWidget::getMaxWidth();
        bubbleSize.rheight() += getBubbleVertPadding();

        return bubbleSize;
    }
QSize ActionButtonWidgetLayout::evaluateProgressTextSize(const QString& progressText) const
{
    assert(Item_);

    if (progressText.isEmpty())
    {
        return QSize(0, 0);
    }

    const auto &font = Item_->getProgressTextFont();

    QFontMetrics m(font);

    auto textSize = m.boundingRect(progressText).size();

    // a workaround for the text width evaluation issues
    textSize.rwidth() *= 110;
    textSize.rwidth() /= 100;

    return textSize;
}
	QImage DocumentAdapter::RenderPage (int page, double xScale, double yScale)
	{
		const auto& size = Doc_->pageSize ();

		auto imgSize = size.toSize ();
		imgSize.rwidth () *= xScale;
		imgSize.rheight () *= yScale;
		QImage image (imgSize, QImage::Format_ARGB32);
		image.fill (Qt::white);

		QRectF rect (QPointF (0, 0), size);
		rect.moveTop (rect.height () * page);

		QPainter painter;
		painter.begin (&image);
		painter.scale (xScale, yScale);
		painter.translate (0, rect.height () * (-page));
		Doc_->drawContents (&painter, rect);
		painter.end ();

		return image;
	}
	QImage Document::RenderPage (int index, double xRes, double yRes)
	{
		auto page = spectre_document_get_page (SD_, index);

		auto rc = spectre_render_context_new ();
		auto size = GetPageSize (index);
		spectre_render_context_set_scale (rc, xRes, yRes);
		size.rwidth () *= xRes;
		size.rheight () *= yRes;

		unsigned char *data = 0;
		int rowLength = 0;
		spectre_page_render (page, rc, &data, &rowLength);
		spectre_render_context_free (rc);
		spectre_page_free (page);

		const QImage& img = rowLength == size.width () * 4 ?
				QImage (data, size.width (), size.height (), QImage::Format_RGB32) :
				QImage (data, rowLength / 4, size.height (), QImage::Format_RGB32)
					.copy (0, 0, size.width (), size.height ());
		free (data);
		return img;
	}