From 5c20d6bbdc6a5a530ea2a95a115f003e504e0957 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Sun, 12 Aug 2012 22:55:17 -0300 Subject: [PATCH] 0000630: User-defined defaults for shape colors The default colors for new geometry (light grey + 2px black line) are now a user preference (In Display->Colors properties) --- src/Gui/DlgSettingsViewColor.cpp | 6 ++ src/Gui/DlgSettingsViewColor.ui | 124 ++++++++++++++++++++++--- src/Gui/ViewProviderGeometryObject.cpp | 10 +- src/Mod/Part/Gui/ViewProviderExt.cpp | 11 ++- 4 files changed, 132 insertions(+), 19 deletions(-) diff --git a/src/Gui/DlgSettingsViewColor.cpp b/src/Gui/DlgSettingsViewColor.cpp index aff8c50676..2bba4faac7 100644 --- a/src/Gui/DlgSettingsViewColor.cpp +++ b/src/Gui/DlgSettingsViewColor.cpp @@ -71,6 +71,9 @@ void DlgSettingsViewColor::saveSettings() EditedVertexColor->onSave(); ConstructionColor->onSave(); FullyConstrainedColor->onSave(); + DefaultShapeColor->onSave(); + DefaultShapeLineColor->onSave(); + DefaultShapeLineWidth->onSave(); } void DlgSettingsViewColor::loadSettings() @@ -91,6 +94,9 @@ void DlgSettingsViewColor::loadSettings() EditedVertexColor->onRestore(); ConstructionColor->onRestore(); FullyConstrainedColor->onRestore(); + DefaultShapeColor->onRestore(); + DefaultShapeLineColor->onRestore(); + DefaultShapeLineWidth->onRestore(); } /** diff --git a/src/Gui/DlgSettingsViewColor.ui b/src/Gui/DlgSettingsViewColor.ui index 709e7675b3..bcd5cd44f8 100644 --- a/src/Gui/DlgSettingsViewColor.ui +++ b/src/Gui/DlgSettingsViewColor.ui @@ -361,7 +361,20 @@ Default colors - + + + + Qt::Horizontal + + + + 40 + 20 + + + + + 0 @@ -509,18 +522,98 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - + + + + + + + 240 + 0 + + + + Default shape color + + + + + + + The default color for new shapes + + + + 204 + 204 + 204 + + + + DefaultShapeColor + + + View + + + + + + + + + + + + 182 + 0 + + + + Default line width and color + + + + + + + The default line color for new shapes + + + + 25 + 25 + 25 + + + + DefaultShapeLineColor + + + View + + + + + + + The default line thickness for new shapes + + + px + + + 2 + + + DefaultShapeLineWidth + + + View + + + + @@ -533,6 +626,11 @@ QPushButton
Gui/Widgets.h
+ + Gui::PrefSpinBox + QSpinBox +
Gui/PrefWidgets.h
+
Gui::PrefColorButton Gui::ColorButton diff --git a/src/Gui/ViewProviderGeometryObject.cpp b/src/Gui/ViewProviderGeometryObject.cpp index 4e17a85e15..4b5b33c3aa 100644 --- a/src/Gui/ViewProviderGeometryObject.cpp +++ b/src/Gui/ViewProviderGeometryObject.cpp @@ -63,14 +63,17 @@ using namespace Gui; - PROPERTY_SOURCE(Gui::ViewProviderGeometryObject, Gui::ViewProviderDocumentObject) const App::PropertyIntegerConstraint::Constraints intPercent = {0,100,1}; ViewProviderGeometryObject::ViewProviderGeometryObject() : pcBoundSwitch(0) { - ADD_PROPERTY(ShapeColor,(0.8f,0.8f,0.8f)); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); + unsigned long shcol = hGrp->GetUnsigned("DefaultShapeColor",3435973887UL); // light gray (204,204,204) + float r,g,b; + 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); App::Material mat(App::Material::DEFAULT); @@ -86,7 +89,8 @@ ViewProviderGeometryObject::ViewProviderGeometryObject() : pcBoundSwitch(0) pcShapeMaterial = new SoMaterial; pcShapeMaterial->ref(); - ShapeMaterial.touch(); + //ShapeMaterial.touch(); materials are rarely used, so better to initialize with default shape color + ShapeColor.touch(); pcBoundingBox = new Gui::SoFCBoundingBox; pcBoundingBox->ref(); diff --git a/src/Mod/Part/Gui/ViewProviderExt.cpp b/src/Mod/Part/Gui/ViewProviderExt.cpp index 1c25848136..b066476ebf 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.cpp +++ b/src/Mod/Part/Gui/ViewProviderExt.cpp @@ -125,9 +125,14 @@ ViewProviderPartExt::ViewProviderPartExt() { VisualTouched = true; + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); + unsigned long lcol = hGrp->GetUnsigned("DefaultShapeLineColor",421075455UL); // dark grey (25,25,25) + float r,g,b; + r = ((lcol >> 24) & 0xff) / 255.0; g = ((lcol >> 16) & 0xff) / 255.0; b = ((lcol >> 8) & 0xff) / 255.0; + int lwidth = hGrp->GetInt("DefaultShapeLineWidth",2); App::Material mat; mat.ambientColor.set(0.2f,0.2f,0.2f); - mat.diffuseColor.set(0.1f,0.1f,0.1f); + mat.diffuseColor.set(r,g,b); mat.specularColor.set(0.0f,0.0f,0.0f); mat.emissiveColor.set(0.0f,0.0f,0.0f); mat.shininess = 1.0f; @@ -137,10 +142,10 @@ ViewProviderPartExt::ViewProviderPartExt() ADD_PROPERTY(LineColor,(mat.diffuseColor)); ADD_PROPERTY(PointColor,(mat.diffuseColor)); ADD_PROPERTY(DiffuseColor,(ShapeColor.getValue())); - ADD_PROPERTY(LineWidth,(2.0f)); + ADD_PROPERTY(LineWidth,(lwidth)); LineWidth.setConstraints(&sizeRange); PointSize.setConstraints(&sizeRange); - ADD_PROPERTY(PointSize,(2.0f)); + ADD_PROPERTY(PointSize,(lwidth)); ADD_PROPERTY(Deviation,(0.5f)); Deviation.setConstraints(&tessRange); ADD_PROPERTY(ControlPoints,(false));