17 #include <QTextDocument>
20 #include <KDChartChart>
28 Q_GLOBAL_STATIC(ChartTextObject, globalChartInterface)
30 void ChartTextObject::registerChartTextObjectHandler(QTextDocument *doc)
32 ChartTextObject *chartInterface = globalChartInterface();
36 QTextObjectInterface *iface = qobject_cast<QTextObjectInterface *>(chartInterface);
40 doc->documentLayout()->registerHandler(ChartTextObject::ChartObjectTextFormat, chartInterface);
43 QSizeF ChartTextObject::intrinsicSize(QTextDocument *doc,
int posInDocument,
const QTextFormat &format)
45 Q_UNUSED(posInDocument);
47 QSizeF size(format.property(Size).toSizeF());
49 switch (format.property(
Unit).toInt()) {
51 const qreal pageWidth = doc->pageSize().width();
52 const qreal percent = size.width();
53 const qreal ratio = size.height() / size.width();
55 qreal newWidth = pageWidth * percent / 100.0;
62 return QSizeF(newWidth, newWidth * ratio);
71 void ChartTextObject::drawObject(QPainter *painter,
const QRectF &r, QTextDocument *doc,
int posInDocument,
const QTextFormat &format)
74 Q_UNUSED(posInDocument);
77 KDChart::Chart *chart = qvariant_cast<KDChart::Chart *>(format.property(ChartObject));
79 chart->paint(painter, r.toRect());