Public Slots | Signals | Public Member Functions | Protected Member Functions

PlotScrollBar Class Reference

#include <PlotScrollBar.h>

Inheritance diagram for PlotScrollBar:
Inheritance graph
[legend]
Collaboration diagram for PlotScrollBar:
Collaboration graph
[legend]

List of all members.

Public Slots

virtual void setBase (double min, double max)
virtual void moveSlider (double min, double max)

Signals

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

Public Member Functions

 PlotScrollBar (QWidget *parent=NULL)
 PlotScrollBar (Qt::Orientation, QWidget *parent=NULL)
 PlotScrollBar (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

Protected Member Functions

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

Constructor & Destructor Documentation

PlotScrollBar::PlotScrollBar ( QWidget parent = NULL  ) 

  : QScrollBar( parent )
{
  //qDebug( "PlotScrollBar::PlotScrollBar" );

  init();
}

PlotScrollBar::PlotScrollBar ( Qt::Orientation  o,
QWidget parent = NULL 
)

  : QScrollBar( o, parent )
{
  //qDebug( "PlotScrollBar::PlotScrollBar" );

  init();
}

PlotScrollBar::PlotScrollBar ( double  minBase,
double  maxBase,
Qt::Orientation  o,
QWidget parent = NULL 
)

                                                                 :
  QScrollBar( o, parent )
{
  //qDebug( "PlotScrollBar::PlotScrollBar" );

  init();
  setBase( minBase, maxBase );
  moveSlider( minBase, maxBase );
}


Member Function Documentation

int PlotScrollBar::extent (  )  const

Referenced by PlotZoomer::layoutScrollBars(), and PlotZoomer::updateScrollBars().

{
  //qDebug( "PlotScrollBar::extent" );

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

bool PlotScrollBar::isInverted (  )  const

Referenced by moveSlider(), and sliderRange().

{
  //qDebug( "PlotScrollBar::isInverted" );

  return m_inverted;
}

double PlotScrollBar::mapFromTick ( int  tick  )  const [protected]

Referenced by sliderRange().

{
  //qDebug( "PlotScrollBar::mapFromTick" );

  return m_minBase + ( m_maxBase - m_minBase ) * tick / m_baseTicks;
}

int PlotScrollBar::mapToTick ( double  v  )  const [protected]

Referenced by moveSlider().

{
  //qDebug( "PlotScrollBar::mapToTick" );

  return (int)( ( v - m_minBase ) / ( m_maxBase - m_minBase ) * m_baseTicks );
}

double PlotScrollBar::maxBaseValue (  )  const

Referenced by PlotZoomer::otherScrollBarMoved().

{
  //qDebug( "PlotScrollBar::maxBaseValue" );

  return m_maxBase;
}

double PlotScrollBar::maxSliderValue (  )  const

Referenced by setBase(), and setInverted().

{
  //qDebug( "PlotScrollBar::maxSliderValue" );

  double max, dummy;
  sliderRange( value(), dummy, max );

  return max;
}

double PlotScrollBar::minBaseValue (  )  const

Referenced by PlotZoomer::otherScrollBarMoved().

{
  //qDebug( "PlotScrollBar::minBaseValue" );

  return m_minBase;
}

double PlotScrollBar::minSliderValue (  )  const

Referenced by setBase(), and setInverted().

{
  //qDebug( "PlotScrollBar::minSliderValue" );

  double min, dummy;
  sliderRange( value(), min, dummy );

  return min;
}

void PlotScrollBar::moveSlider ( double  min,
double  max 
) [virtual, slot]

Referenced by PlotScrollBar(), setBase(), setInverted(), and PlotZoomer::updateScrollBars().

{
  //qDebug( "PlotScrollBar::moveSlider" );

  const int sliderTicks = qRound( ( max - min ) / ( m_maxBase - m_minBase )
      * m_baseTicks );

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

  blockSignals( true );

  setRange( sliderTicks / 2, m_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 = m_baseTicks - tick;

  setSliderPosition( tick );
  blockSignals( false );
}

void PlotScrollBar::setBase ( double  min,
double  max 
) [virtual, slot]

Referenced by PlotScrollBar(), and PlotZoomer::updateScrollBars().

{
  //qDebug( "PlotScrollBar::setBase" );

  if ( min != m_minBase || max != m_maxBase )
  {
    m_minBase = min;
    m_maxBase = max;

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

void PlotScrollBar::setInverted ( bool  inverted  ) 

Referenced by PlotZoomer::updateScrollBars().

{
  //qDebug( "PlotScrollBar::setInverted" );

  if ( m_inverted != inverted )
  {
    m_inverted = inverted;
    moveSlider( minSliderValue(), maxSliderValue() );
  }
}

void PlotScrollBar::sliderMoved ( Qt::Orientation  ,
double  ,
double   
) [signal]
void PlotScrollBar::sliderRange ( int  value,
double &  min,
double &  max 
) const [protected]

Referenced by maxSliderValue(), and minSliderValue().

{
  //qDebug( "PlotScrollBar::sliderRange" );

  if ( isInverted() )
    value = m_baseTicks - value;

  const int visibleTicks = pageStep();

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

void PlotScrollBar::valueChanged ( Qt::Orientation  ,
double  ,
double   
) [signal]

The documentation for this class was generated from the following files: