Changeset - 54a8f1ad64ce
[Not reviewed]
Merge default
0 4 4
Hasan Yavuz ÖZDERYA - 9 years ago 2017-01-30 04:15:51
hy@ozderya.net
Merge with scrollbar
8 files changed with 833 insertions and 13 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -79,24 +79,26 @@ qt5_wrap_ui(UI_FILES
 
if (WIN32)
 
  qt5_add_resources(RES_FILES misc/icons.qrc misc/winicons.qrc)
 
else (WIN32)
 
  qt5_add_resources(RES_FILES misc/icons.qrc)
 
endif (WIN32)
 

	
 
add_executable(${PROGRAM_NAME} WIN32
 
  src/main.cpp
 
  src/mainwindow.cpp
 
  src/portcontrol.cpp
 
  src/plot.cpp
 
  src/zoomer.cpp
 
  src/scrollzoomer.cpp
 
  src/scrollbar.cpp
 
  src/hidabletabwidget.cpp
 
  src/framebuffer.cpp
 
  src/scalepicker.cpp
 
  src/scalezoomer.cpp
 
  src/portlist.cpp
 
  src/snapshot.cpp
 
  src/snapshotview.cpp
 
  src/snapshotmanager.cpp
 
  src/plotsnapshotoverlay.cpp
 
  src/commandpanel.cpp
 
  src/commandwidget.cpp
 
  src/commandedit.cpp
src/plot.cpp
Show inline comments
 
@@ -58,25 +58,25 @@ Plot::Plot(QWidget* parent) :
 

	
 
    connect(this, &QwtPlot::itemAttached,
 
            [this](QwtPlotItem *plotItem, bool on)
 
            {
 
                if (symbolSize) updateSymbols();
 
            });
 

	
 
    // init demo indicator
 
    QwtText demoText(" DEMO RUNNING ");  // looks better with spaces
 
    demoText.setColor(QColor("white"));
 
    demoText.setBackgroundBrush(Qt::darkRed);
 
    demoText.setBorderRadius(4);
 
    demoText.setRenderFlags(Qt::AlignLeft | Qt::AlignTop);
 
    demoText.setRenderFlags(Qt::AlignLeft | Qt::AlignBottom);
 
    demoIndicator.setText(demoText);
 
    demoIndicator.hide();
 
    demoIndicator.attach(this);
 
}
 

	
 
Plot::~Plot()
 
{
 
    if (snapshotOverlay != NULL) delete snapshotOverlay;
 
}
 

	
 
void Plot::setAxis(bool autoScaled, double yAxisMin, double yAxisMax)
 
{
src/scrollbar.cpp
Show inline comments
 
new file 100644
 
/*
 
  Copyright © 2014 Uwe Rathmann
 

	
 
  This file is copied from Qwt project; you can redistribute it and/or modify it
 
  under the terms of the Qwt License, Version 1.0. You can obtain the original
 
  source code and the details of the Qwt License from the Qwt website:
 
  http://qwt.sourceforge.net/
 
*/
 

	
 
#include <qstyle.h>
 
#include <qstyleoption.h>
 
#include "scrollbar.h"
 

	
 
ScrollBar::ScrollBar( QWidget * parent ):
 
    QScrollBar( parent )
 
{
 
    init();
 
}
 

	
 
ScrollBar::ScrollBar( Qt::Orientation o,
 
        QWidget *parent ):
 
    QScrollBar( o, parent )
 
{
 
    init();
 
}
 

	
 
ScrollBar::ScrollBar( double minBase, double maxBase,
 
        Qt::Orientation o, QWidget *parent ):
 
    QScrollBar( o, parent )
 
{
 
    init();
 
    setBase( minBase, maxBase );
 
    moveSlider( minBase, maxBase );
 
}
 

	
 
void ScrollBar::init()
 
{
 
    d_inverted = orientation() == Qt::Vertical;
 
    d_baseTicks = 1000000;
 
    d_minBase = 0.0;
 
    d_maxBase = 1.0;
 
    moveSlider( d_minBase, d_maxBase );
 

	
 
    connect( this, SIGNAL( sliderMoved( int ) ), SLOT( catchSliderMoved( int ) ) );
 
    connect( this, SIGNAL( valueChanged( int ) ), SLOT( catchValueChanged( int ) ) );
 
}
 

	
 
void ScrollBar::setInverted( bool inverted )
 
{
 
    if ( d_inverted != inverted )
 
    {
 
        d_inverted = inverted;
 
        moveSlider( minSliderValue(), maxSliderValue() );
 
    }
 
}
 

	
 
bool ScrollBar::isInverted() const
 
{
 
    return d_inverted;
 
}
 

	
 
void ScrollBar::setBase( double min, double max )
 
{
 
    if ( min != d_minBase || max != d_maxBase )
 
    {
 
        d_minBase = min;
 
        d_maxBase = max;
 

	
 
        moveSlider( minSliderValue(), maxSliderValue() );
 
    }
 
}
 

	
 
void ScrollBar::moveSlider( double min, double max )
 
{
 
    const int sliderTicks = qRound( ( max - min ) /
 
        ( d_maxBase - d_minBase ) * d_baseTicks );
 

	
 
    // setRange initiates a valueChanged of the scrollbars
 
    // in some situations. So we block
 
    // and unblock the signals.
 

	
 
    blockSignals( true );
 

	
 
    setRange( sliderTicks / 2, d_baseTicks - sliderTicks / 2 );
 
    int steps = sliderTicks / 200;
 
    if ( steps <= 0 )
 
        steps = 1;
 

	
 
    setSingleStep( steps );
 
    setPageStep( sliderTicks );
 

	
 
    int tick = mapToTick( min + ( max - min ) / 2 );
 
    if ( isInverted() )
 
        tick = d_baseTicks - tick;
 

	
 
    setSliderPosition( tick );
 
    blockSignals( false );
 
}
 

	
 
double ScrollBar::minBaseValue() const
 
{
 
    return d_minBase;
 
}
 

	
 
double ScrollBar::maxBaseValue() const
 
{
 
    return d_maxBase;
 
}
 

	
 
void ScrollBar::sliderRange( int value, double &min, double &max ) const
 
{
 
    if ( isInverted() )
 
        value = d_baseTicks - value;
 

	
 
    const int visibleTicks = pageStep();
 

	
 
    min = mapFromTick( value - visibleTicks / 2 );
 
    max = mapFromTick( value + visibleTicks / 2 );
 
}
 

	
 
double ScrollBar::minSliderValue() const
 
{
 
    double min, dummy;
 
    sliderRange( value(), min, dummy );
 

	
 
    return min;
 
}
 

	
 
double ScrollBar::maxSliderValue() const
 
{
 
    double max, dummy;
 
    sliderRange( value(), dummy, max );
 

	
 
    return max;
 
}
 

	
 
int ScrollBar::mapToTick( double v ) const
 
{
 
    const double pos = ( v - d_minBase ) / ( d_maxBase - d_minBase ) * d_baseTicks;
 
    return static_cast<int>( pos );
 
}
 

	
 
double ScrollBar::mapFromTick( int tick ) const
 
{
 
    return d_minBase + ( d_maxBase - d_minBase ) * tick / d_baseTicks;
 
}
 

	
 
void ScrollBar::catchValueChanged( int value )
 
{
 
    double min, max;
 
    sliderRange( value, min, max );
 
    Q_EMIT valueChanged( orientation(), min, max );
 
}
 

	
 
void ScrollBar::catchSliderMoved( int value )
 
{
 
    double min, max;
 
    sliderRange( value, min, max );
 
    Q_EMIT sliderMoved( orientation(), min, max );
 
}
 

	
 
int ScrollBar::extent() const
 
{
 
    QStyleOptionSlider opt;
 
    opt.init( this );
 
    opt.subControls = QStyle::SC_None;
 
    opt.activeSubControls = QStyle::SC_None;
 
    opt.orientation = orientation();
 
    opt.minimum = minimum();
 
    opt.maximum = maximum();
 
    opt.sliderPosition = sliderPosition();
 
    opt.sliderValue = value();
 
    opt.singleStep = singleStep();
 
    opt.pageStep = pageStep();
 
    opt.upsideDown = invertedAppearance();
 
    if ( orientation() == Qt::Horizontal )
 
        opt.state |= QStyle::State_Horizontal;
 
    return style()->pixelMetric( QStyle::PM_ScrollBarExtent, &opt, this );
 
}
src/scrollbar.h
Show inline comments
 
new file 100644
 
/*
 
  Copyright © 2014 Uwe Rathmann
 

	
 
  This file is copied from Qwt project; you can redistribute it and/or modify it
 
  under the terms of the Qwt License, Version 1.0. You can obtain the original
 
  source code and the details of the Qwt License from the Qwt website:
 
  http://qwt.sourceforge.net/
 
*/
 

	
 
#ifndef _SCROLLBAR_H
 
#define _SCROLLBAR_H 1
 

	
 
#include <qscrollbar.h>
 

	
 
class ScrollBar: public QScrollBar
 
{
 
    Q_OBJECT
 

	
 
public:
 
    ScrollBar( QWidget *parent = NULL );
 
    ScrollBar( Qt::Orientation, QWidget *parent = NULL );
 
    ScrollBar( double minBase, double maxBase,
 
        Qt::Orientation o, QWidget *parent = NULL );
 

	
 
    void setInverted( bool );
 
    bool isInverted() const;
 

	
 
    double minBaseValue() const;
 
    double maxBaseValue() const;
 

	
 
    double minSliderValue() const;
 
    double maxSliderValue() const;
 

	
 
    int extent() const;
 

	
 
Q_SIGNALS:
 
    void sliderMoved( Qt::Orientation, double, double );
 
    void valueChanged( Qt::Orientation, double, double );
 

	
 
public Q_SLOTS:
 
    virtual void setBase( double min, double max );
 
    virtual void moveSlider( double min, double max );
 

	
 
protected:
 
    void sliderRange( int value, double &min, double &max ) const;
 
    int mapToTick( double ) const;
 
    double mapFromTick( int ) const;
 

	
 
private Q_SLOTS:
 
    void catchValueChanged( int value );
 
    void catchSliderMoved( int value );
 

	
 
private:
 
    void init();
 

	
 
    bool d_inverted;
 
    double d_minBase;
 
    double d_maxBase;
 
    int d_baseTicks;
 
};
 

	
 
#endif
src/scrollzoomer.cpp
Show inline comments
 
new file 100644
 
/*
 
  Copyright © 2014 Uwe Rathmann
 

	
 
  This file is copied from Qwt project; you can redistribute it and/or modify it
 
  under the terms of the Qwt License, Version 1.0. You can obtain the original
 
  source code and the details of the Qwt License from the Qwt website:
 
  http://qwt.sourceforge.net/
 
*/
 

	
 
#include <qevent.h>
 
#include <qwt_plot_canvas.h>
 
#include <qwt_plot_layout.h>
 
#include <qwt_scale_engine.h>
 
#include <qwt_scale_widget.h>
 
#include "scrollbar.h"
 
#include "scrollzoomer.h"
 

	
 
class ScrollData
 
{
 
public:
 
    ScrollData():
 
        scrollBar( NULL ),
 
        position( ScrollZoomer::OppositeToScale ),
 
        mode( Qt::ScrollBarAsNeeded )
 
    {
 
    }
 

	
 
    ~ScrollData()
 
    {
 
        delete scrollBar;
 
    }
 

	
 
    ScrollBar *scrollBar;
 
    ScrollZoomer::ScrollBarPosition position;
 
    Qt::ScrollBarPolicy mode;
 
};
 

	
 
ScrollZoomer::ScrollZoomer( QWidget *canvas ):
 
    QwtPlotZoomer( canvas ),
 
    d_cornerWidget( NULL ),
 
    d_hScrollData( NULL ),
 
    d_vScrollData( NULL ),
 
    d_inZoom( false )
 
{
 
    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
 
        d_alignCanvasToScales[ axis ] = false;
 

	
 
    if ( !canvas )
 
        return;
 

	
 
    d_hScrollData = new ScrollData;
 
    d_vScrollData = new ScrollData;
 
}
 

	
 
ScrollZoomer::~ScrollZoomer()
 
{
 
    delete d_cornerWidget;
 
    delete d_vScrollData;
 
    delete d_hScrollData;
 
}
 

	
 
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();
 

	
 
            for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
 
                layout->setAlignCanvasToScale( axis, d_alignCanvasToScales[ axis ] );
 

	
 
            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();
 
            for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
 
            {
 
                d_alignCanvasToScales[axis] = 
 
                    layout->alignCanvasToScale( axis );
 
            }
 

	
 
            layout->setAlignCanvasToScales( false );
 

	
 
            d_inZoom = true;
 
        }
 
    }
 

	
 
    QwtPlotZoomer::rescale();
 
    updateScrollBars();
 
}
 

	
 
ScrollBar *ScrollZoomer::scrollBar( Qt::Orientation orientation )
 
{
 
    ScrollBar *&sb = ( orientation == Qt::Vertical )
 
        ? d_vScrollData->scrollBar : d_hScrollData->scrollBar;
 

	
 
    if ( sb == NULL )
 
    {
 
        sb = new ScrollBar( orientation, canvas() );
 
        sb->hide();
 
        connect( sb,
 
            SIGNAL( valueChanged( Qt::Orientation, double, double ) ),
 
            SLOT( scrollBarMoved( Qt::Orientation, double, double ) ) );
 
    }
 
    return sb;
 
}
 

	
 
ScrollBar *ScrollZoomer::horizontalScrollBar() const
 
{
 
    return d_hScrollData->scrollBar;
 
}
 

	
 
ScrollBar *ScrollZoomer::verticalScrollBar() const
 
{
 
    return d_vScrollData->scrollBar;
 
}
 

	
 
void ScrollZoomer::setHScrollBarMode( Qt::ScrollBarPolicy mode )
 
{
 
    if ( hScrollBarMode() != mode )
 
    {
 
        d_hScrollData->mode = mode;
 
        updateScrollBars();
 
    }
 
}
 

	
 
void ScrollZoomer::setVScrollBarMode( Qt::ScrollBarPolicy mode )
 
{
 
    if ( vScrollBarMode() != mode )
 
    {
 
        d_vScrollData->mode = mode;
 
        updateScrollBars();
 
    }
 
}
 

	
 
Qt::ScrollBarPolicy ScrollZoomer::hScrollBarMode() const
 
{
 
    return d_hScrollData->mode;
 
}
 

	
 
Qt::ScrollBarPolicy ScrollZoomer::vScrollBarMode() const
 
{
 
    return d_vScrollData->mode;
 
}
 

	
 
void ScrollZoomer::setHScrollBarPosition( ScrollBarPosition pos )
 
{
 
    if ( d_hScrollData->position != pos )
 
    {
 
        d_hScrollData->position = pos;
 
        updateScrollBars();
 
    }
 
}
 

	
 
void ScrollZoomer::setVScrollBarPosition( ScrollBarPosition pos )
 
{
 
    if ( d_vScrollData->position != pos )
 
    {
 
        d_vScrollData->position = pos;
 
        updateScrollBars();
 
    }
 
}
 

	
 
ScrollZoomer::ScrollBarPosition ScrollZoomer::hScrollBarPosition() const
 
{
 
    return d_hScrollData->position;
 
}
 

	
 
ScrollZoomer::ScrollBarPosition ScrollZoomer::vScrollBarPosition() const
 
{
 
    return d_vScrollData->position;
 
}
 

	
 
void ScrollZoomer::setCornerWidget( QWidget *w )
 
{
 
    if ( w != d_cornerWidget )
 
    {
 
        if ( canvas() )
 
        {
 
            delete d_cornerWidget;
 
            d_cornerWidget = w;
 
            if ( d_cornerWidget->parent() != canvas() )
 
                d_cornerWidget->setParent( canvas() );
 

	
 
            updateScrollBars();
 
        }
 
    }
 
}
 

	
 
QWidget *ScrollZoomer::cornerWidget() const
 
{
 
    return d_cornerWidget;
 
}
 

	
 
bool ScrollZoomer::eventFilter( QObject *object, QEvent *event )
 
{
 
    if ( object == canvas() )
 
    {
 
        switch( event->type() )
 
        {
 
            case QEvent::Resize:
 
            {
 
                int left, top, right, bottom;
 
                canvas()->getContentsMargins( &left, &top, &right, &bottom );
 

	
 
                QRect rect;
 
                rect.setSize( static_cast<QResizeEvent *>( event )->size() );
 
                rect.adjust( left, top, -right, -bottom );
 

	
 
                layoutScrollBars( rect );
 
                break;
 
            }
 
            case QEvent::ChildRemoved:
 
            {
 
                const QObject *child =
 
                    static_cast<QChildEvent *>( event )->child();
 

	
 
                if ( child == d_cornerWidget )
 
                    d_cornerWidget = NULL;
 
                else if ( child == d_hScrollData->scrollBar )
 
                    d_hScrollData->scrollBar = NULL;
 
                else if ( child == d_vScrollData->scrollBar )
 
                    d_vScrollData->scrollBar = NULL;
 
                break;
 
            }
 
            default:
 
                break;
 
        }
 
    }
 
    return QwtPlotZoomer::eventFilter( object, event );
 
}
 

	
 
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;
 
}
 

	
 
void ScrollZoomer::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 )
 
    {
 
        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();
 
}
 

	
 
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::scrollBarMoved(
 
    Qt::Orientation o, double min, double max )
 
{
 
    Q_UNUSED( max );
 

	
 
    if ( o == Qt::Horizontal )
 
        moveTo( QPointF( min, zoomRect().top() ) );
 
    else
 
        moveTo( QPointF( zoomRect().left(), min ) );
 

	
 
    Q_EMIT zoomed( zoomRect() );
 
}
 

	
 
int ScrollZoomer::oppositeAxis( int axis ) const
 
{
 
    switch( axis )
 
    {
 
        case QwtPlot::xBottom:
 
            return QwtPlot::xTop;
 
        case QwtPlot::xTop:
 
            return QwtPlot::xBottom;
 
        case QwtPlot::yLeft:
 
            return QwtPlot::yRight;
 
        case QwtPlot::yRight:
 
            return QwtPlot::yLeft;
 
        default:
 
            break;
 
    }
 

	
 
    return axis;
 
}
src/scrollzoomer.h
Show inline comments
 
new file 100644
 
/*
 
  Copyright © 2014 Uwe Rathmann
 

	
 
  This file is copied from Qwt project; you can redistribute it and/or modify it
 
  under the terms of the Qwt License, Version 1.0. You can obtain the original
 
  source code and the details of the Qwt License from the Qwt website:
 
  http://qwt.sourceforge.net/
 
*/
 

	
 
#ifndef _SCROLLZOOMER_H
 
#define _SCROLLZOOMER_H
 

	
 
#include <qglobal.h>
 
#include <qwt_plot_zoomer.h>
 
#include <qwt_plot.h>
 

	
 
class ScrollData;
 
class ScrollBar;
 

	
 
class ScrollZoomer: public QwtPlotZoomer
 
{
 
    Q_OBJECT
 
public:
 
    enum ScrollBarPosition
 
    {
 
        AttachedToScale,
 
        OppositeToScale
 
    };
 

	
 
    ScrollZoomer( QWidget * );
 
    virtual ~ScrollZoomer();
 

	
 
    ScrollBar *horizontalScrollBar() const;
 
    ScrollBar *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();
 

	
 
protected:
 
    virtual ScrollBar *scrollBar( Qt::Orientation );
 
    virtual void updateScrollBars();
 
    virtual void layoutScrollBars( const QRect & );
 

	
 
private Q_SLOTS:
 
    void scrollBarMoved( Qt::Orientation o, double min, double max );
 

	
 
private:
 
    bool needScrollBar( Qt::Orientation ) const;
 
    int oppositeAxis( int ) const;
 

	
 
    QWidget *d_cornerWidget;
 

	
 
    ScrollData *d_hScrollData;
 
    ScrollData *d_vScrollData;
 

	
 
    bool d_inZoom;
 
    bool d_alignCanvasToScales[ QwtPlot::axisCnt ];
 
};
 

	
 
#endif
src/zoomer.cpp
Show inline comments
 
/*
 
  Copyright © 2015 Hasan Yavuz Özderya
 
  Copyright © 2016 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  serialplot is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU General Public License for more details.
 

	
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "zoomer.h"
 
#include <qwt_plot.h>
 
#include <QtDebug>
 

	
 
Zoomer::Zoomer(QWidget* widget, bool doReplot) :
 
    QwtPlotZoomer(widget, doReplot)
 
    ScrollZoomer(widget)
 
{
 
    // do nothing
 
    // set corner widget between the scrollbars with default background color
 
    auto cornerWidget = new QWidget();
 
    auto bgColor = cornerWidget->palette().color(QPalette::Window).name();
 
    auto styleSheet = QString("background-color:%1;").arg(bgColor);
 
    cornerWidget->setStyleSheet(styleSheet);
 
    ScrollZoomer::setCornerWidget(cornerWidget);
 
}
 

	
 
void Zoomer::zoom(int up)
 
{
 
    if (up == +1)
 
    {
 
        this->setZoomBase(this->plot());
 
    }
 

	
 
    QwtPlotZoomer::zoom(up);
 
    ScrollZoomer::zoom(up);
 

	
 
    if(zoomRectIndex() == 0)
 
    {
 
        emit unzoomed();
 
    }
 
}
 

	
 
void Zoomer::zoom( const QRectF & rect)
 
{
 
    // set the zoom base when user zooms in to first level
 
    if (zoomRectIndex() == 0)
 
    {
 
        this->setZoomBase(false);
 
    }
 

	
 
    ScrollZoomer::zoom(rect);
 
}
src/zoomer.h
Show inline comments
 
/*
 
  Copyright © 2015 Hasan Yavuz Özderya
 
  Copyright © 2016 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  serialplot is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU General Public License for more details.
 

	
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#ifndef ZOOMER_H
 
#define ZOOMER_H
 

	
 
#include <qwt_plot_zoomer.h>
 
#include <scrollzoomer.h>
 

	
 
class Zoomer : public QwtPlotZoomer
 
class Zoomer : public ScrollZoomer
 
{
 
    Q_OBJECT
 

	
 
public:
 
    Zoomer(QWidget *, bool doReplot=true);
 
    void zoom(int up);
 
    void zoom( const QRectF & );
 

	
 
signals:
 
    void unzoomed();
 
};
 

	
 
#endif // ZOOMER_H
0 comments (0 inline, 0 general)