| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- #pragma once
- //##########################################################################
- //# #
- //# CLOUDCOMPARE #
- //# #
- //# This program is free software; you can redistribute it and/or modify #
- //# it under the terms of the GNU General Public License as published by #
- //# the Free Software Foundation; version 2 or later of the License. #
- //# #
- //# This program is distributed in the hope that it will be useful, #
- //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
- //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
- //# GNU General Public License for more details. #
- //# #
- //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
- //# #
- //##########################################################################
- //Inspired from ccColorScaleEditorWidget by Richard Steffen (LGPL 2.1)
- #include "CCPluginAPI.h"
- //Qt
- #include <QWidget>
- //qCC_db
- #include <ccColorScale.h>
- //! Color scale element as a widget
- class CCPLUGIN_LIB_API ColorScaleElementSlider : public QWidget, public ccColorScaleElement
- {
- Q_OBJECT
- public:
- //! Default constructor
- ColorScaleElementSlider(double relativePos = 0.0,
- QColor color = Qt::black,
- QWidget* parent = nullptr,
- Qt::Orientation orientation = Qt::Horizontal);
- //! Sets selection state
- inline void setSelected(bool state) { m_selected = state; }
- //! Returns selection state
- inline bool isSelected() const { return m_selected; }
- //! Comparison operator between two (pointers on) color scale elements
- static bool IsSmaller(const ColorScaleElementSlider* e1, const ColorScaleElementSlider* e2)
- {
- return e1->getRelativePos() < e2->getRelativePos();
- }
- protected:
- //inherited from QWidget
- void paintEvent(QPaintEvent* e) override;
- //! Selection state
- bool m_selected;
- //! Widget orientation
- Qt::Orientation m_orientation;
- };
- //! Set of color scale elements (widgets)
- class CCPLUGIN_LIB_API ColorScaleElementSliders
- {
- public:
- //! Type of the set of elements
- using Set = QList<ColorScaleElementSlider*>;
- //! Adds a slider element and sort the whole set
- /** Should be used instead of push_back/push_front!
- **/
- void addSlider(ColorScaleElementSlider* slider);
- //! Returns the size (shortcut)
- inline int size() const { return m_list.size(); }
- //! Sorts the set
- void sort();
- //! Remove all sliders
- void clear();
- //! Remove a given slider
- void removeAt(int i);
- //! Returns the currently selected slider index (or -1 if none)
- int selected() const;
- //! Returns the index of a given slider
- int indexOf(ColorScaleElementSlider* slider);
- //! Returns a given element
- inline ColorScaleElementSlider* element(int index) { return m_list.at(index); }
- //! Returns a given element (const version)
- inline const ColorScaleElementSlider* element(int index) const { return m_list.at(index); }
- //! Return the set of elements
- inline Set& elements() { return m_list; }
- //! Return the set of elements (const version)
- inline const Set& elements() const { return m_list; }
- protected:
- //! Set of elements
- Set m_list;
- };
- //! Shared set of color scale elements (widgets)
- using SharedColorScaleElementSliders = QSharedPointer<ColorScaleElementSliders>;
- //! Base color scale editor (sub)Widget
- /** A widget with a margin (along a preferred orientation)
- **/
- class CCPLUGIN_LIB_API ColorScaleEditorBaseWidget : public QWidget
- {
- Q_OBJECT
- public:
- //! Defautl constructor
- ColorScaleEditorBaseWidget(SharedColorScaleElementSliders sliders,
- Qt::Orientation orientation,
- int margin,
- QWidget* parent = nullptr)
- : QWidget(parent)
- , m_sliders(sliders)
- , m_orientation(orientation)
- , m_margin(margin)
- {}
- //! Returns useful length
- int length() const { return (m_orientation == Qt::Horizontal ? contentsRect().width() : contentsRect().height())-2*m_margin; }
- //! Sets associated sliders set
- virtual void setSliders(SharedColorScaleElementSliders sliders) { m_sliders = sliders; update(); }
- //! Returns orientation
- Qt::Orientation getOrientation() const { return m_orientation; }
- //! Returns margin
- int getMargin() const { return m_margin; }
- protected:
- //! Associated sliders
- SharedColorScaleElementSliders m_sliders;
- //! Orientation
- Qt::Orientation m_orientation;
- //! Margin
- int m_margin;
- };
- //! Color bar widget
- class CCPLUGIN_LIB_API ColorBarWidget : public ColorScaleEditorBaseWidget
- {
- Q_OBJECT
- public:
- //! Default constructor
- ColorBarWidget(SharedColorScaleElementSliders sliders, QWidget* parent = nullptr, Qt::Orientation orientation = Qt::Horizontal);
- Q_SIGNALS:
- //! Signal emitted when the mouse (left) button is clicked
- /** \param relativePos relative click position (between 0 and 1)
- **/
- void pointClicked(double relativePos);
- protected:
- //inherited from QWidget
- void paintEvent(QPaintEvent* e) override;
- void mousePressEvent(QMouseEvent* e) override;
- };
- //! All sliders widget
- class CCPLUGIN_LIB_API SlidersWidget : public ColorScaleEditorBaseWidget
- {
- Q_OBJECT
- public:
- //! Default constructor
- SlidersWidget(SharedColorScaleElementSliders sliders, QWidget* parent = nullptr, Qt::Orientation orientation = Qt::Horizontal);
- //! Manually selects a slider
- void select(int index, bool silent=false);
- //! Adds a new slider widget
- /** \param relativePos slider position (relatively to scale boundaries [0.0,1.0])
- \param color slider color
- \return created slider (pointer on)
- **/
- ColorScaleElementSlider* addNewSlider(double relativePos, QColor color);
- //! Updates slider position
- void updateSliderPos(int index);
- //! Updates all sliders positions
- void updateAllSlidersPos();
- Q_SIGNALS:
- //! Signal emitted when a slider is changed (position or color)
- void sliderModified(int index);
- //! Signal emitted when a slider is selected
- void sliderSelected(int index);
- protected:
- //inherited from QWidget
- void mousePressEvent(QMouseEvent* e) override;
- void mouseMoveEvent(QMouseEvent* e) override;
- //virtual void mouseReleaseEvent(QMouseEvent* e);
- void mouseDoubleClickEvent(QMouseEvent* e) override;
- void resizeEvent(QResizeEvent* e) override;
- };
- //! All sliders labels widget
- class CCPLUGIN_LIB_API SliderLabelWidget : public ColorScaleEditorBaseWidget
- {
- Q_OBJECT
- public:
- //! Default constructor
- SliderLabelWidget(SharedColorScaleElementSliders sliders, QWidget* parent = nullptr, Qt::Orientation orientation = Qt::Horizontal);
- //! Sets text color
- inline void setTextColor(QColor color) { m_textColor = color; }
- //! Sets displayed numbers precision
- inline void setPrecision(int precision) { m_precision = precision; }
- protected:
- //inherited from QWidget
- void paintEvent(QPaintEvent* e) override;
- //! Text color
- QColor m_textColor;
- //! Precision
- int m_precision;
- };
- //! Color scale editor dialog
- class CCPLUGIN_LIB_API ccColorScaleEditorWidget : public ColorScaleEditorBaseWidget
- {
- Q_OBJECT
- public:
- //! Default constructor
- ccColorScaleEditorWidget(QWidget* parent = nullptr, Qt::Orientation orientation = Qt::Horizontal);
- //! Destructor
- ~ccColorScaleEditorWidget() override = default;
- //! Returns the current number of color scale steps
- inline int getStepCount() const { return (m_sliders ? m_sliders->size() : 0); }
- //! Returns a given slider (pointer on)
- inline const ColorScaleElementSlider* getStep(int index) { return m_sliders ? m_sliders->elements().at(index) : nullptr; }
- //! Sets a given slider color
- void setStepColor(int index, QColor color);
- //! Sets a given slider relative position
- void setStepRelativePosition(int index, double relativePos);
- //! Returns currently selected step index
- inline int getSelectedStepIndex() const { return m_sliders ? m_sliders->selected() : -1; }
- //! Sets currently selected step index
- void setSelectedStepIndex(int index, bool silent=false);
- //! Deletes a given step
- /** Warning: first and last steps shouldn't be deleted!
- **/
- void deleteStep(int index);
- //! Exports the current color scale
- void exportColorScale(ccColorScale::Shared& destScale) const;
- //! Imports the current color scale
- void importColorScale(ccColorScale::Shared scale);
- //! Sets whether to show the color elements labels or not
- void showLabels(bool state);
- //! Sets the labels color
- void setLabelColor(QColor color);
- //! Sets the labels precision
- void setLabelPrecision(int precision);
- //inherited from ColorScaleEditorBaseWidget
- void setSliders(SharedColorScaleElementSliders sliders) override;
- Q_SIGNALS:
- //! Signal emitted when a slider is selected
- void stepSelected(int index);
- //! Signal emitted when a slider is modified
- void stepModified(int index);
- protected:
- //! Slot called when a 'point' is clicked on the color bar
- void onPointClicked(double relativePos);
- //! Slot called when a slider is moved or its color is changed
- void onSliderModified(int sliderIndex);
- //! Slot called when a slider is selected
- void onSliderSelected(int sliderIndex);
- protected:
- //! Associated color bar
- ColorBarWidget* m_colorBarWidget;
- //! Associated sliders widget
- SlidersWidget* m_slidersWidget;
- //! Associated (sliders) labels widget
- SliderLabelWidget* m_labelsWidget;
- };
|