void RangeHistogram::mouseMoveEvent(QMouseEvent *e) { QPoint pos = e->pos(); if(ValidRange() && (e->buttons() & Qt::LeftButton) && pos != m_MousePrev) { if(m_DragMode == DraggingMode::White) { float newWhite = (float)(pos.x() - totalSpace()) / (float)regionWidth(); setWhiteDelta(qBound(blackDelta() + m_MinRangeSize, newWhite, 1.0f)); } else if(m_DragMode == DraggingMode::Black) { float newBlack = (float)(pos.x() - totalSpace()) / (float)regionWidth(); setBlackDelta(qBound(0.0f, newBlack, whiteDelta() - m_MinRangeSize)); } emit rangeUpdated(); if(m_DragMode != DraggingMode::None) update(); m_MousePrev = pos; } }
//-------------------------------------------------------------------------------------------------- /// Sets the max and min level of the legend. If the levels previously has been set with setLevelsFromValues() /// only the values between the new max min range becomes visible. //-------------------------------------------------------------------------------------------------- void ScalarMapperRangeBased::setRange(double min, double max) { m_rangeMin = min; m_rangeMax = max; updateSortedLevels(); rangeUpdated(); }
void RangeHistogram::setWhitePoint(float val) { if(val >= m_RangeMax) m_WhitePoint = m_RangeMax = val; else m_WhitePoint = val; update(); emit rangeUpdated(); }
void RangeHistogram::setBlackPoint(float val) { if(val <= m_RangeMin) m_BlackPoint = m_RangeMin = val; else m_BlackPoint = val; update(); emit rangeUpdated(); }
// sets the minimum and maximum as well as the black and white points void RangeHistogram::setRange(float min, float max) { m_RangeMin = min; if(min < 0.0f) m_RangeMax = qMax((min - FLT_EPSILON) * (1.0f - m_MinRangeSize), max); else m_RangeMax = qMax((min + FLT_EPSILON) * (1.0f + m_MinRangeSize), max); m_BlackPoint = m_RangeMin; m_WhitePoint = m_RangeMax; update(); emit rangeUpdated(); }
void RangeHistogram::mousePressEvent(QMouseEvent *e) { if(e->button() != Qt::LeftButton || !ValidRange()) return; QRect r = rect(); r.marginsRemoved(QMargins(totalSpace(), totalSpace(), totalSpace(), totalSpace())); int whiteX = (int)(whiteDelta() * r.width()); int blackX = (int)(blackDelta() * r.width()); QPointF whiteVec(whiteX - e->pos().x(), rect().height() - e->pos().y()); QPointF blackVec(blackX - e->pos().x(), e->pos().y()); float whitedist = (float)sqrt(whiteVec.x() * whiteVec.x() + whiteVec.y() * whiteVec.y()); float blackdist = (float)sqrt(blackVec.x() * blackVec.x() + blackVec.y() * blackVec.y()); if(whitedist < blackdist && whitedist < 18.0f) m_DragMode = DraggingMode::White; else if(blackdist < whitedist && blackdist < 18.0f) m_DragMode = DraggingMode::Black; else if(e->pos().x() > whiteX) m_DragMode = DraggingMode::White; else if(e->pos().x() < blackX) m_DragMode = DraggingMode::Black; if(m_DragMode == DraggingMode::White) { float newWhite = (float)(e->pos().x() - totalSpace()) / (float)regionWidth(); setWhiteDelta(qBound(blackDelta() + m_MinRangeSize, newWhite, 1.0f)); } else if(m_DragMode == DraggingMode::Black) { float newBlack = (float)(e->pos().x() - totalSpace()) / (float)regionWidth(); setBlackDelta(qBound(0.0f, newBlack, whiteDelta() - m_MinRangeSize)); } emit rangeUpdated(); if(m_DragMode != DraggingMode::None) update(); m_MousePrev = e->pos(); }