Beispiel #1
0
bool ScrollZoomer::needScrollBar(Qt::Orientation o) const
{
#if QT_VERSION < 0x040000
  QScrollView::ScrollBarMode mode;
#else
  Qt::ScrollBarPolicy mode;
#endif
  double zoomMin, zoomMax, baseMin, baseMax;

  if (o == Qt::Horizontal)
    {
      mode = d_hScrollData->mode;
      baseMin = zoomBase().left();
      baseMax = zoomBase().right();
      zoomMin = zoomRect().left();
      zoomMax = zoomRect().right();
    }
  else
    {
      mode = d_vScrollData->mode;
      baseMin = zoomBase().top();
      baseMax = zoomBase().bottom();
      zoomMin = zoomRect().top();
      zoomMax = zoomRect().bottom();
    }

  bool needed = false;
  switch (mode)
    {
#if QT_VERSION < 0x040000
  case QScrollView::AlwaysOn:
#else
    case Qt::ScrollBarAlwaysOn:
#endif
    needed = true;
    break;
#if QT_VERSION < 0x040000
  case QScrollView::AlwaysOff:
#else
    case Qt::ScrollBarAlwaysOff:
#endif
    needed = false;
    break;
  default:
    {
      if (baseMin < zoomMin || baseMax > zoomMax)
        needed = true;
      break;
    }
    }
  return needed;
}
Beispiel #2
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();
    }
}
Beispiel #3
0
		virtual void zoom (QRectF const & rect)
		{
			QRectF newRect;
			QRectF const & baseRect = zoomBase();
			newRect.setCoords(rect.left(), baseRect.top(), rect.right(), baseRect.bottom());
			QwtPlotZoomer::zoom(newRect);
		}
bool ScrollZoomer::needScrollBar( Qt::Orientation orientation ) const
{
    Qt::ScrollBarPolicy mode;
    double zoomMin, zoomMax, baseMin, baseMax;

    if ( orientation == Qt::Horizontal )
    {
        mode = d_hScrollData->mode;
        baseMin = zoomBase().left();
        baseMax = zoomBase().right();
        zoomMin = zoomRect().left();
        zoomMax = zoomRect().right();
    }
    else
    {
        mode = d_vScrollData->mode;
        baseMin = zoomBase().top();
        baseMax = zoomBase().bottom();
        zoomMin = zoomRect().top();
        zoomMax = zoomRect().bottom();
    }

    bool needed = false;
    switch( mode )
    {
        case Qt::ScrollBarAlwaysOn:
            needed = true;
            break;
        case Qt::ScrollBarAlwaysOff:
            needed = false;
            break;
        default:
        {
            if ( baseMin < zoomMin || baseMax > zoomMax )
                needed = true;
            break;
        }
    }
    return needed;
}
/*!
  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)
{
    if ( x < zoomBase().left() )
        x = zoomBase().left();
    if ( x > zoomBase().right() - zoomRect().width() )
        x = zoomBase().right() - zoomRect().width();

    if ( y < zoomBase().top() )
        y = zoomBase().top();
    if ( y > zoomBase().bottom() - zoomRect().height() )
        y = zoomBase().bottom() - zoomRect().height();

    if ( x != zoomRect().left() || y != zoomRect().top() )
    {
        d_data->zoomStack[d_data->zoomRectIndex].moveTo(x, y);
        rescale();
    }
}
/*!
  Move the the current zoom rectangle.

  \param pos New position

  \sa QRectF::moveTo()
  \note The changed rectangle is limited by the zoom base
*/
void QwtPlotZoomer::moveTo( const QPointF &pos )
{
    double x = pos.x();
    double y = pos.y();

    if ( x < zoomBase().left() )
        x = zoomBase().left();
    if ( x > zoomBase().right() - zoomRect().width() )
        x = zoomBase().right() - zoomRect().width();

    if ( y < zoomBase().top() )
        y = zoomBase().top();
    if ( y > zoomBase().bottom() - zoomRect().height() )
        y = zoomBase().bottom() - zoomRect().height();

    if ( x != zoomRect().left() || y != zoomRect().top() )
    {
        d_data->zoomStack[d_data->zoomRectIndex].moveTo( x, y );
        rescale();
    }
}
Beispiel #7
0
bool AdvPlotZoomer::accept( QPolygon &pa ) const
{
    if ( !QwtPlotZoomer::accept(pa) )
        return false;
    if ( d_zoomConstrain == NoConstrain )
        return true;

    QRect zoomBaseInt = transform(zoomBase());
    switch ( d_zoomConstrain ) {
    case HZoomOnly:
        pa[0].setY(zoomBaseInt.top());
        pa[1].setY(zoomBaseInt.bottom());
        break;
    case VZoomOnly:
        pa[0].setX(zoomBaseInt.left());
        pa[1].setX(zoomBaseInt.right());
        break;
    default:
        // Nothing to be done here
        break;
    }
    return true;
}
void ScrollZoomer::updateScrollBars()
{
    if ( !canvas() )
        return;

    const int xAxis = QwtPlotZoomer::xAxis().pos;
    const int yAxis = QwtPlotZoomer::yAxis().pos;

    int xScrollBarAxis = xAxis;
    if ( hScrollBarPosition() == OppositeToScale )
        xScrollBarAxis = oppositeAxis( xScrollBarAxis );

    int yScrollBarAxis = yAxis;
    if ( vScrollBarPosition() == OppositeToScale )
        yScrollBarAxis = oppositeAxis( yScrollBarAxis );


    QwtPlotLayout *layout = plot()->plotLayout();

    bool showHScrollBar = needScrollBar( Qt::Horizontal );
    if ( showHScrollBar )
    {
        ScrollBar *sb = scrollBar( Qt::Horizontal );
        sb->setPalette( plot()->palette() );
        sb->setInverted( !plot()->axisScaleDiv( xAxis ).isIncreasing() );
        sb->setBase( zoomBase().left(), zoomBase().right() );
        sb->moveSlider( zoomRect().left(), zoomRect().right() );

        if ( !sb->isVisibleTo( canvas() ) )
        {
            sb->show();
            layout->setCanvasMargin( layout->canvasMargin( xScrollBarAxis )
                + sb->extent(), xScrollBarAxis );
        }
    }
    else
    {
        if ( horizontalScrollBar() )
        {
            horizontalScrollBar()->hide();
            layout->setCanvasMargin( layout->canvasMargin( xScrollBarAxis )
                - horizontalScrollBar()->extent(), xScrollBarAxis );
        }
    }

    bool showVScrollBar = needScrollBar( Qt::Vertical );
    if ( showVScrollBar )
    {
        ScrollBar *sb = scrollBar( Qt::Vertical );
        sb->setPalette( plot()->palette() );
        sb->setInverted( !plot()->axisScaleDiv( yAxis ).isIncreasing() );
        sb->setBase( zoomBase().top(), zoomBase().bottom() );
        sb->moveSlider( zoomRect().top(), zoomRect().bottom() );

        if ( !sb->isVisibleTo( canvas() ) )
        {
            sb->show();
            layout->setCanvasMargin( layout->canvasMargin( yScrollBarAxis )
                + sb->extent(), yScrollBarAxis );
        }
    }
    else
    {
        if ( verticalScrollBar() )
        {
            verticalScrollBar()->hide();
            layout->setCanvasMargin( layout->canvasMargin( yScrollBarAxis )
                - verticalScrollBar()->extent(), yScrollBarAxis );
        }
    }

    if ( showHScrollBar && showVScrollBar )
    {
        if ( d_cornerWidget == NULL )
        {
            d_cornerWidget = new QWidget( canvas() );
            d_cornerWidget->setAutoFillBackground( true );
            d_cornerWidget->setPalette( plot()->palette() );
        }
        d_cornerWidget->show();
    }
    else
    {
        if ( d_cornerWidget )
            d_cornerWidget->hide();
    }

    layoutScrollBars( canvas()->contentsRect() );
    plot()->updateLayout();
}
Beispiel #9
0
LogPlotZoomer::LogPlotZoomer(QWidget *canvas) :
  QwtPlotZoomer(canvas)
#else
LogPlotZoomer::LogPlotZoomer(QwtPlotCanvas *canvas):
  QwtPlotZoomer(canvas)
#endif
{}

#if QWT_VERSION > 0x060000
QwtText LogPlotZoomer::trackerTextF(const QwtDoublePoint &pos) const
#else
QwtText LogPlotZoomer::trackerText(const QwtDoublePoint &pos) const
#endif
{
  switch (rubberBand())
    {
      case HLineRubberBand:
        return QString().sprintf("%.4g", pos.y());

      case VLineRubberBand:
        return QString().sprintf("%.4g", pos.x());

      default:
        return QString().sprintf("%.4g, %.4g", pos.x(), pos.y());
    }

  return QwtText(); // make some dumb compilers happy
}

/*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();
    }
}*/

#if QWT_VERSION > 0x060000
void LogPlotZoomer::moveTo(const QPointF &  pos)
{
  double x = pos.x();
  double y = pos.y();
#else
void LogPlotZoomer::move(double x, double y)
{
#endif
  //QwtPlotZoomer::move(x,y);

  x = qwtMax(x, (double)zoomBase().left());
  x = qwtMin(x, (double)(zoomBase().right() - zoomRect().width()));

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

  if (x != zoomRect().left() || y != zoomRect().top())
    {
      //zoomStack()[zoomRectIndex()].moveTo(x, y);
      QwtDoubleRect & rect = const_cast<QwtDoubleRect &>(zoomStack()[zoomRectIndex()]);

      //handle x axis
      const int xAxis = QwtPlotZoomer::xAxis();
      const QwtScaleEngine *sex = plot()->axisScaleEngine(xAxis);

#if QWT_VERSION > 0x060000

      if (dynamic_cast<const QwtLogScaleEngine*>(sex))
#else
      if (dynamic_cast<const QwtLog10ScaleEngine*>(sex))
#endif
        {
          //logarithmic
          double factor = rect.right() / rect.left();
          rect.setRight(x * factor);
          rect.setLeft(x);
        }
      else
        {
          rect.moveLeft(x);
        }

      const int yAxis = QwtPlotZoomer::yAxis();

      const QwtScaleEngine *sey = plot()->axisScaleEngine(yAxis);

#if QWT_VERSION > 0x060000

      if (dynamic_cast<const QwtLogScaleEngine*>(sey))
#else
      if (dynamic_cast<const QwtLog10ScaleEngine*>(sey))
#endif
        {
          //logarithmic
          double factor = rect.bottom() / rect.top();
          rect.setBottom(y * factor);
          rect.setTop(y);
        }
      else
        {
          rect.moveTop(y);
        }

      //zoomStack()[zoomRectIndex()].moveTo(x, y);
      rescale();
    }
}