bool KoTextOnShapeContainer::loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context) { Q_D(KoTextOnShapeContainer); if (d->textShape == 0) return false; // probably because the factory was not found. KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(d->textShape->userData()); Q_ASSERT(shapeData); // would be a bug in kotext QString styleName = element.attributeNS(KoXmlNS::draw, "style-name"); if (!styleName.isEmpty()) { KoStyleStack &styleStack = context.odfLoadingContext().styleStack(); styleStack.save(); context.odfLoadingContext().fillStyleStack(element, KoXmlNS::draw, "style-name", "graphic"); styleStack.setTypeProperties("graphic"); QString valign = styleStack.property(KoXmlNS::draw, "textarea-vertical-align"); if (valign == "top") { shapeData->setVerticalAlignment(Qt::AlignTop); } else if (valign == "middle") { shapeData->setVerticalAlignment(Qt::AlignVCenter); } else if (valign == "bottom") { shapeData->setVerticalAlignment(Qt::AlignBottom); } styleStack.restore(); } return shapeData->loadOdf(element, context); }
void KoTosContainer::setTextAlignment(Qt::Alignment alignment) { Q_D(KoTosContainer); KoShape *textShape = this->textShape(); if (textShape == 0) { warnFlake << "No text shape present in KoTosContainer"; return; } // vertical KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(textShape->userData()); shapeData->setVerticalAlignment(alignment); // horizontal Q_ASSERT(shapeData->document()); QTextBlockFormat bf; bf.setAlignment(alignment & Qt::AlignHorizontal_Mask); QTextCursor cursor(shapeData->document()); cursor.setPosition(QTextCursor::End, QTextCursor::KeepAnchor); cursor.mergeBlockFormat(bf); d->alignment = alignment; }
/// KoTextOnShapeContainer KoTextOnShapeContainer::KoTextOnShapeContainer(KoShape *childShape, KoResourceManager *documentResources) : KoShapeContainer(*(new KoTextOnShapeContainerPrivate(this))) { Q_D(KoTextOnShapeContainer); Q_ASSERT(childShape); d->content = childShape; setSize(childShape->size()); setZIndex(childShape->zIndex()); setTransformation(childShape->transformation()); if (childShape->parent()) { childShape->parent()->addShape(this); childShape->setParent(0); } childShape->setPosition(QPointF()); // since its relative to my position, this won't move it childShape->setSelectable(false); d->model = new KoTextOnShapeContainerModel(this, d); addShape(childShape); QSet<KoShape*> delegates; delegates << childShape; KoShapeFactoryBase *factory = KoShapeRegistry::instance()->get("TextShapeID"); if (factory) { // not installed, thats too bad, but allowed d->textShape = factory->createDefaultShape(documentResources); Q_ASSERT(d->textShape); // would be a bug in the text shape; if (d->resizeBehavior == TextFollowsPreferredTextRect) { d->textShape->setSize(d->preferredTextRect.size()); } else { d->textShape->setSize(size()); } d->textShape->setTransformation(childShape->transformation()); if (d->resizeBehavior == TextFollowsPreferredTextRect) { d->textShape->setPosition(d->preferredTextRect.topLeft()); } KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(d->textShape->userData()); Q_ASSERT(shapeData); // would be a bug in kotext shapeData->setVerticalAlignment(Qt::AlignVCenter); addShape(d->textShape); d->textShape->setZIndex(childShape->zIndex() + 1); d->textShape->setSelectable(false); delegates << d->textShape; } else { kWarning(30006) << "Text shape factory not found"; } static_cast<KoTextOnShapeContainerModel*>(d->model)->lock = false; setToolDelegates(delegates); }
KoShape *KoTosContainer::createTextShape(KoDocumentResourceManager *documentResources) { if (!documentResources) { warnFlake << "KoDocumentResourceManager not found"; return 0; } Q_D(KoTosContainer); delete textShape(); delete d->model; d->model = new KoTosContainerModel(); QSet<KoShape*> delegates; delegates << this; KoShape *textShape = 0; KoShapeFactoryBase *factory = KoShapeRegistry::instance()->get("TextShapeID"); if (factory) { // not installed, thats too bad, but allowed textShape = factory->createDefaultShape(documentResources); Q_ASSERT(textShape); // would be a bug in the text shape; if (d->resizeBehavior == TextFollowsPreferredTextRect) { textShape->setSize(d->preferredTextRect.size()); } else { textShape->setSize(size()); } if (d->resizeBehavior == TextFollowsPreferredTextRect) { textShape->setPosition(d->preferredTextRect.topLeft()); } else { textShape->setPosition(QPointF(0, 0)); } textShape->setSelectable(false); textShape->setRunThrough(runThrough()); KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(textShape->userData()); Q_ASSERT(shapeData); // would be a bug in kotext // TODO check if that is correct depending on the resize mode shapeData->setVerticalAlignment(Qt::AlignVCenter); addShape(textShape); // textShape->setZIndex(zIndex() + 1); // not needed as there as the text shape is the only sub shape delegates << textShape; } else { warnFlake << "Text shape factory not found"; } setToolDelegates(delegates); return textShape; }