コード例 #1
0
bool ThreeDPieAttributes::operator==( const ThreeDPieAttributes& r ) const
{
    return ( useShadowColors() == r.useShadowColors() &&
             AbstractThreeDAttributes::operator==(r));
}
コード例 #2
0
/**
  Internal method that draws the shadow creating the 3D effect of a pie

  \param painter the QPainter to draw in
  \param drawPosition the position to draw at
  \param dataset the dataset to draw the pie for
  \param pie the pie to draw the shadow for
  \param threeDHeight the height of the shadow
  */
void PieDiagram::draw3DEffect( QPainter* painter,
        const QRectF& drawPosition,
        uint dataset, uint pie,
        qreal granularity,
        const ThreeDPieAttributes& threeDAttrs,
        bool /*explode*/ )
{
    Q_UNUSED( dataset );

    if( ! threeDAttrs.isEnabled() )
        return;

    // NOTE: We cannot optimize away drawing some of the effects (even
    // when not exploding), because some of the pies might be left out
    // in future versions which would make some of the normally hidden
    // pies visible. Complex hidden-line algorithms would be much more
    // expensive than just drawing for nothing.

    // No need to save the brush, will be changed on return from this
    // method anyway.
    const QBrush brush = this->brush( model()->index( 0, pie, rootIndex() ) );
    if( threeDAttrs.useShadowColors() ){        
        painter->setBrush( QBrush( brush.color().darker() ) );
    }
    else{
        painter->setBrush( brush );
    }
    //painter->setBrush( QBrush( threeDAttrs.dataShadow1Color( pie ),
    //            params()->shadowPattern() ) );

    qreal startAngle = d->startAngles[ pie ];
    qreal endAngle = startAngle + d->angleLens[ pie ];
    // Normalize angles
    while ( startAngle >= 360 )
        startAngle -= 360;
    while ( endAngle >= 360 )
        endAngle -= 360;
    Q_ASSERT( startAngle >= 0 && startAngle <= 360 );
    Q_ASSERT( endAngle >= 0 && endAngle <= 360 );

    //int centerY = drawPosition.center().y();

    if ( startAngle == endAngle ||
            startAngle == endAngle - 360 ) { // full circle
        drawArcEffectSegment( painter, drawPosition,
                threeDAttrs.depth(),
                180, 360, granularity );
    } else if ( startAngle <= 90 ) {
        if ( endAngle <= 90 ) {
            if ( startAngle <= endAngle ) {
                /// starts and ends in first quadrant, less than 1/4
                drawStraightEffectSegment( painter, drawPosition,
                    threeDAttrs.depth(), startAngle );
                drawUpperBrinkEffect( painter, drawPosition, endAngle );
            } else {
                /// starts and ends in first quadrant, more than 3/4
                drawStraightEffectSegment( painter, drawPosition,
                    threeDAttrs.depth(), startAngle );
                drawUpperBrinkEffect( painter, drawPosition, endAngle );
                drawArcEffectSegment( painter, drawPosition,
                    threeDAttrs.depth(),
                    180, 360, granularity );
            }
        } else if ( endAngle <= 180 ) {
            /// starts in first quadrant, ends in second quadrant,
            /// less than 1/2
            drawStraightEffectSegment( painter, drawPosition,
                threeDAttrs.depth(), startAngle );
            drawStraightEffectSegment( painter, drawPosition,
                threeDAttrs.depth(), endAngle );
        } else if ( endAngle <= 270 ) {
            /// starts in first quadrant, ends in third quadrant
            drawStraightEffectSegment( painter, drawPosition,
                threeDAttrs.depth(), startAngle );
            drawStraightEffectSegment( painter, drawPosition,
                threeDAttrs.depth(), endAngle );
            drawArcEffectSegment( painter, drawPosition,
                threeDAttrs.depth(),
                180, endAngle, granularity );
        } else { // 270*16 < endAngle < 360*16
            /// starts in first quadrant, ends in fourth quadrant,
            /// more than 3/4
            drawStraightEffectSegment( painter, drawPosition,
                threeDAttrs.depth(), startAngle );
            drawUpperBrinkEffect( painter, drawPosition, endAngle );
            drawArcEffectSegment( painter, drawPosition,
                threeDAttrs.depth(),
                180, endAngle, granularity );
        }
    } else if ( startAngle <= 180 ) {
        if ( endAngle <= 90 ) {
            drawArcEffectSegment( painter, drawPosition,
                threeDAttrs.depth(),
                180, 360, granularity );
            drawUpperBrinkEffect( painter, drawPosition, startAngle );
            drawUpperBrinkEffect( painter, drawPosition, endAngle );
        } else if ( endAngle <= 180 ) {
            if ( startAngle <= endAngle ) {
                /// starts in second quadrant, ends in second
                /// quadrant, less than 1/4
                drawStraightEffectSegment( painter, drawPosition,
                    threeDAttrs.depth(), endAngle );
                drawUpperBrinkEffect( painter, drawPosition, startAngle );
            } else {
                /// starts in second quadrant, ends in second
                /// quadrant, more than 1/4
                drawStraightEffectSegment( painter, drawPosition,
                    threeDAttrs.depth(), endAngle );
                drawUpperBrinkEffect( painter, drawPosition, startAngle );
                drawArcEffectSegment( painter, drawPosition,
                    threeDAttrs.depth(),
                    180, 360, granularity );
            }
        } else if ( endAngle <= 270 ) {
            drawStraightEffectSegment( painter, drawPosition,
                threeDAttrs.depth(), endAngle );
            drawUpperBrinkEffect( painter, drawPosition, startAngle );
            drawArcEffectSegment( painter, drawPosition,
                threeDAttrs.depth(),
                180, endAngle, granularity );
        } else { // 270*16 < endAngle < 360*16
            drawArcEffectSegment( painter, drawPosition,
                threeDAttrs.depth(),
                180, endAngle, granularity );
            drawUpperBrinkEffect( painter, drawPosition, startAngle );
            drawUpperBrinkEffect( painter, drawPosition, endAngle );
        }
    } else if ( startAngle <= 270 ) {
        if ( endAngle <= 90 ) {
            drawArcEffectSegment( painter, drawPosition,
                threeDAttrs.depth(),
                startAngle, 360, granularity );
            drawUpperBrinkEffect( painter, drawPosition, startAngle );
            drawUpperBrinkEffect( painter, drawPosition, endAngle );
        } else if ( endAngle <= 180 ) {
            drawStraightEffectSegment( painter, drawPosition,
                threeDAttrs.depth(), endAngle );
            drawUpperBrinkEffect( painter, drawPosition, startAngle );
            drawArcEffectSegment( painter, drawPosition,
                threeDAttrs.depth(),
                startAngle, 360, granularity );
        } else if ( endAngle <= 270 ) {
            if ( startAngle <= endAngle ) {
                /// starts in third quadrant, ends in third quadrant,
                /// less than 1/4
                drawStraightEffectSegment( painter, drawPosition,
                    threeDAttrs.depth(), endAngle );
                drawUpperBrinkEffect( painter, drawPosition, startAngle );
                drawArcEffectSegment( painter, drawPosition,
                    threeDAttrs.depth(),
                    startAngle, endAngle, granularity );
            } else {
                /// starts in third quadrant, ends in third quadrant,
                /// more than 3/4
                drawStraightEffectSegment( painter, drawPosition,
                    threeDAttrs.depth(), endAngle );
                drawUpperBrinkEffect( painter, drawPosition, startAngle );
                drawArcEffectSegment( painter, drawPosition,
                    threeDAttrs.depth(),
                    180, endAngle, granularity );
                drawArcEffectSegment( painter, drawPosition,
                    threeDAttrs.depth(),
                    startAngle, 360, granularity );
            }
        } else { // 270*16 < endAngle < 360*16
            drawArcEffectSegment( painter, drawPosition,
                threeDAttrs.depth(),
                startAngle, endAngle, granularity );
            drawUpperBrinkEffect( painter, drawPosition, startAngle );
            drawUpperBrinkEffect( painter, drawPosition, endAngle );
        }
    } else { // 270*16 < startAngle < 360*16
        if ( endAngle <= 90 ) {
            drawStraightEffectSegment( painter, drawPosition,
                threeDAttrs.depth(), startAngle );
            drawUpperBrinkEffect( painter, drawPosition, endAngle );
            drawArcEffectSegment( painter, drawPosition,
                threeDAttrs.depth(),
                startAngle, 360, granularity );
        } else if ( endAngle <= 180 ) {
            drawStraightEffectSegment( painter, drawPosition,
                threeDAttrs.depth(), startAngle );
            drawStraightEffectSegment( painter, drawPosition,
                threeDAttrs.depth(), endAngle );
            drawArcEffectSegment( painter, drawPosition,
                threeDAttrs.depth(),
                startAngle, 360, granularity );
        } else if ( endAngle <= 270 ) {
            drawStraightEffectSegment( painter, drawPosition,
                threeDAttrs.depth(), startAngle );
            drawStraightEffectSegment( painter, drawPosition,
                threeDAttrs.depth(), endAngle );
            drawArcEffectSegment( painter, drawPosition,
                threeDAttrs.depth(),
                180, endAngle, granularity );
            drawArcEffectSegment( painter, drawPosition,
                threeDAttrs.depth(),
                startAngle, 360, granularity );
        } else { // 270*16 < endAngle < 360*16
            if ( startAngle <= endAngle ) {
                /// starts in fourth quadrant, ends in fourth
                /// quadrant, less than 1/4
                drawStraightEffectSegment( painter, drawPosition,
                    threeDAttrs.depth(), startAngle );
                drawUpperBrinkEffect( painter, drawPosition, endAngle );
                drawArcEffectSegment( painter, drawPosition,
                    threeDAttrs.depth(),
                    startAngle, endAngle, granularity );
            } else {
                /// starts in fourth quadrant, ends in fourth
                /// quadrant, more than 3/4
                drawStraightEffectSegment( painter, drawPosition,
                    threeDAttrs.depth(), startAngle );
                drawUpperBrinkEffect( painter, drawPosition, endAngle );
                drawArcEffectSegment( painter, drawPosition,
                    threeDAttrs.depth(),
                    startAngle, 360, granularity );
                drawArcEffectSegment( painter, drawPosition,
                    threeDAttrs.depth(),
                    180, endAngle, granularity );
            }
        }
    }
    drawArcUpperBrinkEffectSegment( painter, drawPosition, startAngle, endAngle, granularity );
}