ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvColorGradientDlg.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 
8 #include "ecvColorGradientDlg.h"
9 
10 // common
11 #include <ecvQtHelpers.h>
12 
13 // Qt
14 #include <QColorDialog>
15 
16 // system
17 #include <assert.h>
18 
19 // persistent parameters
20 static QColor s_firstColor(Qt::black);
21 static QColor s_secondColor(Qt::white);
23 static double s_lastFreq = 5.0;
24 static int s_lastDimIndex = 2;
25 
27  : QDialog(parent, Qt::Tool), Ui::ColorGradientDialog() {
28  setupUi(this);
29 
30  connect(firstColorButton, &QAbstractButton::clicked, this,
32  connect(secondColorButton, &QAbstractButton::clicked, this,
34 
35  // restore previous parameters
36  ccQtHelpers::SetButtonColor(secondColorButton, s_secondColor);
37  ccQtHelpers::SetButtonColor(firstColorButton, s_firstColor);
39  bandingFreqSpinBox->setValue(s_lastFreq);
40  directionComboBox->setCurrentIndex(s_lastDimIndex);
41 }
42 
43 unsigned char ccColorGradientDlg::getDimension() const {
44  s_lastDimIndex = directionComboBox->currentIndex();
45  return static_cast<unsigned char>(s_lastDimIndex);
46 }
47 
49  switch (type) {
50  case Default:
51  defaultRampRadioButton->setChecked(true);
52  break;
53  case TwoColors:
54  customRampRadioButton->setChecked(true);
55  break;
56  case Banding:
57  bandingRadioButton->setChecked(true);
58  break;
59  default:
60  assert(false);
61  }
62 }
63 
65  // ugly hack: we use 's_lastType' here as the type is only requested
66  // when the dialog is accepted
67  if (customRampRadioButton->isChecked())
69  else if (bandingRadioButton->isChecked())
71  else
73 
74  return s_lastType;
75 }
76 
77 void ccColorGradientDlg::getColors(QColor& first, QColor& second) const {
78  assert(customRampRadioButton->isChecked());
79  first = s_firstColor;
80  second = s_secondColor;
81 }
82 
84  // ugly hack: we use 's_lastFreq' here as the frequency is only requested
85  // when the dialog is accepted
86  s_lastFreq = bandingFreqSpinBox->value();
87  return s_lastFreq;
88 }
89 
91  QColor newCol = QColorDialog::getColor(s_firstColor, this);
92  if (newCol.isValid()) {
93  s_firstColor = newCol;
94  ccQtHelpers::SetButtonColor(firstColorButton, s_firstColor);
95  }
96 }
97 
99  QColor newCol = QColorDialog::getColor(s_secondColor, this);
100  if (newCol.isValid()) {
101  s_secondColor = newCol;
102  ccQtHelpers::SetButtonColor(secondColorButton, s_secondColor);
103  }
104 }
char type
double getBandingFrequency() const
Returns the frequency of the gradient ('Banding' mode)
GradientType
Gradient types.
void getColors(QColor &first, QColor &second) const
Returns the two colors of the gradient ('TwoColors' mode)
ccColorGradientDlg(QWidget *parent)
Default constructor.
unsigned char getDimension() const
Returns the ramp dimension.
void setType(GradientType type)
Sets the currently activated type.
GradientType getType() const
Returns selected gradient type.
static void SetButtonColor(QAbstractButton *button, const QColor &col)
Sets a button background color.
Definition: ecvQtHelpers.h:17
static ccColorGradientDlg::GradientType s_lastType(ccColorGradientDlg::Default)
static int s_lastDimIndex
static QColor s_firstColor(Qt::black)
static QColor s_secondColor(Qt::white)
static double s_lastFreq
constexpr Rgb black(0, 0, 0)
constexpr Rgb white(MAX, MAX, MAX)