void CSliderMultiPos::mouseMoveEvent(QMouseEvent* event){
    QStyleOptionSlider opt;

    previousMousePos = event->globalPos();
    if( lastPressedIndex==INVALID_INDEX ){
        event->ignore();
        return;
    }

    initStyleOption( &opt );
    const int m = style()->pixelMetric( QStyle::PM_MaximumDragDistance,&opt,this );
    int newPosition = pixelPosToRangeValue( pick( event->pos() ) - offset );
    if( m >= 0 ){
        const QRect r = rect().adjusted( -m,-m,m,m );
        if( !r.contains( event->pos() ) ){
            newPosition = tempPosition;
        }
    }

    newPosition = collisionDetection( newPosition );
    setCurPosition( lastPressedIndex, newPosition);

    event->accept();
    update();
}
Ejemplo n.º 2
0
// Based on code from qslider.cpp
void Slider::mousePressEvent( QMouseEvent *e )
{
	qDebug("pressed (%d, %d)", e->pos().x(), e->pos().y());
	if( e->button() == Qt::LeftButton )
	{
		qDebug( "Left button" );
		QStyleOptionSlider opt;
		initStyleOption( &opt );
		const QRect sliderRect = style()->subControlRect( QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this );
		const QPoint center = sliderRect.center() - sliderRect.topLeft();
		// to take half of the slider off for the setSliderPosition call we use the center - topLeft

		if ( ! sliderRect.contains( e->pos() ) )
		{
			qDebug( "accept" );
			e->accept();

			int v = pixelPosToRangeValue( pick( e->pos() - center ) );
			setSliderPosition( v );
			triggerAction( SliderMove );
			setRepeatAction( SliderNoAction );
			emit sliderMoved( v );//TODO: ok?
			emit sliderPressed(); //TODO: ok?
		}
		else
		{
			QSlider::mousePressEvent( e );
		}
	}
	else
	{
		QSlider::mousePressEvent( e );
	}
}
Ejemplo n.º 3
0
void rphSlider::mouseMoveEvent(QMouseEvent *e){
    QStyleOptionSlider opt;
    initStyleOption(&opt);
    const QRect sliderRect = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
    const QPoint center = sliderRect.center() - sliderRect.topLeft();
    QPoint *pts;
    pts=new QPoint (e->pos());
    pt=new QPoint (e->pos());
    //qDebug("%d",pixelPosToRangeValue(pick(e->pos() - center)));
    emit hoverValue(QString::number(pixelPosToRangeValue(pick(e->pos() - center))),pts);
   //QToolTip::showText(e->globalPos(),this->toolTip());


        QSlider::mouseMoveEvent(e);

}
Ejemplo n.º 4
0
bool PlatformScrollbar::handleContextMenuEvent(const PlatformMouseEvent& event)
{
#ifndef QT_NO_CONTEXTMENU
    bool horizontal = (m_orientation == HorizontalScrollbar);

    QMenu menu;
    QAction* actScrollHere = menu.addAction(tr("Scroll here"));
    menu.addSeparator();

    QAction* actScrollTop = menu.addAction(horizontal ? tr("Left edge") : tr("Top"));
    QAction* actScrollBottom = menu.addAction(horizontal ? tr("Right edge") : tr("Bottom"));
    menu.addSeparator();

    QAction* actPageUp = menu.addAction(horizontal ? tr("Page left") : tr("Page up"));
    QAction* actPageDown = menu.addAction(horizontal ? tr("Page right") : tr("Page down"));
    menu.addSeparator();

    QAction* actScrollUp = menu.addAction(horizontal ? tr("Scroll left") : tr("Scroll up"));
    QAction* actScrollDown = menu.addAction(horizontal ? tr("Scroll right") : tr("Scroll down"));

    const QPoint globalPos = QPoint(event.globalX(), event.globalY());
    QAction* actionSelected = menu.exec(globalPos);

    if (actionSelected == 0)
        /* Do nothing */ ;
    else if (actionSelected == actScrollHere) {
        const QPoint pos = convertFromContainingWindow(event.pos());
        setValue(pixelPosToRangeValue(horizontal ? pos.x() : pos.y()));
    } else if (actionSelected == actScrollTop)
        setValue(0);
    else if (actionSelected == actScrollBottom)
        setValue(m_totalSize - m_visibleSize);
    else if (actionSelected == actPageUp)
        scroll(horizontal ? ScrollLeft: ScrollUp, ScrollByPage, 1);
    else if (actionSelected == actPageDown)
        scroll(horizontal ? ScrollRight : ScrollDown, ScrollByPage, 1);
    else if (actionSelected == actScrollUp)
        scroll(horizontal ? ScrollLeft : ScrollUp, ScrollByLine, 1);
    else if (actionSelected == actScrollDown)
        scroll(horizontal ? ScrollRight : ScrollDown, ScrollByLine, 1);
#endif // QT_NO_CONTEXTMENU
    return true;
}
Ejemplo n.º 5
0
bool PlatformScrollbar::handleMousePressEvent(const PlatformMouseEvent& evt)
{
    // Early exit for right click
    if (evt.button() == RightButton)
        return true; // Handled as context menu

    const QPoint pos = convertFromContainingWindow(evt.pos());
    bool midButtonAbsPos = QApplication::style()->styleHint(QStyle::SH_ScrollBar_MiddleClickAbsolutePosition);

    // Middle click centers slider thumb, if supported
    if (midButtonAbsPos && evt.button() == MiddleButton) {
        setValue(pixelPosToRangeValue((m_orientation == HorizontalScrollbar ?
                                        pos.x() : pos.y()) - thumbLength() / 2));

    } else { // Left button, or if middle click centering is not supported
        const QPoint topLeft = m_opt.rect.topLeft();
        m_opt.rect.moveTo(QPoint(0, 0));
        QStyle::SubControl sc = QApplication::style()->hitTestComplexControl(QStyle::CC_ScrollBar, &m_opt, pos, 0);
        m_opt.rect.moveTo(topLeft);
        switch (sc) {
            case QStyle::SC_ScrollBarAddLine:
            case QStyle::SC_ScrollBarSubLine:
            case QStyle::SC_ScrollBarSlider:
                m_opt.state |= QStyle::State_Sunken;
            case QStyle::SC_ScrollBarAddPage:
            case QStyle::SC_ScrollBarSubPage:
            case QStyle::SC_ScrollBarGroove:
                m_pressedPart = sc;
                break;
            default:
                m_pressedPart = QStyle::SC_None;
                return false;
        }
        m_pressedPos = m_orientation == HorizontalScrollbar ? pos.x() : pos.y();
        autoscrollPressedPart(cInitialTimerDelay);
        invalidate();
    }

    return true;
}
Ejemplo n.º 6
0
bool TTimeSlider::event(QEvent* event) {

	if (event->type() == QEvent::ToolTip) {
		QHelpEvent* help_event = static_cast<QHelpEvent*>(event);
		QStyleOptionSlider opt;
		initStyleOption(&opt);
        // Rect of handle/knob
        const QRect sliderRect = style()->subControlRect(
            QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
        // Center of handle
		const QPoint center = sliderRect.center() - sliderRect.topLeft();

		int val = pixelPosToRangeValue(pick(help_event->pos() - center));
        int time = qRound(val * _duration / maximum());
        QToolTip::showText(help_event->globalPos(), Helper::formatTime(time),
                           this);
		event->accept();
		return true;
	}

	return QWidget::event(event);
}
Ejemplo n.º 7
0
void rphSlider::mousePressEvent( QMouseEvent* e )
{
    if (e->button() == Qt::LeftButton) {

        QStyleOptionSlider opt;
    initStyleOption(&opt);
    const QRect sliderRect = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
    const QPoint center = sliderRect.center() - sliderRect.topLeft();
    // to take half of the slider off for the setSliderPosition call we use the center - topLeft

    if (!sliderRect.contains(e->pos())) {
        e->accept();

        setSliderPosition(pixelPosToRangeValue(pick(e->pos() - center)));
        triggerAction(SliderMove);
        setRepeatAction(SliderNoAction);
        pressedControl=QStyle::SC_SliderHandle;
    } else {
        QSlider::mousePressEvent(e);
            }
    } else {
            QSlider::mousePressEvent(e);
    }
}