void GraphView::setSliderPosition(qreal pos) { if (_visible.isEmpty()) return; _sliderPos = pos; updateSliderPosition(); }
void ControlSaturationBrightnessPicker::updateDraggerWithHSV(HSV hsv) { // Set the position of the slider to the correct saturation and brightness Vec2 pos(_startPos.x + boxPos + (boxSize*(1 - hsv.s)), _startPos.y + boxPos + (boxSize*hsv.v)); // update updateSliderPosition(pos); }
void CCControlSaturationBrightnessPicker::ccTouchMoved(CCTouch* touch, CCEvent* event) { // Get the touch location CCPoint touchLocation=getTouchLocation(touch); //small modification: this allows changing of the colour, even if the touch leaves the bounding area updateSliderPosition(touchLocation); sendActionsForControlEvents(CCControlEventValueChanged); // Check the touch position on the slider //checkSliderPosition(touchLocation); }
void GraphView::emitSliderPositionChanged(const QPointF &pos) { if (_slider->area().width() <= 0) return; _sliderPos = (pos.x() / _slider->area().width()) * bounds().width(); _sliderPos = qMax(_sliderPos, bounds().left()); _sliderPos = qMin(_sliderPos, bounds().right()); updateSliderPosition(); emit sliderPositionChanged(_sliderPos); }
bool ControlHuePicker::checkSliderPosition(Vector2 location) { // compute the distance between the current location and the center double distance = sqrt(pow (location.x + 10, 2) + pow(location.y, 2)); // check that the touch location is within the circle if (80 > distance && distance > 59) { updateSliderPosition(location); return true; } return false; }
/*! \reimp */ void KScrollBar::timerEvent(QTimerEvent *event) { if (m_initialDelayTimer.timerId() == event->timerId()) { m_repeatActionTimer.start(m_repeatFrequency, this); } else if (m_repeatActionTimer.timerId() == event->timerId()) { performSubControlAction(m_pressedControl); } else if(m_timer.timerId() == event->timerId()) { m_timer.stop(); updateSliderPosition(); } }
bool ControlSaturationBrightnessPicker::checkSliderPosition(Vec2 location) { // Clamp the position of the icon within the circle // get the center point of the bkgd image float centerX = _startPos.x + _background->getBoundingBox().size.width*0.5f; float centerY = _startPos.y + _background->getBoundingBox().size.height*0.5f; // work out the distance difference between the location and center float dx = location.x - centerX; float dy = location.y - centerY; float dist = sqrtf(dx*dx+dy*dy); // check that the touch location is within the bounding rectangle before sending updates if (dist <= _background->getBoundingBox().size.width*0.5f) { updateSliderPosition(location); sendActionsForControlEvents(Control::EventType::VALUE_CHANGED); return true; } return false; }
bool CCControlSaturationBrightnessPicker::checkSliderPosition(CCPoint location) { // Clamp the position of the icon within the circle // get the center point of the bkgd image float centerX = m_startPos.x + m_background->boundingBox().size.width*.5; float centerY = m_startPos.y + m_background->boundingBox().size.height*.5; // work out the distance difference between the location and center float dx = location.x - centerX; float dy = location.y - centerY; float dist = sqrtf(dx*dx+dy*dy); // check that the touch location is within the bounding rectangle before sending updates if (dist <= m_background->boundingBox().size.width*.5) { updateSliderPosition(location); sendActionsForControlEvents(CCControlEventValueChanged); return true; } return false; }
void PaintedSlider::onSliderReleased(int u) { if (slider_->orientation() == Orientation::Horizontal) u -= slider_->handleWidth() / 2; else u = (int)h() - (u + slider_->handleWidth() / 2); double l = (slider_->orientation() == Orientation::Horizontal) ? w() : h(); double pixelsPerUnit = (l - slider_->handleWidth()) / range(); double v = std::max(slider_->minimum(), std::min(slider_->maximum(), slider_->minimum() + (int)((double)u / pixelsPerUnit + 0.5))); // TODO changed() ? slider_->sliderMoved().emit(static_cast<int>(v)); slider_->setValue(static_cast<int>(v)); slider_->valueChanged().emit(slider_->value()); updateSliderPosition(); }
void GraphView::redraw(const QSizeF &size) { QRectF r; QSizeF mx, my; RangeF rx, ry; qreal sx, sy; if (_visible.isEmpty() || _bounds.isNull()) { removeItem(_xAxis); removeItem(_yAxis); removeItem(_slider); removeItem(_info); removeItem(_grid); _scene->setSceneRect(QRectF()); return; } addItem(_xAxis); addItem(_yAxis); addItem(_slider); addItem(_info); addItem(_grid); rx = RangeF(bounds().left() * _xScale, bounds().right() * _xScale); ry = RangeF(bounds().top() * _yScale + _yOffset, bounds().bottom() * _yScale + _yOffset); if (ry.size() < _minYRange) ry.resize(_minYRange); _xAxis->setRange(rx); _yAxis->setRange(ry); mx = _xAxis->margin(); my = _yAxis->margin(); r = _bounds; if (r.height() < _minYRange) r.adjust(0, -(_minYRange/2 - r.height()/2), 0, _minYRange/2 - r.height()/2); sx = (size.width() - (my.width() + mx.width())) / r.width(); sy = (size.height() - (mx.height() + my.height()) - _info->boundingRect().height()) / r.height(); for (int i = 0; i < _visible.size(); i++) _visible.at(i)->setScale(sx, sy); QPointF p(r.left() * sx, r.top() * sy); QSizeF s(r.width() * sx, r.height() * sy); r = QRectF(p, s); if (r.height() < _minYRange * sy) r.adjust(0, -(_minYRange/2 * sy - r.height()/2), 0, (_minYRange/2) * sy - r.height()/2); _xAxis->setSize(r.width()); _yAxis->setSize(r.height()); _xAxis->setPos(r.bottomLeft()); _yAxis->setPos(r.bottomLeft()); _grid->setSize(r.size()); _grid->setTicks(_xAxis->ticks(), _yAxis->ticks()); _grid->setPos(r.bottomLeft()); _slider->setArea(r); updateSliderPosition(); r |= _xAxis->sceneBoundingRect(); r |= _yAxis->sceneBoundingRect(); _info->setPos(r.topLeft() + QPointF(r.width()/2 - _info->boundingRect().width()/2, -_info->boundingRect().height())); _scene->setSceneRect(_scene->itemsBoundingRect()); }
void KScrollBar::updateSlider() { //m_timer.start(30, this); updateSliderPosition(); }
void PaintedSlider::updateState() { bool rtl = WApplication::instance()->layoutDirection() == LayoutDirection::RightToLeft; Orientation o = slider_->orientation(); if (o == Orientation::Horizontal) { handle_->resize(slider_->handleWidth(), h()); handle_->setOffsets(0, Side::Top); } else { handle_->resize(w(), slider_->handleWidth()); handle_->setOffsets(0, Side::Left); } double l = o == Orientation::Horizontal ? w() : h(); double pixelsPerUnit = (l - slider_->handleWidth()) / range(); std::string dir; std::string size; if (o == Orientation::Horizontal) { dir = rtl ? "right" : "left"; size = "width"; } else { dir = "top"; size = "height"; } char u = (o == Orientation::Horizontal ? 'x' : 'y'); double max = l - slider_->handleWidth(); bool horizontal = o == Orientation::Horizontal; char buf[30]; // Buffer for round_js_str /* * Note: cancelling the mouseDown event prevents the selection behaviour */ WStringStream mouseDownJS; mouseDownJS << "obj.setAttribute('down', " WT_CLASS << ".widgetCoordinates(obj, event)." << u << ");" << WT_CLASS ".cancelEvent(event);"; WStringStream computeD; // = 'u' position relative to background, corrected for slider computeD << "var objh = " << handle_->jsRef() << "," << "objf = " << fill_->jsRef() << "," << "objb = " << slider_->jsRef() << "," << "page_u = WT.pageCoordinates(event)." << u << "," << "widget_page_u = WT.widgetPageCoordinates(objb)." << u << "," << "pos = page_u - widget_page_u," << "rtl = " << rtl << "," << "horizontal = " << horizontal << ";" << "if (rtl && horizontal)"; computeD << "pos = " << Utils::round_js_str(l, 3, buf) << " - pos;"; computeD << "var d = pos - down;"; WStringStream mouseMovedJS; mouseMovedJS << "var down = obj.getAttribute('down');" << "var WT = " WT_CLASS ";" << "if (down != null && down != '') {" << computeD.str(); mouseMovedJS << "d = Math.max(0, Math.min(d, " << Utils::round_js_str(max, 3, buf) << "));"; mouseMovedJS << "var v = Math.round(d/" << Utils::round_js_str(pixelsPerUnit, 3, buf) << ");"; mouseMovedJS << "var intd = v*" << Utils::round_js_str(pixelsPerUnit, 3, buf) << ";"; mouseMovedJS << "if (Math.abs(WT.pxself(objh, '" << dir << "') - intd) > 1) {" << "objf.style." << size << " = "; if (o == Orientation::Vertical) { mouseMovedJS << '(' << Utils::round_js_str(max, 3, buf); mouseMovedJS << " - intd + " << (slider_->handleWidth() / 2) << ")"; } else mouseMovedJS << "intd + " << (slider_->handleWidth() / 2); mouseMovedJS << " + 'px';" << "objh.style." << dir << " = intd + 'px';" << "var vs = "; if (o == Orientation::Horizontal) mouseMovedJS << "v + " << slider_->minimum(); else mouseMovedJS << slider_->maximum() << " - v"; mouseMovedJS << ";" << "var f = objb.onValueChange;" << "if (f) f(vs);"; if (slider_->sliderMoved().needsUpdate(true)) { #ifndef WT_TARGET_JAVA mouseMovedJS << slider_->sliderMoved().createCall({"vs"}); #else mouseMovedJS << slider_->sliderMoved().createCall("vs"); #endif } mouseMovedJS << "}" << "}"; WStringStream mouseUpJS; mouseUpJS << "var down = obj.getAttribute('down');" << "var WT = " WT_CLASS ";" << "if (down != null && down != '') {" << computeD.str() << "d += " << (slider_->handleWidth() / 2) << ";" #ifndef WT_TARGET_JAVA << sliderReleased_.createCall({"Math.round(d)"}) #else << sliderReleased_.createCall("Math.round(d)") #endif << "obj.removeAttribute('down');" << "}"; bool enabled = !slider_->isDisabled(); mouseDownJS_.setJavaScript(std::string("function(obj, event) {") + (enabled ? mouseDownJS.str() : "") + "}"); mouseMovedJS_.setJavaScript(std::string("function(obj, event) {") + (enabled ? mouseMovedJS.str() : "") + "}"); mouseUpJS_.setJavaScript(std::string("function(obj, event) {") + (enabled ? mouseUpJS.str() : "") + "}"); handleClickedJS_.setJavaScript(std::string("function(obj, event) {") + WT_CLASS + ".cancelEvent(event," + WT_CLASS + ".CancelPropagate); }"); update(); updateSliderPosition(); }
void PaintedSlider::updateState() { bool rtl = WApplication::instance()->layoutDirection() == RightToLeft; std::string resourcesURL = WApplication::resourcesUrl(); Orientation o = slider_->orientation(); handle_->setStyleClass("handle"); if (o == Horizontal) { handle_->resize(HANDLE_WIDTH, h()); handle_->setOffsets(0, Top); } else { handle_->resize(w(), HANDLE_WIDTH); handle_->setOffsets(0, Left); } double l = o == Horizontal ? w() : h(); double pixelsPerUnit = (l - HANDLE_WIDTH) / range(); std::string dir; if (o == Horizontal) dir = rtl ? "right" : "left"; else dir = "top"; std::string u = (o == Horizontal ? "x" : "y"); std::string U = (o == Horizontal ? "X" : "Y"); std::string maxS = boost::lexical_cast<std::string>(l - HANDLE_WIDTH); std::string ppU = boost::lexical_cast<std::string>(pixelsPerUnit); std::string minimumS = boost::lexical_cast<std::string>(slider_->minimum()); std::string maximumS = boost::lexical_cast<std::string>(slider_->maximum()); std::string width = boost::lexical_cast<std::string>(w()); std::string horizontal = boost::lexical_cast<std::string>(o == Horizontal); /* * Note: cancelling the mouseDown event prevents the selection behaviour */ std::string mouseDownJS = """obj.setAttribute('down', " WT_CLASS ".widgetCoordinates(obj, event)." + u + "); " WT_CLASS ".cancelEvent(event);"; // = 'u' position relative to background, corrected for slider std::string computeD = "" "var objh = " + handle_->jsRef() + "," "" "objb = " + jsRef() + "," "" "page_u = WT.pageCoordinates(event)." + u + "," "" "widget_page_u = WT.widgetPageCoordinates(objb)." + u + "," "" "pos = page_u - widget_page_u," "" "rtl = " + boost::lexical_cast<std::string>(rtl) + "," "" "horizontal = " + horizontal + ";" "" "if (rtl && horizontal)" "" " pos = " + width + " - pos;" "" "var d = pos - down;"; std::string mouseMovedJS = """var down = obj.getAttribute('down');" """var WT = " WT_CLASS ";" """if (down != null && down != '') {" + computeD + "" "d = Math.max(0, Math.min(d, " + maxS + "));" "" "var v = Math.round(d/" + ppU + ");" "" "var intd = v*" + ppU + ";" "" "if (Math.abs(WT.pxself(objh, '" + dir + "') - intd) > 1) {" "" "objh.style." + dir + " = intd + 'px';" + slider_->sliderMoved().createCall(o == Horizontal ? "v + " + minimumS : maximumS + " - v") + "" "}" """}"; std::string mouseUpJS = """var down = obj.getAttribute('down');" """var WT = " WT_CLASS ";" """if (down != null && down != '') {" + computeD + """d += " + boost::lexical_cast<std::string>(HANDLE_WIDTH / 2) + ";" + sliderReleased_.createCall("d") + "" "obj.removeAttribute('down');" """}"; bool enabled = !slider_->isDisabled(); mouseDownJS_.setJavaScript(std::string("function(obj, event) {") + (enabled ? mouseDownJS : "") + "}"); mouseMovedJS_.setJavaScript(std::string("function(obj, event) {") + (enabled ? mouseMovedJS : "") + "}"); mouseUpJS_.setJavaScript(std::string("function(obj, event) {") + (enabled ? mouseUpJS : "") + "}"); update(); updateSliderPosition(); }