void Slider::mousePressEvent(QMouseEvent *e) { int handlePos = QStyle::sliderPositionFromValue(minimum(),maximum(),sliderPosition(),width()); if(handlePos<e->pos().x()-5||handlePos>e->pos().x()+5) { int position = QStyle::sliderValueFromPosition(minimum(),maximum(),e->pos().x(),width()); setSliderPosition(position); emit sliderMoved(sliderPosition()); } }
// 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; }
void wxQtScrollBar::sliderReleased() { wxScrollBar *handler = GetHandler(); if ( handler ) { wxScrollEvent e( wxEVT_SCROLL_THUMBRELEASE, handler->GetId(), sliderPosition(), wxQtConvertOrientation( orientation() )); EmitEvent( e ); } }
bool pHexEdit::QtHexEditScrollBar::event(QEvent* event) { if(event->type() == QEvent::Wheel) { QWheelEvent* wheelEvent = (QWheelEvent*)event; if(wheelEvent->orientation() == Qt::Vertical) { signed offset = wheelEvent->delta() < 0 ? +1 : -1; self.scrollTo(sliderPosition() + offset); return true; } } return QScrollBar::event(event); }
double QScaleSlider::GetScaleFactor() const { double const oldV = value(); double const newV = sliderPosition(); if (oldV != newV) { double const f = pow(2, fabs(oldV - newV) / m_factor); return (newV > oldV ? f : 1.0 / f); } else return 1.0; }
void VerticalSlider::draw() const { UiElement::draw(); Vector2f origin = getTopLeft(); int mirror(locales::getCurrentLocale().LTR_ ? 1 : -1); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // draw line // Hover effect Color3f((Color3f(1, 1, 1)*(1-hoveredFadeTime_) + hoveredFadeTime_*Color3f(1.f, 0.8f, 0.9f))*(0.7f+focusedFadeTime_*0.3f)).gl4f(0.7f); glLineWidth(2); glBegin(GL_LINES); glVertex2f(10*mirror + origin.x_, origin.y_); glVertex2f(10*mirror + origin.x_, height_ + origin.y_); glEnd(); // Hover effect Vector2f sliderPosition(10*mirror + origin.x_, (height_-10)*(*value_- minValue_)/(maxValue_ - minValue_) + origin.y_+5); glEnable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBindTexture(GL_TEXTURE_2D, texture::getTexture(texture::Widgets)); int x(0), y(0); if (hovered_ && pressed_) { x = 3; y = 2; } else if (hovered_){ x = 3; y = 1; } else { x = 3; y = 0; } glColor3f(1.f, 1.f, 1.f); glBegin(GL_QUADS); glTexCoord2f(x*0.25f, y*0.25f+0.25f); glVertex2f(sliderPosition.x_-8.f, sliderPosition.y_-8.f); glTexCoord2f(x*0.25f+0.25f, y*0.25f+0.25f); glVertex2f(sliderPosition.x_-8.f, sliderPosition.y_+8.f); glTexCoord2f(x*0.25f+0.25f, y*0.25f); glVertex2f(sliderPosition.x_+8.f, sliderPosition.y_+8.f); glTexCoord2f(x*0.25f, y*0.25f); glVertex2f(sliderPosition.x_+8.f, sliderPosition.y_-8.f); glEnd(); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); }
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)); }
void LayoutSliderContainer::layout() { HTMLInputElement* input = toHTMLInputElement(node()->shadowHost()); bool isVertical = hasVerticalAppearance(input); mutableStyleRef().setFlexDirection(isVertical ? FlowColumn : FlowRow); TextDirection oldTextDirection = style()->direction(); if (isVertical) { // FIXME: Work around rounding issues in RTL vertical sliders. We want them to // render identically to LTR vertical sliders. We can remove this work around when // subpixel rendering is enabled on all ports. mutableStyleRef().setDirection(LTR); } Element* thumbElement = input->userAgentShadowRoot()->getElementById(ShadowElementNames::sliderThumb()); Element* trackElement = input->userAgentShadowRoot()->getElementById(ShadowElementNames::sliderTrack()); LayoutBox* thumb = thumbElement ? thumbElement->layoutBox() : 0; LayoutBox* track = trackElement ? trackElement->layoutBox() : 0; SubtreeLayoutScope layoutScope(*this); // Force a layout to reset the position of the thumb so the code below doesn't move the thumb to the wrong place. // FIXME: Make a custom layout class for the track and move the thumb positioning code there. if (track) layoutScope.setChildNeedsLayout(track); LayoutFlexibleBox::layout(); mutableStyleRef().setDirection(oldTextDirection); // These should always exist, unless someone mutates the shadow DOM (e.g., in the inspector). if (!thumb || !track) return; double percentageOffset = sliderPosition(input).toDouble(); LayoutUnit availableExtent = isVertical ? track->contentHeight() : track->contentWidth(); availableExtent -= isVertical ? thumb->size().height() : thumb->size().width(); LayoutUnit offset = percentageOffset * availableExtent; LayoutPoint thumbLocation = thumb->location(); if (isVertical) thumbLocation.setY(thumbLocation.y() + track->contentHeight() - thumb->size().height() - offset); else if (style()->isLeftToRightDirection()) thumbLocation.setX(thumbLocation.x() + offset); else thumbLocation.setX(thumbLocation.x() - offset); thumb->setLocation(thumbLocation); // We need one-off invalidation code here because painting of the timeline element does not go through style. // Instead it has a custom implementation in C++ code. // Therefore the style system cannot understand when it needs to be paint invalidated. setShouldDoFullPaintInvalidation(); }
// Alternate mouse behavior event handlers. void Knob::mousePressEvent ( QMouseEvent *pMouseEvent ) { if (m_dialMode == QDialMode) { QDial::mousePressEvent(pMouseEvent); } else if (pMouseEvent->button() == Qt::LeftButton) { m_bMousePressed = true; m_posMouse = pMouseEvent->pos(); m_lastDragValue = float(sliderPosition()); emit sliderPressed(); } else if (pMouseEvent->button() == Qt::MidButton) { // Reset to default value... if (m_iDefaultValue < minimum() || m_iDefaultValue > maximum()) m_iDefaultValue = (maximum() + minimum()) / 2; updatePosition(m_iDefaultValue); } }
void RenderSliderThumb::layout() { // Do not cast node() to SliderThumbElement. This renderer is used for // TrackLimitElement too. HTMLInputElement* input = node()->shadowAncestorNode()->toInputElement(); bool isVertical = style()->appearance() == SliderThumbVerticalPart || style()->appearance() == MediaVolumeSliderThumbPart; double fraction = sliderPosition(input) * 100; if (isVertical) style()->setTop(Length(100 - fraction, Percent)); else if (style()->isLeftToRightDirection()) style()->setLeft(Length(fraction, Percent)); else style()->setRight(Length(fraction, Percent)); RenderBlock::layout(); }
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); }
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); } }
void PropertyRowNumberField::redraw(IDrawContext& context) { if(multiValue()) context.drawEntry(context.widgetRect, " ... ", false, userReadOnly(), 0); else if (userReadOnly()) context.drawValueText(pulledSelected(), valueAsString().c_str()); else { double sliderPos = sliderPosition(); int flags = 0; if (context.captured) flags |= FIELD_SELECTED; if (pressed_) flags |= FIELD_PRESSED; if (userReadOnly()) flags |= FIELD_DISABLED; context.drawNumberEntry(valueAsString().c_str(), context.widgetRect, flags, sliderPos); } }
void Knob::mouseMoveEvent ( QMouseEvent *pMouseEvent ) { if (m_dialMode == QDialMode) { QDial::mouseMoveEvent(pMouseEvent); return; } if (!m_bMousePressed) return; const QPoint& posMouse = pMouseEvent->pos(); int xdelta = posMouse.x() - m_posMouse.x(); int ydelta = posMouse.y() - m_posMouse.y(); float angleDelta = mouseAngle(posMouse) - mouseAngle(m_posMouse); int iNewValue = sliderPosition(); switch (m_dialMode) { case LinearMode: iNewValue = int(m_lastDragValue + xdelta - ydelta); if (iNewValue > maximum()) iNewValue = maximum(); else if (iNewValue < minimum()) iNewValue = minimum(); break; case AngularMode: default: // Forget about the drag origin to be robust on full rotations if (angleDelta > +180.0f) angleDelta = angleDelta - 360.0f; if (angleDelta < -180.0f) angleDelta = angleDelta + 360.0f; m_lastDragValue += float(maximum() - minimum()) * angleDelta / 270.0f; if (m_lastDragValue > float(maximum())) m_lastDragValue = float(maximum()); if (m_lastDragValue < float(minimum())) m_lastDragValue = float(minimum()); m_posMouse = posMouse; iNewValue = int(m_lastDragValue + 0.5f); break; } updatePosition(iNewValue); }
void RenderSliderContainer::layout() { HTMLInputElement* input = element()->shadowHost()->toInputElement(); bool isVertical = hasVerticalAppearance(input); style().setFlexDirection(isVertical ? FlowColumn : FlowRow); TextDirection oldTextDirection = style().direction(); if (isVertical) { // FIXME: Work around rounding issues in RTL vertical sliders. We want them to // render identically to LTR vertical sliders. We can remove this work around when // subpixel rendering is enabled on all ports. style().setDirection(LTR); } RenderBox* thumb = input->sliderThumbElement() ? input->sliderThumbElement()->renderBox() : 0; RenderBox* track = input->sliderTrackElement() ? input->sliderTrackElement()->renderBox() : 0; // Force a layout to reset the position of the thumb so the code below doesn't move the thumb to the wrong place. // FIXME: Make a custom Render class for the track and move the thumb positioning code there. if (track) track->setChildNeedsLayout(MarkOnlyThis); RenderFlexibleBox::layout(); style().setDirection(oldTextDirection); // These should always exist, unless someone mutates the shadow DOM (e.g., in the inspector). if (!thumb || !track) return; double percentageOffset = sliderPosition(input).toDouble(); LayoutUnit availableExtent = isVertical ? track->contentHeight() : track->contentWidth(); availableExtent -= isVertical ? thumb->height() : thumb->width(); LayoutUnit offset = percentageOffset * availableExtent; LayoutPoint thumbLocation = thumb->location(); if (isVertical) thumbLocation.setY(thumbLocation.y() + track->contentHeight() - thumb->height() - offset); else if (style().isLeftToRightDirection()) thumbLocation.setX(thumbLocation.x() + offset); else thumbLocation.setX(thumbLocation.x() - offset); thumb->setLocation(thumbLocation); thumb->repaint(); }
void wxQtScrollBar::actionTriggered( int action ) { wxEventType eventType = wxEVT_NULL; switch( action ) { case QAbstractSlider::SliderSingleStepAdd: eventType = wxEVT_SCROLL_LINEDOWN; break; case QAbstractSlider::SliderSingleStepSub: eventType = wxEVT_SCROLL_LINEUP; break; case QAbstractSlider::SliderPageStepAdd: eventType = wxEVT_SCROLL_PAGEDOWN; break; case QAbstractSlider::SliderPageStepSub: eventType = wxEVT_SCROLL_PAGEUP; break; case QAbstractSlider::SliderToMinimum: eventType = wxEVT_SCROLL_TOP; break; case QAbstractSlider::SliderToMaximum: eventType = wxEVT_SCROLL_BOTTOM; break; case QAbstractSlider::SliderMove: eventType = wxEVT_SCROLL_THUMBTRACK; break; default: return; } wxScrollBar *handler = GetHandler(); if ( handler ) { wxScrollEvent e( eventType, handler->GetId(), sliderPosition(), wxQtConvertOrientation( orientation() )); EmitEvent( e ); } }
IntRect RenderSlider::thumbRect() { if (!m_thumb) return IntRect(); IntRect thumbRect; RenderBox* thumb = toRenderBox(m_thumb->renderer()); thumbRect.setWidth(thumb->style()->width().calcMinValue(contentWidth())); thumbRect.setHeight(thumb->style()->height().calcMinValue(contentHeight())); double fraction = sliderPosition(static_cast<HTMLInputElement*>(node())); IntRect contentRect = contentBoxRect(); if (style()->appearance() == SliderVerticalPart || style()->appearance() == MediaVolumeSliderPart) { thumbRect.setX(contentRect.x() + (contentRect.width() - thumbRect.width()) / 2); thumbRect.setY(contentRect.y() + static_cast<int>(nextafter((contentRect.height() - thumbRect.height()) + 1, 0) * (1 - fraction))); } else { thumbRect.setX(contentRect.x() + static_cast<int>(nextafter((contentRect.width() - thumbRect.width()) + 1, 0) * fraction)); thumbRect.setY(contentRect.y() + (contentRect.height() - thumbRect.height()) / 2); } return thumbRect; }
int QAbstractSlider::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: valueChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 1: sliderPressed(); break; case 2: sliderMoved((*reinterpret_cast< int(*)>(_a[1]))); break; case 3: sliderReleased(); break; case 4: rangeChanged((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; case 5: actionTriggered((*reinterpret_cast< int(*)>(_a[1]))); break; case 6: setValue((*reinterpret_cast< int(*)>(_a[1]))); break; case 7: setOrientation((*reinterpret_cast< Qt::Orientation(*)>(_a[1]))); break; } _id -= 8; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< int*>(_v) = minimum(); break; case 1: *reinterpret_cast< int*>(_v) = maximum(); break; case 2: *reinterpret_cast< int*>(_v) = singleStep(); break; case 3: *reinterpret_cast< int*>(_v) = pageStep(); break; case 4: *reinterpret_cast< int*>(_v) = value(); break; case 5: *reinterpret_cast< int*>(_v) = sliderPosition(); break; case 6: *reinterpret_cast< bool*>(_v) = hasTracking(); break; case 7: *reinterpret_cast< Qt::Orientation*>(_v) = orientation(); break; case 8: *reinterpret_cast< bool*>(_v) = invertedAppearance(); break; case 9: *reinterpret_cast< bool*>(_v) = invertedControls(); break; case 10: *reinterpret_cast< bool*>(_v) = isSliderDown(); break; } _id -= 11; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setMinimum(*reinterpret_cast< int*>(_v)); break; case 1: setMaximum(*reinterpret_cast< int*>(_v)); break; case 2: setSingleStep(*reinterpret_cast< int*>(_v)); break; case 3: setPageStep(*reinterpret_cast< int*>(_v)); break; case 4: setValue(*reinterpret_cast< int*>(_v)); break; case 5: setSliderPosition(*reinterpret_cast< int*>(_v)); break; case 6: setTracking(*reinterpret_cast< bool*>(_v)); break; case 7: setOrientation(*reinterpret_cast< Qt::Orientation*>(_v)); break; case 8: setInvertedAppearance(*reinterpret_cast< bool*>(_v)); break; case 9: setInvertedControls(*reinterpret_cast< bool*>(_v)); break; case 10: setSliderDown(*reinterpret_cast< bool*>(_v)); break; } _id -= 11; } else if (_c == QMetaObject::ResetProperty) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 11; } #endif // QT_NO_PROPERTIES return _id; }