Esempio n. 1
0
int TimelineWidget::transform(double value) const
{
   const double min = qwtMin(mpD->map.s1(), mpD->map.s2());
   const double max = qwtMax(mpD->map.s1(), mpD->map.s2());
   value = qwtMax(qwtMin(value, max), min);
   return mpD->map.transform(value);
}
Esempio n. 2
0
/*!
  \brief Set the internal border width of the wheel.

  The internal border must not be smaller than 1
  and is limited in dependence on the wheel's size.
  Values outside the allowed range will be clipped.

  The internal border defaults to 2.

  \param w border width
  \sa internalBorder()
*/
void QwtWheel::setInternalBorder(int w)
{
    const int d = qwtMin( width(), height() ) / 3;
    w = qwtMin( w, d );
    d_data->intBorder = qwtMax( w, 1 );
    layoutWheel();
}
Esempio n. 3
0
void PreviewPlot2D::onZoomRec(const QMouseEvent& e)
{
    // some shortcuts
    int axl= QwtPlot::yLeft, axb= QwtPlot::xBottom;
 
	// Don't invert any scales which aren't inverted
	int x1 = qwtMin(memPoint.x(), e.pos().x());
    int x2 = qwtMax(memPoint.x(), e.pos().x());
    int y1 = qwtMin(memPoint.y(), e.pos().y());
    int y2 = qwtMax(memPoint.y(), e.pos().y());
        
	// limit selected area to a minimum of 11x11 points
	int lim = 5 - (y2 - y1) / 2;
	if (lim > 0)
	{
		y1 -= lim;
		y2 += lim;
	}
	lim = 5 - (x2 - x1 + 1) / 2;
	if (lim > 0)
	{
		x1 -= lim;
		x2 += lim;
	}
        
	// Set fixed scales
	if(!autoscaleY)
		pPlot->setAxisScale(axl, pPlot->invTransform(axl,y1), pPlot->invTransform(axl,y2));
	if(!autoscaleX)
		pPlot->setAxisScale(axb, pPlot->invTransform(axb,x1), pPlot->invTransform(axb,x2));
	pPlot->replot();
}
Esempio n. 4
0
int DiMap::limTransform(double x) const
{
	if (x > qwtMax(d_x1, d_x2))
		x = qwtMax(d_x1, d_x2);
	else if (x < qwtMin(d_x1, d_x2))
		x = qwtMin(d_x1, d_x2);
	return transform(x);
}
/*!
    Returns a size with the minimum width and height of this size and other.
*/
QwtDoubleSize QwtDoubleSize::boundedTo(
    const QwtDoubleSize &other) const
{
    return QwtDoubleSize(
        qwtMin(d_width, other.d_width),
        qwtMin(d_height, other.d_height)
    );
}
Esempio n. 6
0
QRect QwtPicker::trackerRect(QPainter *painter) const
{
    if ( trackerMode() == AlwaysOff || 
        (trackerMode() == ActiveOnly && !isActive() ) )
    {
        return QRect();
    }

    if ( d_data->labelPosition.x() < 0 || d_data->labelPosition.y() < 0 )
        return QRect();

    QwtText text = trackerText(d_data->labelPosition);
    if ( text.isEmpty() )
        return QRect();

    QRect textRect(QPoint(0, 0), text.textSize(painter->font()));

    const QPoint &pos = d_data->labelPosition;

    int alignment = 0;
    if ( isActive() && d_data->selection.count() > 1 
        && rubberBand() != NoRubberBand )
    {
        const QPoint last = 
            d_data->selection[int(d_data->selection.count()) - 2];

        alignment |= (pos.x() >= last.x()) ? Qt::AlignRight : Qt::AlignLeft;
        alignment |= (pos.y() > last.y()) ? Qt::AlignBottom : Qt::AlignTop;
    }
    else
        alignment = Qt::AlignTop | Qt::AlignRight;

    const int margin = 5;

    int x = pos.x();
    if ( alignment & Qt::AlignLeft )
        x -= textRect.width() + margin;
    else if ( alignment & Qt::AlignRight )
        x += margin;

    int y = pos.y();
    if ( alignment & Qt::AlignBottom )
        y += margin;
    else if ( alignment & Qt::AlignTop )
        y -= textRect.height() + margin;
    
    textRect.moveTopLeft(QPoint(x, y));

    int right = qwtMin(textRect.right(), pickRect().right() - margin);
    int bottom = qwtMin(textRect.bottom(), pickRect().bottom() - margin);
    textRect.moveBottomRight(QPoint(right, bottom));

    int left = qwtMax(textRect.left(), pickRect().left() + margin);
    int top = qwtMax(textRect.top(), pickRect().top() + margin);
    textRect.moveTopLeft(QPoint(left, top));

    return textRect;
}
Esempio n. 7
0
QRect QwtPlotLayout::layoutLegend(int options, 
    const QRect &rect) const
{
    const QSize hint(d_data->layoutData.legend.hint);

    int dim;
    if ( d_data->legendPos == QwtPlot::LeftLegend 
        || d_data->legendPos == QwtPlot::RightLegend )
    {
        // We don't allow vertical legends to take more than
        // half of the available space.

        dim = qwtMin(hint.width(), int(rect.width() * d_data->legendRatio));

        if ( !(options & IgnoreScrollbars) )
        {
            if ( hint.height() > rect.height() )
            {
                // The legend will need additional
                // space for the vertical scrollbar. 

                dim += d_data->layoutData.legend.vScrollBarWidth;
            }
        }
    }
    else
    {
        dim = qwtMin(hint.height(), int(rect.height() * d_data->legendRatio));
        dim = qwtMax(dim, d_data->layoutData.legend.hScrollBarHeight);
    }

    QRect legendRect = rect;
    switch(d_data->legendPos)
    {
        case QwtPlot::LeftLegend:
            legendRect.setWidth(dim);
            break;
        case QwtPlot::RightLegend:
            legendRect.setX(rect.right() - dim + 1);
            legendRect.setWidth(dim);
            break;
        case QwtPlot::TopLegend:
            legendRect.setHeight(dim);
            break;
        case QwtPlot::BottomLegend:
            legendRect.setY(rect.bottom() - dim + 1);
            legendRect.setHeight(dim);
            break;
        case QwtPlot::ExternalLegend:
            break;
    }

    return legendRect;
}
Esempio n. 8
0
/*!
  Move the the current zoom rectangle.

  \param x X value
  \param y Y value

  \sa QwtDoubleRect::move
  \note The changed rectangle is limited by the zoom base
*/
void QwtPlotZoomer::move(double x, double y)
{
    x = qwtMax(x, zoomBase().left());
    x = qwtMin(x, zoomBase().right() - zoomRect().width());

    y = qwtMax(y, zoomBase().top());
    y = qwtMin(y, zoomBase().bottom() - zoomRect().height());

    if ( x != zoomRect().left() || y != zoomRect().top() )
    {
        d_data->zoomStack[d_data->zoomRectIndex].moveTo(x, y);
        rescale();
    }
}
/*!
  Returns the bounding rectangle of this rectangle and rectangle other.
  The bounding rectangle of a nonempty rectangle and an empty or
  invalid rectangle is defined to be the nonempty rectangle.
*/
QwtDoubleRect QwtDoubleRect::operator|(const QwtDoubleRect &other) const
{
    if ( isEmpty() )
        return other;

    if ( other.isEmpty() )
        return *this;

    const double minX = qwtMin(d_left, other.d_left);
    const double maxX = qwtMax(d_right, other.d_right);
    const double minY = qwtMin(d_top, other.d_top);
    const double maxY = qwtMax(d_bottom, other.d_bottom);

    return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY);
}
Esempio n. 10
0
/*!
  Returns the intersection of this rectangle and rectangle other.
  Returns an empty rectangle if there is no intersection.
*/
QwtDoubleRect QwtDoubleRect::operator&(const QwtDoubleRect &other) const
{
    if (isNull() || other.isNull())
        return QwtDoubleRect();

    const QwtDoubleRect r1 = normalized();
    const QwtDoubleRect r2 = other.normalized();

    const double minX = qwtMax(r1.left(), r2.left());
    const double maxX = qwtMin(r1.right(), r2.right());
    const double minY = qwtMax(r1.top(), r2.top());
    const double maxY = qwtMin(r1.bottom(), r2.bottom());

    return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY);
}
Esempio n. 11
0
/*!
  \brief No docs

  Description
  \param x ???
  \param align
  \todo Documentation
*/
void QwtDoubleRange::setNewValue(double x, bool align)
{
    double vmin,vmax;

    d_prevValue = d_value;

    vmin = qwtMin(d_minValue, d_maxValue);
    vmax = qwtMax(d_minValue, d_maxValue);

    //
    // Range check
    //
    if (x < vmin)
    {
        if ((d_periodic) && (vmin != vmax))
            d_value = x + ::ceil( (vmin - x) / (vmax - vmin ) )
                      * (vmax - vmin);
        else
            d_value = vmin;
    }
    else if (x > vmax)
    {
        if ((d_periodic) && (vmin != vmax))
            d_value = x - ::ceil( ( x - vmax) / (vmax - vmin ))
                      * (vmax - vmin);
        else
            d_value = vmax;
    }
    else
        d_value = x;

    d_exactPrevValue = d_exactValue;
    d_exactValue = d_value;

    // align to grid
    if (align)
    {
        if (d_step != 0.0)
        {
            d_value = d_minValue +
                      qwtRound((d_value - d_minValue) / d_step) * d_step;
        }
        else
            d_value = d_minValue;

        // correct rounding error at the border
        if (fabs(d_value - d_maxValue) < MinEps * qwtAbs(d_step))
            d_value = d_maxValue;

        // correct rounding error if value = 0
        if (::fabs(d_value) < MinEps * qwtAbs(d_step))
            d_value = 0.0;
    }

    if (!d_isValid || d_prevValue != d_value)
    {
        d_isValid = true;
        valueChange();
    }
}
Esempio n. 12
0
bool ScaleDiv::rebuild(double x1, double x2, int maxMajSteps, int maxMinSteps,
		bool log, double step, bool ascend)
{

	int rv;

	d_lBound = qwtMin(x1, x2);
	d_hBound = qwtMax(x1, x2);
	d_log = log;

	if (d_log)
		rv = buildLogDiv(maxMajSteps, maxMinSteps, step);
	else
		rv = buildLinDiv(maxMajSteps, maxMinSteps, step);

	if ((!ascend) && (x2 < x1))
	{
		d_lBound = x1;
		d_hBound = x2;
		qwtTwistArray(d_majMarks.data(), d_majMarks.size());
		qwtTwistArray(d_minMarks.data(), d_minMarks.size());
	}

	return rv;

}
/*!
    Align and divide an interval

   \param maxNumSteps Max. number of steps
   \param x1 First limit of the interval (In/Out)
   \param x2 Second limit of the interval (In/Out)
   \param stepSize Step size (Out)

   \sa QwtScaleEngine::setAttribute()
*/
void QwtLog10ScaleEngine::autoScale(int maxNumSteps, 
    double &x1, double &x2, double &stepSize) const
{
    if ( x1 > x2 )
        qSwap(x1, x2);

    QwtDoubleInterval interval(x1 / pow(10.0, lowerMargin()), 
        x2 * pow(10.0, upperMargin()) );

    if (interval.maxValue() / interval.minValue() < 10.0)
    {
        // scale width is less than one decade -> build linear scale

        QwtLinearScaleEngine linearScaler;
        linearScaler.setAttributes(attributes());
        linearScaler.setReference(reference());
        linearScaler.setMargins(lowerMargin(), upperMargin());

        linearScaler.autoScale(maxNumSteps, x1, x2, stepSize);
        stepSize = ::log10(stepSize);

        return;
    }

    double logRef = 1.0;
    if (reference() > LOG_MIN / 2)
        logRef = qwtMin(reference(), LOG_MAX / 2);

    if (testAttribute(QwtScaleEngine::Symmetric))
    {
        const double delta = qwtMax(interval.maxValue() / logRef,  
            logRef / interval.minValue());
        interval.setInterval(logRef / delta, logRef * delta);
    }

    if (testAttribute(QwtScaleEngine::IncludeReference))
        interval = interval.extend(logRef);

    interval = interval.limited(LOG_MIN, LOG_MAX);

    if (interval.width() == 0.0)
        interval = buildInterval(interval.minValue());

    stepSize = divideInterval(log10(interval).width(), qwtMax(maxNumSteps, 1));
    if ( stepSize < 1.0 )
        stepSize = 1.0;

    if (!testAttribute(QwtScaleEngine::Floating))
        interval = align(interval, stepSize);

    x1 = interval.minValue();
    x2 = interval.maxValue();

    if (testAttribute(QwtScaleEngine::Inverted))
    {
        qSwap(x1, x2);
        stepSize = -stepSize;
    }
}
Esempio n. 14
0
void Slider::setBorderWidth(int bd)
{
	d_borderWidth = qwtMin(qwtMax(bd, 0), 10);
	if (d_bgStyle & BgTrough)
		d_bwTrough = d_borderWidth;
	else
		d_bwTrough = 0;
}
//! Set the border width of the pipe.
void QwtThermo::setBorderWidth(int w)
{
    if ((w >= 0) && (w < (qwtMin(d_data->thermoRect.width(),
                                 d_data->thermoRect.height()) + d_data->borderWidth) / 2  - 1))
    {
        d_data->borderWidth = w;
        layoutThermo();
    }
}
Esempio n. 16
0
QSize TimelineWidget::minimumSizeHint() const
{
   int scaleWidth = scaleDraw()->minLength(QPen(), font());
   int scaleHeight = scaleDraw()->extent(QPen(), font());
   int animHeight = mpD->animRect.height();
   int w = qwtMin(scaleWidth, 200); // at least 200 pixels wide
   int h = scaleHeight + animHeight + mpD->scaleDist + 2 * mpD->borderWidth;
   return QSize(w, h);
}
Esempio n. 17
0
/*!
  Handle a key press event for the observed widget.

  Selections can be completely done by the keyboard. The arrow keys
  move the cursor, the abort key aborts a selection. All other keys
  are handled by the current state machine.

  \sa QwtPicker, selectionFlags()
  \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),
      widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(),
      widgetWheelEvent(), widgetKeyReleaseEvent(), stateMachine(),
      QwtEventPattern::KeyPatternCode
*/
void QwtPicker::widgetKeyPressEvent(QKeyEvent *ke)
{
    int dx = 0;
    int dy = 0;

    int offset = 1;
    if ( ke->isAutoRepeat() )
        offset = 5;

    if ( keyMatch(KeyLeft, ke) )
        dx = -offset;
    else if ( keyMatch(KeyRight, ke) )
        dx = offset;
    else if ( keyMatch(KeyUp, ke) )
        dy = -offset;
    else if ( keyMatch(KeyDown, ke) )
        dy = offset;
    else if ( keyMatch(KeyAbort, ke) )
    {
        if ( d_data->stateMachine )
            d_data->stateMachine->reset();

        if (isActive())
            end(false);
    }
    else
        transition(ke);

    if ( dx != 0 || dy != 0 )
    {
        const QRect rect = pickRect();
        const QPoint pos = parentWidget()->mapFromGlobal(QCursor::pos());

        int x = pos.x() + dx;
        x = qwtMax(rect.left(), x);
        x = qwtMin(rect.right(), x);

        int y = pos.y() + dy;
        y = qwtMax(rect.top(), y);
        y = qwtMin(rect.bottom(), y);

        QCursor::setPos(parentWidget()->mapToGlobal(QPoint(x, y)));
    }
}
Esempio n. 18
0
bool QwtScaleDiv::contains(double v) const
{
    if ( !d_isValid )
        return false;

    const double min = qwtMin(d_lBound, d_hBound);
    const double max = qwtMax(d_lBound, d_hBound);

    return v >= min && v <= max;
}
Esempio n. 19
0
/*!
  \brief Specify a reference point
  \param r new reference value

  The reference point is needed if the auto-scaler options IncludeRef or
  Symmetric are active. Its default value is 0 for linear scales and 1 for
  logarithmic scales.

  \warning The reference value for logarithmic scales is limited to
  ( LOG_MIN / 2 <= reference <= LOG_MAX /2 ). If the specified
  value is less than LOG_MIN (defined in qwt_math.h), it will
  be set to 1.0 for logarithmic scales.
*/
void QwtAutoScale::setReference(double r)
{
    d_ref = r;
    
    if (r > LOG_MIN / 2) 
        d_lref = qwtMin(r, LOG_MAX / 2);
    else
       d_lref = 1.0;

    build();
}
Esempio n. 20
0
/*!
  \brief Find the smallest value in an array
  \param array Pointer to an array
  \param size Array size
*/
double qwtGetMin(const double *array, int size)
{
    if (size <= 0)
       return 0.0;

    double rv = array[0];
    for (int i = 1; i < size; i++)
       rv = qwtMin(rv, array[i]);

    return rv;
}
Esempio n. 21
0
//! Recalculate the slider's geometry and layout based on
//  the current rect and fonts.
//  \param update_geometry  notify the layout system and call update
//         to redraw the scale
void QwtKnob::layoutKnob( bool update_geometry )
{
    const QRect &r = rect();

    const int width = qwtMin(qwtMin(r.height(), r.width()), d_knobWidth);
    const int width_2 = width / 2;

    d_kRect.setRect(r.x() + r.width() / 2 - width_2,
            r.y() + r.height() / 2 - width_2,
            width, width);

    scaleDraw()->setGeometry(d_kRect.x() - d_scaleDist,
            d_kRect.y() - d_scaleDist,
            width + 2 * d_scaleDist, QwtScaleDraw::Round );

    if ( update_geometry )
    {
        updateGeometry();
        update();
    }
}
int QwtThermo::transform(double value) const
{
    const double min = qwtMin(d_data->map.s1(), d_data->map.s2());
    const double max = qwtMax(d_data->map.s1(), d_data->map.s2());

    if ( value > max )
        value = max;
    if ( value < min )
        value = min;

    return d_data->map.transform(value);
}
/*!
    Align and divide an interval

   \param maxNumSteps Max. number of steps
   \param x1 First limit of the interval (In/Out)
   \param x2 Second limit of the interval (In/Out)
   \param stepSize Step size (Out)

   \sa QwtScaleEngine::setAttribute
*/
void LogTimeScaleEngine::autoScale(int maxNumSteps, 
    double &x1, double &x2, double &stepSize) const
{
    if ( x1 > x2 )
        qSwap(x1, x2);

    QwtDoubleInterval interval(
                               
     #if (QWT_VERSION >= 0x050200)
            x1 / pow(10.0, lowerMargin()), 
            x2 * pow(10.0, upperMargin())
     #else
            x1 / pow(10.0, loMargin()), 
            x2 * pow(10.0, hiMargin())
    #endif
    );

    double logRef = 1.0;
    if (reference() > LOG_MIN / 2)
        logRef = qwtMin(reference(), LOG_MAX / 2);

    if (testAttribute(QwtScaleEngine::Symmetric))
    {
        const double delta = qwtMax(interval.maxValue() / logRef,  
            logRef / interval.minValue());
        interval.setInterval(logRef / delta, logRef * delta);
    }

    if (testAttribute(QwtScaleEngine::IncludeReference))
        interval = interval.extend(logRef);

    interval = interval.limited(LOG_MIN, LOG_MAX);

    if (interval.width() == 0.0)
        interval = buildInterval(interval.minValue());

    stepSize = divideInterval(log10(interval).width(), qwtMax(maxNumSteps, 1));
    if ( stepSize < 1.0 )
        stepSize = 1.0;

    if (!testAttribute(QwtScaleEngine::Floating))
        interval = align(interval, stepSize);

    x1 = interval.minValue();
    x2 = interval.maxValue();

    if (testAttribute(QwtScaleEngine::Inverted))
    {
        qSwap(x1, x2);
        stepSize = -stepSize;
    }
}
Esempio n. 24
0
/*!
  \todo Documentation
*/
void QwtAutoScale::setRange(double x1, double x2)
{
    double minval = qwtMin(x1, x2);
    double maxval = qwtMax(x1, x2);

    if (d_scaleOpt & Logarithmic)
    {
        minval = qwtMin(qwtMax(minval, LOG_MIN), LOG_MAX);
        maxval = qwtMin(qwtMax(maxval,LOG_MIN), LOG_MAX);
    }
    
    double delta = maxval - minval;
    
    if (delta <= 0.0)       // all values are equal
    {               
        if (minval > 0)
        {
            d_scaleMin = minval * 0.5;
            d_scaleMax = maxval * 1.5;
        }
        else if (minval < 0)
        {
            d_scaleMin = minval * 1.5;
            d_scaleMax = maxval * 0.5;
        }
        else              // all values are zero
        {           
            d_scaleMin = -0.5;
            d_scaleMax = 0.5;
        }

        delta = d_scaleMax - d_scaleMin;
    }
    else            // the normal case
    {               
        d_scaleMin = minval;
        d_scaleMax = maxval;
    }
}
Esempio n. 25
0
/*!
  \brief Zoom in or out

  Activate a rectangle on the zoom stack with an offset relative
  to the current position. Negative values of offest will zoom out,
  positive zoom in. A value of 0 zooms out to the zoom base.

  \param offset Offset relative to the current position of the zoom stack.
  \sa zoomRectIndex()
*/
void QwtPlotZoomer::zoom(int offset)
{
    if ( offset == 0 )
        d_data->zoomRectIndex = 0;
    else
    {
        int newIndex = d_data->zoomRectIndex + offset;
        newIndex = qwtMax(0, newIndex);
        newIndex = qwtMin(int(d_data->zoomStack.count()) - 1, newIndex);

        d_data->zoomRectIndex = uint(newIndex);
    }

    rescale();
}
Esempio n. 26
0
/*!
  \brief Draw the knob
  \param painter painter
  \param r Bounding rectangle of the knob (without scale)
*/
void QwtKnob::drawKnob(QPainter *painter, const QRect &r)
{
#if QT_VERSION < 0x040000
    const QBrush buttonBrush = colorGroup().brush(QColorGroup::Button);
    const QColor buttonTextColor = colorGroup().buttonText();
    const QColor lightColor = colorGroup().light();
    const QColor darkColor = colorGroup().dark();
#else
    const QBrush buttonBrush = palette().brush(QPalette::Button);
    const QColor buttonTextColor = palette().color(QPalette::ButtonText);
    const QColor lightColor = palette().color(QPalette::Light);
    const QColor darkColor = palette().color(QPalette::Dark);
#endif

    const int bw2 = d_data->borderWidth / 2;

    const int radius = (qwtMin(r.width(), r.height()) - bw2) / 2;

    const QRect aRect( 
        r.center().x() - radius, r.center().y() - radius,
        2 * radius, 2 * radius);

    //
    // draw button face
    //
    painter->setBrush(buttonBrush);
    painter->drawEllipse(aRect);

    //
    // draw button shades
    //
    QPen pn;
    pn.setWidth(d_data->borderWidth);

    pn.setColor(lightColor);
    painter->setPen(pn);
    painter->drawArc(aRect, 45*16, 180*16);

    pn.setColor(darkColor);
    painter->setPen(pn);
    painter->drawArc(aRect, 225*16, 180*16);

    //
    // draw marker
    //
    if ( isValid() )
        drawMarker(painter, d_data->angle, buttonTextColor);
}
Esempio n. 27
0
double qwtGetMin(double *array, int size)
{
	double rv;
	int i;

	if (size > 0)
	{
		rv = array[0];
		for (i = 1; i < size; i++)
			rv = qwtMin(rv, array[i]);
		return rv;
	}
	else
		return 0.0;

}
Esempio n. 28
0
void QwtPolarLayout::LayoutData::init(
  const QwtPolarPlot *plot, const QRect &rect )
{
  // legend

  if ( plot->plotLayout()->legendPosition() != QwtPolarPlot::ExternalLegend
       && plot->legend() )
  {
    legend.frameWidth = plot->legend()->frameWidth();
    legend.vScrollBarWidth =
      plot->legend()->verticalScrollBar()->sizeHint().width();
    legend.hScrollBarHeight =
      plot->legend()->horizontalScrollBar()->sizeHint().height();

    const QSize hint = plot->legend()->sizeHint();

    int w = qwtMin( hint.width(), rect.width() );
    int h = plot->legend()->heightForWidth( w );
    if ( h == 0 )
      h = hint.height();

    if ( h > rect.height() )
      w += legend.vScrollBarWidth;

    legend.hint = QSize( w, h );
  }

  // title

  title.frameWidth = 0;
  title.text = QwtText();

  if ( plot->titleLabel() )
  {
    const QwtTextLabel *label = plot->titleLabel();
    title.text = label->text();
    if ( !( title.text.testPaintAttribute( QwtText::PaintUsingTextFont ) ) )
      title.text.setFont( label->font() );

    title.frameWidth = plot->titleLabel()->frameWidth();
  }

  // canvas

  canvas.frameWidth = plot->canvas()->frameWidth();
}
Esempio n. 29
0
void QwtPainter::drawPolyline(QPainter *painter, const QwtPolygonF &pa)
{
    QRect clipRect;
    const bool deviceClipping = isClippingNeeded(painter, clipRect);

    QwtPolygonF cpa = d_metricsMap.layoutToDevice(pa);
    if ( deviceClipping )
        cpa = QwtClipper::clipPolygonF(clipRect, cpa);

#if QT_VERSION >= 0x040000
    bool doSplit = false;

    const QPaintEngine *pe = painter->paintEngine();
    if ( pe && pe->type() == QPaintEngine::Raster &&
        painter->pen().width() >= 2 )
    {
        /*
            The raster paint engine seems to use some algo with O(n*n).
            ( Qt 4.3 is better than Qt 4.2, but remains unacceptable)
            To work around this problem, we have to split the polygon into
            smaller pieces.
         */
        doSplit = true;
    }

    if ( doSplit )
    {
        const int numPoints = cpa.size();
        const QPointF *points = cpa.data();

        const int splitSize = 20;
        for ( int i = 0; i < numPoints; i += splitSize )
        {
            const int n = qwtMin(splitSize + 1, cpa.size() - i);
            painter->drawPolyline(points + i, n);
        }
    }
    else
#endif
        painter->drawPolyline(cpa);
}
Esempio n. 30
0
void QmitkHistogram::draw(QPainter *painter, const QwtScaleMap &xMap, 
                          const QwtScaleMap &yMap, const QRect &) const
{
  const QwtIntervalData &iData = m_Data->data;

  painter->setPen(QPen(m_Data->color));

  //const int x0 = xMap.transform(baseline());
  const int y0 = yMap.transform(baseline());

  for ( int i = 0; i < (int)iData.size(); i++ )
  {
    const int y2 = yMap.transform(iData.value(i));
    if ( y2 == y0 )
      continue;

    int x1 = xMap.transform(iData.interval(i).minValue());
    int x2 = xMap.transform(iData.interval(i).maxValue());
    if ( x1 > x2 )
      qSwap(x1, x2);

    if ( i < (int)iData.size() - 2 )
    {
      const int xx1 = xMap.transform(iData.interval(i+1).minValue());
      const int xx2 = xMap.transform(iData.interval(i+1).maxValue());

      if ( x2 == qwtMin(xx1, xx2) )
      {
        const int yy2 = yMap.transform(iData.value(i+1));
        if ( yy2 != y0 && ( (yy2 < y0 && y2 < y0) ||
          (yy2 > y0 && y2 > y0) ) )
        {
          // One pixel distance between neighbored bars
          x2--;
        }
      }
    }
    drawBar(painter, Qt::Vertical,
      QRect(x1, y0, x2 - x1, y2 - y0) );
  }
}