VectorShape::VectorShape() : KoFrameShape( KoXmlNS::draw, "image" ) , m_type(VectorTypeNone) , m_isRendering(false) { setShapeId(VectorShape_SHAPEID); // Default size of the shape. KoShape::setSize( QSizeF( CM_TO_POINT( 8 ), CM_TO_POINT( 5 ) ) ); m_cache.setMaxCost(3); }
FoRegion::FoRegion() { /* default param region */ margin_top = CM_TO_POINT(2.5); margin_bottom = CM_TO_POINT(2.5); margin_left = CM_TO_POINT(1.5); margin_right = CM_TO_POINT(1.5); bg = QColor(Qt::white); bog = QColor(Qt::transparent); edom = QByteArray("<scribe/>"); border = 0.; /* border > 0 draw */ rpen = QPen(Qt::NoPen); enable = false; }
qreal ToPoint( qreal unit , const QString unita ) { qreal ri = 0; if (unita == "cm") { ri = CM_TO_POINT( unit ); } else if (unita == "pt" || unita == "px" ) { ri = unit; return ri; } else if (unita == "mm") { ri = MM_TO_POINT( unit ); } else if (unita == "dm") { ri = DM_TO_POINT( unit ); } else if (unita == "inch") { ri = INCH_TO_POINT( unit ); } else if (unita == "pi") { ri = PI_TO_POINT( unit ); } else if (unita == "dd") { ri = DD_TO_POINT( unit ); } else if (unita == "cc") { ri = CC_TO_POINT( unit ); } else { ri = 10; } return ri; }
qreal FopInt( const QString datain ) { QString ctmp = datain; const QString data = ctmp.replace(" ","").trimmed(); //////////qDebug() << "### request unit data->" << datain << " size->" << datain.size(); qreal points = 0; if (data.size() < 1) { return points; } if ( data.endsWith( "%" )) { return 12.5; } if (datain == "0") { return points; } if ( data.endsWith( "pt" ) || data.endsWith( "px" ) ) { points = data.left( data.length() - 2 ).toDouble(); return points; } else if ( data.endsWith( "cm" ) ) { double value = data.left( data.length() - 2 ).toDouble(); points = CM_TO_POINT( value ); } else if ( data.endsWith( "em" ) ) { points = data.left( data.length() - 2 ).toDouble(); } else if ( data.endsWith( "mm" ) ) { double value = data.left( data.length() - 2 ).toDouble(); points = MM_TO_POINT( value ); } else if ( data.endsWith( "dm" ) ) { double value = data.left( data.length() - 2 ).toDouble(); points = DM_TO_POINT( value ); } else if ( data.endsWith( "in" ) ) { double value = data.left( data.length() - 2 ).toDouble(); points = INCH_TO_POINT( value ); } else if ( data.endsWith( "inch" ) ) { double value = data.left( data.length() - 4 ).toDouble(); points = INCH_TO_POINT( value ); } else if ( data.endsWith( "pi" ) ) { double value = data.left( data.length() - 4 ).toDouble(); points = PI_TO_POINT( value ); } else if ( data.endsWith( "dd" ) ) { double value = data.left( data.length() - 4 ).toDouble(); points = DD_TO_POINT( value ); } else if ( data.endsWith( "cc" ) ) { double value = data.left( data.length() - 4 ).toDouble(); points = CC_TO_POINT( value ); } else { points = 0; } return points; }
qreal KoUnit::convertFromUnitToUnit(const qreal value, const KoUnit &fromUnit, const KoUnit &toUnit, qreal factor) { qreal pt; switch (fromUnit.type()) { case Millimeter: pt = MM_TO_POINT(value); break; case Centimeter: pt = CM_TO_POINT(value); break; case Decimeter: pt = DM_TO_POINT(value); break; case Inch: pt = INCH_TO_POINT(value); break; case Pica: pt = PI_TO_POINT(value); break; case Cicero: pt = CC_TO_POINT(value); break; case Pixel: pt = value / factor; break; case Point: default: pt = value; } switch (toUnit.type()) { case Millimeter: return POINT_TO_MM(pt); case Centimeter: return POINT_TO_CM(pt); case Decimeter: return POINT_TO_DM(pt); case Inch: return POINT_TO_INCH(pt); case Pica: return POINT_TO_PI(pt); case Cicero: return POINT_TO_CC(pt); case Pixel: return pt * factor; case Point: default: return pt; } }
qreal KoUnit::fromUserValue(qreal value) const { switch (m_type) { case Millimeter: return MM_TO_POINT(value); case Centimeter: return CM_TO_POINT(value); case Decimeter: return DM_TO_POINT(value); case Inch: return INCH_TO_POINT(value); case Pica: return PI_TO_POINT(value); case Cicero: return CC_TO_POINT(value); case Pixel: return value / m_pixelConversion; case Point: default: return value; } }
ChartShape::ChartShape(KoDocumentResourceManager *resourceManager) : KoFrameShape(KoXmlNS::draw, "object") , KoShapeContainer(new ChartLayout) , d (new Private(this)) { d->resourceManager = resourceManager; setShapeId(ChartShapeId); // Instantiated all children first d->proxyModel = new ChartProxyModel(this, &d->tableSource); d->plotArea = new PlotArea(this); d->document = new ChartDocument(this); d->legend = new Legend(this); // Configure the plotarea. // We need this as the very first step, because some methods // here rely on the d->plotArea pointer. addShape(d->plotArea); d->plotArea->plotAreaInit(); d->plotArea->setZIndex(0); setClipped(d->plotArea, true); setInheritsTransform(d->plotArea, true); // Configure the legend. d->legend->setVisible(true); d->legend->setZIndex(1); setClipped(d->legend, true); setInheritsTransform(d->legend, true); // A few simple defaults (chart type and subtype in this case) setChartType(BarChartType); setChartSubType(NormalChartSubtype); // Create the Title, which is a standard TextShape. KoShapeFactoryBase *textShapeFactory = KoShapeRegistry::instance()->value(TextShapeId); if (textShapeFactory) d->title = textShapeFactory->createDefaultShape(resourceManager); // Potential problem 1) No TextShape installed if (!d->title) { d->title = new TextLabelDummy; if (ENABLE_USER_INTERACTION) KMessageBox::error(0, i18n("The plugin needed for displaying text labels in a chart is not available."), i18n("Plugin Missing")); // Potential problem 2) TextShape incompatible } else if (dynamic_cast<TextLabelData*>(d->title->userData()) == 0 && ENABLE_USER_INTERACTION) KMessageBox::error(0, i18n("The plugin needed for displaying text labels is not compatible with the current version of the chart Flake shape."), i18n("Plugin Incompatible")); // In both cases we need a KoTextShapeData instance to function. This is // enough for unit tests, so there has to be no TextShape plugin doing the // actual text rendering, we just need KoTextShapeData which is in the libs. if (dynamic_cast<TextLabelData*>(d->title->userData()) == 0) { TextLabelData *dataDummy = new TextLabelData; KoTextDocumentLayout *documentLayout = new KoTextDocumentLayout(dataDummy->document()); dataDummy->document()->setDocumentLayout(documentLayout); d->title->setUserData(dataDummy); } // Start with a reasonable default size that we can base all following relative // positions of chart elements on. setSize(QSizeF(CM_TO_POINT(8), CM_TO_POINT(5))); // Add the title to the shape addShape(d->title); QFont font = titleData()->document()->defaultFont(); font.setPointSizeF(12.0); titleData()->document()->setDefaultFont(font); titleData()->document()->setHtml("<div align=\"center\">" + i18n("Title") + "</font></div>"); // Position the title center at the very top. d->title->setSize(QSizeF(CM_TO_POINT(5), CM_TO_POINT(0.7))); d->title->setPosition(QPointF(size().width() / 2.0 - d->title->size().width() / 2.0, 0.0)); d->title->setVisible(false); d->title->setZIndex(2); setClipped(d->title, true); setInheritsTransform(d->title, true); // Create the Subtitle and add it to the shape. if (textShapeFactory) d->subTitle = textShapeFactory->createDefaultShape(resourceManager); if (!d->subTitle) { d->subTitle = new TextLabelDummy; } if (dynamic_cast<TextLabelData*>(d->subTitle->userData()) == 0) { TextLabelData *dataDummy = new TextLabelData; KoTextDocumentLayout *documentLayout = new KoTextDocumentLayout(dataDummy->document()); dataDummy->document()->setDocumentLayout(documentLayout); d->subTitle->setUserData(dataDummy); } addShape(d->subTitle); font = subTitleData()->document()->defaultFont(); font.setPointSizeF(10.0); subTitleData()->document()->setDefaultFont(font); subTitleData()->document()->setHtml("<div align=\"center\">" + i18n("Subtitle") + "</div>"); // Position it in the center, just below the title. d->subTitle->setSize(QSizeF(CM_TO_POINT(5), CM_TO_POINT(0.6))); d->subTitle->setPosition(QPointF(size().width() / 2.0 - d->title->size().width() / 2.0, d->title->size().height())); d->subTitle->setVisible(false); d->subTitle->setZIndex(3); setClipped(d->subTitle, true); setInheritsTransform(d->subTitle, true); // Create the Footer and add it to the shape. if (textShapeFactory) d->footer = textShapeFactory->createDefaultShape(resourceManager); if (!d->footer) { d->footer = new TextLabelDummy; } if (dynamic_cast<TextLabelData*>(d->footer->userData()) == 0) { TextLabelData *dataDummy = new TextLabelData; KoTextDocumentLayout *documentLayout = new KoTextDocumentLayout(dataDummy->document()); dataDummy->document()->setDocumentLayout(documentLayout); d->footer->setUserData(dataDummy); } addShape(d->footer); font = footerData()->document()->defaultFont(); font.setPointSizeF(10.0); footerData()->document()->setDefaultFont(font); footerData()->document()->setHtml("<div align=\"center\">" + i18n("Footer") + "</div>"); // Position the footer in the center, at the bottom. d->footer->setSize(QSizeF(CM_TO_POINT(5), CM_TO_POINT(0.6))); d->footer->setPosition(QPointF(size().width() / 2.0 - d->footer->size().width() / 2.0, size().height() - d->footer->size().height())); d->footer->setVisible(false); d->footer->setZIndex(4); setClipped(d->footer, true); setInheritsTransform(d->footer, true); // Set default contour (for how text run around is done around this shape) // to prevent a crash in LO setTextRunAroundContour(KoShape::ContourBox); // Enable auto-resizing of chart labels foreach(KoShape *label, labels()) { TextLabelData *labelData = qobject_cast<TextLabelData*>(label->userData()); KoTextDocument doc(labelData->document()); //FIXME doc.setResizeMethod(KoTextDocument::AutoResize); }
bool ChartShape::Private::loadOdfLabel(KoShape *label, KoXmlElement &labelElement, KoShapeLoadingContext &context) { TextLabelData *labelData = qobject_cast<TextLabelData*>(label->userData()); if (!labelData) return false; // Following will always return false cause KoTextShapeData::loadOdf will try to load // a frame while our text:p is not within a frame. So, let's just not call loadOdf then... //label->loadOdf(labelElement, context); // 1. set the text KoXmlElement pElement = KoXml::namedItemNS(labelElement, KoXmlNS::text, "p"); QTextDocument* doc = labelData->document(); doc->setPlainText(pElement.text()); // 2. set the position QPointF pos = label->position(); bool posChanged = false; if (labelElement.hasAttributeNS(KoXmlNS::svg, "x")) { pos.setX(KoUnit::parseValue(labelElement.attributeNS(KoXmlNS::svg, "x", QString()))); posChanged = true; } if (labelElement.hasAttributeNS(KoXmlNS::svg, "y")) { pos.setY(KoUnit::parseValue(labelElement.attributeNS(KoXmlNS::svg, "y", QString()))); posChanged = true; } if (posChanged) { label->setPosition(pos); } // 3. set the styles if (labelElement.hasAttributeNS(KoXmlNS::chart, "style-name")) { KoStyleStack &styleStack = context.odfLoadingContext().styleStack(); styleStack.clear(); context.odfLoadingContext().fillStyleStack(labelElement, KoXmlNS::chart, "style-name", "chart"); styleStack.setTypeProperties("chart"); if (styleStack.hasProperty(KoXmlNS::style, "rotation-angle")) { qreal rotationAngle = 360 - KoUnit::parseValue(styleStack.property(KoXmlNS::style, "rotation-angle")); label->rotate(rotationAngle); } styleStack.setTypeProperties("text"); if (styleStack.hasProperty(KoXmlNS::fo, "font-size")) { const qreal fontSize = KoUnit::parseValue(styleStack.property(KoXmlNS::fo, "font-size")); QFont font = doc->defaultFont(); font.setPointSizeF(fontSize); doc->setDefaultFont(font); } if (styleStack.hasProperty(KoXmlNS::fo, "font-family")) { const QString fontFamily = styleStack.property(KoXmlNS::fo, "font-family"); QFont font = doc->defaultFont(); font.setFamily(fontFamily); doc->setDefaultFont(font); } } // 4. set the size if (labelElement.hasAttributeNS(KoXmlNS::svg, "width") && labelElement.hasAttributeNS(KoXmlNS::svg, "height")) { const qreal width = KoUnit::parseValue(labelElement.attributeNS(KoXmlNS::svg, "width")); const qreal height = KoUnit::parseValue(labelElement.attributeNS(KoXmlNS::svg, "height")); label->setSize(QSizeF(width, height)); } else { QSizeF size = shape->size(); QRect r = QFontMetrics(doc->defaultFont()).boundingRect( labelData->shapeMargins().left, labelData->shapeMargins().top, qMax(CM_TO_POINT(5), qreal(size.width() - pos.x() * 2.0 - labelData->shapeMargins().right)), qMax(CM_TO_POINT(0.6), qreal(size.height() - labelData->shapeMargins().bottom)), Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, doc->toPlainText()); label->setSize(r.size()); } return true; }
M_PageSize::M_PageSize() { landscape = false; body = FoRegion(); coolspace = 0; modus = 0; name = "A4 (210 x 297 mm)"; P_rect = QPrinter::A4; G_regt = QRectF(0,0,MM_TO_POINT(210),MM_TO_POINT(297)); RealSize = G_regt.size(); AllowHeaderFooter = true; FoRegion topR; FoRegion bottomR; FoRegion leftR; FoRegion rightR; area[0] = topR; area[1] = bottomR; area[2] = leftR; area[3] = rightR; /* FoRegion region_before() const { return area[0]; } FoRegion region_after() const { return area[1]; } FoRegion region_start() const { return area[2]; } FoRegion region_end() const { return area[3]; } */ area[0].margin_top = CM_TO_POINT(0.4); area[0].margin_bottom = CM_TO_POINT(0.4); area[0].margin_left = CM_TO_POINT(0); area[0].margin_right = CM_TO_POINT(0); area[1].margin_top = CM_TO_POINT(0.4); area[1].margin_bottom = CM_TO_POINT(0.4); area[1].margin_left = CM_TO_POINT(0); area[1].margin_right = CM_TO_POINT(0); area[2].margin_top = CM_TO_POINT(0); area[2].margin_bottom = CM_TO_POINT(0); area[2].margin_left = CM_TO_POINT(0); area[2].margin_right = CM_TO_POINT(0); area[3].margin_top = CM_TO_POINT(0); area[3].margin_bottom = CM_TO_POINT(0); area[3].margin_left = CM_TO_POINT(0); area[3].margin_right = CM_TO_POINT(0); area[0].enable = false; area[1].enable = false; area[2].enable = false; area[3].enable = false; }