Beispiel #1
0
void QRangeControl::addPage()
{
    if ( value() + pageStep() > value() )
	setValue( value() + pageStep() );
    else
	setValue( maxValue() );
}
Beispiel #2
0
void RichHScrollBar::changePageStep(int p)
{
    p = qMax(p, MinVisible);
    p = qMin(p, maximum() - value() + pageStep());
    if(p != pageStep())
    {
        setMaximum(maximum() + pageStep() - p);
        setPageStep(p);
    }
}
Beispiel #3
0
void RichHScrollBar::setTotalMaximum(int m)
{
    int w = m - minimum();

    if(pageStep() > w)
    {
        changePageStep(w);
        m = minimum() + pageStep();
    }
    setMaximum(m - pageStep());
}
Beispiel #4
0
// Function copied from qslider.cpp and modified to make it compile
void Slider::initStyleOption_Qt430( QStyleOptionSlider *option ) const
{
	if (!option)
		return;

	option->initFrom( this );
	option->subControls       = QStyle::SC_None;
	option->activeSubControls = QStyle::SC_None;
	option->orientation       = orientation();
	option->maximum           = maximum();
	option->minimum           = minimum();
	option->tickPosition      = (QSlider::TickPosition) tickPosition();
	option->tickInterval      = tickInterval();
	option->upsideDown        = (orientation() == Qt::Horizontal) ?
								   (invertedAppearance() != (option->direction == Qt::RightToLeft))
								 : (!invertedAppearance());
	option->direction         = Qt::LeftToRight; // we use the upsideDown option instead
	option->sliderPosition    = sliderPosition();
	option->sliderValue       = value();
	option->singleStep        = singleStep();
	option->pageStep          = pageStep();

	if (orientation() == Qt::Horizontal)
		option->state |= QStyle::State_Horizontal;
}
Beispiel #5
0
void QDial::calcLines()
{
    if ( !d->lines.size() ) {
	double r = QMIN( width(), height() ) / 2.0;
	int bigLineSize = calcBigLineSize();
	double xc = width() / 2.0;
	double yc = height() / 2.0;
	int ns = notchSize();
	int notches = ( maxValue() + ns - 1 - minValue() ) / ns;
	d->lines.resize( 2 + 2 * notches );
	int smallLineSize = bigLineSize / 2;
	int i;
	for( i = 0; i <= notches; i++ ) {
	    double angle = d->wrapping
		? m_pi * 3 / 2 - i * 2 * m_pi / notches
		: (m_pi * 8 - i * 10 * m_pi / notches) / 6;

	    double s = sin( angle ); // sin/cos aren't defined as const...
	    double c = cos( angle );
	    if ( i == 0 || ( ((ns * i ) % pageStep() ) == 0 ) ) {
		d->lines[2*i] = QPoint( (int)( xc + ( r - bigLineSize ) * c ),
					(int)( yc - ( r - bigLineSize ) * s ) );
		d->lines[2*i+1] = QPoint( (int)( xc + r * c ),
					  (int)( yc - r * s ) );
	    } else {
		d->lines[2*i] = QPoint( (int)( xc + ( r - 1 - smallLineSize ) * c ),
					(int)( yc - ( r - 1 - smallLineSize ) * s ) );
		d->lines[2*i+1] = QPoint( (int)( xc + ( r - 1 ) * c ),
					  (int)( yc -( r - 1 ) * s ) );
	    }
	}
    }
}
ScrollResultOneDimensional ScrollableArea::userScroll(ScrollDirectionPhysical direction, ScrollGranularity granularity, float delta)
{
    ScrollbarOrientation orientation;
    if (direction == ScrollUp || direction == ScrollDown)
        orientation = VerticalScrollbar;
    else
        orientation = HorizontalScrollbar;

    if (!userInputScrollable(orientation))
        return ScrollResultOneDimensional(false, delta);

    cancelProgrammaticScrollAnimation();

    float step = 0;
    switch (granularity) {
    case ScrollByLine:
        step = lineStep(orientation);
        break;
    case ScrollByPage:
        step = pageStep(orientation);
        break;
    case ScrollByDocument:
        step = documentStep(orientation);
        break;
    case ScrollByPixel:
    case ScrollByPrecisePixel:
        step = pixelStep(orientation);
        break;
    }

    if (direction == ScrollUp || direction == ScrollLeft)
        delta = -delta;

    return scrollAnimator()->userScroll(orientation, granularity, step, delta);
}
Beispiel #7
0
/*!\reimp
*/
void QSlider::paintEvent( QPaintEvent * )
{

    QPainter p( this );
    const QRect & sliderR = sliderRect();
    const QColorGroup & g = colorGroup();
    int mid = thickness()/2;
    if ( ticks & Above )
	mid += style().sliderLength() / 8;
    if ( ticks & Below )
	mid -= style().sliderLength() / 8;
    if ( orient == Horizontal ) {
	style().drawSliderGroove(&p, 0, tickOffset, width(), thickness(),
				     g, mid, Horizontal );
// 	    p.fillRect( 0, 0, width(), tickOffset, g.background() );
// 	    p.fillRect( 0, tickOffset + thickness(),
// 			width(), height()/*###*/, g.background() );
	erase( 0, 0, width(), tickOffset );
	erase( 0, tickOffset + thickness(), width(), height() );
    }
    else {
	style().drawSliderGroove( &p, tickOffset, 0, thickness(), height(),
				      g, mid, Vertical );
// 	    p.fillRect( 0, 0,  tickOffset, height(), g.background() );
// 	    p.fillRect( tickOffset + thickness(), 0,
// 			width()/*###*/, height(), g.background() );
	erase( 0, 0,  tickOffset, height() );
	erase( tickOffset + thickness(), 0, width()/*###*/, height() );
    }

    int interval = tickInt;
    if ( interval <= 0 ) {
	interval = lineStep();
	if ( positionFromValue( interval ) - positionFromValue( 0 ) < 3 )
	    interval = pageStep();
    }
    if ( ticks & Above )
	drawTicks( &p, g, 0, tickOffset - 2, interval );

    if ( ticks & Below ) {
	int avail = (orient == Horizontal) ? height() : width();
	avail -= tickOffset + thickness();
	drawTicks( &p, g, tickOffset + thickness() + 1, avail - 2, interval );
    }
    if ( hasFocus() ) {
	QRect r;
	if ( orient == Horizontal )
	    r.setRect( 0, tickOffset-1, width(), thickness()+2 );
	else
	    r.setRect( tickOffset-1, 0, thickness()+2, height() );
	r = r.intersect( rect() );
	if (style() == MotifStyle)
	    style().drawFocusRect(&p, QRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2), g);
	else
	    style().drawFocusRect(&p, r, g);
    }
    paintSlider( &p, g, sliderR );

}
Beispiel #8
0
void Knob::wheelEvent ( QWheelEvent *pWheelEvent )
{
    if (m_dialMode == QDialMode) {
        QDial::wheelEvent(pWheelEvent);
    } else {
        int iValue = sliderPosition();
        if (pWheelEvent->delta() > 0)
            iValue -= pageStep();
        else
            iValue += pageStep();
        if (iValue > maximum())
            iValue = maximum();
        else
            if (iValue < minimum())
                iValue = minimum();
        updatePosition(iValue);
    }
}
Beispiel #9
0
void Knob::wheelEvent ( QWheelEvent *pWheelEvent )
{
	if (m_dialMode == QDialMode) {
		QDial::wheelEvent(pWheelEvent);
	} else {
		int iValue = value();
		if (pWheelEvent->delta() > 0)
			iValue -= pageStep();
		else
			iValue += pageStep();
		if (iValue > maximum())
			iValue = maximum();
		else
		if (iValue < minimum())
			iValue = minimum();
		setValue(iValue);
	}
}
Beispiel #10
0
void RichHScrollBar::sliderChange(SliderChange change)
{
    updateLeftRight();
    if (change == QAbstractSlider::SliderStepsChange)
    {
        emit pageStepChanged(pageStep());
    }
    update();
}
Beispiel #11
0
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);
}
Beispiel #12
0
void TickSlider::addDefaultTickLabels()
{
    int interval = tickInterval();
    if (interval == 0) {
        interval = pageStep();
    }
    for (int i = minimum(); i <= maximum(); i += interval) {
        m_tick_labels[i] = QString::number(i);
    }
}
Beispiel #13
0
int QDial::notchSize() const
{
    // radius of the arc
    int r = QMIN( width(), height() )/2;
    // length of the whole arc
    int l = (int)(r*(d->wrapping ? 6 : 5)*m_pi/6);
    // length of the arc from minValue() to minValue()+pageStep()
    if ( maxValue() > minValue()+pageStep() )
	l = (int)(0.5 + l * pageStep() / (maxValue()-minValue()));
    // length of a lineStep() arc
    l = l * lineStep() / pageStep();
    if ( l < 1 )
	l = 1;
    // how many times lineStep can be draw in d->target pixels
    l = (int)(0.5 + d->target / l);
    // we want notchSize() to be a non-zero multiple of lineStep()
    if ( !l )
	l = 1;
    return lineStep() * l;
}
Beispiel #14
0
void OverlayScrollBar::mouseReleaseEvent(QMouseEvent *event)
{
    QRect pm_r(0, 0, packet_map_width_, height());

    if (pm_r.contains(event->pos())) {
        qreal map_ratio = qreal(end_pos_ - start_pos_) / geometry().height();

        // Try to put the clicked packet near but not at the top.
        setValue((event->pos().y() * map_ratio) + start_pos_ - (pageStep() / 4));
    }
}
Beispiel #15
0
double RullerSlider::rullerScale() const
{
	int length = maximum() + pageStep() - minimum();
	double scale = double(length);
	if (orientation() == Qt::Horizontal)
		scale /= m_view->scene()->width();
	else
		scale /= m_view->scene()->height();

	return scale;
}
Beispiel #16
0
/*!\reimp
*/
void QSlider::wheelEvent( QWheelEvent * e){
    static float offset = 0;
    static QSlider* offset_owner = 0;
    if (offset_owner != this){
	offset_owner = this;
	offset = 0;
    }
    offset += -e->delta()*QMAX(pageStep(),lineStep())/120;
    if (QABS(offset)<1)
	return;
    setValue( value() + int(offset) );
    offset -= int(offset);
}
Beispiel #17
0
/*!
  \reimp
 */
void KScrollBar::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if (m_pressedValue == -1 || m_initialDelayTimer.isActive() || m_repeatActionTimer.isActive())
        return;
 
    QRect rect = subControlRect(QStyle::SC_ScrollBarGroove);
	QPointF pos = event->pos();
	QPointF downPos = event->buttonDownPos(Qt::LeftButton);
    QPointF delta = event->pos() - event->buttonDownPos(Qt::LeftButton);
    qreal range = maximum() - minimum();

    if (orientation() == Qt::Vertical) 
	{
        qreal scale = rect.height() / (range + pageStep());
        setValue((delta.y() / scale) + m_pressedValue);
    }
	else 
	{
        qreal scale = rect.width() / (range + pageStep());
        setValue((delta.x() / scale) + m_pressedValue);
    }
}
void ScrollBar::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event)

    Q_D(ScrollBar);

    QPainter painter(this);

    painter.fillRect(rect(), palette().color(QPalette::Window));

    int x, y, w, h;
    rect().getRect(&x, &y, &w, &h);

    QMargins margins(2, 2, 2, 2);

    QBrush brush;
    brush.setStyle(Qt::SolidPattern);
    brush.setColor(backgroundColor());
    painter.setBrush(brush);
    painter.setPen(Qt::NoPen);

    if (d->hideOnMouseOut) {
        painter.setOpacity(d->machine->opacity());
    }

    painter.drawRect(rect().marginsRemoved(margins));

    const qreal q = h / static_cast<qreal>(maximum() - minimum() + pageStep());

    QRect handle = Qt::Horizontal == orientation()
            ? QRect(sliderPosition()*q, y, pageStep()*q, h)
            : QRect(x, sliderPosition()*q, w, pageStep()*q);

    brush.setColor(sliderColor());
    painter.setBrush(brush);

    painter.drawRect(handle.marginsRemoved(margins));
}
Beispiel #19
0
void AbstractSlider::keyPressEvent(QKeyEvent* ev)
      {
      double oval = _value;

      switch (ev->key()) {
            case Qt::Key_Home:    _value = _minValue; break;
            case Qt::Key_End:     _value = _maxValue; break;
            case Qt::Key_Up:
            case Qt::Key_Left:    _value += lineStep(); break;
            case Qt::Key_Down:
            case Qt::Key_Right:   _value -= lineStep(); break;
            case Qt::Key_PageDown: _value -= pageStep(); break;
            case Qt::Key_PageUp:   _value += pageStep(); break;
            default:
                  break;
            }
      if (_value < _minValue)
            _value = _minValue;
      else if (_value > _maxValue)
            _value = _maxValue;
      if (oval != _value)
            valueChange();
      }
Beispiel #20
0
void RichHScrollBar::updateLeftRight()
{
    int w = total();

    if(w > 0)
    {
        _left = HBorder + (value() - minimum()) * useableWidth() / w;
        _right = HBorder + (value() - minimum() + pageStep()) * useableWidth() / w;
    }
    else
    {
        _left = HBorder;
        _right = width() - HBorder;
    }
}
Beispiel #21
0
void
QvisOpacitySlider::wheelEvent(QWheelEvent * e)
{
    static float offset = 0;
    static QvisOpacitySlider* offset_owner = 0;
    if(offset_owner != this)
    {
        offset_owner = this;
        offset = 0;
    }
    offset += -e->delta()*qMax(pageStep(),singleStep())/120;
    if(qAbs(offset)<1)
        return;
    setValue( value() + int(offset) );
    offset -= int(offset);
}
Beispiel #22
0
void
QvisOpacitySlider::paintEvent(QPaintEvent *)
{
    QPainter p(this);
    int mid = thickness()/2 + sliderLength() / 8;

    // Draw the gradient pixmap.
    if(gradientImage == 0)
        createGradientImage();
    p.drawImage(0, tickOffset, *gradientImage);

    // Draw the groove on which the slider slides.    
    drawSliderGroove(&p, 0, tickOffset, imageWidth(), thickness(), mid);

    // Figure out the interval between the tick marks.
    int interval = tickInt;
    if(interval <= 0)
    {
        interval = singleStep();
        if(positionFromValue(interval) - positionFromValue(0) < 3)
            interval = pageStep();
    }

    // Draw the tick marks.
    p.fillRect(0, 0, imageWidth(), tickOffset,
               palette().brush(QPalette::Background));
    p.fillRect(0, tickOffset + thickness(), imageWidth(), height(),
               palette().brush(QPalette::Background));
    drawTicks(&p, palette(), 0, tickOffset - 2, interval);

    // Draw the slider
    paintSlider(&p, palette(), sliderRect());

    // Draw the value text.
    paintValueText(&p, palette(), imageWidth(), height());

    // If this widget has focus, draw the focus rectangle.
    if(hasFocus())
    {
        QStyleOptionFocusRect so;
        so.initFrom(this);
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, 
                               &so,
                               &p);
    }
}
Beispiel #23
0
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);
}
Beispiel #24
0
/*!

 Reimplementation of QWidget::updateMask(). Draws the mask of the
 slider when transparency is required.

 \sa QWidget::setAutoMask()
*/
void QSlider::updateMask()
{
    QBitmap bm( size() );
    bm.fill( color0 );

    {
	QPainter p( &bm, this );
	QRect sliderR = sliderRect();
	QColorGroup g(color1, color1, color1, color1, color1, color1, color1, color1, color0);
	int mid = tickOffset + thickness()/2;
	if ( ticks & Above )
	    mid += style().sliderLength() / 8;
	if ( ticks & Below )
	    mid -= style().sliderLength() / 8;
	if ( orient == Horizontal ) {
	    style().drawSliderGrooveMask(&p, 0, tickOffset, width(), thickness(),
					 mid, Horizontal );
	}
	else {
	    style().drawSliderGrooveMask( &p, tickOffset, 0, thickness(), height(),
					  mid, Vertical );
	}
	style().drawSliderMask( &p, sliderR.x(), sliderR.y(),
				sliderR.width(), sliderR.height(),
				orient, ticks & Above, ticks & Below );

	int interval = tickInt;
	if ( interval <= 0 ) {
	    interval = lineStep();
	    if ( positionFromValue( interval ) - positionFromValue( 0 ) < 3 )
		interval = pageStep();
	}
	if ( ticks & Above )
	    drawTicks( &p, g, 0, tickOffset - 2, interval );

	if ( ticks & Below ) {
	    int avail = (orient == Horizontal) ? height() : width();
	    avail -= tickOffset + thickness();
	    drawTicks( &p, g, tickOffset + thickness() + 1, avail - 2, interval );
	}

    }
    setMask( bm );
}
Beispiel #25
0
void RullerSlider::paintEvent(QPaintEvent* event)
{
	Q_UNUSED(event);

	QPainter painter(this);
	QColor backgroundColor(245, 245, 200);
	QBrush backgroundBrush(backgroundColor);
	QPen backgroundPen(backgroundColor);
	QPen mainTickPen(Qt::black);
	QPen secondTickPen(Qt::lightGray);

	double scale = rullerScale();
	double spacing = (orientation() == Qt::Horizontal ? 0.01 : 0.00005);
	int lastStep = int(double(value() + pageStep())/(scale*spacing)) + 1;
	int firstStep = int(double(value())/(scale*spacing)) - 1;

	painter.setBrush(backgroundBrush);
	painter.setPen(backgroundPen);
	painter.drawRect(rect());
	painter.setPen(secondTickPen);
	for (double x = double(lastStep)*spacing; x >= double(firstStep)*spacing; x -= spacing)
	{
		double pos = x*scale - double(value());
		drawGraduation(painter, pos, 0.4);
		if (abs((int(round(x/spacing)) % 10)) == 5)
			drawGraduation(painter, pos, 0.65);
		else if ((int(round(x/spacing)) % 10) == 0)
		{
			painter.setPen(mainTickPen);
			drawGraduation(painter, pos, 0.8);
			QString text;
			text.setNum(round(x*1000.));
			QRectF textRect(0., 0., 0., 0.);
			textRect.moveCenter(QPointF(pos + 2., height()/2.));
			textRect = painter.boundingRect(textRect, Qt::AlignLeft | Qt::AlignVCenter, text);
			painter.drawText(textRect, Qt::AlignCenter, text);
			painter.setPen(secondTickPen);
		}
	}
}
Beispiel #26
0
        void Dial::keyPressEvent(QKeyEvent* _event) {
            if (((_event->key() == Qt::Key_Enter) ||
                 (_event->key() == Qt::Key_Return)))
            {
                setEditorVisible(!editor()->hasFocus());
            }

            float _step = singleStep();

            if (_event->modifiers() & Qt::ShiftModifier) {
                _step = 1.0;
            }
            if (_event->modifiers() & Qt::ControlModifier) {
                _step = pageStep();
            }

            if (_event->key() == Qt::Key_Left) {
                setValue(value() - _step);
            }
            if (_event->key() == Qt::Key_Right) {
                setValue(value() + _step);
            }
        }
void VanishingScrollBar::mouseMoveEvent(QMouseEvent *event)
{
    if (_isDragged)
    {
        int validLen;

        if (orientation() == Qt::Horizontal)
            validLen = geometry().width() - 2 * barMargin();
        else
            validLen = geometry().height() - 2 * barMargin();

        auto diff = double(scrollPos(event->pos(), orientation()) - _dragStartPos) / double(validLen);
        auto value = _dragStartValue + diff * (maximum() - minimum() + pageStep());
        setValue(value);
        emit sliderMoved(value);

        event->accept();
    }
    else
    {
        event->ignore();
    }
}
void VanishingScrollBar::paintEvent(QPaintEvent *)
{
    if (!_isAwake)
        return;

    QPainter painter(this);

    double begin, end;
    std::tie(begin, end) = scrollBarBeginEndPos(value(), minimum(), maximum(), pageStep());
    _barRect = scrollBarRect(begin, end, rect(), barMargin(), orientation());
    auto path = scrollBarPath(_barRect);
    //auto outerPath = scrollBarPath(_barRect.adjusted(-1,-1,1,1), orientation());
    //auto stroke = path.subtracted(outerPath);

    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setPen(Qt::NoPen);
    painter.setBrush(Qt::black);
    painter.setOpacity(0.5 * _barOpacity);

    painter.drawPath(path);

    //painter.setPen(Qt::white);
    //painter.drawPath(stroke);
}
void ManuallyTaggerWindow::scrollBottom() {
    auto vert = ui->scrollArea->verticalScrollBar();
    vert->setValue(int(vert->value() + vert->pageStep()/8));
}
Beispiel #30
-1
void QRangeControl::subtractPage()
{
    if ( value() - pageStep() < value() )
	setValue( value() - pageStep() );
    else
	setValue( minValue() );
}