Example #1
0
//将位置转换成字符串
QwtText RectPicker::trackerTextF(const QPointF &pos) const
{
	QwtText text;

	const QPolygon points = selection();//选择的点
	if (!points.isEmpty())
	{
		QString num;
		QPoint point = points[0];
		QPointF point2 = invTransform(point);
		num = QString("(%1,%2),(,)").arg(point2.x()).arg(point2.y());
		QColor bg(Qt::white);
		bg.setAlpha(200);
		if (points.size() == 2)
		{

			QPointF point0 = invTransform(points[0]);
			QPointF point1 = invTransform(points[1]);
			num = QString("(%1,%2),(%3,%4)").arg(point0.x()).arg(point0.y()).arg(point1.x()).arg(point1.y());
		}
		text.setBackgroundBrush(QBrush(bg));
		text.setText(num);
	}
	return text;
}
Example #2
0
void OneCurvePlot::mouseReleaseEvent(QMouseEvent* e)
{
  if (e->button() == Qt::LeftButton)
  {
    if (m_x0 == e->x() && m_y0 == e->y())
    {// there were no dragging
      emit clickedAt(invTransform(xBottom,e->x()-canvas()->x()),invTransform(yLeft,e->y()-canvas()->y()));
    }
  }
}
bool QwtPlotPicker::end( bool ok )
{
    ok = QwtPicker::end( ok );
    if ( !ok )
        return false;

    QwtPlot *plot = QwtPlotPicker::plot();
    if ( !plot )
        return false;

    const QPolygon pa = selection();
    if ( pa.count() == 0 )
        return false;

    QwtPickerMachine::SelectionType selectionType =
        QwtPickerMachine::NoSelection;

    if ( stateMachine() )
        selectionType = stateMachine()->selectionType();

    switch ( selectionType )
    {
        case QwtPickerMachine::PointSelection:
        {
            const QPointF pos = invTransform( pa[0] );
            Q_EMIT selected( pos );
            break;
        }
        case QwtPickerMachine::RectSelection:
        {
            if ( pa.count() >= 2 )
            {
                const QPoint p1 = pa[0];
                const QPoint p2 = pa[int( pa.count() - 1 )];

                const QRect rect = QRect( p1, p2 ).normalized();
                Q_EMIT selected( invTransform( rect ) );
            }
            break;
        }
        case QwtPickerMachine::PolygonSelection:
        {
            QVector<QPointF> dpa( pa.count() );
            for ( int i = 0; i < int( pa.count() ); i++ )
                dpa[i] = invTransform( pa[i] );

            Q_EMIT selected( dpa );
        }
        default:
            break;
    }

    return true;
}
Example #4
0
bool QwtPlotPicker::end(bool ok)
{
    ok = QwtPicker::end(ok);
    if ( !ok )
        return false;

    QwtPlot *plot = QwtPlotPicker::plot();
    if ( !plot )
        return false;

    const QwtPolygon &pa = selection();
    if ( pa.count() == 0 )
        return false;

    if ( selectionFlags() & PointSelection )
    {
        const QwtDoublePoint pos = invTransform(pa[0]);
        emit selected(pos);
    }
    else if ( (selectionFlags() & RectSelection) && pa.count() >= 2 )
    {
        QPoint p1 = pa[0];
        QPoint p2 = pa[int(pa.count() - 1)];

        if ( selectionFlags() & CenterToCorner )
        {
            p1.setX(p1.x() - (p2.x() - p1.x()));
            p1.setY(p1.y() - (p2.y() - p1.y()));
        }
        else if ( selectionFlags() & CenterToRadius )
        {
            const int radius = qwtMax(qwtAbs(p2.x() - p1.x()),
                qwtAbs(p2.y() - p1.y()));
            p2.setX(p1.x() + radius);
            p2.setY(p1.y() + radius);
            p1.setX(p1.x() - radius);
            p1.setY(p1.y() - radius);
        }

        emit selected(invTransform(QRect(p1, p2)).normalized());
    }
    else 
    {
        QwtArray<QwtDoublePoint> dpa(pa.count());
        for ( int i = 0; i < int(pa.count()); i++ )
            dpa[i] = invTransform(pa[i]);

        emit selected(dpa);
    }

    return true;
}
/*!
  Expand the selected rectangle to minZoomSize() and zoom in
  if accepted.

  \sa accept(), minZoomSize()
*/
bool QwtPlotZoomer::end( bool ok )
{
    ok = QwtPlotPicker::end( ok );
    if ( !ok )
        return false;

    QwtPlot *plot = QwtPlotZoomer::plot();
    if ( !plot )
        return false;

    const QPolygon &pa = selection();
    if ( pa.count() < 2 )
        return false;

    QRect rect = QRect( pa[0], pa[int( pa.count() - 1 )] );
    rect = rect.normalized();

    QRectF zoomRect = invTransform( rect ).normalized();

    const QSizeF minSize = minZoomSize();
    if ( minSize.isValid() )
    {
        const QPointF center = zoomRect.center();
        zoomRect.setSize( zoomRect.size().expandedTo( minZoomSize() ) );
        zoomRect.moveCenter( center );
    }

    zoom( zoomRect );

    return true;
}
Example #6
0
bool Ship::addImpulse(Brick* brick, vec3 pos, vec3 impulse)
{
	if (brick == m_base)
		return false;

	Transform t = invTransform(m_body->getTransform());
	vec3 _pos = transformVec3(pos, t);
	vec3 _impulse = rotate(impulse, t.q);

	m_minAxis = abs(_impulse.x) > abs(_impulse.z) ? X : Z;

	// clear flow network
	clearFlowNetwork(brick, _impulse, _pos, g_tick++);

	//bool destroy = false;

	bool destroy = checkAxis(brick, impulse, pos, X);

	if (!destroy)
		destroy = checkAxis(brick, impulse, pos, Z);

	//if (!destroy)
	//	destroy = checkVertical(brick, abs(_impulse.y), impulse, pos);

	//if (destroy)
	//{
	//	m_body->applyImpulse(-impulse, pos);
	//}

	return destroy;
}
void ImageMarker::updateBoundingRect()
{
if (!plot())
	return;

d_rect = invTransform(plot()->canvasMap(xAxis()), plot()->canvasMap(yAxis()), QRect(d_pos, d_size));
}
Example #8
0
QRect CurveTracker::trackerRect( const QFont &font ) const
{
    QRect r = QwtPlotPicker::trackerRect( font );
    
    // align r to the first curve

    const QwtPlotItemList curves = plot()->itemList( QwtPlotItem::Rtti_PlotCurve );
    if ( curves.size() > 0 )
    {
        QPointF pos = invTransform( trackerPosition() );

        const QLineF line = curveLineAt(    
            static_cast<const QwtPlotCurve *>( curves[0] ), pos.x() );
        if ( !line.isNull() )
        {
            const double curveY = line.pointAt(
                ( pos.x() - line.p1().x() ) / line.dx() ).y();

            pos.setY( curveY );
            pos = transform( pos );

            r.moveBottom( pos.y() );            
        }
    }

    return r;
}
/*!
  Expand the selected rectangle to minZoomSize() and zoom in
  if accepted.

  \sa QwtPlotZoomer::accept()a, QwtPlotZoomer::minZoomSize()
*/
bool QwtPlotZoomer::end(bool ok)
{
    ok = QwtPlotPicker::end(ok);
    if (!ok)
        return false;

    QwtPlot *plot = QwtPlotZoomer::plot();
    if ( !plot )
        return false;

    const QwtPolygon &pa = selection();
    if ( pa.count() < 2 )
        return false;

    QRect rect = QRect(pa[0], pa[int(pa.count() - 1)]);
#if QT_VERSION < 0x040000
    rect = rect.normalize();
#else
    rect = rect.normalized();
#endif


    QwtDoubleRect zoomRect = invTransform(rect).normalized();

    const QwtDoublePoint center = zoomRect.center();
    zoomRect.setSize(zoomRect.size().expandedTo(minZoomSize()));
    zoomRect.moveCenter(center);

    zoom(zoomRect);

    return true;
}
void LineChartPicker::select(const QPoint& pos)
{
  LineChart *curve = NULL;
  SuggestionItem *suggestionItem = NULL;
  int index = -1;
  double dist = 10e10;
  QPointF p = invTransform(pos);

  const QwtPlotItemList& itmList = plot()->itemList();
  if (!itmList.isEmpty())
  {
    QwtPlotItemIterator itr = itmList.end();
    while (true)
    {
      --itr;
      if ((*itr)->rtti() == LineChart::RttiLineChart && (*itr)->isVisible())
      {
        LineChart *c = (LineChart*)(*itr);

        double d;
        int idx = c->closestPoint(pos, &d);
        // Find the nearest chart
        if (d < dist)
        {
          curve = c;
          index = idx;
          dist = d;
        }
      }
      else if ((*itr)->rtti() == SuggestionItem::RTTI && (*itr)->isVisible())
      {
        // Find the first suggestion item covers the point
        int idx = ((SuggestionItem *) *itr)->in(p);
        if (idx >= 0)
        {
          index = idx;
          suggestionItem = (SuggestionItem *) (*itr);
        }
        break;
      }
      if (itr == itmList.begin())
        break;
    }
  }

  if (suggestionItem != NULL)
  {
    // Show the suggestion
    const SuggestionItem::SuggestionUnit *item = suggestionItem->getSuggestions()[index];
    QToolTip::showText(plot()->canvas()->mapToGlobal(pos),
                       item->suggestion);
  }
  else if (curve != NULL && dist < 5)
  {
    // Show the tooltip
    QToolTip::showText(plot()->canvas()->mapToGlobal(pos),
                       tr("%1").arg(curve->getTooptipAt(index)));
  }
}
Example #11
0
bool PlotZoomer::end(bool ok)
{
  // Code here is taken from QwtPlotZoomer. The only modification is around the _zoomMode handling.
  ok = QwtPlotPicker::end(ok);
  if (!ok)
  {
    return false;
  }

  QwtPlot *plot = QwtPlotZoomer::plot();
  if (!plot)
  {
    return false;
  }

  const QPolygon &pa = selection();
  if (pa.count() < 2)
  {
    return false;
  }

  QRect rect = QRect(pa[0], pa[int(pa.count() - 1)]);
  rect = rect.normalized();

  QRectF currentZoomRect = zoomRect();
  QRectF zoomRect = invTransform(rect).normalized();

  switch (_zoomMode)
  {
  default:
  case ZoomBoth:
    // nothing.
    break;

  case ZoomX:
    // Maintain current zoom y and height.
    zoomRect.setY(currentZoomRect.y());
    zoomRect.setHeight(currentZoomRect.height());
    break;

  case ZoomY:
    // Maintain current zoom x and width.
    zoomRect.setX(currentZoomRect.x());
    zoomRect.setWidth(currentZoomRect.width());
    break;
  }

  const QSizeF minSize = minZoomSize();
  if (minSize.isValid())
  {
    const QPointF center = zoomRect.center();
    zoomRect.setSize(zoomRect.size().expandedTo(minZoomSize()));
    zoomRect.moveCenter(center);
  }

  zoom(zoomRect);

  return true;
}
Example #12
0
boolean UStencil::contains (PointObj& po, Graphic* gs) {
    Bitmap* bitmap = (_mask == nil) ? _image : _mask;
    PointObj pt (&po);

    invTransform(pt._x, pt._y, gs);
    BoxObj b (0, 0, bitmap->Width(), bitmap->Height());
    return b.Contains(pt);
}
Example #13
0
boolean ULabel::contains (PointObj& po, Graphic* gs) {
    PointObj pt (&po);
    PSFont* f = gs->GetFont();

    invTransform(pt._x, pt._y, gs);
    BoxObj b (0, 0, f->Width(_string), f->Height());
    return b.Contains(pt);
}
Example #14
0
void
MUPlot::mouseMoved()
{
    if ((!slowDrag && !fastDrag)) return;

    // where is the mouse ?
    QPoint pos = QCursor::pos();

    // cursor position
    QPoint cpos = canvas()->mapFromGlobal(pos);

    double mean = invTransform(xBottom,cpos.x());
    double variance = invTransform(yLeft, cpos.y()) / 40.0f;

    // dragging slow
    if (fastDrag) {

        fastNormal->setMean(mean);
        fastNormal->setVariance(variance);

        // move the handle
        fastHandle->setValue(mean, variance * 40.0f);

        // move the line
        fastLine->setValue(mean, 0);
    }

    // dragging slow
    if (slowDrag) {

        slowNormal->setMean(mean);
        slowNormal->setVariance(variance);

        // move the handle
        slowHandle->setValue(mean, variance * 40.0f);

        // move the line
        slowLine->setValue(mean, 0);
    }

    // redo MMP
    setMUSet();

    replot();
}
Example #15
0
void
PfPvDoubleClickPicker::widgetMouseDoubleClickEvent( QMouseEvent *me )
{
    QPointF p1 = invTransform(me->pos());
    QPoint p2 = pfPvTransform(p1);

    // emit the itemMoved signal
    Q_EMIT doubleClicked(p2.x(), p2.y());
}
Example #16
0
void Plot::mouseMove (QPoint p)
{
//    qDebug() << "mouse move";
  if (! _plotSettings.info)
    return;
  
  if (! g_symbol)
    return;

  if (_plotSettings.selected)
  {
    _plotSettings.selected->move(_plotSettings.status, p);
    return;
  }

  QHashIterator<QString, Marker *> it2(_plotSettings.markers);
  while (it2.hasNext())
  {
    it2.next();
    Marker *m = it2.value();
    
    if (! m->isSelected(p))
      continue;

    QStringList info;
    info << _plotSettings.name;
    
    if (! m->info(info))
      continue;

    _plotInfo->setData(info);
    replot();

    return;
  }

  int index = (int) invTransform(QwtPlot::xBottom, p.x());
  
  QStringList info;
  info << _plotSettings.name;

  _dateScaleDraw->info(index, info);

  QHashIterator<QString, Curve *> it(_plotSettings.curves);
  while (it.hasNext())
  {
    it.next();
    Curve *curve = it.value();
    curve->info(index, info);
  }

  _plotInfo->setData(info);
  
  replot();
}
Example #17
0
boolean MultiLine::s_contains (PointObj& po, Graphic* gs) {
    MultiLineObj &ml = *_pts;
    PointObj pt (&po);
    BoxObj b;
    getBox(b, gs);

    if (b.Contains(po)) {
	invTransform(pt._x, pt._y, gs);
	return ml.Contains(pt);
    }
    return false;
}
Example #18
0
boolean MultiLine::f_contains (PointObj& po, Graphic* gs) {
    BoxObj b;
    PointObj pt (&po);
    getBox(b, gs);

    if (b.Contains(pt)) {
	FillPolygonObj fp (x(), y(), count());
	invTransform(pt._x, pt._y, gs);
	return fp.Contains(pt);
    }
    return false;
}
Example #19
0
bool OpenBSpline::s_contains (PointObj& po, Graphic* gs) {
    PointObj pt (&po);
    BoxObj b;
    getBox(b, gs);

    if (b.Contains(pt)) {
	invTransform(pt._x, pt._y, gs);
	MultiLineObj ml;
	ml.SplineToMultiLine(_x, _y, _count);
	return ml.Contains(pt);
    }
    return false;
}
Example #20
0
bool OpenBSpline::f_contains (PointObj& po, Graphic* gs) {
    PointObj pt (&po);
    BoxObj b;
    getBox(b, gs);

    if (b.Contains(pt)) {
	invTransform(pt._x, pt._y, gs);
	FillPolygonObj fp;
	fp.ClosedSplineToPolygon(_x, _y, _count);
	return fp.Contains(pt);
    }
    return false;
}
/*!
  Draw the SVG item

  \param painter Painter
  \param xMap X-Scale Map
  \param yMap Y-Scale Map
  \param canvasRect Contents rect of the plot canvas
*/
void QwtPlotSvgItem::draw(QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRect &canvasRect) const
{
    const QwtDoubleRect cRect = invTransform(xMap, yMap, canvasRect);
    const QwtDoubleRect bRect = boundingRect();
    if ( bRect.isValid() && cRect.isValid() )
    {
        QwtDoubleRect rect = bRect;
        if ( bRect.contains(cRect) )
            rect = cRect;

        render(painter, viewBox(rect),
            transform(xMap, yMap, rect) );
    }
}
Example #22
0
/*!
  \brief Determine the value for a new position of the
         slider handle.

  \param pos Mouse position

  \return Value for the mouse position
  \sa isScrollPosition()
*/
double QwtSlider::scrolledTo( const QPoint &pos ) const
{
    int p = ( orientation() == Qt::Horizontal ) 
        ? pos.x() : pos.y();

    p -= d_data->mouseOffset;

    int min = transform( lowerBound() );
    int max = transform( upperBound() );
    if ( min > max )
        qSwap( min, max );

    p = qBound( min, p, max );

    return invTransform( p );
}
Example #23
0
/*!
  \brief Determine the value for a new position of the mouse

  \param pos Mouse position

  \return Value for the mouse position
  \sa isScrollPosition()
*/
double QwtKnob::scrolledTo( const QPoint &pos ) const
{
    double angle = QLineF( rect().center(), pos ).angle();
    angle = qwtNormalizeDegrees( angle - d_data->mouseOffset );

    if ( scaleMap().pDist() > 360.0 )
    {
        angle = qwtToDegrees( angle );

        const double v = transform( value() );

        int numTurns = qFloor( ( v - scaleMap().p1() ) / 360.0 );

        double valueAngle = qwtNormalizeDegrees( v );
        if ( qAbs( valueAngle - angle ) > 180.0 )
        {
            numTurns += ( angle > valueAngle ) ? -1 : 1;
        }

        angle += scaleMap().p1() + numTurns * 360.0;

        if ( !wrapping() )
        {
            const double boundedAngle = 
                qBound( scaleMap().p1(), angle, scaleMap().p2() );

            d_data->mouseOffset += ( boundedAngle - angle );
            angle = boundedAngle;
        }
    }
    else
    {
        angle = qwtToScaleAngle( angle );

        const double boundedAngle = 
            qBound( scaleMap().p1(), angle, scaleMap().p2() );

        if ( !wrapping() )
            d_data->mouseOffset += ( boundedAngle - angle );

        angle = boundedAngle;
    }

    return invTransform( angle );
}
Example #24
0
    virtual QwtText trackerTextF( const QPointF &pos ) const
    {
        QwtText text;

        const QPolygon points = selection();
        if ( !points.isEmpty() )
        {
            QString num;
            num.setNum( QLineF( pos, invTransform( points[0] ) ).length() );

            QColor bg( Qt::green );
            bg.setAlpha( 200 );

            text.setBackgroundBrush( QBrush( bg ) );
            text.setText( num );
        }
        return text;
    }
Example #25
0
boolean TextGraphic::contains (PointObj& po, Graphic* gs) {
    PointObj pt (&po);
    PSFont* f = gs->GetFont();
    BoxObj box(0, 0, 0, f->Height());
    int beg, end, lineSize, nextBeg, ypos = 0;
    const char* s = GetOriginal();
    int size = strlen(s);

    invTransform(pt._x, pt._y, gs);
    
    for (beg = 0; beg < size; beg = nextBeg) {
        GetLine(s, size, beg, end, lineSize, nextBeg);
        box._right = f->Width(&s[beg], lineSize) - 1;
        if (box.Contains(pt)) {
            return true;
        }
        box._top -= _lineHt;
        box._bottom -= _lineHt;
    }
    return false;
}
Example #26
0
QwtText ViSpectrumPlotPicker::trackerText(const QPoint &position) const
{
	QColor bg(Qt::white);
	bg.setAlpha(200);
	QPointF point = invTransform(position);

	QString valueX = QString::number(point.x(), 'f', 4);
	QString valueY = QString::number(mPlot->valueAt(point.x()), 'f', 4);
	qint32 stringSizeX = qMax(mLabelX.size(), mLabelY.size()) + 2;
	qint32 stringSizeY = qMax(valueX.size(), valueY.size());

	QString string;
	QTextStream stream(&string);
	stream << qSetFieldWidth(stringSizeX) << left << (mLabelX + ": ") << qSetFieldWidth(stringSizeY) << left << valueX << qSetFieldWidth(0) << left << mUnitX << endl;
	stream << qSetFieldWidth(stringSizeX) << left << (mLabelY + ": ") << qSetFieldWidth(stringSizeY) << right << valueY << qSetFieldWidth(0) << mUnitY;

	QwtText text(string);
	text.setFont(QFont("Courier"));
	text.setBackgroundBrush( QBrush( bg ));

	return text;
}
Example #27
0
void ZoomPlot :: mouseReleaseEvent ( QMouseEvent * event ) {
  int mx = event->x() - axisWidget(yLeft)->sizeHint().width();	//current mouse coordinates
  int my = event->y();						//in reference to plot origin (w/o scale)

  if (event->button() == Qt::LeftButton) { //LMB - zooming
     drawing = false;
     delete kwadrat;

     zoom_start_x -= axisWidget(yLeft)->sizeHint().width();

     if (mx == zoom_start_x || my == zoom_start_y) {std::cout << "Cannot zoom!\n"; return;}

     double to_x = invTransform (xBottom, mx), to_y = invTransform (yLeft, my);
     double from_x = invTransform (xBottom, zoom_start_x), from_y = invTransform (yLeft, zoom_start_y);

     ZoomIn (from_x,from_y,to_x,to_y);
  }
  else if (event->button() == Qt::MidButton) { emit clicked(Qt::MidButton, invTransform (xBottom, event->x()-axisWidget(yLeft)->sizeHint().width()), invTransform (yLeft, event->y()));} //ustaw lewy kraniec?
  else if (event->button() == Qt::RightButton) { emit clicked(Qt::RightButton, invTransform (xBottom, event->x()-axisWidget(yLeft)->sizeHint().width()), invTransform (yLeft, event->y()));} //ustaw prawy kraniec?
}
Example #28
0
void CurveTracker::move(const QPoint &pos)
{
    currentX = invTransform( pos ).x();
    QwtPlotPicker::move(pos);
}
/*!
  Append a point to the selection and update rubberband and tracker.

  \param pos Additional point
  \sa isActive, begin(), end(), move(), appended()

  \note The appended(const QPoint &), appended(const QDoublePoint &)
        signals are emitted.
*/
void QwtPlotPicker::append( const QPoint &pos )
{
    QwtPicker::append( pos );
    Q_EMIT appended( invTransform( pos ) );
}
/*!
  Move the last point of the selection

  \param pos New position
  \sa isActive, begin(), end(), append()

  \note The moved(const QPoint &), moved(const QDoublePoint &)
        signals are emitted.
*/
void QwtPlotPicker::move( const QPoint &pos )
{
    QwtPicker::move( pos );
    Q_EMIT moved( invTransform( pos ) );
}