ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvColorScaleEditorWidget.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 // Qt
11 #include <QColorDialog>
12 #include <QHBoxLayout>
13 #include <QMouseEvent>
14 #include <QPainter>
15 #include <QVBoxLayout>
16 
17 // System
18 #include <cassert>
19 
20 static const int DEFAULT_SLIDER_SYMBOL_SIZE = 8;
21 static const int DEFAULT_MARGIN = DEFAULT_SLIDER_SYMBOL_SIZE / 2 + 1;
22 static const int DEFAULT_TEXT_MARGIN = 2;
23 static const int DEFAULT_LABEL_HEIGHT = 12;
24 
25 /*******************************/
26 /*** ColorScaleElementSlider ***/
27 /*******************************/
28 
30  double relativePos /*=0.0*/,
31  QColor color /*=Qt::black*/,
32  QWidget* parent /*=0*/,
33  Qt::Orientation orientation /*=Qt::Horizontal*/)
34  : QWidget(parent),
35  ccColorScaleElement(relativePos, color),
36  m_selected(false),
37  m_orientation(orientation) {
38  if (m_orientation == Qt::Horizontal)
39  setFixedSize(DEFAULT_SLIDER_SYMBOL_SIZE,
41  else
42  setFixedSize(2 * DEFAULT_SLIDER_SYMBOL_SIZE,
44 }
45 
47  QPainter painter(this);
48 
49  painter.setPen(m_selected ? Qt::red : Qt::black);
50  painter.setBrush(m_color);
51 
52  QRect box(0, 0, DEFAULT_SLIDER_SYMBOL_SIZE - 1,
54  QPolygon pointyHead;
55  if (m_orientation == Qt::Horizontal) {
56  box.moveTop(DEFAULT_SLIDER_SYMBOL_SIZE - 1);
57  pointyHead << QPoint(0, DEFAULT_SLIDER_SYMBOL_SIZE - 1)
58  << QPoint(DEFAULT_SLIDER_SYMBOL_SIZE / 2, 0)
59  << QPoint(DEFAULT_SLIDER_SYMBOL_SIZE - 1,
61  } else {
62  box.moveLeft(DEFAULT_SLIDER_SYMBOL_SIZE - 1);
63  pointyHead << QPoint(DEFAULT_SLIDER_SYMBOL_SIZE - 1, 0)
64  << QPoint(0, DEFAULT_SLIDER_SYMBOL_SIZE / 2)
65  << QPoint(DEFAULT_SLIDER_SYMBOL_SIZE - 1,
67  }
68 
69  painter.drawRect(box);
70  painter.drawPolygon(pointyHead, Qt::OddEvenFill);
71 }
72 
73 /********************************/
74 /*** ColorScaleElementSliders ***/
75 /********************************/
76 
78  assert(slider);
79 
80  if (slider) {
81  push_back(slider);
82  sort();
83  }
84 }
85 
87  std::sort(begin(), end(), ColorScaleElementSlider::IsSmaller);
88 }
89 
91  while (!isEmpty()) {
92  back()->setParent(nullptr);
93  delete back();
94  pop_back();
95  }
96 }
97 
99  if (i < 0 || i >= size()) {
100  assert(false);
101  return;
102  }
103 
104  ColorScaleElementSlider* slider = at(i);
105  if (slider) {
106  slider->setParent(nullptr);
107  delete slider;
108  slider = nullptr;
109  }
110 
111  QList<ColorScaleElementSlider*>::removeAt(i);
112 }
113 
115  for (int i = 0; i < size(); ++i)
116  if (at(i)->isSelected()) return i;
117 
118  return -1;
119 }
120 
122  for (int i = 0; i < size(); ++i)
123  if (at(i) == slider) return i;
124 
125  return -1;
126 }
127 
128 /**********************/
129 /*** ColorBarWidget ***/
130 /**********************/
131 
133  QWidget* parent /*=0*/,
134  Qt::Orientation orientation /*=Qt::Horizontal*/)
135  : ColorScaleEditorBaseWidget(sliders, orientation, DEFAULT_MARGIN, parent) {
136  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
137  setContentsMargins(0, 0, 0, 0);
138  setMinimumSize(DEFAULT_MARGIN * 3, DEFAULT_MARGIN * 3);
139 }
140 
141 void ColorBarWidget::mousePressEvent(QMouseEvent* e) {
142  if (e->button() == Qt::LeftButton) {
143  QRect contentRect = contentsRect();
144  if (m_orientation == Qt::Horizontal)
145  contentRect.adjust(m_margin, 0, -m_margin, 0);
146  else
147  contentRect.adjust(0, m_margin, 0, -m_margin);
148 
149  if (contentRect.contains(e->pos(), true)) {
150  double relativePos = -1.0;
151  if (m_orientation == Qt::Horizontal) {
152  relativePos =
153  static_cast<double>(e->pos().x() - contentRect.left()) /
154  contentRect.width();
155  } else {
156  relativePos =
157  static_cast<double>(e->pos().y() - contentRect.top()) /
158  contentRect.height();
159  }
160 
161  emit pointClicked(relativePos);
162  e->accept();
163  return;
164  }
165  }
166 
167  e->ignore();
168 }
169 
170 void ColorBarWidget::paintEvent(QPaintEvent* e) {
171  if (m_sliders && m_sliders->size() >= 2) {
172  QPainter painter(this);
173  painter.setPen(Qt::black);
174 
175  QRect contentRect = contentsRect();
176  if (m_orientation == Qt::Horizontal)
177  contentRect.adjust(m_margin, 0, -m_margin, -1);
178  else
179  contentRect.adjust(0, m_margin, -1, -m_margin);
180 
181  assert(m_sliders->front()->getRelativePos() == 0.0 &&
182  m_sliders->back()->getRelativePos() == 1.0);
183 
184  // color gradient
185  {
186  QLinearGradient gradient;
187  if (m_orientation == Qt::Horizontal)
188  gradient = QLinearGradient(contentRect.left(), 0,
189  contentRect.right(), 0);
190  else
191  gradient = QLinearGradient(0, contentRect.bottom(), 0,
192  contentRect.top());
193 
194  // fill gradient with sliders
195  {
196  for (int i = 0; i < m_sliders->size(); i++) {
197  gradient.setColorAt(m_sliders->at(i)->getRelativePos(),
198  m_sliders->at(i)->getColor());
199  }
200  }
201 
202  painter.fillRect(contentRect, gradient);
203  painter.drawRect(contentRect);
204  }
205 
206  // draw a line for each slider position (apart from the first and the
207  // last one)
208  {
209  QPoint A = contentRect.topLeft();
210  QPoint B = contentRect.bottomRight();
211 
212  for (int i = 0; i < m_sliders->size(); i++) {
213  double relativePos = m_sliders->at(i)->getRelativePos();
214  if (m_orientation == Qt::Horizontal) {
215  int pos =
216  contentRect.left() +
217  static_cast<int>(relativePos * contentRect.width());
218  A.setX(pos);
219  B.setX(pos);
220  } else {
221  int pos = contentRect.top() +
222  static_cast<int>(relativePos *
223  contentRect.height());
224  A.setY(pos);
225  B.setY(pos);
226  }
227 
228  painter.drawLine(A, B);
229  }
230  }
231  }
232 
233  QWidget::paintEvent(e);
234 }
235 
236 /*********************/
237 /*** SlidersWidget ***/
238 /*********************/
239 
241  QWidget* parent /*=0*/,
242  Qt::Orientation orientation /*=Qt::Horizontal*/)
243  : ColorScaleEditorBaseWidget(sliders, orientation, DEFAULT_MARGIN, parent) {
244  setContentsMargins(0, 0, 0, 0);
245  if (m_orientation == Qt::Horizontal) {
246  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
247  setMinimumSize(0, 2 * DEFAULT_SLIDER_SYMBOL_SIZE);
248  } else {
249  setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
250  setMinimumSize(2 * DEFAULT_SLIDER_SYMBOL_SIZE, 0);
251  }
252 }
253 
254 void SlidersWidget::select(int index, bool silent /*=false*/) {
255  assert(m_sliders);
256 
257  // look for previously selected slider
258  int activeSliderIndex = m_sliders->selected();
259 
260  if (index == activeSliderIndex) // nothing to do
261  return;
262 
263  // deselect old one (if any)
264  if (activeSliderIndex >= 0)
265  m_sliders->at(activeSliderIndex)->setSelected(false);
266 
267  // select new one (if any)
268  if (index >= 0) m_sliders->at(index)->setSelected(true);
269 
270  if (!silent) emit sliderSelected(index);
271 }
272 
274  QColor color) {
275  select(-1); // be sure to deselect any selected slider before modifying the
276  // global set contents!
277 
279  relativePos, color, this, m_orientation);
280 
281  m_sliders->addSlider(slider);
282 
283  int pos = static_cast<int>(length() * relativePos);
284 
285  if (m_orientation == Qt::Horizontal) {
286  pos += DEFAULT_MARGIN - slider->width() / 2;
287  slider->move(pos, 0);
288  } else {
289  pos += DEFAULT_MARGIN - slider->height() / 2;
290  slider->move(0, pos);
291  }
292  slider->setVisible(true);
293 
294  return slider;
295 }
296 
298 
300  if (!m_sliders || m_sliders->size() < 2) return;
301 
302  int rectLength = length();
303 
304  for (ColorScaleElementSliders::iterator it = m_sliders->begin();
305  it != m_sliders->end(); ++it) {
306  ColorScaleElementSlider* slider = *it;
307  int pos = static_cast<int>(slider->getRelativePos() * rectLength);
308 
309  if (m_orientation == Qt::Horizontal) {
310  pos += DEFAULT_MARGIN - slider->width() / 2;
311  slider->move(pos, 0);
312  } else {
313  pos += DEFAULT_MARGIN - slider->height() / 2;
314  slider->move(0, pos);
315  }
316  }
317 }
318 
320  if (!m_sliders || m_sliders->size() < 2 || index < 0) return;
321 
322  ColorScaleElementSlider* slider = m_sliders->at(index);
323 
324  int pos = static_cast<int>(slider->getRelativePos() * length());
325 
326  if (m_orientation == Qt::Horizontal) {
327  pos += DEFAULT_MARGIN - slider->width() / 2;
328  slider->move(pos, 0);
329  } else {
330  pos += DEFAULT_MARGIN - slider->height() / 2;
331  slider->move(0, pos);
332  }
333 }
334 
335 void SlidersWidget::mousePressEvent(QMouseEvent* e) {
336  if (e->button() == Qt::LeftButton) {
337  if (!m_sliders || m_sliders->size() < 2) return;
338 
339  for (int i = 0; i < m_sliders->size(); i++) {
340  QRect rect = m_sliders->at(i)->geometry();
341  if (rect.contains(e->pos(), true)) {
342  select(i);
343  e->accept();
344  break;
345  }
346  }
347  }
348 }
349 
350 void SlidersWidget::mouseMoveEvent(QMouseEvent* e) {
351  if (!m_sliders || m_sliders->size() <= 2) return;
352 
353  int pos = (m_orientation == Qt::Horizontal ? e->pos().x() : e->pos().y());
354  double relativePos = static_cast<double>(pos - DEFAULT_MARGIN) /
355  static_cast<double>(length());
356 
357  if (relativePos > 0.0 && relativePos < 1.0) {
358  int activeSliderIndex = m_sliders->selected();
359 
360  if (activeSliderIndex > 0 &&
361  activeSliderIndex + 1 <
362  m_sliders->size()) // first and last sliders can't move!
363  {
364  ColorScaleElementSlider* slider = m_sliders->at(activeSliderIndex);
365  assert(slider && slider->isSelected());
366 
367  if (m_orientation == Qt::Horizontal)
368  slider->move(pos - slider->width() / 2, 0);
369  else
370  slider->move(0, pos - slider->height() / 2);
371 
372  slider->setRelativePos(relativePos);
373 
374  m_sliders->sort();
375 
376  emit sliderModified(activeSliderIndex);
377 
378  e->accept();
379 
380  // update();
381  }
382  }
383 }
384 
385 // void SlidersWidget::mouseReleaseEvent(QMouseEvent* e)
386 //{
387 // }
388 
390  if (e->button() == Qt::LeftButton) {
391  for (int i = 0; i < m_sliders->size(); i++) {
392  QRect rect = m_sliders->at(i)->geometry();
393  if (rect.contains(e->pos(), true)) {
394  select(i);
395 
396  ColorScaleElementSlider* slider = m_sliders->at(i);
397  assert(slider && slider->isSelected());
398 
399  // spawn a color choosing dialog?
400  QColor newColor = QColorDialog::getColor(
401  m_sliders->at(i)->getColor(), this);
402  if (newColor.isValid() && newColor != slider->getColor()) {
403  slider->setColor(newColor);
404  emit sliderModified(i);
405  }
406 
407  break;
408  }
409  }
410  }
411 }
412 
413 /*************************/
414 /*** SliderLabelWidget ***/
415 /*************************/
416 
419  QWidget* parent /*=0*/,
420  Qt::Orientation orientation /*=Qt::Horizontal*/)
421  : ColorScaleEditorBaseWidget(sliders, orientation, DEFAULT_MARGIN, parent),
422  m_textColor(Qt::black),
423  m_precision(6) {
424  setContentsMargins(0, 0, 0, 0);
425 }
426 
427 void SliderLabelWidget::paintEvent(QPaintEvent* e) {
428  if (m_sliders) {
429  QPainter painter(this);
430 
431  QFont font = painter.font();
432  font.setPixelSize(8);
433  painter.setFont(font);
434 
435  painter.setPen(m_textColor);
436  painter.setBrush(m_textColor);
437 
438  QFontMetrics fm(font);
439 
440  if (m_orientation == Qt::Horizontal) {
441  int labelHeight = fm.height() + DEFAULT_TEXT_MARGIN;
442 
443  // adjust height if necessary
444  setMinimumSize(0, labelHeight);
445 
446  for (int i = 0; i < m_sliders->size(); i++) {
447  int pos = m_sliders->at(i)->pos().x();
448 
449  double val = m_sliders->at(i)->getRelativePos();
450  QString label = QString("%1 %").arg(
451  val * 100.0, 0, 'f',
452  std::max(m_precision - 2,
453  0)); // display as a percentage
454 
455  // int labelWidth = fm.width(label);
456  int labelWidth = fm.horizontalAdvance(label);
457 
458  if (pos + labelWidth > width())
459  pos -= (labelWidth - m_sliders->at(i)->width());
460 
461  painter.drawText(pos, labelHeight, label);
462  }
463  } else {
464  // adjust width if necessary
465  {
466  QString firstLabel = QString::number(
467  m_sliders->first()->getRelativePos(), 'f', m_precision);
468  QString lastLabel = QString::number(
469  m_sliders->last()->getRelativePos(), 'f', m_precision);
470  // int labelWidth =
471  // std::max(fm.width(firstLabel),fm.width(lastLabel))+2*DEFAULT_TEXT_MARGIN;
472  int labelWidth = std::max(fm.horizontalAdvance(firstLabel),
473  fm.horizontalAdvance(lastLabel)) +
475  setMinimumSize(labelWidth, 0);
476  }
477  // draw the text for vertical orientation
478  for (int i = 0; i < m_sliders->size(); i++) {
479  int pos = m_sliders->at(i)->pos().y();
480 
481  double val = m_sliders->at(i)->getRelativePos();
482  QString label = QString("%1 %").arg(
483  val * 100.0, 0, 'f',
484  std::max(m_precision - 2,
485  0)); // display as a percentage
486 
487  painter.drawText(DEFAULT_TEXT_MARGIN,
488  pos + m_sliders->at(i)->height(), label);
489  }
490  }
491  }
492 
493  QWidget::paintEvent(e);
494 }
495 
496 /********************************/
497 /*** ccColorScaleEditorWidget ***/
498 /********************************/
499 
501  QWidget* parent /*=0*/, Qt::Orientation orientation /*=Qt::Horizontal*/)
504  orientation,
505  0,
506  parent) {
507  // size and margin
508  setMinimumSize(40, 40);
509  setContentsMargins(0, 0, 0, 0);
510 
511  // layout
512  setLayout(m_orientation == Qt::Horizontal
513  ? static_cast<QLayout*>(new QVBoxLayout())
514  : static_cast<QLayout*>(new QHBoxLayout()));
515 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
516  layout()->setMargin(0);
517 #endif
518  layout()->setSpacing(0);
519  layout()->setContentsMargins(0, 0, 0, 0);
520 
521  // color bar
522  {
523  m_colorBarWidget = new ColorBarWidget(m_sliders, parent, orientation);
524  m_colorBarWidget->setSizePolicy(QSizePolicy::Expanding,
525  QSizePolicy::Expanding);
526  m_colorBarWidget->setContentsMargins(0, 0, 0, 0);
527  layout()->addWidget(m_colorBarWidget);
528 
529  connect(m_colorBarWidget, SIGNAL(pointClicked(double)), this,
530  SLOT(onPointClicked(double)));
531  }
532 
533  // sliders widget
534  {
535  m_slidersWidget = new SlidersWidget(m_sliders, parent, orientation);
536  m_slidersWidget->setContentsMargins(0, 0, 0, 0);
537  layout()->addWidget(m_slidersWidget);
538 
539  // add default min and max elements
542 
543  connect(m_slidersWidget, SIGNAL(sliderModified(int)), this,
544  SLOT(onSliderModified(int)));
545  connect(m_slidersWidget, SIGNAL(sliderSelected(int)), this,
546  SLOT(onSliderSelected(int)));
547  }
548 
549  // Labels widget
550  {
551  m_labelsWidget = new SliderLabelWidget(m_sliders, parent, orientation);
552  if (m_orientation == Qt::Horizontal) {
553  m_labelsWidget->setSizePolicy(QSizePolicy::Expanding,
554  QSizePolicy::Fixed);
555  m_labelsWidget->setFixedHeight(DEFAULT_LABEL_HEIGHT);
556  } else {
557  m_labelsWidget->setSizePolicy(QSizePolicy::Fixed,
558  QSizePolicy::Expanding);
559  m_labelsWidget->setFixedWidth(DEFAULT_LABEL_HEIGHT);
560  }
561  layout()->addWidget(m_labelsWidget);
562  m_labelsWidget->setVisible(false); // hidden by default
563  }
564 }
565 
567  assert(relativePos >= 0.0 && relativePos <= 1.0);
569 
570  if (!m_sliders) return;
571 
572  // look first if this position corresponds to an already existing slider
573  const double maxDist = static_cast<double>(DEFAULT_SLIDER_SYMBOL_SIZE) /
575  for (int i = 0; i < m_sliders->size(); ++i) {
576  if (fabs(m_sliders->at(i)->getRelativePos() - relativePos) < maxDist) {
578  return;
579  }
580  }
581 
582  // determine the new slider defaut color
583  QColor color = Qt::white;
584  if (m_sliders->size() > 1) {
585  QLinearGradient gradient(0, 0, 256, 0);
586  // fill gradient with sliders
587  for (int i = 0; i < m_sliders->size(); i++) {
588  gradient.setColorAt(m_sliders->at(i)->getRelativePos(),
589  m_sliders->at(i)->getColor());
590  }
591  // generate fake color bar (1 pixel high)
592  QPixmap pix(256, 1);
593  QPainter painter(&pix);
594  painter.fillRect(pix.rect(), gradient);
595  color = pix.toImage().pixel(static_cast<int>(relativePos * 255), 0);
596  }
597  ColorScaleElementSlider* slider =
598  m_slidersWidget->addNewSlider(relativePos, color);
599 
600  if (slider) {
601  int pos = m_sliders->indexOf(slider);
602  if (pos >= 0) {
603  m_slidersWidget->select(pos);
604  onSliderModified(pos);
605  }
606  }
607 
608  update();
609 }
610 
612  if (sliderIndex < 0) {
613  assert(false);
614  return;
615  }
616 
617  if (m_colorBarWidget) m_colorBarWidget->update();
618  if (m_slidersWidget) m_slidersWidget->update();
619  if (m_labelsWidget) m_labelsWidget->update();
620 
621  emit stepModified(sliderIndex);
622 }
623 
626  if (m_sliders) {
627  // onSliderSelected(-1);
628  // release all previously defined sliders
629  m_sliders->clear();
630  }
631 
632  for (int i = 0; i < sliders->size(); ++i)
633  m_slidersWidget->addNewSlider(sliders->at(i)->getRelativePos(),
634  sliders->at(i)->getColor());
635 
636  update();
637 }
638 
640  if (m_slidersWidget) m_slidersWidget->update();
641 
642  emit stepSelected(sliderIndex);
643 }
644 
646  m_sliders->clear();
647 
648  if (scale) {
649  assert(scale->stepCount() >= 2);
650  for (int i = 0; i < scale->stepCount(); ++i) {
651  double relativePos = scale->step(i).getRelativePos();
652  const QColor& color = scale->step(i).getColor();
653  m_slidersWidget->addNewSlider(relativePos, color);
654  }
655  }
656 
657  update();
658 }
659 
661  ccColorScale::Shared& destScale) const {
662  if (!destScale) return;
663 
664  destScale->clear();
665 
666  for (int i = 0; i < m_sliders->size(); ++i)
667  destScale->insert(*m_sliders->at(i), false);
668 
669  destScale->update();
670 }
671 
673  if (m_labelsWidget) {
674  m_labelsWidget->setVisible(state);
675  m_labelsWidget->update();
676  }
677 }
678 
680  if (m_labelsWidget) {
682  m_labelsWidget->update();
683  }
684 }
685 
687  if (m_labelsWidget) {
688  m_labelsWidget->setPrecision(precision);
689  m_labelsWidget->update();
690  }
691 }
692 
694  assert(m_sliders);
695 
696  if (index >= 0) {
697  if (m_sliders->at(index)->isSelected()) onSliderSelected(-1);
698  m_sliders->removeAt(index);
699 
700  update();
701  }
702 }
703 
705  bool silent /*=false*/) {
706  if (m_slidersWidget) m_slidersWidget->select(index, silent);
707 }
708 
710  if (index < 0) return;
711 
712  m_sliders->at(index)->setColor(color);
713  onSliderModified(index);
714 }
715 
717  double relativePos) {
718  if (index < 0) return;
719 
720  m_sliders->at(index)->setRelativePos(relativePos);
721 
722  if (m_slidersWidget) {
723  if (index == 0 || index + 1 == m_sliders->size()) {
724  // update all sliders!
726  } else {
727  // update only the selected one
729  }
730  }
731 
732  onSliderModified(index);
733 }
int width
int size
math::float4 color
void mousePressEvent(QMouseEvent *e) override
void paintEvent(QPaintEvent *e) override
void pointClicked(double relativePos)
Signal emitted when the mouse (left) button is clicked.
ColorBarWidget(SharedColorScaleElementSliders sliders, QWidget *parent=nullptr, Qt::Orientation orientation=Qt::Horizontal)
Default constructor.
Base color scale editor (sub)Widget.
int length() const
Returns useful length.
SharedColorScaleElementSliders m_sliders
Associated sliders.
Qt::Orientation m_orientation
Orientation.
Color scale element as a widget.
Qt::Orientation m_orientation
Widget orientation.
static bool IsSmaller(const ColorScaleElementSlider *e1, const ColorScaleElementSlider *e2)
Comparison operator between two (pointers on) color scale elements.
void paintEvent(QPaintEvent *e) override
bool isSelected() const
Returns selection state.
ColorScaleElementSlider(double relativePos=0.0, QColor color=Qt::black, QWidget *parent=nullptr, Qt::Orientation orientation=Qt::Horizontal)
Default constructor.
Set of color scale elements (widgets)
void addSlider(ColorScaleElementSlider *slider)
Adds a slider element and sort the whole set.
void clear()
Remove all sliders.
void removeAt(int i)
Remove a given slider.
int selected() const
Returns the currently selected slider index (or -1 if none)
int indexOf(ColorScaleElementSlider *slider)
Returns the index of a given slider.
All sliders labels widget.
void paintEvent(QPaintEvent *e) override
void setTextColor(QColor color)
Sets text color.
SliderLabelWidget(SharedColorScaleElementSliders sliders, QWidget *parent=nullptr, Qt::Orientation orientation=Qt::Horizontal)
Default constructor.
QColor m_textColor
Text color.
void setPrecision(int precision)
Sets displayed numbers precision.
All sliders widget.
void select(int index, bool silent=false)
Manually selects a slider.
void updateAllSlidersPos()
Updates all sliders positions.
SlidersWidget(SharedColorScaleElementSliders sliders, QWidget *parent=nullptr, Qt::Orientation orientation=Qt::Horizontal)
Default constructor.
void mouseDoubleClickEvent(QMouseEvent *e) override
void resizeEvent(QResizeEvent *e) override
void mousePressEvent(QMouseEvent *e) override
ColorScaleElementSlider * addNewSlider(double relativePos, QColor color)
Adds a new slider widget.
void updateSliderPos(int index)
Updates slider position.
void sliderSelected(int index)
Signal emitted when a slider is selected.
void sliderModified(int index)
Signal emitted when a slider is changed (position or color)
void mouseMoveEvent(QMouseEvent *e) override
void setSelectedStepIndex(int index, bool silent=false)
Sets currently selected step index.
void showLabels(bool state)
Sets whether to show the color elements labels or not.
ColorBarWidget * m_colorBarWidget
Associated color bar.
void onSliderModified(int sliderIndex)
Slot called when a slider is moved or its color is changed.
void setSliders(SharedColorScaleElementSliders sliders) override
Sets associated sliders set.
ccColorScaleEditorWidget(QWidget *parent=nullptr, Qt::Orientation orientation=Qt::Horizontal)
Default constructor.
void setLabelColor(QColor color)
Sets the labels color.
void setLabelPrecision(int precision)
Sets the labels precision.
void exportColorScale(ccColorScale::Shared &destScale) const
Exports the current color scale.
void setStepRelativePosition(int index, double relativePos)
Sets a given slider relative position.
void onSliderSelected(int sliderIndex)
Slot called when a slider is selected.
void stepModified(int index)
Signal emitted when a slider is modified.
SliderLabelWidget * m_labelsWidget
Associated (sliders) labels widget.
void stepSelected(int index)
Signal emitted when a slider is selected.
void importColorScale(ccColorScale::Shared scale)
Imports the current color scale.
void deleteStep(int index)
Deletes a given step.
SlidersWidget * m_slidersWidget
Associated sliders widget.
void setStepColor(int index, QColor color)
Sets a given slider color.
void onPointClicked(double relativePos)
Slot called when a 'point' is clicked on the color bar.
Color scale element: one value + one color.
Definition: ecvColorScale.h:22
const QColor & getColor() const
Returns color.
Definition: ecvColorScale.h:43
double getRelativePos() const
Returns step position (relative to scale boundaries)
Definition: ecvColorScale.h:38
QColor m_color
Color.
Definition: ecvColorScale.h:57
void setRelativePos(double pos)
Sets associated value (relative to scale boundaries)
Definition: ecvColorScale.h:34
void setColor(QColor color)
Sets color.
Definition: ecvColorScale.h:41
QSharedPointer< ccColorScale > Shared
Shared pointer type.
Definition: ecvColorScale.h:74
__host__ __device__ float2 fabs(float2 v)
Definition: cutil_math.h:1254
int max(int a, int b)
Definition: cutil_math.h:48
static const int DEFAULT_LABEL_HEIGHT
static const int DEFAULT_TEXT_MARGIN
static const int DEFAULT_SLIDER_SYMBOL_SIZE
static const int DEFAULT_MARGIN
QSharedPointer< ColorScaleElementSliders > SharedColorScaleElementSliders
Shared set of color scale elements (widgets)
Rgb at(size_t color_id)
constexpr Rgb black(0, 0, 0)
constexpr Rgb white(MAX, MAX, MAX)
constexpr Rgb red(MAX, 0, 0)
constexpr Rgb blue(0, 0, MAX)
Definition: lsd.c:1170