| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#ifndef QCP_ITEM_RICH_TEXT |
| 2 |
|
|
#define QCP_ITEM_RICH_TEXT |
| 3 |
|
|
#include <qcustomplot.h> |
| 4 |
|
|
|
| 5 |
|
|
#include <QTextDocument> |
| 6 |
|
|
|
| 7 |
|
|
class QCP_LIB_DECL QCPItemRichText : public QCPItemText { |
| 8 |
|
|
Q_OBJECT |
| 9 |
|
|
Q_PROPERTY(QString text READ text WRITE setText) |
| 10 |
|
|
public: |
| 11 |
|
|
QCPItemRichText(QCustomPlot *parentPlot) : QCPItemText(parentPlot) {} |
| 12 |
|
✗ |
virtual ~QCPItemRichText() {} |
| 13 |
|
|
|
| 14 |
|
✗ |
void setText(const QString &text) { |
| 15 |
|
✗ |
QCPItemText::setText(text); |
| 16 |
|
✗ |
doc.setHtml(text); |
| 17 |
|
|
} |
| 18 |
|
|
|
| 19 |
|
|
protected: |
| 20 |
|
|
// reimplemented virtual methods: |
| 21 |
|
✗ |
virtual void draw(QCPPainter *painter) { |
| 22 |
|
✗ |
QPointF pos(position->pixelPoint()); |
| 23 |
|
✗ |
QTransform transform = painter->transform(); |
| 24 |
|
✗ |
transform.translate(pos.x(), pos.y()); |
| 25 |
|
✗ |
if (!qFuzzyIsNull(mRotation)) transform.rotate(mRotation); |
| 26 |
|
✗ |
painter->setFont(mainFont()); |
| 27 |
|
✗ |
QRect textRect = painter->fontMetrics().boundingRect( |
| 28 |
|
✗ |
0, 0, 0, 0, Qt::TextDontClip | mTextAlignment, mText); |
| 29 |
|
✗ |
QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), |
| 30 |
|
|
mPadding.right(), mPadding.bottom()); |
| 31 |
|
✗ |
QPointF textPos = getTextDrawPoint( |
| 32 |
|
✗ |
QPointF(0, 0), textBoxRect, |
| 33 |
|
|
mPositionAlignment); // 0, 0 because the transform does the translation |
| 34 |
|
✗ |
textRect.moveTopLeft(textPos.toPoint() + |
| 35 |
|
✗ |
QPoint(mPadding.left(), mPadding.top())); |
| 36 |
|
✗ |
textBoxRect.moveTopLeft(textPos.toPoint()); |
| 37 |
|
✗ |
qreal clipPadF = mainPen().widthF(); |
| 38 |
|
✗ |
int clipPad = (int)clipPadF; |
| 39 |
|
|
QRect boundingRect = |
| 40 |
|
✗ |
textBoxRect.adjusted(-clipPad, -clipPad, clipPad, clipPad); |
| 41 |
|
✗ |
if (transform.mapRect(boundingRect) |
| 42 |
|
✗ |
.intersects(painter->transform().mapRect(clipRect()))) { |
| 43 |
|
✗ |
painter->setTransform(transform); |
| 44 |
|
✗ |
if ((mainBrush().style() != Qt::NoBrush && |
| 45 |
|
✗ |
mainBrush().color().alpha() != 0) || |
| 46 |
|
✗ |
(mainPen().style() != Qt::NoPen && mainPen().color().alpha() != 0)) { |
| 47 |
|
✗ |
painter->setPen(mainPen()); |
| 48 |
|
✗ |
painter->setBrush(mainBrush()); |
| 49 |
|
✗ |
painter->drawRect(textBoxRect); |
| 50 |
|
|
} |
| 51 |
|
✗ |
painter->setBrush(Qt::NoBrush); |
| 52 |
|
✗ |
painter->setPen(QPen(mainColor())); |
| 53 |
|
✗ |
doc.setDefaultFont(mainFont()); |
| 54 |
|
✗ |
doc.drawContents(painter); |
| 55 |
|
|
} |
| 56 |
|
|
} |
| 57 |
|
|
|
| 58 |
|
|
QTextDocument doc; |
| 59 |
|
|
}; |
| 60 |
|
|
#endif // QCP_ITEM_RICH_TEXT |
| 61 |
|
|
|