11 #include <QTextDocument>
14 #include <KDChartChart>
22 Q_GLOBAL_STATIC(ChartTextObject, globalChartInterface)
24 void ChartTextObject::registerChartTextObjectHandler(QTextDocument *doc)
26 ChartTextObject *chartInterface = globalChartInterface();
30 QTextObjectInterface *iface = qobject_cast<QTextObjectInterface *>(chartInterface);
34 doc->documentLayout()->registerHandler(ChartTextObject::ChartObjectTextFormat, chartInterface);
37 QSizeF ChartTextObject::intrinsicSize(QTextDocument *doc,
int posInDocument,
const QTextFormat &format)
39 Q_UNUSED(posInDocument);
41 QSizeF size(format.property(Size).toSizeF());
43 switch (format.property(
Unit).toInt()) {
45 const qreal pageWidth = doc->pageSize().width();
46 const qreal percent = size.width();
47 const qreal ratio = size.height() / size.width();
49 qreal newWidth = pageWidth * percent / 100.0;
56 return QSizeF(newWidth, newWidth * ratio);
65 void ChartTextObject::drawObject(QPainter *painter,
const QRectF &r, QTextDocument *doc,
int posInDocument,
const QTextFormat &format)
68 Q_UNUSED(posInDocument);
71 KDChart::Chart *chart = qvariant_cast<KDChart::Chart *>(format.property(ChartObject));
73 chart->paint(painter, r.toRect());
@ Percent
Percentage of the text width, i.e. the page width minus margins.
@ Millimeters
Millimeters (the default)
KDREPORTS_EXPORT qreal mmToPixels(qreal mm)