ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvColorScaleEditorWidget.h
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 
8 #pragma once
9 
10 #ifdef _MSC_VER
11 #pragma warning(disable : 4996) // Use of [[deprecated]] feature
12 #endif
13 
14 #include "CVPluginAPI.h"
15 
16 // Qt
17 #include <QWidget>
18 
19 // CV_DB_LIB
20 #include <ecvColorScale.h>
21 
24  public ccColorScaleElement {
25  Q_OBJECT
26 
27 public:
29  ColorScaleElementSlider(double relativePos = 0.0,
30  QColor color = Qt::black,
31  QWidget* parent = nullptr,
32  Qt::Orientation orientation = Qt::Horizontal);
33 
35  void setSelected(bool state) { m_selected = state; }
36 
38  bool isSelected() const { return m_selected; }
39 
41  static bool IsSmaller(const ColorScaleElementSlider* e1,
42  const ColorScaleElementSlider* e2) {
43  return e1->getRelativePos() < e2->getRelativePos();
44  }
45 
46 protected:
47  // inherited from QWidget
48  void paintEvent(QPaintEvent* e) override;
49 
51  bool m_selected;
52 
54  Qt::Orientation m_orientation;
55 };
56 
59  : public QList<ColorScaleElementSlider*> {
60 public:
62 
64  void addSlider(ColorScaleElementSlider* slider);
65 
67  void sort();
68 
70  void clear();
71 
73  void removeAt(int i);
74 
76  int selected() const;
77 
79  int indexOf(ColorScaleElementSlider* slider);
80 };
81 
83 using SharedColorScaleElementSliders = QSharedPointer<ColorScaleElementSliders>;
84 
86 
89  Q_OBJECT
90 
91 public:
94  Qt::Orientation orientation,
95  int margin,
96  QWidget* parent = nullptr)
97  : QWidget(parent),
98  m_sliders(sliders),
99  m_orientation(orientation),
100  m_margin(margin) {}
101 
103  int length() const {
104  return (m_orientation == Qt::Horizontal ? contentsRect().width()
105  : contentsRect().height()) -
106  2 * m_margin;
107  }
108 
111  m_sliders = sliders;
112  update();
113  }
114 
116  Qt::Orientation getOrientation() const { return m_orientation; }
118  int getMargin() const { return m_margin; }
119 
120 protected:
123 
125  Qt::Orientation m_orientation;
126 
128  int m_margin;
129 };
130 
133  Q_OBJECT
134 
135 public:
138  QWidget* parent = nullptr,
139  Qt::Orientation orientation = Qt::Horizontal);
140 
141 signals:
142 
144 
146  void pointClicked(double relativePos);
147 
148 protected:
149  // inherited from QWidget
150  void paintEvent(QPaintEvent* e) override;
151  void mousePressEvent(QMouseEvent* e) override;
152 };
153 
156  Q_OBJECT
157 
158 public:
161  QWidget* parent = nullptr,
162  Qt::Orientation orientation = Qt::Horizontal);
163 
165  void select(int index, bool silent = false);
166 
168 
171  ColorScaleElementSlider* addNewSlider(double relativePos, QColor color);
172 
174  void updateSliderPos(int index);
175 
177  void updateAllSlidersPos();
178 
179 signals:
180 
182  void sliderModified(int index);
183 
185  void sliderSelected(int index);
186 
187 protected:
188  // inherited from QWidget
189  void mousePressEvent(QMouseEvent* e) override;
190  void mouseMoveEvent(QMouseEvent* e) override;
191  // virtual void mouseReleaseEvent(QMouseEvent* e);
192  void mouseDoubleClickEvent(QMouseEvent* e) override;
193  void resizeEvent(QResizeEvent* e) override;
194 };
195 
198  Q_OBJECT
199 
200 public:
203  QWidget* parent = nullptr,
204  Qt::Orientation orientation = Qt::Horizontal);
205 
207  inline void setTextColor(QColor color) { m_textColor = color; }
208 
210  inline void setPrecision(int precision) { m_precision = precision; }
211 
212 protected:
213  // inherited from QWidget
214  void paintEvent(QPaintEvent* e) override;
215 
217  QColor m_textColor;
218 
221 };
222 
225  : public ColorScaleEditorBaseWidget {
226  Q_OBJECT
227 
228 public:
230  ccColorScaleEditorWidget(QWidget* parent = nullptr,
231  Qt::Orientation orientation = Qt::Horizontal);
232 
234  ~ccColorScaleEditorWidget() override = default;
235 
237  inline int getStepCount() const {
238  return (m_sliders ? m_sliders->size() : 0);
239  }
240 
242  inline const ColorScaleElementSlider* getStep(int index) {
243  return m_sliders ? m_sliders->at(index) : nullptr;
244  }
245 
247  void setStepColor(int index, QColor color);
248 
250  void setStepRelativePosition(int index, double relativePos);
251 
253  inline int getSelectedStepIndex() const {
254  return m_sliders ? m_sliders->selected() : -1;
255  }
256 
258  void setSelectedStepIndex(int index, bool silent = false);
259 
261 
263  void deleteStep(int index);
264 
266  void exportColorScale(ccColorScale::Shared& destScale) const;
267 
269  void importColorScale(ccColorScale::Shared scale);
270 
272  void showLabels(bool state);
273 
275  void setLabelColor(QColor color);
276 
278  void setLabelPrecision(int precision);
279 
280  // inherited from ColorScaleEditorBaseWidget
281  void setSliders(SharedColorScaleElementSliders sliders) override;
282 
283 signals:
284 
286  void stepSelected(int index);
287 
289  void stepModified(int index);
290 
291 protected slots:
292 
294  void onPointClicked(double relativePos);
295 
297  void onSliderModified(int sliderIndex);
298 
300  void onSliderSelected(int sliderIndex);
301 
302 protected:
305 
308 
311 };
#define CVPLUGIN_LIB_API
Definition: CVPluginAPI.h:15
int width
int height
math::float4 color
#define slots
#define signals
void pointClicked(double relativePos)
Signal emitted when the mouse (left) button is clicked.
Base color scale editor (sub)Widget.
int length() const
Returns useful length.
SharedColorScaleElementSliders m_sliders
Associated sliders.
int getMargin() const
Returns margin.
virtual void setSliders(SharedColorScaleElementSliders sliders)
Sets associated sliders set.
Qt::Orientation m_orientation
Orientation.
Qt::Orientation getOrientation() const
Returns orientation.
ColorScaleEditorBaseWidget(SharedColorScaleElementSliders sliders, Qt::Orientation orientation, int margin, QWidget *parent=nullptr)
Defautl constructor.
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 setSelected(bool state)
Sets selection state.
bool isSelected() const
Returns selection state.
Set of color scale elements (widgets)
All sliders labels widget.
void setTextColor(QColor color)
Sets text color.
QColor m_textColor
Text color.
void setPrecision(int precision)
Sets displayed numbers precision.
All sliders widget.
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)
Color scale editor dialog.
const ColorScaleElementSlider * getStep(int index)
Returns a given slider (pointer on)
ColorBarWidget * m_colorBarWidget
Associated color bar.
int getSelectedStepIndex() const
Returns currently selected step index.
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.
SlidersWidget * m_slidersWidget
Associated sliders widget.
~ccColorScaleEditorWidget() override=default
Destructor.
int getStepCount() const
Returns the current number of color scale steps.
Color scale element: one value + one color.
Definition: ecvColorScale.h:22
double getRelativePos() const
Returns step position (relative to scale boundaries)
Definition: ecvColorScale.h:38
QSharedPointer< ccColorScale > Shared
Shared pointer type.
Definition: ecvColorScale.h:74
QSharedPointer< ColorScaleElementSliders > SharedColorScaleElementSliders
Shared set of color scale elements (widgets)
int indexOf(T *arr, int n, const T &what)
Definition: StaticVector.h:160
constexpr Rgb black(0, 0, 0)