From d289e2b8f76041be971179267ae9e5e8df356568 Mon Sep 17 00:00:00 2001 From: Roy-043 Date: Sun, 24 Mar 2024 09:58:51 +0100 Subject: [PATCH] Let param observer trigger grid color change If you change the grid color in the preferences and cick the Apply button, the color of all grids is updated now. So you can experiment while the Preferences Editor is open. I have kept but moved the grid color button in the Draft_SelectPlane task panel for now. So that both options can be tested. --- src/Mod/Draft/Resources/ui/TaskSelectPlane.ui | 24 ++++++++----------- .../Draft/draftguitools/gui_selectplane.py | 12 ++++------ src/Mod/Draft/draftguitools/gui_trackers.py | 9 ++----- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/Mod/Draft/Resources/ui/TaskSelectPlane.ui b/src/Mod/Draft/Resources/ui/TaskSelectPlane.ui index b744c1c377..16cb11103b 100644 --- a/src/Mod/Draft/Resources/ui/TaskSelectPlane.ui +++ b/src/Mod/Draft/Resources/ui/TaskSelectPlane.ui @@ -153,6 +153,16 @@ will be moved to the center of the view + + + + Grid color + + + + + + @@ -243,20 +253,6 @@ value by using the [ and ] keys while drawing - - - - - - Grid color - - - - - - - - diff --git a/src/Mod/Draft/draftguitools/gui_selectplane.py b/src/Mod/Draft/draftguitools/gui_selectplane.py index ea0b99d515..a229eac03c 100644 --- a/src/Mod/Draft/draftguitools/gui_selectplane.py +++ b/src/Mod/Draft/draftguitools/gui_selectplane.py @@ -37,6 +37,7 @@ import WorkingPlane from FreeCAD import Units from drafttaskpanels import task_selectplane from draftutils import params +from draftutils import utils from draftutils.messages import _msg from draftutils.todo import todo from draftutils.translate import translate @@ -112,12 +113,9 @@ class Draft_SelectPlane: form.buttonPrevious.setIcon(QtGui.QIcon(":/icons/sel-back.svg")) form.buttonNext.setIcon(QtGui.QIcon(":/icons/sel-forward.svg")) - # color and transparency + # Grid color color = params.get_param("gridColor") - r = ((color >> 24) & 0xFF) / 255.0 - g = ((color >> 16) & 0xFF) / 255.0 - b = ((color >> 8) & 0xFF) / 255.0 - form.buttonColor.setProperty("color", QtGui.QColor.fromRgbF(r, g, b)) + form.buttonColor.setProperty("color", QtGui.QColor(utils.rgba_to_argb(color))) # Connect slots form.buttonTop.clicked.connect(self.on_click_top) @@ -285,10 +283,8 @@ class Draft_SelectPlane: Gui.Snapper.showradius() def on_color_changed(self): - color = self.taskd.form.buttonColor.property("color").rgb() << 8 + color = utils.argb_to_rgba(self.taskd.form.buttonColor.property("color").rgba()) params.set_param("gridColor", color) - if self.grid is not None: - self.grid.update() Gui.addCommand('Draft_SelectPlane', Draft_SelectPlane()) diff --git a/src/Mod/Draft/draftguitools/gui_trackers.py b/src/Mod/Draft/draftguitools/gui_trackers.py index a99a7a3701..2f5e9e31f5 100644 --- a/src/Mod/Draft/draftguitools/gui_trackers.py +++ b/src/Mod/Draft/draftguitools/gui_trackers.py @@ -42,7 +42,6 @@ import FreeCAD import FreeCADGui import Draft import DraftVecUtils -import WorkingPlane from FreeCAD import Vector from draftutils import params from draftutils import utils @@ -1173,12 +1172,12 @@ class gridTracker(Tracker): self.coords3.point.setValues(apts) #self.lines3.numVertices.setValues(aidx) self.pts = pts + # update the grid colors col, red, green, blue, gtrans = self.getGridColors() self.mat1.diffuseColor.setValue(col) self.mat2.diffuseColor.setValue(col) self.mat3.diffuseColor.setValues([col,red,green,blue]) - self.setAxesColor() def getGridColors(self): """Returns grid colors stored in the preferences""" @@ -1222,12 +1221,8 @@ class gridTracker(Tracker): self.coords_human.point.setValues(pts) self.human.numVertices.setValues(pidx) - def setAxesColor(self, wp=None): + def setAxesColor(self, wp): """set axes color""" - if not wp: - wp = getattr(FreeCAD, "DraftWorkingPlane", None) - if not wp: - wp = WorkingPlane.plane() cols = [0,0] if params.get_param("coloredGridAxes"): if round(wp.u.getAngle(FreeCAD.Vector(1,0,0)),2) in (0,3.14):