Salome HOME
Issue #1015: The validate icon must be greyed and inactive instead of red and active
[modules/shaper.git] / src / XGUI / XGUI_ColorDialog.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        XGUI_ColorDialog.cpp
4 // Created:     27 Apr 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include <XGUI_ColorDialog.h>
8
9 #include <ModelAPI_Tools.h>
10
11 #include <QtxColorButton.h>
12
13 #include <QLabel>
14 #include <QButtonGroup>
15 #include <QGridLayout>
16 #include <QRadioButton>
17 #include <QDialogButtonBox>
18
19 XGUI_ColorDialog::XGUI_ColorDialog(QWidget* theParent)
20   : QDialog(theParent)
21 {
22   setWindowTitle("Color");
23   QGridLayout* aLay = new QGridLayout(this);
24
25   QRadioButton* aRandomChoiceBtn = new QRadioButton(this);
26   QRadioButton* aColorChoiceBtn = new QRadioButton(this);
27   aColorChoiceBtn->setChecked(true);
28   myButtonGroup = new QButtonGroup(this);
29   myButtonGroup->setExclusive(true);
30   myButtonGroup->addButton(aColorChoiceBtn, 0);
31   myButtonGroup->addButton(aRandomChoiceBtn, 1);
32
33   aLay->addWidget(aColorChoiceBtn, 0, 0);
34   aLay->addWidget(aRandomChoiceBtn, 1, 0);
35
36   myColorButton = new QtxColorButton(this);
37   myColorButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
38   aLay->addWidget(myColorButton, 0, 1);
39
40   QLabel* aRandomLabel = new QLabel("Random", this);
41   aLay->addWidget(aRandomLabel, 1, 1);
42
43   QDialogButtonBox* aButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
44                                                     Qt::Horizontal, this);
45   connect(aButtons, SIGNAL(accepted()), this, SLOT(accept()));
46   connect(aButtons, SIGNAL(rejected()), this, SLOT(reject()));
47   aLay->addWidget(aButtons, 2, 0, 1, 2);
48 }
49
50 bool XGUI_ColorDialog::isRandomColor() const
51 {
52   int anId = myButtonGroup->checkedId();
53
54   return myButtonGroup->checkedId() == 1;
55 }
56
57 void XGUI_ColorDialog::setColor(const std::vector<int>& theValue)
58 {
59   if (theValue.size() != 3)
60     return;
61
62   myColorButton->setColor(QColor(theValue[0], theValue[1], theValue[2]));
63 }
64
65 std::vector<int> XGUI_ColorDialog::getColor() const
66 {
67   QColor aColorResult = myColorButton->color();
68
69   std::vector<int> aValues;
70   aValues.push_back(aColorResult.red());
71   aValues.push_back(aColorResult.green());
72   aValues.push_back(aColorResult.blue());
73
74   return aValues;
75 }
76
77 std::vector<int> XGUI_ColorDialog::getRandomColor() const
78 {
79   std::vector<int> aValues;
80   if (isRandomColor()) {
81     ModelAPI_Tools::findRandomColor(aValues);
82   }
83   return aValues;
84 }