// ---------------------------------------------------------------------------- // Draws all of the spans for 2 edges // ---------------------------------------------------------------------------- void drawSpansBetweenEdges(std::shared_ptr<TransferMap> & map, Edge & e1, Edge & e2) { // Calculate differences between the y coordinates float e1ydiff = (float)(e1.p2[1] - e1.p1[1]); if (e1ydiff == 0.0f) return; float e2ydiff = (float)(e2.p2[1] - e2.p1[1]); if (e2ydiff == 0.0f) return; // Calculate differences between the x coordinates float e1xdiff = (float)(e1.p2[0] - e1.p1[0]); float e2xdiff = (float)(e2.p2[0] - e2.p1[0]); // Calculate factors to use for interpolation // with the edges and the step values to increase // them by after drawing each span float factor1 = (float)(e2.p1[1] - e1.p1[1]) / e1ydiff; float factorStep1 = 1.0f / e1ydiff; float factor2 = 0.0f; float factorStep2 = 1.0f / e2ydiff; // Loop through the lines between the edges and draw spans for(int y = e2.p1[1]; y < e2.p2[1]; y++) { // Draw the span auto m1 = interp(*e1.m1, *e1.m2, factor1); auto m2 = interp(*e2.m1, *e2.m2, factor2); drawSpan(map, Span(m1, e1.p1[0] + (int)(e1xdiff * factor1), m2, e2.p1[0] + (int)(e2xdiff * factor2)), y); // Increase factors factor1 += factorStep1; factor2 += factorStep2; } }
void CSliderMultiPos::paintEvent(QPaintEvent* event){ int currentIndex; QStyleOptionSlider opt; Q_UNUSED(event); QStylePainter painter(this); initStyleOption(&opt); // ticks opt.subControls = QStyle::SC_SliderTickmarks; painter.drawComplexControl(QStyle::CC_Slider, opt); // groove opt.sliderValue = 0; opt.sliderPosition = 0; opt.subControls = QStyle::SC_SliderGroove; painter.drawComplexControl(QStyle::CC_Slider, opt); for( currentIndex=0;currentIndex<nbValues()-1;currentIndex++ ){ if( intervals.at(currentIndex).isEnable() ){ // handle rects opt.sliderPosition = handles.at(currentIndex).getPosition(); const QRect rectHandleFirst = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this); const int lrv = pick(rectHandleFirst.center()); opt.sliderPosition = handles.at(currentIndex+1).getPosition(); const QRect rectHandleSecond = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this); const int urv = pick(rectHandleSecond.center()); // span const int minv = qMin(lrv, urv); const int maxv = qMax(lrv, urv); const QPoint c = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, this).center(); QRect spanRect; if( orientation()==Qt::Horizontal){ spanRect = QRect(QPoint(minv, c.y() - 2), QPoint(maxv, c.y() + 1)); } else{ spanRect = QRect(QPoint(c.x() - 2, minv), QPoint(c.x() + 1, maxv)); } drawSpan(&painter, spanRect,currentIndex); } } // handles for(int index=0;index<nbValues();index++){ // Call drawHandle for all, with the last pressed index at last of call (for being on top) drawHandle( &painter, (lastPressedIndex+index+1)%nbValues() ); } }