void ScalePicker::selectTitle(QwtScaleWidget *scale, bool select)
{
    if (!scale)
        return;

    if (d_title_selected == select && d_selected_axis == scale)
        return;

    Graph *g = plot();
    g->deselect();

    d_title_selected = select;
    d_selected_axis = scale;
	d_labels_selected = false;

    QwtText title = scale->title();
    if (select){
        title.setBackgroundPen(QPen(Qt::blue));
		g->notifyFontChange(title.font());
		g->notifyColorChange(title.color());
    } else
        title.setBackgroundPen(QPen(Qt::NoPen));

    scale->setTitle(title);
}
void QwtPlotPrintFilter::apply(QwtPlotItem *item) const
{
    PrivateData::Cache &cache = *d_data->cache;

    switch(item->rtti())
    {
        case QwtPlotItem::Rtti_PlotGrid:
        {
            QwtPlotGrid *grid = (QwtPlotGrid *)item;

            QPen pen = grid->majPen();
            cache.gridColors[0] = pen.color();
            pen.setColor(color(pen.color(), MajorGrid));
            grid->setMajPen(pen);

            pen = grid->minPen();
            cache.gridColors[1] = pen.color();
            pen.setColor(color(pen.color(), MinorGrid));
            grid->setMinPen(pen);

            break;
        }
        case QwtPlotItem::Rtti_PlotCurve:
        {
            QwtPlotCurve *c = (QwtPlotCurve *)item;

            QwtSymbol symbol = c->symbol();

            QPen pen = symbol.pen();
            cache.curveSymbolPenColors.insert(c, pen.color());
            pen.setColor(color(pen.color(), CurveSymbol));
            symbol.setPen(pen);

            QBrush brush = symbol.brush();
            cache.curveSymbolBrushColors.insert(c, brush.color());
            brush.setColor(color(brush.color(), CurveSymbol));
            symbol.setBrush(brush);

            c->setSymbol(symbol);

            pen = c->pen();
            cache.curveColors.insert(c, pen.color());
            pen.setColor(color(pen.color(), Curve));
            c->setPen(pen);

            break;
        }
        case QwtPlotItem::Rtti_PlotMarker:
        {
            QwtPlotMarker *m = (QwtPlotMarker *)item;

            QwtText label = m->label();
            cache.markerFonts.insert(m, label.font());
            label.setFont(font(label.font(), Marker));
            cache.markerLabelColors.insert(m, label.color());
            label.setColor(color(label.color(), Marker));
            m->setLabel(label);
            
            QPen pen = m->linePen();
            cache.markerLineColors.insert(m, pen.color());
            pen.setColor(color(pen.color(), Marker));
            m->setLinePen(pen);

            QwtSymbol symbol = m->symbol();

            pen = symbol.pen();
            cache.markerSymbolPenColors.insert(m, pen.color());
            pen.setColor(color(pen.color(), MarkerSymbol));
            symbol.setPen(pen);

            QBrush brush = symbol.brush();
            cache.markerSymbolBrushColors.insert(m, brush.color());
            brush.setColor(color(brush.color(), MarkerSymbol));
            symbol.setBrush(brush);

            m->setSymbol(symbol);

            break;
        }
        default:    
            break;
    }
}
/*! 
  Change color and fonts of a plot
  \sa apply()
*/
void QwtPlotPrintFilter::apply(QwtPlot *plot) const
{
    const bool doAutoReplot = plot->autoReplot();
    plot->setAutoReplot(false);

    delete d_data->cache;
    d_data->cache = new PrivateData::Cache;

    PrivateData::Cache &cache = *d_data->cache;

    if ( plot->titleLabel() )
    {
        QPalette palette = plot->titleLabel()->palette();
        cache.titleColor = palette.color(
            QPalette::Active, Palette::Text);
        palette.setColor(QPalette::Active, Palette::Text,
                         color(cache.titleColor, Title));
        plot->titleLabel()->setPalette(palette);

        cache.titleFont = plot->titleLabel()->font();
        plot->titleLabel()->setFont(font(cache.titleFont, Title));
    }
    if ( plot->legend() )
    {
#if QT_VERSION < 0x040000
        QValueList<QWidget *> list = plot->legend()->legendItems();
        for ( QValueListIterator<QWidget *> it = list.begin();
            it != list.end(); ++it )
#else
        QList<QWidget *> list = plot->legend()->legendItems();
        for ( QList<QWidget*>::iterator it = list.begin();
            it != list.end(); ++it )
#endif
        {
            QWidget *w = *it;

            cache.legendFonts.insert(w, w->font());
            w->setFont(font(w->font(), Legend));

            if ( w->inherits("QwtLegendItem") )
            {
                QwtLegendItem *label = (QwtLegendItem *)w;

                QwtSymbol symbol = label->symbol();
                QPen pen = symbol.pen();
                QBrush brush = symbol.brush();

                pen.setColor(color(pen.color(), CurveSymbol));
                brush.setColor(color(brush.color(), CurveSymbol));

                symbol.setPen(pen);
                symbol.setBrush(brush);
                label->setSymbol(symbol);

                pen = label->curvePen();
                pen.setColor(color(pen.color(), Curve));
                label->setCurvePen(pen);
            }
        }
    }
    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    {
        QwtScaleWidget *scaleWidget = plot->axisWidget(axis);
        if ( scaleWidget )
        {
            cache.scaleColor[axis] = scaleWidget->palette().color(
                QPalette::Active, Palette::Foreground);
            QPalette palette = scaleWidget->palette();
            palette.setColor(QPalette::Active, Palette::Foreground,
                             color(cache.scaleColor[axis], AxisScale));
            scaleWidget->setPalette(palette);

            cache.scaleFont[axis] = scaleWidget->font();
            scaleWidget->setFont(font(cache.scaleFont[axis], AxisScale));

            cache.scaleTitle[axis] = scaleWidget->title();

            QwtText scaleTitle = scaleWidget->title();
            if ( scaleTitle.testPaintAttribute(QwtText::PaintUsingTextColor) )
            {
                cache.scaleTitleColor[axis] = scaleTitle.color();
                scaleTitle.setColor(
                    color(cache.scaleTitleColor[axis], AxisTitle));
            }

            if ( scaleTitle.testPaintAttribute(QwtText::PaintUsingTextFont) )
            {
                cache.scaleTitleFont[axis] = scaleTitle.font();
                scaleTitle.setFont(
                    font(cache.scaleTitleFont[axis], AxisTitle));
            }

            scaleWidget->setTitle(scaleTitle);

            int startDist, endDist;
            scaleWidget->getBorderDistHint(startDist, endDist);
            scaleWidget->setBorderDist(startDist, endDist);
        }
    }

    if ( hasBackgroundColor(plot) )
    {
        QPalette p = plot->palette();
        cache.widgetBackground = plot->palette().color(
            QPalette::Active, Palette::Background);
        p.setColor(QPalette::Active, Palette::Background, 
            color(cache.widgetBackground, WidgetBackground));
        plot->setPalette(p);
    }

    if ( hasBackgroundColor(plot->canvas()))
    {
        cache.canvasBackground = plot->canvasBackground();
        plot->setCanvasBackground(color(cache.canvasBackground, CanvasBackground));
    }

    const QwtPlotItemList& itmList = plot->itemList();
    for ( QwtPlotItemIterator it = itmList.begin();
        it != itmList.end(); ++it )
    {
        apply(*it);
    }

    plot->setAutoReplot(doAutoReplot);
}
Esempio n. 4
0
void MavPlot::apply_print_colors(bool yes) {
    if (yes && !_havePrintColors) {
        const QColor printcol = QColor(0,0,0); // default color: black
        /*******************
         *  ENABLE PRINT COLS
         *******************/
        // title
        QwtText plottitle = title();
        _col_title_screen = plottitle.color();
        plottitle.setColor(printcol);
        setTitle(plottitle);
        // all legend entries ->
        for (dataplotmap::iterator d = _series.begin(); d != _series.end(); ++d) {
            QWT_ABSTRACT_SERIESITEM * s = d->second;
            if (!s) continue;
            if (d == _series.begin()) {
                _col_legend_screen = s->title().color(); // save color of first legend text
            }

            // thicker lines for all
            QwtPlotCurve * const q = dynamic_cast<QwtPlotCurve * const>(s);
            if (q) {
                QPen p = q->pen();
                p.setWidth(PLOT_LINE_WIDTH);
                p.setCosmetic(true);
                q->setPen(p);
            }

            // text of legend -> black
            QwtText title = s->title();
            title.setColor(printcol);
            s->setTitle(title);
        }
        // axes
        _pal_axis_screen = axisWidget(QwtPlot::xBottom)->palette();
        QPalette pal_print;
        pal_print.setColor(QPalette::WindowText, printcol);
        pal_print.setColor(QPalette::Text, printcol);
        axisWidget(QwtPlot::xBottom)->setPalette(pal_print);
        axisWidget(QwtPlot::yLeft)->setPalette(pal_print);
    } else {
        if (_havePrintColors) {
            /*******************
             *  UNDO
             *******************/
            // title
            QwtText plottitle = title();
            plottitle.setColor(_col_title_screen);
            setTitle(plottitle);
            // all legend entries ->
            for (dataplotmap::iterator d = _series.begin(); d != _series.end(); ++d) {
                QWT_ABSTRACT_SERIESITEM * s = d->second;
                if (!s) continue;
                // thinner lines for all
                QwtPlotCurve * const q = dynamic_cast<QwtPlotCurve * const>(s);
                if (q) {
                    QPen p = q->pen();
                    p.setWidth(1);
                    p.setCosmetic(false);
                    q->setPen(p);
                }
                // restore legend text color
                QwtText title = s->title();
                title.setColor(_col_legend_screen);
                s->setTitle(title);
            }            
            // axes
            axisWidget(QwtPlot::xBottom)->setPalette(_pal_axis_screen);
            axisWidget(QwtPlot::yLeft)->setPalette(_pal_axis_screen);
        }
    }
    _havePrintColors = yes;
}