void ScrollZoomer::layoutScrollBars(const QRect &rect) { int hPos = xAxis(); if (hScrollBarPosition() == OppositeToScale) hPos = oppositeAxis(hPos); int vPos = yAxis(); if (vScrollBarPosition() == OppositeToScale) vPos = oppositeAxis(vPos); ScrollBar *hScrollBar = horizontalScrollBar(); ScrollBar *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 (d_cornerWidget) { QRect cornerRect(vScrollBar->pos().x(), hScrollBar->pos().y(), vdim, hdim); d_cornerWidget->setGeometry(cornerRect); } } }
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(); }