MCPcopy Create free account
hub / github.com/CloudCompare/CloudCompare / onPointClicked

Method onPointClicked

libs/CCPluginAPI/src/ccColorScaleEditorWidget.cpp:596–645  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

594}
595
596void ccColorScaleEditorWidget::onPointClicked(double relativePos)
597{
598 assert(relativePos >= 0.0 && relativePos <= 1.0);
599 assert(m_colorBarWidget && m_slidersWidget);
600
601 if (!m_sliders)
602 return;
603
604 //look first if this position corresponds to an already existing slider
605 const double maxDist = static_cast<double>(DEFAULT_SLIDER_SYMBOL_SIZE) / m_colorBarWidget->length();
606 for (int i = 0; i < m_sliders->size(); ++i)
607 {
608 if (std::abs(m_sliders->element(i)->getRelativePos() - relativePos) < maxDist)
609 {
610 m_slidersWidget->select(i);
611 return;
612 }
613 }
614
615 //determine the new slider default color
616 QColor color = Qt::white;
617 if (m_sliders->size() > 1)
618 {
619 QLinearGradient gradient(0, 0, 256, 0);
620 //fill gradient with sliders
621 for (int i = 0; i < m_sliders->size(); i++)
622 {
623 ColorScaleElementSlider* slider = m_sliders->element(i);
624 gradient.setColorAt(slider->getRelativePos(), slider->getColor());
625 }
626 //generate fake color bar (1 pixel high)
627 QPixmap pix(256, 1);
628 QPainter painter(&pix);
629 painter.fillRect(pix.rect(), gradient);
630 color = pix.toImage().pixel(static_cast<int>(relativePos * 255), 0);
631 }
632 ColorScaleElementSlider* slider = m_slidersWidget->addNewSlider(relativePos, color);
633
634 if (slider)
635 {
636 int pos = m_sliders->indexOf(slider);
637 if (pos >= 0)
638 {
639 m_slidersWidget->select(pos);
640 onSliderModified(pos);
641 }
642 }
643
644 update();
645}
646
647void ccColorScaleEditorWidget::onSliderModified(int sliderIndex)
648{

Callers

nothing calls this directly

Calls 11

lengthMethod · 0.80
getRelativePosMethod · 0.80
elementMethod · 0.80
selectMethod · 0.80
getColorMethod · 0.80
rectMethod · 0.80
toImageMethod · 0.80
addNewSliderMethod · 0.80
updateFunction · 0.50
sizeMethod · 0.45
indexOfMethod · 0.45

Tested by

no test coverage detected