15#include <QApplication>
24#define INC_HIT_COUNT \
28#define INC_MISS_COUNT \
32#define DUMP_CACHE_STATS \
33 if (HitCount != 0 && MissCount != 0) { \
34 int total = HitCount + MissCount; \
35 qreal hitQuote = (1.0 * HitCount) / total; \
36 qDebug() << "PrerenderedLabel dtor: hits/misses/total:" \
37 << HitCount << "/" << MissCount << "/" << total \
38 << "(" << 100 * hitQuote << "% hits)"; \
43#define DUMP_CACHE_STATS
62 m_referencePoint = point;
67 return m_referencePoint;
72 , m_font(qApp->font())
170void PrerenderedLabel::paint()
const
175 const int Width = 1000;
176 const int Height = Width;
179 const QColor FullTransparent(255, 255, 255, 0);
182 qWarning() <<
"PrerenderedLabel::paint: using QImage for prerendered labels "
183 <<
"to work around XRender/Qt4 bug.";
189 static const QPointF Center(0.0, 0.0);
196 painter.setPen(FullTransparent);
197 painter.setBrush(FullTransparent);
200 painter.drawRect(0, 0, Width, Height);
201 painter.setCompositionMode(mode);
204 matrix.
translate(0.5 * Width, 0.5 * Height);
206 painter.setWorldTransform(matrix);
208 painter.setPen(m_pen);
209 painter.setBrush(m_brush);
210 painter.setFont(m_font);
211 QRectF container(-0.5 * Width, -0.5 * Height, Width, 0.5 * Height);
213 m_text, &boundingRect);
216 m_textAscendVector = boundingRect.
topRight() - textBottomRight;
217 m_textBaseLineVector = textBottomRight - m_referenceBottomLeft;
220 boundingRect = matrix.
mapRect(boundingRect);
221 m_referenceBottomLeft = matrix.
map(m_referenceBottomLeft)
223 textBottomRight = matrix.
map(textBottomRight)
225 m_textAscendVector = matrix.
map(m_textAscendVector)
226 - matrix.
map(Center);
227 m_textBaseLineVector = matrix.
map(m_textBaseLineVector)
228 - matrix.
map(Center);
234 static_cast<int>(boundingRect.
height()));
236 temp.fill(FullTransparent);
244#ifdef PRERENDEREDLABEL_DEBUG
260 static const double Radius = 0.5;
261 static const double Diameter = 2 * Radius;
265 QSizeF(Diameter, Diameter)));
289 return m_referenceBottomLeft + 0.5 * m_textBaseLineVector + 0.5 * m_textAscendVector;
291 return m_referenceBottomLeft + m_textAscendVector;
293 return m_referenceBottomLeft + 0.5 * m_textBaseLineVector + m_textAscendVector;
295 return m_referenceBottomLeft + m_textBaseLineVector + m_textAscendVector;
297 return m_referenceBottomLeft + 0.5 * m_textAscendVector;
299 return m_referenceBottomLeft + m_textBaseLineVector;
301 return m_referenceBottomLeft + 0.5 * m_textBaseLineVector;
303 return m_referenceBottomLeft;
305 return m_referenceBottomLeft + m_textBaseLineVector + 0.5 * m_textAscendVector;
base class for prerendered elements like labels, pixmaps, markers, etc.
KDChartEnums::PositionValue referencePoint() const
void setReferencePoint(KDChartEnums::PositionValue)
void setPosition(const QPointF &position)
const QPointF & position() const
void setAngle(qreal angle)
const QString & text() const
QPointF referencePointLocation() const
void setFont(const QFont &font)
const QBrush & brush() const
~PrerenderedLabel() override
void invalidate() const override
const QFont & font() const
void setBrush(const QBrush &brush)
const QPixmap & pixmap() const override
void setText(const QString &text)
QPointF bottomLeft() const const
QPointF bottomRight() const const
qreal height() const const
QPointF topLeft() const const
QPointF topRight() const const
qreal width() const const