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); } }
int countNodes(TreeNode* root) { if (root == NULL) return 0; int leftHeigth = lheight(root->left); int rightHeight = rheight(root->right); if (leftHeigth == rightHeight) //可以快速判断是满完全二叉树 return pow(2, leftHeigth + 1) - 1; else// if (leftHeigth > rightHeight){ //并非满完全二叉树 return countNodes(root->left) + countNodes(root->right) + 1; //} //else if (leftHeigth < rightHeight) //对于完全二叉树而言,不会出现这种情况 }
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; }
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; }