ccColorGradientDlg.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //##########################################################################
  2. //# #
  3. //# CLOUDCOMPARE #
  4. //# #
  5. //# This program is free software; you can redistribute it and/or modify #
  6. //# it under the terms of the GNU General Public License as published by #
  7. //# the Free Software Foundation; version 2 or later of the License. #
  8. //# #
  9. //# This program is distributed in the hope that it will be useful, #
  10. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  11. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  12. //# GNU General Public License for more details. #
  13. //# #
  14. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  15. //# #
  16. //##########################################################################
  17. #include "ccColorGradientDlg.h"
  18. //common
  19. #include <ccQtHelpers.h>
  20. //Qt
  21. #include <QColorDialog>
  22. //system
  23. #include <assert.h>
  24. //persistent parameters
  25. static QColor s_firstColor(Qt::black);
  26. static QColor s_secondColor(Qt::white);
  27. static ccColorGradientDlg::GradientType s_lastType(ccColorGradientDlg::Default);
  28. static double s_lastFreq = 5.0;
  29. static int s_lastDimIndex = 2;
  30. ccColorGradientDlg::ccColorGradientDlg(QWidget* parent)
  31. : QDialog(parent, Qt::Tool)
  32. , Ui::ColorGradientDialog()
  33. {
  34. setupUi(this);
  35. connect(firstColorButton, &QAbstractButton::clicked, this, &ccColorGradientDlg::changeFirstColor);
  36. connect(secondColorButton, &QAbstractButton::clicked, this, &ccColorGradientDlg::changeSecondColor);
  37. //restore previous parameters
  38. ccQtHelpers::SetButtonColor(secondColorButton, s_secondColor);
  39. ccQtHelpers::SetButtonColor(firstColorButton, s_firstColor);
  40. setType(s_lastType);
  41. bandingFreqSpinBox->setValue(s_lastFreq);
  42. directionComboBox->setCurrentIndex(s_lastDimIndex);
  43. }
  44. unsigned char ccColorGradientDlg::getDimension() const
  45. {
  46. s_lastDimIndex = directionComboBox->currentIndex();
  47. return static_cast<unsigned char>(s_lastDimIndex);
  48. }
  49. void ccColorGradientDlg::setType(ccColorGradientDlg::GradientType type)
  50. {
  51. switch(type)
  52. {
  53. case Default:
  54. defaultRampRadioButton->setChecked(true);
  55. break;
  56. case TwoColors:
  57. customRampRadioButton->setChecked(true);
  58. break;
  59. case Banding:
  60. bandingRadioButton->setChecked(true);
  61. break;
  62. default:
  63. assert(false);
  64. }
  65. }
  66. ccColorGradientDlg::GradientType ccColorGradientDlg::getType() const
  67. {
  68. //ugly hack: we use 's_lastType' here as the type is only requested
  69. //when the dialog is accepted
  70. if (customRampRadioButton->isChecked())
  71. s_lastType = TwoColors;
  72. else if (bandingRadioButton->isChecked())
  73. s_lastType = Banding;
  74. else
  75. s_lastType = Default;
  76. return s_lastType;
  77. }
  78. void ccColorGradientDlg::getColors(QColor& first, QColor& second) const
  79. {
  80. assert(customRampRadioButton->isChecked());
  81. first = s_firstColor;
  82. second = s_secondColor;
  83. }
  84. double ccColorGradientDlg::getBandingFrequency() const
  85. {
  86. //ugly hack: we use 's_lastFreq' here as the frequency is only requested
  87. //when the dialog is accepted
  88. s_lastFreq = bandingFreqSpinBox->value();
  89. return s_lastFreq;
  90. }
  91. void ccColorGradientDlg::changeFirstColor()
  92. {
  93. QColor newCol = QColorDialog::getColor(s_firstColor, this);
  94. if (newCol.isValid())
  95. {
  96. s_firstColor = newCol;
  97. ccQtHelpers::SetButtonColor(firstColorButton, s_firstColor);
  98. }
  99. }
  100. void ccColorGradientDlg::changeSecondColor()
  101. {
  102. QColor newCol = QColorDialog::getColor(s_secondColor, this);
  103. if (newCol.isValid())
  104. {
  105. s_secondColor = newCol;
  106. ccQtHelpers::SetButtonColor(secondColorButton, s_secondColor);
  107. }
  108. }