File: ccColorGradientDlg.cpp

package info (click to toggle)
cloudcompare 2.10.1-2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 55,916 kB
  • sloc: cpp: 219,837; ansic: 29,944; makefile: 67; sh: 45
file content (124 lines) | stat: -rw-r--r-- 3,928 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//##########################################################################
//#                                                                        #
//#                              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)             #
//#                                                                        #
//##########################################################################

#include "ccColorGradientDlg.h"

//common
#include <ccQtHelpers.h>

//Qt
#include <QColorDialog>

//system
#include <assert.h>

//persistent parameters
static QColor s_firstColor(Qt::black);
static QColor s_secondColor(Qt::white);
static ccColorGradientDlg::GradientType s_lastType(ccColorGradientDlg::Default);
static double s_lastFreq = 5.0;
static int s_lastDimIndex = 2;

ccColorGradientDlg::ccColorGradientDlg(QWidget* parent)
	: QDialog(parent, Qt::Tool)
	, Ui::ColorGradientDialog()
{
	setupUi(this);

	connect(firstColorButton, &QAbstractButton::clicked, this, &ccColorGradientDlg::changeFirstColor);
	connect(secondColorButton, &QAbstractButton::clicked, this, &ccColorGradientDlg::changeSecondColor);

	//restore previous parameters
	ccQtHelpers::SetButtonColor(secondColorButton, s_secondColor);
	ccQtHelpers::SetButtonColor(firstColorButton, s_firstColor);
	setType(s_lastType);
	bandingFreqSpinBox->setValue(s_lastFreq);
	directionComboBox->setCurrentIndex(s_lastDimIndex);
}

unsigned char ccColorGradientDlg::getDimension() const
{
	s_lastDimIndex = directionComboBox->currentIndex();
	return static_cast<unsigned char>(s_lastDimIndex);
}

void ccColorGradientDlg::setType(ccColorGradientDlg::GradientType type)
{
	switch(type)
	{
	case Default:
		defaultRampRadioButton->setChecked(true);
		break;
	case TwoColors:
		customRampRadioButton->setChecked(true);
		break;
	case Banding:
		bandingRadioButton->setChecked(true);
		break;
	default:
		assert(false);
	}
}

ccColorGradientDlg::GradientType ccColorGradientDlg::getType() const
{
	//ugly hack: we use 's_lastType' here as the type is only requested
	//when the dialog is accepted
	if (customRampRadioButton->isChecked())
		s_lastType = TwoColors;
	else if (bandingRadioButton->isChecked())
		s_lastType = Banding;
	else
		s_lastType = Default;

	return s_lastType;
}

void ccColorGradientDlg::getColors(QColor& first, QColor& second) const
{
	assert(customRampRadioButton->isChecked());
	first = s_firstColor;
	second = s_secondColor;
}

double ccColorGradientDlg::getBandingFrequency() const
{
	//ugly hack: we use 's_lastFreq' here as the frequency is only requested
	//when the dialog is accepted
	s_lastFreq = bandingFreqSpinBox->value();
	return s_lastFreq;
}

void ccColorGradientDlg::changeFirstColor()
{
	QColor newCol = QColorDialog::getColor(s_firstColor, this);
	if (newCol.isValid())
	{
		s_firstColor = newCol;
		ccQtHelpers::SetButtonColor(firstColorButton, s_firstColor);
	}
}

void ccColorGradientDlg::changeSecondColor()
{
	QColor newCol = QColorDialog::getColor(s_secondColor, this);
	if (newCol.isValid())
	{
		s_secondColor = newCol;
		ccQtHelpers::SetButtonColor(secondColorButton, s_secondColor);
	}
}