From 767d23b987f457f215c1ce550cf0d2e384162f7c Mon Sep 17 00:00:00 2001 From: Arne Schmidt Date: Thu, 1 Mar 2018 01:26:51 +0100 Subject: [PATCH] random shapecolor with toggle in settings dialog --- src/Gui/ViewProviderGeometryObject.cpp | 16 +++++++++-- src/Mod/Part/Gui/DlgSettingsObjectColor.cpp | 3 ++ src/Mod/Part/Gui/DlgSettingsObjectColor.ui | 31 ++++++++++++++++++++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/Gui/ViewProviderGeometryObject.cpp b/src/Gui/ViewProviderGeometryObject.cpp index 96ae294826..f71911c01c 100644 --- a/src/Gui/ViewProviderGeometryObject.cpp +++ b/src/Gui/ViewProviderGeometryObject.cpp @@ -77,9 +77,21 @@ const App::PropertyIntegerConstraint::Constraints intPercent = {0,100,1}; ViewProviderGeometryObject::ViewProviderGeometryObject() : pcBoundSwitch(0),pcBoundColor(0) { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); - unsigned long shcol = hGrp->GetUnsigned("DefaultShapeColor",3435973887UL); // light gray (204,204,204) + bool randomColor = hGrp->GetBool("randomColor", true); float r,g,b; - r = ((shcol >> 24) & 0xff) / 255.0; g = ((shcol >> 16) & 0xff) / 255.0; b = ((shcol >> 8) & 0xff) / 255.0; + if(randomColor){ // random box checked + float fMax = (float)RAND_MAX; + r = (float)rand()/fMax; + g = (float)rand()/fMax; + b = (float)rand()/fMax; + } + else { + unsigned long shcol = hGrp->GetUnsigned("DefaultShapeColor",3435973887UL); // light gray (204,204,204) + r = ((shcol >> 24) & 0xff) / 255.0; + g = ((shcol >> 16) & 0xff) / 255.0; + b = ((shcol >> 8) & 0xff) / 255.0; + } + ADD_PROPERTY(ShapeColor,(r, g, b)); ADD_PROPERTY(Transparency,(0)); Transparency.setConstraints(&intPercent); diff --git a/src/Mod/Part/Gui/DlgSettingsObjectColor.cpp b/src/Mod/Part/Gui/DlgSettingsObjectColor.cpp index 31092d00b0..5fa55e98ab 100644 --- a/src/Mod/Part/Gui/DlgSettingsObjectColor.cpp +++ b/src/Mod/Part/Gui/DlgSettingsObjectColor.cpp @@ -41,6 +41,7 @@ DlgSettingsObjectColor::DlgSettingsObjectColor(QWidget* parent) : PreferencePage(parent) { this->setupUi(this); + this->DefaultShapeColor->setDisabled(this->checkRandomColor->isChecked()); } /** @@ -55,6 +56,7 @@ void DlgSettingsObjectColor::saveSettings() { // Part DefaultShapeColor->onSave(); + checkRandomColor->onSave(); DefaultShapeLineColor->onSave(); DefaultShapeLineWidth->onSave(); DefaultShapeVertexColor->onSave(); @@ -68,6 +70,7 @@ void DlgSettingsObjectColor::loadSettings() { // Part DefaultShapeColor->onRestore(); + checkRandomColor->onRestore(); DefaultShapeLineColor->onRestore(); DefaultShapeLineWidth->onRestore(); DefaultShapeVertexColor->onRestore(); diff --git a/src/Mod/Part/Gui/DlgSettingsObjectColor.ui b/src/Mod/Part/Gui/DlgSettingsObjectColor.ui index 3bbf5d1030..cfe4124ad6 100644 --- a/src/Mod/Part/Gui/DlgSettingsObjectColor.ui +++ b/src/Mod/Part/Gui/DlgSettingsObjectColor.ui @@ -292,6 +292,22 @@ + + + + random shapecolor + + + randomColor + + + View + + + + + + Qt::Vertical @@ -322,13 +338,26 @@ Gui::ColorButton
Gui/PrefWidgets.h
+ + Gui::PrefCheckBox + QCheckBox +
Gui/PrefWidgets.h
+
DefaultShapeColor + checkRandomColor DefaultShapeLineWidth DefaultShapeLineColor BoundingBoxColor - + + + checkRandomColor + toggled(bool) + DefaultShapeColor + setDisabled(bool) + +