1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: XGUI_ColorDialog.cpp
4 // Created: 27 Apr 2015
5 // Author: Natalia ERMOLAEVA
7 #include <XGUI_ColorDialog.h>
9 #include <ModelAPI_Tools.h>
11 #include <QtxColorButton.h>
14 #include <QButtonGroup>
15 #include <QGridLayout>
16 #include <QRadioButton>
17 #include <QDialogButtonBox>
19 XGUI_ColorDialog::XGUI_ColorDialog(QWidget* theParent)
22 setWindowTitle("Color");
23 QGridLayout* aLay = new QGridLayout(this);
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);
33 aLay->addWidget(aColorChoiceBtn, 0, 0);
34 aLay->addWidget(aRandomChoiceBtn, 1, 0);
36 myColorButton = new QtxColorButton(this);
37 myColorButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
38 aLay->addWidget(myColorButton, 0, 1);
40 QLabel* aRandomLabel = new QLabel("Random", this);
41 aLay->addWidget(aRandomLabel, 1, 1);
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);
50 bool XGUI_ColorDialog::isRandomColor() const
52 int anId = myButtonGroup->checkedId();
54 return myButtonGroup->checkedId() == 1;
57 void XGUI_ColorDialog::setColor(const std::vector<int>& theValue)
59 if (theValue.size() != 3)
62 myColorButton->setColor(QColor(theValue[0], theValue[1], theValue[2]));
65 std::vector<int> XGUI_ColorDialog::getColor() const
67 std::vector<int> aValues;
68 if (isRandomColor()) {
69 ModelAPI_Tools::findRandomColor(aValues);
72 QColor aColorResult = myColorButton->color();
73 aValues.push_back(aColorResult.red());
74 aValues.push_back(aColorResult.green());
75 aValues.push_back(aColorResult.blue());