QDebug operator<<(QDebug dbg, const KDChart::BackgroundAttributes& ba)
{
    dbg << "KDChart::BackgroundAttributes("
	<< "visible="<<ba.isVisible()
	<< "brush="<<ba.brush()
	<< "pixmapmode="<<ba.pixmapMode()
	<< "pixmap="<<QVariant(ba.pixmap())
	<< ")";
    return dbg;
}
Esempio n. 2
0
bool Surface::loadOdf( const KoXmlElement &surfaceElement, KoShapeLoadingContext &context )
{
    KoStyleStack &styleStack = context.odfLoadingContext().styleStack();
    styleStack.save();
    
    if ( surfaceElement.hasAttributeNS( KoXmlNS::chart, "style-name" ) )
    {
        KDChart::BackgroundAttributes backgroundAttributes = d->kdPlane->backgroundAttributes();
        KDChart::FrameAttributes frameAttributes = d->kdPlane->frameAttributes();
        
        styleStack.clear();
        context.odfLoadingContext().fillStyleStack( surfaceElement, KoXmlNS::chart, "style-name", "chart" );
        
        styleStack.setTypeProperties( "graphic" );
        
        if ( styleStack.hasProperty( KoXmlNS::draw, "stroke" ) )
        {
            frameAttributes.setVisible( true );
            QString stroke = styleStack.property( KoXmlNS::draw, "stroke" );
            if( stroke == "solid" || stroke == "dash" )
            {
                QPen pen = KoOdfGraphicStyles::loadOdfStrokeStyle( styleStack, stroke, context.odfLoadingContext().stylesReader() );
                frameAttributes.setPen( pen );
            }
        }
        
        if ( styleStack.hasProperty( KoXmlNS::draw, "fill" ) )
        {
            backgroundAttributes.setVisible( true );
            QBrush brush;
            QString fill = styleStack.property( KoXmlNS::draw, "fill" );
            if ( fill == "solid" || fill == "hatch" )
                brush = KoOdfGraphicStyles::loadOdfFillStyle( styleStack, fill, context.odfLoadingContext().stylesReader() );
            else if ( fill == "gradient" )
            {
                brush = KoOdfGraphicStyles::loadOdfGradientStyle( styleStack, context.odfLoadingContext().stylesReader(), QSizeF( 5.0, 60.0 ) );
            }
            else if ( fill == "bitmap" )
                brush = KoOdfGraphicStyles::loadOdfPatternStyle( styleStack, context.odfLoadingContext(), QSizeF( 5.0, 60.0 ) );
            backgroundAttributes.setBrush( brush );
        }
        
        d->kdPlane->setBackgroundAttributes( backgroundAttributes );
        d->kdPlane->setFrameAttributes( frameAttributes );
    }

    styleStack.restore();
    
    return true;
}
Esempio n. 3
0
static void updateCommonBrush( QBrush& commonBrush, bool& bStart, const KDChart::AbstractArea& area )
{
    const KDChart::BackgroundAttributes ba( area.backgroundAttributes() );
    const bool hasSimpleBrush = (
            ! area.frameAttributes().isVisible() &&
            ba.isVisible() &&
            ba.pixmapMode() == KDChart::BackgroundAttributes::BackgroundPixmapModeNone &&
            ba.brush().gradient() == 0 );
    if( bStart ){
        bStart = false;
        commonBrush = hasSimpleBrush ? ba.brush() : QBrush();
    }else{
        if( ! hasSimpleBrush || ba.brush() != commonBrush )
        {
            commonBrush = QBrush();
        }
    }
}
Esempio n. 4
0
MainWindow::MainWindow( QWidget* parent ) :
    QWidget( parent )
{
    setupUi( this );

    m_chartLayout = new QHBoxLayout( chartFrame );
    m_chart = new KDChart::Chart();
    m_chartLayout->addWidget( m_chart );

    // add a small left-side leading because we use a coloured Y axis background
    m_chart->setGlobalLeadingLeft( 1 );


    initializeDataModel();


    // register our own serializer for saving / loading the Y axis:
    KDChart::registerElementSerializer<
            AdjustedCartesianAxisSerializer,
            AdjustedCartesianAxis >( 0 ); // will be un-registered in ~Mainwindow()


    // Set up the diagrams
    KDChart::LineDiagram* lines = new KDChart::LineDiagram();
    lines->setModel( m_model );

    // increase the line width
    for ( int iRow = 0; iRow < lines->model()->rowCount(); ++iRow ) {
        QPen pen( lines->pen( iRow ) );
        pen.setWidth(2);
        pen.setColor( pen.color().dark(133) );
        lines->setPen( iRow, pen );
    }

    // Assign some axes
    KDChart::CartesianAxis *xAxis = new KDChart::CartesianAxis( lines );
    AdjustedCartesianAxis *yAxis = new AdjustedCartesianAxis( lines );
    yAxis->setBounds(29.9, 31.0);
    xAxis->setPosition ( KDChart::CartesianAxis::Bottom );
    yAxis->setPosition ( KDChart::CartesianAxis::Left );
    yAxis->setTitleText ( "an axis class with customized labels" );

    lines->addAxis( xAxis );
    lines->addAxis( yAxis );


    KDChart::CartesianCoordinatePlane* plane =
            static_cast< KDChart::CartesianCoordinatePlane * >(m_chart->coordinatePlane());

    plane->replaceDiagram( lines );

    KDChart::HeaderFooter* headerFooter = new KDChart::HeaderFooter( m_chart );
    m_chart->addHeaderFooter( headerFooter );
    headerFooter->setText( "Line diagram using a custom axis class" );

    KDChart::TextAttributes textAttrs( headerFooter->textAttributes() );
    textAttrs.setPen( QPen( Qt::red ) );
    headerFooter->setTextAttributes( textAttrs );
    headerFooter->setType( KDChart::HeaderFooter::Header );
    headerFooter->setPosition( KDChart::Position::North );

    // assign some bg colors
    KDChart::BackgroundAttributes ba = yAxis->backgroundAttributes();
    ba.setVisible(true);
    ba.setBrush(QBrush(QColor(255,255,200)));
    yAxis->setBackgroundAttributes(ba);
}
Esempio n. 5
0
bool Surface::loadOdf(const KoXmlElement &surfaceElement,
                       KoShapeLoadingContext &context)
{
    // Get the current style stack and save it's state.
    KoStyleStack &styleStack = context.odfLoadingContext().styleStack();

    bool brushLoaded = false;
    
    if (surfaceElement.hasAttributeNS(KoXmlNS::chart, "style-name")) {
        KDChart::BackgroundAttributes backgroundAttributes = d->kdPlane->backgroundAttributes();
        KDChart::FrameAttributes frameAttributes = d->kdPlane->frameAttributes();
        
        // Add the chart style to the style stack.
        styleStack.clear();
        context.odfLoadingContext().fillStyleStack(surfaceElement, KoXmlNS::chart, "style-name", "chart");
        
        styleStack.setTypeProperties("graphic");
        
        // If there is a "stroke" property, then get the stroke style
        // and set the pen accordingly.
        if (styleStack.hasProperty(KoXmlNS::draw, "stroke")) {
            frameAttributes.setVisible(true);

            QString  stroke = styleStack.property(KoXmlNS::draw, "stroke");
            QPen pen(Qt::NoPen);
            if (stroke == "solid" || stroke == "dash")
                pen = KoOdfGraphicStyles::loadOdfStrokeStyle(styleStack, stroke,
                                                             context.odfLoadingContext().stylesReader());

            frameAttributes.setPen(pen);
        }
        
        // If there is a "fill" property, then get the fill style, and
        // set the brush for the surface accordingly.
        if (styleStack.hasProperty(KoXmlNS::draw, "fill")) {
            backgroundAttributes.setVisible(true);

            QBrush   brush;
            QString  fill = styleStack.property(KoXmlNS::draw, "fill");
            if (fill == "solid" || fill == "hatch") {
                brushLoaded = true;
                brush = KoOdfGraphicStyles::loadOdfFillStyle(styleStack, fill,
                                                             context.odfLoadingContext().stylesReader());
            }
            else if (fill == "gradient") {
                brushLoaded = true;
                brush = KoOdfGraphicStyles::loadOdfGradientStyle(styleStack, context.odfLoadingContext().stylesReader(), QSizeF(5.0, 60.0));
            }
            else if (fill == "bitmap") {
                brushLoaded = true;
                brush = loadOdfPatternStyle(styleStack, context.odfLoadingContext(), QSizeF(5.0, 60.0));
            }

            backgroundAttributes.setBrush(brush);
        }
        
        // Finally actually set the attributes.
        d->kdPlane->setBackgroundAttributes(backgroundAttributes);
        d->kdPlane->setFrameAttributes(frameAttributes);
    }

#ifndef NWORKAROUND_ODF_BUGS
    if (!brushLoaded) {
        KDChart::BackgroundAttributes backgroundAttributes = d->kdPlane->backgroundAttributes();
        QColor fillColor = KoOdfWorkaround::fixMissingFillColor(surfaceElement, context);
        if (fillColor.isValid()) {
            backgroundAttributes.setVisible(true);
            backgroundAttributes.setBrush(fillColor);
            d->kdPlane->setBackgroundAttributes(backgroundAttributes);
        }
    }
#endif
    
    return true;
}