예제 #1
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();
}
/*!
  \return a minimum size hint
*/
QSize QwtScaleWidget::minimumSizeHint() const
{
    const Qt::Orientation o = d_data->scaleDraw->orientation();

    // Border Distance cannot be less than the scale borderDistHint
    // Note, the borderDistHint is already included in minHeight/minWidth
    int length = 0;
    int mbd1, mbd2;
    getBorderDistHint(mbd1, mbd2);
    length += qwtMax( 0, d_data->borderDist[0] - mbd1 );
    length += qwtMax( 0, d_data->borderDist[1] - mbd2 );
    length += d_data->scaleDraw->minLength(
        QPen(Qt::black, d_data->penWidth), font());

    int dim = dimForLength(length, font());
    if ( length < dim )
    {
        // compensate for long titles
        length = dim;
        dim = dimForLength(length, font());
    }

    QSize size(length + 2, dim);
    if ( o == Qt::Vertical )
        size.transpose();

    return size;
}
예제 #3
0
/*!
  Adjust contents widget and item layout to the size of the viewport().
*/
void QwtLegend::layoutContents()
{
    const QSize visibleSize = d_data->view->viewport()->size();

    const QLayout *l = d_data->view->contentsWidget->layout();
    if ( l && l->inherits("QwtDynGridLayout") )
    {
        const QwtDynGridLayout *tl = (const QwtDynGridLayout *)l;

        const int minW = int(tl->maxItemWidth()) + 2 * tl->margin();

        int w = qwtMax(visibleSize.width(), minW);
        int h = qwtMax(tl->heightForWidth(w), visibleSize.height());

        const int vpWidth = d_data->view->viewportSize(w, h).width();
        if ( w > vpWidth )
        {
            w = qwtMax(vpWidth, minW);
            h = qwtMax(tl->heightForWidth(w), visibleSize.height());
        }

        d_data->view->contentsWidget->resize(w, h);
#if QT_VERSION < 0x040000
        d_data->view->resizeContents(w, h);
#endif
    }
}
예제 #4
0
/*!
   Calculate the minimum length that is needed to draw the scale

   \param pen Pen that is used for painting backbone and ticks
   \param font Font used for painting the labels

   \sa extent()
*/
int QwtScaleDraw::minLength(const QPen &pen, const QFont &font) const
{
    int startDist, endDist;
    getBorderDistHint(font, startDist, endDist);

    const QwtScaleDiv &sd = scaleDiv();

    const uint minorCount =
        sd.ticks(QwtScaleDiv::MinorTick).count() +
        sd.ticks(QwtScaleDiv::MediumTick).count();
    const uint majorCount =
        sd.ticks(QwtScaleDiv::MajorTick).count();

    int lengthForLabels = 0;
    if ( hasComponent(QwtAbstractScaleDraw::Labels) )
    {
        if ( majorCount >= 2 )
            lengthForLabels = minLabelDist(font) * (majorCount - 1);
    }

    int lengthForTicks = 0;
    if ( hasComponent(QwtAbstractScaleDraw::Ticks) )
    {
        const int pw = qwtMax( 1, pen.width() );  // penwidth can be zero
        lengthForTicks = 2 * (majorCount + minorCount) * pw;
    }

    return startDist + endDist + qwtMax(lengthForLabels, lengthForTicks);
}
예제 #5
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);
}
예제 #6
0
/*!
   Calculate the width/height that is needed for a
   vertical/horizontal scale.

   The extent is calculated from the pen width of the backbone,
   the major tick length, the spacing and the maximum width/height
   of the labels.

   \param pen Pen that is used for painting backbone and ticks
   \param font Font used for painting the labels

   \sa minLength()
*/
int QwtScaleDraw::extent(const QPen &pen, const QFont &font) const
{
    int d = 0;

    if ( hasComponent(QwtAbstractScaleDraw::Labels) )
    {
        if ( orientation() == Qt::Vertical )
            d = maxLabelWidth(font);
        else
            d = maxLabelHeight(font);

        if ( d > 0 )
            d += spacing();
    }

    if ( hasComponent(QwtAbstractScaleDraw::Ticks) )
    {
        d += majTickLength();
    }

    if ( hasComponent(QwtAbstractScaleDraw::Backbone) )
    {
        const int pw = qwtMax( 1, pen.width() );  // penwidth can be zero
        d += pw;
    }

    d = qwtMax(d, minimumExtent());
    return d;
}
/*!
    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;
    }
}
예제 #8
0
파일: dimap.cpp 프로젝트: ViktorNova/los
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);
}
예제 #9
0
/*!
    Returns a size with the maximum width and height of this
    size and other.
*/
QwtDoubleSize QwtDoubleSize::expandedTo(
    const QwtDoubleSize &other) const
{
    return QwtDoubleSize(
        qwtMax(d_width, other.d_width),
        qwtMax(d_height, other.d_height)
    );
}
예제 #10
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;
}
/*!
    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;
    }
}
예제 #12
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();
    }
}
예제 #13
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);
}
예제 #14
0
/*!
  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);
}
예제 #15
0
파일: knob.cpp 프로젝트: 87maxi/oom
void Knob::drawMarker(QPainter *p, double arc, const QColor &c)
{

	QPen pn;
	int radius;
	double rb, re;
	double rarc;

	rarc = arc * M_PI / 180.0;
	double ca = cos(rarc);
	double sa = -sin(rarc);
	radius = kRect.width() / 2 - d_borderWidth;
	if (radius < 3) radius = 3;
	int ym = kRect.y() + radius + d_borderWidth;
	int xm = kRect.x() + radius + d_borderWidth;

	switch (d_symbol)
	{
		case Dot:

			p->setBrush(c);
			p->setPen(Qt::NoPen);
			rb = double(qwtMax(radius - 4 - d_dotWidth / 2, 0));
			p->drawEllipse(xm - int(rint(sa * rb)) - d_dotWidth / 2,
					ym - int(rint(ca * rb)) - d_dotWidth / 2,
					d_dotWidth, d_dotWidth);

			break;

		case Line:

			pn.setColor(c);
			pn.setWidth(3);
			p->setPen(pn);

			rb = qwtMax(double((radius - 4) / 3.0), 0.0);
			re = qwtMax(double(radius - 4), 0.0);

			p->drawLine(xm - int(rint(sa * rb)),
					ym - int(rint(ca * rb)),
					xm - int(rint(sa * re)),
					ym - int(rint(ca * re)));

			break;
	}


}
예제 #16
0
/*!
    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 setAttribute()
*/
void QwtLinearScaleEngine::autoScale(int maxNumSteps, 
    double &x1, double &x2, double &stepSize) const
{
    QwtDoubleInterval interval(x1, x2);
    interval = interval.normalized();

    interval.setMinValue(interval.minValue() - lowerMargin());
    interval.setMaxValue(interval.maxValue() + upperMargin());

    if (testAttribute(QwtScaleEngine::Symmetric))
        interval = interval.symmetrize(reference());
 
    if (testAttribute(QwtScaleEngine::IncludeReference))
        interval = interval.extend(reference());

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

    stepSize = divideInterval(interval.width(), qwtMax(maxNumSteps, 1));

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

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

    if (testAttribute(QwtScaleEngine::Inverted))
    {
        qSwap(x1, x2);
        stepSize = -stepSize;
    }
}
예제 #17
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();
}
예제 #18
0
/*!
  Draw a needle looking like an arrow
*/
void QwtDialSimpleNeedle::drawArrowNeedle(QPainter *painter, 
    const QPalette &palette, QPalette::ColorGroup colorGroup,
    const QPoint &center, int length, int width,
    double direction, bool hasKnob)
{
    direction *= M_PI / 180.0;

    painter->save();

    if ( width <= 0 )
    {
        width = (int)qwtMax(length * 0.06, 9.0);
        if ( width % 2 == 0 )
            width++;
    }

    const int peak = 3;
    const QPoint p1(center.x() + 1, center.y() + 1);
    const QPoint p2 = qwtPolar2Pos(p1, length - peak, direction);
    const QPoint p3 = qwtPolar2Pos(p1, length, direction);

    QwtPointArray pa(5);
    pa.setPoint(0, qwtPolar2Pos(p1, width / 2, direction - M_PI_2));
    pa.setPoint(1, qwtPolar2Pos(p2, 1, direction - M_PI_2));
    pa.setPoint(2, p3);
    pa.setPoint(3, qwtPolar2Pos(p2, 1, direction + M_PI_2));
    pa.setPoint(4, qwtPolar2Pos(p1, width / 2, direction + M_PI_2));

    painter->setPen(Qt::NoPen);
    painter->setBrush(palette.brush(colorGroup, QwtPalette::Mid));
    painter->drawPolygon(pa);

    QwtPointArray shadowPa(3);

    const int colorOffset = 10;

    int i;
    for ( i = 0; i < 3; i++ )
        shadowPa.setPoint(i, pa[i]);

    const QColor midColor = palette.color(colorGroup, QwtPalette::Mid);

    painter->setPen(midColor.dark(100 + colorOffset));
    painter->drawPolyline(shadowPa);

    for ( i = 0; i < 3; i++ )
        shadowPa.setPoint(i, pa[i + 2]);

    painter->setPen(midColor.dark(100 - colorOffset));
    painter->drawPolyline(shadowPa);

    if ( hasKnob )
    {
        drawKnob(painter, center, qRound(width * 1.3), 
            palette.brush(colorGroup, QwtPalette::Base),
            false);
    }

    painter->restore();
}
예제 #19
0
파일: scldiv.cpp 프로젝트: ViktorNova/los
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;

}
/*! 
  Calculate the width of a layout for a given number of
  columns.

  \param numCols Given number of columns
  \param itemWidth Array of the width hints for all items
*/
int QwtDynGridLayout::maxRowWidth(int numCols) const
{
    int col;

    QwtArray<int> colWidth(numCols);
    for ( col = 0; col < (int)numCols; col++ )
        colWidth[col] = 0;

    if ( d_data->isDirty )
        ((QwtDynGridLayout*)this)->updateLayoutCache();

    for ( uint index = 0; 
        index < (uint)d_data->itemSizeHints.count(); index++ )
    {
        col = index % numCols;
        colWidth[col] = qwtMax(colWidth[col], 
            d_data->itemSizeHints[int(index)].width());
    }

    int rowWidth = 2 * margin() + (numCols - 1) * spacing();
    for ( col = 0; col < (int)numCols; col++ )
        rowWidth += colWidth[col];

    return rowWidth;
}
예제 #21
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();
    }
}
예제 #22
0
파일: slider.cpp 프로젝트: Adamiko/los
void Slider::setBorderWidth(int bd)
{
	d_borderWidth = qwtMin(qwtMax(bd, 0), 10);
	if (d_bgStyle & BgTrough)
		d_bwTrough = d_borderWidth;
	else
		d_bwTrough = 0;
}
/*!
  \brief Specify the distance between color bar, scale and title
  \param spacing Spacing
  \sa QwtScaleWidget::spacing
*/
void QwtScaleWidget::setSpacing(int spacing)
{
    spacing = qwtMax( 0, spacing );
    if ( spacing != d_data->spacing )
    {
        d_data->spacing = spacing;
        layoutScale();
    }
}
/*!
  \brief Specify the margin to the colorBar/base line.
  \param margin Margin
  \sa QwtScaleWidget::margin
*/
void QwtScaleWidget::setMargin(int margin)
{
    margin = qwtMax( 0, margin );
    if ( margin != d_data->margin )
    {
        d_data->margin = margin;
        layoutScale();
    }
}
예제 #25
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)));
    }
}
예제 #26
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;
}
예제 #27
0
/*!
  \brief Draw the marker at the knob's front
  \param p Painter
  \param arc Angle of the marker
  \param c Marker color
*/
void QwtKnob::drawMarker(QPainter *p, double arc, const QColor &c)
{
    const double rarc = arc * M_PI / 180.0;
    const double ca = cos(rarc);
    const double sa = - sin(rarc);

    int radius = d_kRect.width() / 2 - d_borderWidth;
    if (radius < 3) 
        radius = 3; 

    const int ym = d_kRect.y() + radius + d_borderWidth;
    const int xm = d_kRect.x() + radius + d_borderWidth;

    switch (d_symbol)
    {
        case Dot:
        {
            p->setBrush(c);
            p->setPen(Qt::NoPen);

            const double rb = double(qwtMax(radius - 4 - d_dotWidth / 2, 0));
            p->drawEllipse(xm - int(floor (sa * rb + 0.5)) - d_dotWidth / 2,
                   ym - int(floor (ca * rb + 0.5)) - d_dotWidth / 2,
                   d_dotWidth, d_dotWidth);
            break;
        }
        case Line:
        {
            p->setPen(QPen(c, 2));

            const double rb = qwtMax(double((radius - 4) / 3.0), 0.0);
            const double re = qwtMax(double(radius - 4), 0.0);
            
            p->drawLine (xm - int (floor (sa * rb + 0.5)),
                 ym - int (floor (ca * rb + 0.5)),
                 xm - int (floor (sa * re + 0.5)),
                 ym - int (floor (ca * re + 0.5)));
            
            break;
        }
    }
}
예제 #28
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;
}
예제 #29
0
파일: qwt_math.cpp 프로젝트: 376473984/pvb
/*!
  \brief Find the largest value in an array
  \param array Pointer to an array
  \param size Array size
*/
double qwtGetMax(const double *array, int size)
{
    if (size <= 0)
       return 0.0;
    
    double rv = array[0];
    for (int i = 1; i < size; i++)
       rv = qwtMax(rv, array[i]);

    return rv;
}
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);
}