void TernaryAxis::updatePrerenderedLabels() { TextAttributes attributes = titleTextAttributes(); double axisLabelAngle = 0.0; double fiftyMarkAngle = 0.0; QPointF axisLabelPosition; QPointF fiftyMarkPosition; KDChartEnums::PositionValue fiftyMarkReferencePoint = KDChartEnums::PositionUnknown; switch( position().value() ) { case KDChartEnums::PositionSouth: // this is the axis on the other side of A axisLabelAngle = 0.0; fiftyMarkAngle = 0.0; axisLabelPosition = TriangleTop; fiftyMarkPosition = 0.5 * AxisVector_B_C - RelMarkerLength * Norm_B_C; fiftyMarkReferencePoint = KDChartEnums::PositionNorth; break; case KDChartEnums::PositionEast: // this is the axis on the other side of B axisLabelAngle = 240.0; fiftyMarkAngle = 60; axisLabelPosition = TriangleBottomLeft; fiftyMarkPosition = AxisVector_B_C + 0.5 * AxisVector_C_A - RelMarkerLength * Norm_C_A; fiftyMarkReferencePoint = KDChartEnums::PositionSouth; break; case KDChartEnums::PositionWest: // this is the axis on the other side of C axisLabelAngle = 120.0; fiftyMarkAngle = 300.0; axisLabelPosition = TriangleBottomRight; fiftyMarkPosition = 0.5 * AxisVector_B_A + RelMarkerLength * Norm_B_A; fiftyMarkReferencePoint = KDChartEnums::PositionSouth; break; case KDChartEnums::PositionUnknown: break; // initial value default: qDebug() << "TernaryAxis::updatePrerenderedLabel: unknown location"; }; m_label->setFont( attributes.font() ); // m_label->setText( titleText() ); // done by setTitleText() m_label->setAngle( axisLabelAngle ); m_label->setPosition( axisLabelPosition ); m_label->setReferencePoint( KDChartEnums::PositionSouth ); QFont font = attributes.font(); font.setPointSizeF( 0.85 * font.pointSizeF() ); m_fifty->setFont( font ); m_fifty->setAngle( fiftyMarkAngle ); m_fifty->setPosition( fiftyMarkPosition ); m_fifty->setReferencePoint( fiftyMarkReferencePoint ); }
/** \brief Use this to specify the text attributes to be used for this item. \sa textAttributes */ void KDChart::TextLayoutItem::setTextAttributes( const TextAttributes &a ) { mAttributes = a; cachedFont = a.font(); cachedSizeHint = QSize(); // invalidate size hint sizeHint(); if( mParent ) mParent->update(); }
bool TextAttributes::operator==( const TextAttributes& r ) const { // the following works around a bug in gcc 4.3.2 // causing StyleHint to be set to Zero when copying a QFont const QFont myFont( font() ); QFont r_font( r.font() ); r_font.setStyleHint( myFont.styleHint(), myFont.styleStrategy() ); return ( isVisible() == r.isVisible() && myFont == r_font && fontSize() == r.fontSize() && minimalFontSize() == r.minimalFontSize() && autoRotate() == r.autoRotate() && autoShrink() == r.autoShrink() && rotation() == r.rotation() && pen() == r.pen() && textDocument() == r.textDocument() ); }
void RadarDiagram::paint( PaintContext* ctx, bool calculateListAndReturnScale, qreal& newZoomX, qreal& newZoomY ) { // note: Not having any data model assigned is no bug // but we can not draw a diagram then either. if ( !checkInvariants(true) ) return; d->reverseMapper.clear(); const int rowCount = model()->rowCount( rootIndex() ); const int colCount = model()->columnCount( rootIndex() ); int iRow, iCol; const qreal min = dataBoundaries().first.y(); const qreal r = qAbs( min ) + dataBoundaries().second.y(); const qreal step = ( r - qAbs( min ) ) / ( numberOfGridRings() ); RadarCoordinatePlane* plane = dynamic_cast<RadarCoordinatePlane*>(ctx->coordinatePlane()); TextAttributes ta = plane->textAttributes(); QRectF fontRect = ctx->rectangle(); fontRect.setSize( QSizeF( fontRect.width(), step / 2.0 ) ); const qreal labelFontSize = fitFontSizeToGeometry( QString::fromLatin1( "TestXYWQgqy" ), ta.font(), fontRect, ta ); QFont labelFont = ta.font(); ctx->painter()->setPen( ta.pen() ); labelFont.setPointSizeF( labelFontSize ); const QFontMetricsF metric( labelFont ); const qreal labelHeight = metric.height(); QPointF offset; QRectF destRect = ctx->rectangle(); if ( ta.isVisible() ) { destRect.setY( destRect.y() + 2 * labelHeight ); destRect.setHeight( destRect.height() - 4 * labelHeight ); } if ( calculateListAndReturnScale ) { ctx->painter()->save(); // Check if all of the data value texts / data comments will fit // into the available space: d->labelPaintCache.clear(); ctx->painter()->save(); for ( iCol=0; iCol < colCount; ++iCol ) { for ( iRow=0; iRow < rowCount; ++iRow ) { QModelIndex index = model()->index( iRow, iCol, rootIndex() ); // checked const qreal value = model()->data( index ).toReal(); QPointF point = scaleToRealPosition( QPointF( value, iRow ), ctx->rectangle(), destRect, *ctx->coordinatePlane() ); d->addLabel( &d->labelPaintCache, index, 0, PositionPoints( point ), Position::Center, Position::Center, value ); } } ctx->painter()->restore(); const qreal oldZoomX = coordinatePlane()->zoomFactorX(); const qreal oldZoomY = coordinatePlane()->zoomFactorY(); newZoomX = oldZoomX; newZoomY = oldZoomY; if ( d->labelPaintCache.paintReplay.count() ) { QRectF txtRectF; d->paintDataValueTextsAndMarkers( ctx, d->labelPaintCache, true, true, &txtRectF ); const QRect txtRect = txtRectF.toRect(); const QRect curRect = coordinatePlane()->geometry(); const qreal gapX = qMin( txtRect.left() - curRect.left(), curRect.right() - txtRect.right() ); const qreal gapY = qMin( txtRect.top() - curRect.top(), curRect.bottom() - txtRect.bottom() ); newZoomX = oldZoomX; newZoomY = oldZoomY; if ( gapX < 0.0 ) newZoomX *= 1.0 + (gapX-1.0) / curRect.width(); if ( gapY < 0.0 ) newZoomY *= 1.0 + (gapY-1.0) / curRect.height(); } ctx->painter()->restore(); } else { // Iterate through data sets and create a list of polygons out of them. QList<Polygon> polygons; for ( iCol=0; iCol < colCount; ++iCol ) { //TODO(khz): As of yet RadarDiagram can not show per-segment line attributes // but it draws every polyline in one go - using one color. // This needs to be enhanced to allow for cell-specific settings // in the same way as LineDiagram does it. QPolygonF polygon; QPointF point0; for ( iRow=0; iRow < rowCount; ++iRow ) { QModelIndex index = model()->index( iRow, iCol, rootIndex() ); // checked const qreal value = model()->data( index ).toReal(); QPointF point = scaleToRealPosition( QPointF( value, d->reverseData ? ( rowCount - iRow ) : iRow ), ctx->rectangle(), destRect, *ctx->coordinatePlane() ); polygon.append( point ); if ( ! iRow ) point0= point; } if ( closeDatasets() && rowCount ) polygon.append( point0 ); QBrush brush = d->datasetAttrs( iCol, KChart::DatasetBrushRole ).value<QBrush>(); QPen p = d->datasetAttrs( iCol, KChart::DatasetPenRole ).value< QPen >(); if ( p.style() != Qt::NoPen ) { polygons.append( Polygon( polygon, brush, PrintingParameters::scalePen( p ) ) ); } } // first fill the areas with the brush-color and the defined alpha-value. if (d->fillAlpha > 0.0) { Q_FOREACH(const Polygon& p, polygons) { PainterSaver painterSaver( ctx->painter() ); ctx->painter()->setRenderHint ( QPainter::Antialiasing ); QBrush br = p.brush; QColor c = br.color(); c.setAlphaF(d->fillAlpha); br.setColor(c); ctx->painter()->setBrush( br ); ctx->painter()->setPen( p.pen ); ctx->painter()->drawPolygon( p.polygon ); } }