From 0dead4b18211b5a2f4842be24943093cea1076e0 Mon Sep 17 00:00:00 2001 From: Arne Schmidt Date: Thu, 1 Mar 2018 01:26:51 +0100 Subject: [PATCH 1/2] 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) + + From 373a594eb1c5cb0721d5adfcd94a258c74c3c647 Mon Sep 17 00:00:00 2001 From: dulouie Date: Thu, 1 Mar 2018 21:48:15 +0100 Subject: [PATCH 2/2] fix small layout issues --- src/Gui/ViewProviderGeometryObject.cpp | 5 +- src/Mod/Part/Gui/DlgSettingsObjectColor.ui | 257 +++++++++++---------- 2 files changed, 136 insertions(+), 126 deletions(-) diff --git a/src/Gui/ViewProviderGeometryObject.cpp b/src/Gui/ViewProviderGeometryObject.cpp index f71911c01c..5b95d2f318 100644 --- a/src/Gui/ViewProviderGeometryObject.cpp +++ b/src/Gui/ViewProviderGeometryObject.cpp @@ -77,9 +77,10 @@ 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"); - bool randomColor = hGrp->GetBool("randomColor", true); + bool randomColor = hGrp->GetBool("RandomColor", true); float r,g,b; - if(randomColor){ // random box checked + + if(randomColor){ float fMax = (float)RAND_MAX; r = (float)rand()/fMax; g = (float)rand()/fMax; diff --git a/src/Mod/Part/Gui/DlgSettingsObjectColor.ui b/src/Mod/Part/Gui/DlgSettingsObjectColor.ui index cfe4124ad6..43b8269e15 100644 --- a/src/Mod/Part/Gui/DlgSettingsObjectColor.ui +++ b/src/Mod/Part/Gui/DlgSettingsObjectColor.ui @@ -6,8 +6,8 @@ 0 0 - 332 - 331 + 476 + 395
@@ -22,6 +22,32 @@ + + + + + 182 + 0 + + + + Default vertex color + + + + + + + + 182 + 0 + + + + Bounding box color + + + @@ -35,45 +61,12 @@ - - - - The default color for new shapes - - - - 204 - 204 - 204 - - - - DefaultShapeColor - - - View - - - - - - - - 182 - 0 - - - - Default line color - - - The default line color for new shapes - + 25 25 @@ -88,16 +81,23 @@ - - - - - 182 - 0 - + + + + The default color for new shapes - - Default line width + + + 204 + 204 + 204 + + + + DefaultShapeColor + + + View @@ -123,52 +123,6 @@ - - - - - 182 - 0 - - - - Default vertex color - - - - - - - The default line color for new shapes - - - - 25 - 25 - 25 - - - - DefaultShapeVertexColor - - - View - - - - - - - - 182 - 0 - - - - Default vertex size - - - @@ -191,25 +145,12 @@ - - - - - 182 - 0 - - - - Bounding box color - - - The color of bounding boxes in the 3D view - + 255 255 @@ -224,6 +165,81 @@ + + + + + 182 + 0 + + + + Default vertex size + + + + + + + + 182 + 0 + + + + Default line width + + + + + + + + 182 + 0 + + + + Default line color + + + + + + + The default line color for new shapes + + + + 25 + 25 + 25 + + + + DefaultShapeVertexColor + + + View + + + + + + + random shapecolor + + + true + + + RandomColor + + + View + + + @@ -292,22 +308,6 @@ - - - - random shapecolor - - - randomColor - - - View - - - - -
- Qt::Vertical @@ -346,18 +346,27 @@ DefaultShapeColor - checkRandomColor DefaultShapeLineWidth DefaultShapeLineColor BoundingBoxColor - + checkRandomColor toggled(bool) DefaultShapeColor setDisabled(bool) + + + 20 + 20 + + + 20 + 20 + + - +