IntPoint ScrollableArea::constrainScrollPositionForOverhang(const IntRect& visibleContentRect, const IntSize& totalContentsSize, const IntPoint& scrollPosition, const IntPoint& scrollOrigin, int headerHeight, int footerHeight) { // The viewport rect that we're scrolling shouldn't be larger than our document. IntSize idealScrollRectSize(std::min(visibleContentRect.width(), totalContentsSize.width()), std::min(visibleContentRect.height(), totalContentsSize.height())); IntRect scrollRect(scrollPosition + scrollOrigin - IntSize(0, headerHeight), idealScrollRectSize); IntRect documentRect(IntPoint(), IntSize(totalContentsSize.width(), totalContentsSize.height() - headerHeight - footerHeight)); // Use intersection to constrain our ideal scroll rect by the document rect. scrollRect.intersect(documentRect); if (scrollRect.size() != idealScrollRectSize) { // If the rect was clipped, restore its size, effectively pushing it "down" from the top left. scrollRect.setSize(idealScrollRectSize); // If we still clip, push our rect "up" from the bottom right. scrollRect.intersect(documentRect); if (scrollRect.width() < idealScrollRectSize.width()) scrollRect.move(-(idealScrollRectSize.width() - scrollRect.width()), 0); if (scrollRect.height() < idealScrollRectSize.height()) scrollRect.move(0, -(idealScrollRectSize.height() - scrollRect.height())); } return scrollRect.location() - toIntSize(scrollOrigin); }
void QLabelPrivate::ensureTextLayouted() const { if (!textLayoutDirty) return; ensureTextPopulated(); if (control) { QTextDocument *doc = control->document(); QTextOption opt = doc->defaultTextOption(); opt.setAlignment(QFlag(this->align)); if (this->align & Qt::TextWordWrap) opt.setWrapMode(QTextOption::WordWrap); else opt.setWrapMode(QTextOption::ManualWrap); doc->setDefaultTextOption(opt); QTextFrameFormat fmt = doc->rootFrame()->frameFormat(); fmt.setMargin(0); doc->rootFrame()->setFrameFormat(fmt); doc->setTextWidth(documentRect().width()); } textLayoutDirty = false; }
// Return the layout rect - this is the rect that is given to the layout painting code // This may be different from the document rect since vertical alignment is not // done by the text layout code QRectF QLabelPrivate::layoutRect() const { QRectF cr = documentRect(); if (!control) return cr; ensureTextLayouted(); // Caculate y position manually qreal rh = control->document()->documentLayout()->documentSize().height(); qreal yo = 0; if (align & Qt::AlignVCenter) yo = qMax((cr.height()-rh)/2, qreal(0)); else if (align & Qt::AlignBottom) yo = qMax(cr.height()-rh, qreal(0)); return QRectF(cr.x(), yo + cr.y(), cr.width(), cr.height()); }
void KPrViewModePreviewShapeAnimations::activate(KoPAViewMode *previousViewMode) { m_savedViewMode = previousViewMode; // store the previous view mode m_animationCache = new KPrAnimationCache(); m_canvas->shapeManager()->setPaintingStrategy(new KPrShapeManagerAnimationStrategy(m_canvas->shapeManager(), m_animationCache, new KPrPageSelectStrategyActive(m_canvas))); // the update of the canvas is needed so that the old page gets drawn fully before the effect starts const KoPageLayout &layout = activePageLayout(); QSizeF pageSize(layout.width, layout.height); //calculate size of union page + viewport QSizeF documentMinSize(view()->zoomController()->documentSize()); // create a rect out of it with origin in tp left of page QRectF documentRect(QPointF((documentMinSize.width() - layout.width) * -0.5, (documentMinSize.height() - layout.height) * -0.5), documentMinSize); QPointF offset = -documentRect.topLeft(); m_canvas->setDocumentOrigin(offset); m_view->zoomController()->setPageSize(pageSize); m_canvas->resourceManager()->setResource(KoCanvasResourceManager::PageSize, pageSize); m_canvas->repaint(); m_timeLine.setDuration(m_shapeAnimation->duration()); m_timeLine.setCurrentTime(0); m_animationCache->clear(); m_animationCache->setPageSize(view()->zoomController()->pageSize()); qreal zoom; view()->zoomHandler()->zoom(&zoom, &zoom); m_animationCache->setZoom(zoom); m_shapeAnimation->init(m_animationCache, 0); m_animationCache->startStep(0); m_timeLine.start(); connect(&m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate())); }