void ScrollZoomer::rescale() { QwtScaleWidget *xScale = plot()->axisWidget( xAxis() ); QwtScaleWidget *yScale = plot()->axisWidget( yAxis() ); if ( zoomRectIndex() <= 0 ) { if ( d_inZoom ) { xScale->setMinBorderDist( 0, 0 ); yScale->setMinBorderDist( 0, 0 ); QwtPlotLayout *layout = plot()->plotLayout(); layout->setAlignCanvasToScales( d_alignCanvasToScales ); d_inZoom = false; } } else { if ( !d_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 ); QwtPlotLayout *layout = plot()->plotLayout(); d_alignCanvasToScales = layout->alignCanvasToScales(); layout->setAlignCanvasToScales( false ); d_inZoom = true; } } QwtPlotZoomer::rescale(); updateScrollBars(); }
Plot::Plot(int width, int height, QWidget *parent, const char *) : QwtPlot(parent) { setAutoReplot (false); marker_key = 0; curve_key = 0; minTickLength = 5; majTickLength = 9; setGeometry(QRect(0, 0, width, height)); setAxisTitle(QwtPlot::yLeft, tr("Y Axis Title")); setAxisTitle(QwtPlot::xBottom, tr("X Axis Title")); //due to the plot layout updates, we must always have a non empty title setAxisTitle(QwtPlot::yRight, tr(" ")); setAxisTitle(QwtPlot::xTop, tr(" ")); // grid d_grid = new Grid(); d_grid->attach(this); //custom scale for (int i= 0; i<QwtPlot::axisCnt; i++) { QwtScaleWidget *scale = (QwtScaleWidget *) axisWidget(i); if (scale) { scale->setMargin(0); //the axis title color must be initialized... QwtText title = scale->title(); title.setColor(Qt::black); scale->setTitle(title); //...same for axis color QPalette pal = scale->palette(); pal.setColor(QPalette::Foreground, QColor(Qt::black)); scale->setPalette(pal); ScaleDraw *sd = new ScaleDraw(this); sd->setTickLength(QwtScaleDiv::MinorTick, minTickLength); sd->setTickLength(QwtScaleDiv::MediumTick, minTickLength); sd->setTickLength(QwtScaleDiv::MajorTick, majTickLength); setAxisScaleDraw (i, sd); setAxisScaleEngine (i, new ScaleEngine()); } } QwtPlotLayout *pLayout = plotLayout(); pLayout->setCanvasMargin(0); pLayout->setAlignCanvasToScales (true); QwtPlotCanvas* plCanvas = canvas(); plCanvas->setFocusPolicy(Qt::StrongFocus); plCanvas->setFocusIndicator(QwtPlotCanvas::ItemFocusIndicator); //plCanvas->setFocus(); plCanvas->setFrameShadow(QwtPlot::Plain); plCanvas->setCursor(Qt::arrowCursor); plCanvas->setLineWidth(0); plCanvas->setPaintAttribute(QwtPlotCanvas::PaintCached, false); plCanvas->setPaintAttribute(QwtPlotCanvas::PaintPacked, false); QColor background = QColor(Qt::white); background.setAlpha(255); QPalette palette; palette.setColor(QPalette::Window, background); setPalette(palette); setCanvasBackground (background); setFocusPolicy(Qt::StrongFocus); //setFocusProxy(plCanvas); setFrameShape(QFrame::Box); setLineWidth(0); }