QRectF SimpleRootAreaProvider::suggestRect(KoTextLayoutRootArea *rootArea) { //Come up with a rect, but actually we don't need the height, as we set it to infinite below // Still better keep it for completeness sake QRectF rect(QPointF(), m_textShape->size()); rect.adjust(m_textShapeData->leftPadding(), m_textShapeData->topPadding(), -m_textShapeData->rightPadding(), - m_textShapeData->bottomPadding()); KoBorder *border = m_textShape->border(); if (border) { rect.adjust(border->borderWidth(KoBorder::LeftBorder), border->borderWidth(KoBorder::TopBorder), -border->borderWidth(KoBorder::RightBorder), - border->borderWidth(KoBorder::BottomBorder)); } // In simple cases we always set height way too high so that we have no breaking // If the shape grows afterwards or not is handled in doPostLayout() rect.setHeight(1E6); if (m_textShapeData->resizeMethod() == KoTextShapeData::AutoGrowWidthAndHeight ||m_textShapeData->resizeMethod() == KoTextShapeData::AutoGrowWidth) { rootArea->setNoWrap(1E6); } // Make sure the size is not negative due to padding and border with // This can happen on vertical lines containing text on shape. if (rect.width() < 0) { rect.setWidth(0); } return rect; }
void KWRootAreaProviderBase::doPostLayout(KoTextLayoutRootArea *rootArea, bool /*isNewRootArea*/) { KoShape *shape = rootArea->associatedShape(); if (!shape) { return; } KoTextShapeData *data = qobject_cast<KoTextShapeData*>(shape->userData()); Q_ASSERT(data); QRectF updateRect = shape->outlineRect(); QSizeF newSize = shape->size() - QSizeF(data->leftPadding() + data->rightPadding(), data->topPadding() + data->bottomPadding()); KoBorder *border = shape->border(); if (border) { newSize -= QSizeF(border->borderWidth(KoBorder::LeftBorder) + border->borderWidth(KoBorder::RightBorder), border->borderWidth(KoBorder::TopBorder) + border->borderWidth(KoBorder::BottomBorder)); } if (data->resizeMethod() == KoTextShapeData::AutoGrowWidthAndHeight ||data->resizeMethod() == KoTextShapeData::AutoGrowHeight) { newSize.setHeight(rootArea->bottom() - rootArea->top()); // adjust size to have at least the defined minimum height Q_ASSERT(frameSet()->shapeCount() > 0); KoShape *firstShape = frameSet()->shapes().first(); if (firstShape->minimumHeight() > newSize.height()) newSize.setHeight(firstShape->minimumHeight()); } if (data->resizeMethod() == KoTextShapeData::AutoGrowWidthAndHeight ||data->resizeMethod() == KoTextShapeData::AutoGrowWidth) { newSize.setWidth(rootArea->right() - rootArea->left()); } newSize += QSizeF(data->leftPadding() + data->rightPadding(), data->topPadding() + data->bottomPadding()); if (border) { newSize += QSizeF(border->borderWidth(KoBorder::LeftBorder) + border->borderWidth(KoBorder::RightBorder), border->borderWidth(KoBorder::TopBorder) + border->borderWidth(KoBorder::BottomBorder)); } if (newSize != rootArea->associatedShape()->size()) { rootArea->associatedShape()->setSize(newSize); // transfer the new size to the copy-shapes foreach(KWCopyShape *cs, frameSet()->copyShapes()) { cs->setSize(newSize); }
void TestTableCellStyle::testPen() { // Test basic functionality of the table cell style (roundtripping to format). QTextTableCellFormat format1; KoBorder border; KoBorder::BorderData data; data.outerPen = QPen(Qt::red, 5.0); data.innerPen = QPen(Qt::red, 7.0); border.setBorderData(KoBorder::TopBorder, data); data.outerPen = QPen(Qt::red, 8.0); data.innerPen = QPen(Qt::red, 10.0); border.setBorderData(KoBorder::LeftBorder, data); data.outerPen = QPen(Qt::red, 11.0); data.innerPen = QPen(Qt::red, 13.0); border.setBorderData(KoBorder::BottomBorder, data); data.outerPen = QPen(Qt::red, 14.0); data.innerPen = QPen(Qt::red, 16.0); border.setBorderData(KoBorder::RightBorder, data); format1.setProperty(KoTableCellStyle::Borders, QVariant::fromValue<KoBorder>(border)); KoTableCellStyle *style = new KoTableCellStyle(format1); QVERIFY(style); QTextTableCellFormat format2; style->applyStyle(format2); KoBorder border2 = format2.property(KoTableCellStyle::Borders).value<KoBorder>(); QCOMPARE(border2.borderData(KoBorder::TopBorder).outerPen, QPen(Qt::red, 5.0)); QCOMPARE(border2.borderData(KoBorder::TopBorder).innerPen, QPen(Qt::red, 7.0)); QCOMPARE(border2.borderData(KoBorder::LeftBorder).outerPen, QPen(Qt::red, 8.0)); QCOMPARE(border2.borderData(KoBorder::LeftBorder).innerPen, QPen(Qt::red, 10.0)); QCOMPARE(border2.borderData(KoBorder::BottomBorder).outerPen, QPen(Qt::red, 11.0)); QCOMPARE(border2.borderData(KoBorder::BottomBorder).innerPen, QPen(Qt::red, 13.0)); QCOMPARE(border2.borderData(KoBorder::RightBorder).outerPen, QPen(Qt::red, 14.0)); QCOMPARE(border2.borderData(KoBorder::RightBorder).innerPen, QPen(Qt::red, 16.0)); }
void SimpleRootAreaProvider::doPostLayout(KoTextLayoutRootArea *rootArea, bool isNewRootArea) { Q_UNUSED(isNewRootArea); m_textShape->update(m_textShape->outlineRect()); QSizeF newSize = m_textShape->size() - QSizeF(m_textShapeData->leftPadding() + m_textShapeData->rightPadding(), m_textShapeData->topPadding() + m_textShapeData->bottomPadding()); KoBorder *border = m_textShape->border(); if (border) { newSize -= QSizeF(border->borderWidth(KoBorder::LeftBorder) + border->borderWidth(KoBorder::RightBorder), border->borderWidth(KoBorder::TopBorder) + border->borderWidth(KoBorder::BottomBorder)); } if (m_textShapeData->verticalAlignment() & Qt::AlignBottom) { } if (m_textShapeData->verticalAlignment() & Qt::AlignVCenter) { } if (m_textShapeData->resizeMethod() == KoTextShapeData::AutoGrowWidthAndHeight ||m_textShapeData->resizeMethod() == KoTextShapeData::AutoGrowHeight) { qreal height = rootArea->bottom() - rootArea->top(); if (height > newSize.height()) { newSize.setHeight(height); } } if (m_textShapeData->resizeMethod() == KoTextShapeData::AutoGrowWidthAndHeight ||m_textShapeData->resizeMethod() == KoTextShapeData::AutoGrowWidth) { qreal width = rootArea->right() - rootArea->left(); if (width > newSize.width()) { newSize.setWidth(rootArea->right() - rootArea->left()); } } qreal newBottom = rootArea->top() + newSize.height(); KoFlake::Position sizeAnchor= KoFlake::TopLeftCorner; if (m_textShapeData->verticalAlignment() & Qt::AlignBottom) { if (true /*FIXME test no page based shapes interfering*/) { rootArea->setVerticalAlignOffset(newBottom - rootArea->bottom()); sizeAnchor= KoFlake::BottomLeftCorner; } } if (m_textShapeData->verticalAlignment() & Qt::AlignVCenter) { if (true /*FIXME test no page based shapes interfering*/) { rootArea->setVerticalAlignOffset((newBottom - rootArea->bottom()) / 2); sizeAnchor = KoFlake::CenteredPosition; } } newSize += QSizeF(m_textShapeData->leftPadding() + m_textShapeData->rightPadding(), m_textShapeData->topPadding() + m_textShapeData->bottomPadding()); if (border) { newSize += QSizeF(border->borderWidth(KoBorder::LeftBorder) + border->borderWidth(KoBorder::RightBorder), border->borderWidth(KoBorder::TopBorder) + border->borderWidth(KoBorder::BottomBorder)); } if (newSize != m_textShape->size()) { // OO grows to both sides so when to small the initial layouting needs // to keep that into account. if (m_fixAutogrow) { m_fixAutogrow = false; QSizeF tmpSize = m_textShape->size(); tmpSize.setWidth(newSize.width()); QPointF centerpos = rootArea->associatedShape()->absolutePosition(KoFlake::CenteredPosition); m_textShape->setSize(tmpSize); m_textShape->setAbsolutePosition(centerpos, KoFlake::CenteredPosition); centerpos = rootArea->associatedShape()->absolutePosition(sizeAnchor); m_textShape->setSize(newSize); m_textShape->setAbsolutePosition(centerpos, sizeAnchor); } m_textShape->setSize(newSize); } m_textShape->update(m_textShape->outlineRect()); }