31 #include <QApplication>
36 #define INC_HIT_COUNT { ++HitCount; }
37 #define INC_MISS_COUNT { ++MissCount; }
38 #define DUMP_CACHE_STATS \
39 if ( HitCount != 0 && MissCount != 0 ) { \
40 int total = HitCount + MissCount; \
41 qreal hitQuote = ( 1.0 * HitCount ) / total; \
42 qDebug() << "PrerenderedLabel dtor: hits/misses/total:" \
43 << HitCount << "/" << MissCount << "/" << total \
44 << "(" << 100 * hitQuote << "% hits)"; \
48 #define INC_MISS_COUNT
49 #define DUMP_CACHE_STATS
69 m_referencePoint = point;
74 return m_referencePoint;
80 , m_font( qApp->font() )
81 , m_brush( Qt::black )
179 void PrerenderedLabel::paint()
const
184 const int Width = 1000;
185 const int Height = Width;
188 const QColor FullTransparent( 255, 255, 255, 0 );
190 QImage
pixmap( Width, Height, QImage::Format_ARGB32_Premultiplied );
191 qWarning() <<
"PrerenderedLabel::paint: using QImage for prerendered labels "
192 <<
"to work around XRender/Qt4 bug.";
194 QPixmap
pixmap( Width, Height );
198 static const QPointF Center ( 0.0, 0.0 );
199 QPointF textBottomRight;
200 QPainter painter( &
pixmap );
201 painter.setRenderHint(QPainter::TextAntialiasing,
true );
202 painter.setRenderHint(QPainter::Antialiasing,
true );
205 painter.setPen( FullTransparent );
206 painter.setBrush( FullTransparent );
207 QPainter::CompositionMode mode = painter.compositionMode();
208 painter.setCompositionMode( QPainter::CompositionMode_Clear );
209 painter.drawRect( 0, 0, Width, Height );
210 painter.setCompositionMode( mode );
213 matrix.translate( 0.5 * Width, 0.5 * Height );
214 matrix.rotate( m_angle );
215 #if QT_VERSION > 0x040199
216 painter.setWorldMatrix( matrix );
218 painter.setMatrix( matrix );
221 painter.setPen( m_pen );
222 painter.setBrush( m_brush );
223 painter.setFont( m_font );
224 QRectF container( -0.5 * Width, -0.5 * Height, Width, 0.5 * Height );
225 painter.drawText( container, Qt::AlignHCenter | Qt::AlignBottom,
226 m_text, &boundingRect );
227 m_referenceBottomLeft = QPointF( boundingRect.bottomLeft().x(), 0.0 );
228 textBottomRight = QPointF( boundingRect.bottomRight().x(), 0.0 );
229 m_textAscendVector = boundingRect.topRight() - textBottomRight;
230 m_textBaseLineVector = textBottomRight - m_referenceBottomLeft;
233 boundingRect = matrix.mapRect( boundingRect );
234 m_referenceBottomLeft = matrix.map( m_referenceBottomLeft )
235 - boundingRect.topLeft();
236 textBottomRight = matrix.map( textBottomRight )
237 - boundingRect.topLeft();
238 m_textAscendVector = matrix.map( m_textAscendVector )
239 - matrix.map( Center );
240 m_textBaseLineVector = matrix.map( m_textBaseLineVector )
241 - matrix.map( Center );
246 QPixmap temp( static_cast<int>( boundingRect.width() ),
247 static_cast<int>( boundingRect.height() ) );
249 temp.fill( FullTransparent );
250 QPainter painter( &temp );
252 painter.drawImage( QPointF( 0.0, 0.0 ),
pixmap, boundingRect );
254 painter.drawPixmap( QPointF( 0.0, 0.0 ),
pixmap, boundingRect );
257 #ifdef PRERENDEREDLABEL_DEBUG
258 painter.setPen( QPen( Qt::red, 2 ) );
259 painter.setBrush( Qt::red );
272 static const double Radius = 0.5;
273 static const double Diameter = 2 * Radius;
276 painter.drawEllipse( QRectF( point - QPointF( Radius, Radius ),
277 QSizeF( Diameter, Diameter ) ) );
299 switch ( position ) {
301 return m_referenceBottomLeft + 0.5 * m_textBaseLineVector + 0.5 * m_textAscendVector;
303 return m_referenceBottomLeft + m_textAscendVector;
305 return m_referenceBottomLeft + 0.5 * m_textBaseLineVector + m_textAscendVector;
307 return m_referenceBottomLeft + m_textBaseLineVector + m_textAscendVector;
309 return m_referenceBottomLeft + 0.5 * m_textAscendVector;
311 return m_referenceBottomLeft + m_textBaseLineVector;
313 return m_referenceBottomLeft + 0.5 * m_textBaseLineVector;
315 return m_referenceBottomLeft;
316 case KDChartEnums::PositionWest:
317 return m_referenceBottomLeft + m_textBaseLineVector + 0.5 * m_textAscendVector;