#include <PlotZoomer.h>
Public Types | |
enum | ScrollBarPosition { AttachedToScale, OppositeToScale } |
Public Slots | |
virtual void | zoom (const QwtDoubleRect &rect) |
virtual void | zoom (int offset) |
void | otherScrollBarMoved (Qt::Orientation o, double min, double max, double minBase, double maxBase) |
Signals | |
void | scrollBarMovedSignal (Qt::Orientation o, double min, double max, double minBase, double maxBase) |
Public Member Functions | |
PlotZoomer (QwtPlotCanvas *canvas, bool doReplot=true) | |
PlotZoomer (int xAxis, int yAxis, QwtPlotCanvas *canvas, bool doReplot=true) | |
PlotZoomer (int xAxis, int yAxis, int selectionFlags, DisplayMode trackerMode, QwtPlotCanvas *canvas, bool doReplot=true) | |
virtual | ~PlotZoomer () |
PlotScrollBar * | horizontalScrollBar () const |
PlotScrollBar * | verticalScrollBar () const |
void | setHScrollBarMode (Qt::ScrollBarPolicy) |
void | setVScrollBarMode (Qt::ScrollBarPolicy) |
Qt::ScrollBarPolicy | vScrollBarMode () const |
Qt::ScrollBarPolicy | hScrollBarMode () const |
void | setHScrollBarPosition (ScrollBarPosition) |
void | setVScrollBarPosition (ScrollBarPosition) |
ScrollBarPosition | hScrollBarPosition () const |
ScrollBarPosition | vScrollBarPosition () const |
QWidget * | cornerWidget () const |
virtual void | setCornerWidget (QWidget *) |
virtual bool | eventFilter (QObject *, QEvent *) |
virtual void | rescale () |
virtual void | updateScrollBars () |
Protected Member Functions | |
virtual PlotScrollBar * | scrollBar (Qt::Orientation) |
virtual void | layoutScrollBars (const QRect &) |
virtual void | begin () |
virtual bool | end (bool flag=true) |
{ AttachedToScale, OppositeToScale };
PlotZoomer::PlotZoomer | ( | QwtPlotCanvas * | canvas, | |
bool | doReplot = true | |||
) |
: QwtPlotZoomer( canvas, doReplot ) { //qDebug( "PlotZoomer::PlotZoomer" ); init(); }
PlotZoomer::PlotZoomer | ( | int | xAxis, | |
int | yAxis, | |||
QwtPlotCanvas * | canvas, | |||
bool | doReplot = true | |||
) |
: QwtPlotZoomer( xAxis, yAxis, canvas, doReplot ) { //qDebug( "PlotZoomer::PlotZoomer" ); init(); }
PlotZoomer::PlotZoomer | ( | int | xAxis, | |
int | yAxis, | |||
int | selectionFlags, | |||
DisplayMode | trackerMode, | |||
QwtPlotCanvas * | canvas, | |||
bool | doReplot = true | |||
) |
: QwtPlotZoomer( xAxis, yAxis, selectionFlags, trackerMode, canvas, doReplot ) { //qDebug( "PlotZoomer::PlotZoomer" ); init(); }
PlotZoomer::~PlotZoomer | ( | ) | [virtual] |
{ //qDebug( "PlotZoomer::~PlotZoomer" ); delete m_cornerWidget; delete m_vScrollData; delete m_hScrollData; }
void PlotZoomer::begin | ( | ) | [protected, virtual] |
Reimplemented from QwtPlotZoomer.
{ //qDebug( "PlotZoomer::begin" ); // Classical cursor (otherwise the zoom cursor would interfere with the tracker text) plot()->canvas()->setCursor( Qt::CrossCursor ); QwtPlotZoomer::begin(); }
QWidget * PlotZoomer::cornerWidget | ( | ) | const |
{ //qDebug( "PlotZoomer::cornerWidget" ); return m_cornerWidget; }
bool PlotZoomer::end | ( | bool | flag = true |
) | [protected, virtual] |
Reimplemented from QwtPlotZoomer.
{ //qDebug( "PlotZoomer::end" ); // Restore the zoom cursor plot()->canvas()->setCursor( QCursor( QPixmap( ":/PhytoLib/icons/Plot/32x32/ZoomCursor.png" ), 7, 7 ) ); return QwtPlotZoomer::end( flag ); }
Reimplemented from QwtPicker.
{ //qDebug( "PlotZoomer::eventFilter" ); if ( o == canvas() ) { switch( e->type() ) { case QEvent::Resize: { const int fw = ( ( QwtPlotCanvas* )canvas() )->frameWidth(); QRect rect; rect.setSize( ( ( QResizeEvent* )e )->size() ); rect.setRect( rect.x() + fw, rect.y() + fw, rect.width() - 2 * fw, rect.height() - 2 * fw ); layoutScrollBars( rect ); break; } case QEvent::ChildRemoved: { const QObject* child = ( ( QChildEvent* )e )->child(); if ( child == m_cornerWidget ) m_cornerWidget = NULL; else if ( child == m_hScrollData->m_scrollBar ) m_hScrollData->m_scrollBar = NULL; else if ( child == m_vScrollData->m_scrollBar ) m_vScrollData->m_scrollBar = NULL; break; } case QEvent::Wheel: { if ( zoomRectIndex() == 0 ) { setZoomBase( false ); } double multiplier; if ( dynamic_cast< QWheelEvent* > ( e )->delta() > 0 ) { // Zoom in a certain amount multiplier = 0.2; } else { multiplier = -0.2; } if ( zoomRect() == zoomBase() && multiplier < 0 ) { // If we have a zoomRect which is the same as the zoomBase, then // discard everything on the zoomstack and return to the zoomBase zoom( 0 ); } else { double width = zoomRect().right() - zoomRect().left(); double height = zoomRect().top() - zoomRect().bottom(); zoom( QwtDoubleRect( zoomRect().left() + multiplier / 2.0 * width, zoomRect().bottom() + multiplier / 2.0 * height, width - multiplier * width, height - multiplier * height ) ); } break; } default: break; } } return QwtPlotZoomer::eventFilter( o, e ); }
PlotScrollBar * PlotZoomer::horizontalScrollBar | ( | ) | const |
Referenced by layoutScrollBars(), otherScrollBarMoved(), and updateScrollBars().
{ //qDebug( "PlotZoomer::horizontalScrollBar" ); return m_hScrollData->m_scrollBar; }
Qt::ScrollBarPolicy PlotZoomer::hScrollBarMode | ( | ) | const |
Referenced by setHScrollBarMode().
{ //qDebug( "PlotZoomer::hScrollBarMode" ); return m_hScrollData->m_mode; }
PlotZoomer::ScrollBarPosition PlotZoomer::hScrollBarPosition | ( | ) | const |
Referenced by layoutScrollBars(), and updateScrollBars().
{ //qDebug( "PlotZoomer::hScrollBarPosition" ); return m_hScrollData->m_position; }
void PlotZoomer::layoutScrollBars | ( | const QRect & | rect | ) | [protected, virtual] |
Referenced by eventFilter(), and updateScrollBars().
{ //qDebug( "PlotZoomer::layoutScrollBars" ); int hPos = xAxis(); if ( hScrollBarPosition() == OppositeToScale ) hPos = oppositeAxis( hPos ); int vPos = yAxis(); if ( vScrollBarPosition() == OppositeToScale ) vPos = oppositeAxis( vPos ); PlotScrollBar *hScrollBar = horizontalScrollBar(); PlotScrollBar *vScrollBar = verticalScrollBar(); const int hdim = hScrollBar ? hScrollBar->extent() : 0; const int vdim = vScrollBar ? vScrollBar->extent() : 0; if ( hScrollBar && hScrollBar->isVisible() ) { int x = rect.x(); int y = ( hPos == QwtPlot::xTop ) ? rect.top() : rect.bottom() - hdim + 1; int w = rect.width(); if ( vScrollBar && vScrollBar->isVisible() ) { if ( vPos == QwtPlot::yLeft ) x += vdim; w -= vdim; } hScrollBar->setGeometry( x, y, w, hdim ); } if ( vScrollBar && vScrollBar->isVisible() ) { int pos = yAxis(); if ( vScrollBarPosition() == OppositeToScale ) pos = oppositeAxis( pos ); int x = ( vPos == QwtPlot::yLeft ) ? rect.left() : rect.right() - vdim + 1; int y = rect.y(); int h = rect.height(); if ( hScrollBar && hScrollBar->isVisible() ) { if ( hPos == QwtPlot::xTop ) y += hdim; h -= hdim; } vScrollBar->setGeometry( x, y, vdim, h ); } if ( hScrollBar && hScrollBar->isVisible() && vScrollBar && vScrollBar->isVisible() ) { if ( m_cornerWidget ) { QRect cornerRect( vScrollBar->pos().x(), hScrollBar->pos().y(), vdim, hdim ); m_cornerWidget->setGeometry( cornerRect ); } } }
void PlotZoomer::otherScrollBarMoved | ( | Qt::Orientation | o, | |
double | min, | |||
double | max, | |||
double | minBase, | |||
double | maxBase | |||
) | [slot] |
{ //qDebug( "PlotZoomer::otherScrollBarMoved" ); // This function syncs the scrollbar movement of this zoomer with the scrollbar movement // of a zoomer attached to the opposite axis // TODO: unfortunately the sync is not perfect due to some rounding errors somewhere along the way if ( maxBase == minBase ) return; double thisMinBase = 0.0; double thisMaxBase = 0.0; if ( o == Qt::Horizontal ) { thisMinBase = horizontalScrollBar()->minBaseValue(); thisMaxBase = horizontalScrollBar()->maxBaseValue(); } else { thisMinBase = verticalScrollBar()->minBaseValue(); thisMaxBase = verticalScrollBar()->maxBaseValue(); } double slope = ( thisMaxBase - thisMinBase ) / ( maxBase - minBase ); double thisMin = slope * ( min - minBase ) + thisMinBase; double thisMax = slope * ( max - minBase ) + thisMinBase; scrollBarMoved( o, thisMin, thisMax ); }
void PlotZoomer::rescale | ( | ) | [virtual] |
Reimplemented from QwtPlotZoomer.
{ //qDebug( "PlotZoomer::rescale" ); QwtScaleWidget *xScale = plot()->axisWidget( xAxis() ); QwtScaleWidget *yScale = plot()->axisWidget( yAxis() ); if ( zoomRectIndex() <= 0 ) { if ( m_inZoom ) { xScale->setMinBorderDist( 0, 0 ); yScale->setMinBorderDist( 0, 0 ); m_inZoom = false; } } else { if ( !m_inZoom ) { /* We set a minimum border distance. Otherwise the canvas size changes when scrolling, between situations where the major ticks are at the canvas borders (requiring extra space for the label) and situations where all labels can be painted below/top or left/right of the canvas. */ int start, end; xScale->getBorderDistHint( start, end ); xScale->setMinBorderDist( start, end ); yScale->getBorderDistHint( start, end ); yScale->setMinBorderDist( start, end ); m_inZoom = false; } } QwtPlotZoomer::rescale(); updateScrollBars(); }
PlotScrollBar * PlotZoomer::scrollBar | ( | Qt::Orientation | o | ) | [protected, virtual] |
Referenced by updateScrollBars().
{ //qDebug( "PlotZoomer::scrollBar" ); PlotScrollBar* &sb = ( o == Qt::Vertical ) ? m_vScrollData->m_scrollBar : m_hScrollData->m_scrollBar; if ( sb == NULL ) { sb = new PlotScrollBar( o, canvas() ); sb->hide(); connect( sb, SIGNAL( valueChanged( Qt::Orientation, double, double ) ), SLOT( scrollBarMoved( Qt::Orientation, double, double ) ) ); } return sb; }
void PlotZoomer::scrollBarMovedSignal | ( | Qt::Orientation | o, | |
double | min, | |||
double | max, | |||
double | minBase, | |||
double | maxBase | |||
) | [signal] |
Referenced by zoom().
void PlotZoomer::setCornerWidget | ( | QWidget * | w | ) | [virtual] |
{ //qDebug( "PlotZoomer::setCornerWidget" ); if ( w != m_cornerWidget ) { if ( canvas() ) { delete m_cornerWidget; m_cornerWidget = w; if ( m_cornerWidget->parent() != canvas() ) { m_cornerWidget->setParent( canvas() ); } updateScrollBars(); } } }
void PlotZoomer::setHScrollBarMode | ( | Qt::ScrollBarPolicy | mode | ) |
{ //qDebug( "PlotZoomer::setHScrollBarMode" ); if ( hScrollBarMode() != mode ) { m_hScrollData->m_mode = mode; updateScrollBars(); } }
void PlotZoomer::setHScrollBarPosition | ( | ScrollBarPosition | pos | ) |
Referenced by Plot::Plot().
{ //qDebug( "PlotZoomer::setHScrollBarPosition" ); if ( m_hScrollData->m_position != pos ) { m_hScrollData->m_position = pos; updateScrollBars(); } }
void PlotZoomer::setVScrollBarMode | ( | Qt::ScrollBarPolicy | mode | ) |
{ //qDebug( "PlotZoomer::setVScrollBarMode" ); if ( vScrollBarMode() != mode ) { m_vScrollData->m_mode = mode; updateScrollBars(); } }
void PlotZoomer::setVScrollBarPosition | ( | ScrollBarPosition | pos | ) |
Referenced by Plot::Plot().
{ //qDebug( "PlotZoomer::setVScrollBarPosition" ); if ( m_vScrollData->m_position != pos ) { m_vScrollData->m_position = pos; updateScrollBars(); } }
void PlotZoomer::updateScrollBars | ( | ) | [virtual] |
Referenced by rescale(), Plot::resizeEvent(), setCornerWidget(), setHScrollBarMode(), setHScrollBarPosition(), setVScrollBarMode(), and setVScrollBarPosition().
{ //qDebug( "PlotZoomer::updateScrollBars" ); if ( !canvas() ) return; const int xAxis = QwtPlotZoomer::xAxis(); const int yAxis = QwtPlotZoomer::yAxis(); 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 ) { PlotScrollBar *sb = scrollBar( Qt::Horizontal ); sb->setPalette( plot()->palette() ); const QwtScaleEngine* se = plot()->axisScaleEngine( xAxis ); sb->setInverted( se->testAttribute( QwtScaleEngine::Inverted ) ); 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 ) { PlotScrollBar *sb = scrollBar( Qt::Vertical ); sb->setPalette( plot()->palette() ); const QwtScaleEngine *se = plot()->axisScaleEngine( xAxis ); sb->setInverted( !( se->testAttribute( QwtScaleEngine::Inverted ) ) ); 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 ( m_cornerWidget == NULL ) { m_cornerWidget = new QWidget( canvas() ); m_cornerWidget->setAutoFillBackground( true ); m_cornerWidget->setPalette( plot()->palette() ); } m_cornerWidget->show(); } else { if ( m_cornerWidget ) m_cornerWidget->hide(); } layoutScrollBars( ( ( QwtPlotCanvas* )canvas() )->contentsRect() ); plot()->updateLayout(); }
PlotScrollBar * PlotZoomer::verticalScrollBar | ( | ) | const |
Referenced by layoutScrollBars(), otherScrollBarMoved(), updateScrollBars(), and zoom().
{ //qDebug( "PlotZoomer::verticalScrollBar" ); return m_vScrollData->m_scrollBar; }
Qt::ScrollBarPolicy PlotZoomer::vScrollBarMode | ( | ) | const |
Referenced by setVScrollBarMode().
{ //qDebug( "PlotZoomer::vScrollBarMode" ); return m_vScrollData->m_mode; }
PlotZoomer::ScrollBarPosition PlotZoomer::vScrollBarPosition | ( | ) | const |
Referenced by layoutScrollBars(), and updateScrollBars().
{ //qDebug( "PlotZoomer::vScrollBarPosition" ); return m_vScrollData->m_position; }
void PlotZoomer::zoom | ( | int | offset | ) | [virtual, slot] |
Reimplemented from QwtPlotZoomer.
{ //qDebug( "PlotZoomer::zoom( int )" ); if ( zoomRectIndex() == 0 ) { storeAxesStates(); } QwtPlotZoomer::zoom( offset ); if ( zoomRectIndex() == 0 ) { restoreAxesStates(); } // This signal is emitted to sync another zoomer attached to the opposite axis if ( verticalScrollBar() != NULL ) { emit scrollBarMovedSignal( Qt::Vertical, verticalScrollBar()->minSliderValue(), verticalScrollBar()->maxSliderValue(), verticalScrollBar()->minBaseValue(), verticalScrollBar()->maxBaseValue() ); } QTimer::singleShot(0, plot(), SLOT(replot())); }
void PlotZoomer::zoom | ( | const QwtDoubleRect & | rect | ) | [virtual, slot] |
Reimplemented from QwtPlotZoomer.
Referenced by eventFilter(), and zoom().
{ //qDebug( "PlotZoomer::zoom( QwtDoubleRect )" ); if ( zoomRectIndex() == 0 ) { storeAxesStates(); } QwtPlotZoomer::zoom( rect ); if ( zoomRectIndex() == 0 ) { restoreAxesStates(); } // This signal is emitted to sync another zoomer attached to the opposite axis if ( verticalScrollBar() != NULL ) { emit scrollBarMovedSignal( Qt::Vertical, verticalScrollBar()->minSliderValue(), verticalScrollBar()->maxSliderValue(), verticalScrollBar()->minBaseValue(), verticalScrollBar()->maxBaseValue() ); } QTimer::singleShot(0, plot(), SLOT(replot())); }