From 583b59c29f60d4061be55a92dae37be1a125705a Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Tue, 10 Nov 2020 14:14:18 +0100 Subject: [PATCH] Draft: Condensed the Draft toolbar style buttons into one with more options --- src/Mod/Draft/CMakeLists.txt | 1 + src/Mod/Draft/DraftGui.py | 128 +++++-- src/Mod/Draft/DraftTools.py | 1 + src/Mod/Draft/Resources/Draft.qrc | 1 + .../Draft/Resources/ui/TaskPanel_SetStyle.ui | 315 ++++++++++++++++++ src/Mod/Draft/draftguitools/gui_setstyle.py | 117 +++++++ src/Mod/Draft/draftguitools/gui_snapper.py | 11 +- src/Mod/Draft/draftguitools/gui_trackers.py | 6 +- src/Mod/Draft/draftmake/make_point.py | 2 +- src/Mod/Draft/draftutils/gui_utils.py | 20 +- src/Mod/Draft/draftutils/init_tools.py | 3 +- 11 files changed, 562 insertions(+), 43 deletions(-) create mode 100644 src/Mod/Draft/Resources/ui/TaskPanel_SetStyle.ui create mode 100644 src/Mod/Draft/draftguitools/gui_setstyle.py diff --git a/src/Mod/Draft/CMakeLists.txt b/src/Mod/Draft/CMakeLists.txt index b684d6f33d..8ba6ce8e71 100644 --- a/src/Mod/Draft/CMakeLists.txt +++ b/src/Mod/Draft/CMakeLists.txt @@ -268,6 +268,7 @@ SET(Draft_GUI_tools draftguitools/gui_dimension_ops.py draftguitools/gui_lineslope.py draftguitools/gui_layers.py + draftguitools/gui_setstyle.py ${Creator_tools} ${Modifier_tools} draftguitools/README.md diff --git a/src/Mod/Draft/DraftGui.py b/src/Mod/Draft/DraftGui.py index f6af7743fb..d573da77aa 100644 --- a/src/Mod/Draft/DraftGui.py +++ b/src/Mod/Draft/DraftGui.py @@ -167,11 +167,14 @@ class DraftToolBar: self.taskmode = 1 # Draft.getParam("UiMode",1) # taskmode = 0 was used by draft toolbar that is now obsolete. # print("taskmode: ",str(self.taskmode)) - self.paramcolor = Draft.getParam("color",255)>>8 - self.color = QtGui.QColor(self.paramcolor) - self.facecolor = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeColor",4294967295)>>8 - self.linewidth = Draft.getParam("linewidth",2) - self.fontsize = Draft.getParam("textheight",0.20) + + # OBSOLETE - TO BE REMOVED + #self.paramcolor = Draft.getParam("color",255)>>8 + #self.color = QtGui.QColor(self.paramcolor) + #self.facecolor = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeColor",4294967295)>>8 + #self.linewidth = Draft.getParam("linewidth",2) + #self.fontsize = Draft.getParam("textheight",0.20) + self.paramconstr = Draft.getParam("constructioncolor",746455039)>>8 self.constrMode = False self.continueMode = False @@ -489,6 +492,7 @@ class DraftToolBar: QtCore.QObject.connect(self.textValue,QtCore.SIGNAL("textChanged()"),self.checkEnterText) QtCore.QObject.connect(self.textOkButton,QtCore.SIGNAL("clicked()"),self.sendText) QtCore.QObject.connect(self.zValue,QtCore.SIGNAL("returnPressed()"),self.setFocus) + # Draft Edit UI obsolete due to introduction of incommand context menu # QtCore.QObject.connect(self.addButton,QtCore.SIGNAL("toggled(bool)"),self.setAddMode) # QtCore.QObject.connect(self.delButton,QtCore.SIGNAL("toggled(bool)"),self.setDelMode) @@ -496,6 +500,7 @@ class DraftToolBar: # QtCore.QObject.connect(self.tangentButton,QtCore.SIGNAL("toggled(bool)"),self.setTangentMode) # QtCore.QObject.connect(self.symmetricButton,QtCore.SIGNAL("toggled(bool)"),self.setSymmetricMode) # QtCore.QObject.connect(self.arc3PtButton,QtCore.SIGNAL("toggled(bool)"),self.setArc3PtMode) + QtCore.QObject.connect(self.finishButton,QtCore.SIGNAL("pressed()"),self.finish) QtCore.QObject.connect(self.closeButton,QtCore.SIGNAL("pressed()"),self.closeLine) QtCore.QObject.connect(self.wipeButton,QtCore.SIGNAL("pressed()"),self.wipeLine) @@ -545,35 +550,44 @@ class DraftToolBar: self.wplabel.setText(translate("draft","Side")) else: self.wplabel.setText(translate("draft","Auto")) - self.constrButton = self._pushbutton("constrButton", self.toptray, hide=False, icon='Draft_Construction',checkable=True,square=True) - self.constrColor = QtGui.QColor(self.paramconstr) - self.colorButton = self._pushbutton("colorButton",self.bottomtray, hide=False,square=True) - self.colorPix = QtGui.QPixmap(16,16) - self.colorPix.fill(self.color) - self.colorButton.setIcon(QtGui.QIcon(self.colorPix)) - self.facecolorButton = self._pushbutton("facecolorButton",self.bottomtray, hide=False,square=True) - self.facecolorPix = QtGui.QPixmap(16,16) - self.facecolorPix.fill(QtGui.QColor(self.facecolor)) - self.facecolorButton.setIcon(QtGui.QIcon(self.facecolorPix)) p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/General") bsize = p.GetInt("ToolbarIconSize",24)+2 - self.widthButton = self._spinbox("widthButton", self.bottomtray, val=self.linewidth,hide=False,size=(bsize * 2,bsize)) - self.widthButton.setSuffix("px") - self.fontsizeButton = self._spinbox("fontsizeButton",self.bottomtray, val=self.fontsize,vmax=999, hide=False,double=True,size=(bsize * 4,bsize)) + + # OBSOLETE - replaced by style button + #self.colorButton = self._pushbutton("colorButton",self.bottomtray, hide=False,square=True) + #self.colorPix = QtGui.QPixmap(16,16) + #self.colorPix.fill(self.color) + #self.colorButton.setIcon(QtGui.QIcon(self.colorPix)) + #self.facecolorButton = self._pushbutton("facecolorButton",self.bottomtray, hide=False,square=True) + #self.facecolorPix = QtGui.QPixmap(16,16) + #self.facecolorPix.fill(QtGui.QColor(self.facecolor)) + #self.facecolorButton.setIcon(QtGui.QIcon(self.facecolorPix)) + #self.widthButton = self._spinbox("widthButton", self.bottomtray, val=self.linewidth,hide=False,size=(bsize * 2,bsize)) + #self.widthButton.setSuffix("px") + #self.fontsizeButton = self._spinbox("fontsizeButton",self.bottomtray, val=self.fontsize,vmax=999, hide=False,double=True,size=(bsize * 4,bsize)) + #self.applyButton = self._pushbutton("applyButton", self.toptray, hide=False, icon='Draft_Apply',square=True) + + self.styleButton = self._pushbutton("stylebutton", self.toptray, icon='Draft_Apply',hide=False,width=120) + self.setStyleButton() + + self.constrButton = self._pushbutton("constrButton", self.toptray, hide=False, icon='Draft_Construction',checkable=True,square=True) + self.constrColor = QtGui.QColor(self.paramconstr) self.autoGroupButton = self._pushbutton("autoGroup",self.bottomtray,icon=":/icons/button_invalid.svg",hide=False,width=120) self.autoGroupButton.setText("None") self.autoGroupButton.setFlat(True) - self.applyButton = self._pushbutton("applyButton", self.toptray, hide=False, icon='Draft_Apply',square=True) QtCore.QObject.connect(self.wplabel,QtCore.SIGNAL("pressed()"),self.selectplane) - QtCore.QObject.connect(self.colorButton,QtCore.SIGNAL("pressed()"),self.getcol) - QtCore.QObject.connect(self.facecolorButton,QtCore.SIGNAL("pressed()"),self.getfacecol) - QtCore.QObject.connect(self.widthButton,QtCore.SIGNAL("valueChanged(int)"),self.setwidth) - QtCore.QObject.connect(self.fontsizeButton,QtCore.SIGNAL("valueChanged(double)"),self.setfontsize) - QtCore.QObject.connect(self.applyButton,QtCore.SIGNAL("pressed()"),self.apply) + QtCore.QObject.connect(self.styleButton,QtCore.SIGNAL("pressed()"),self.setstyle) QtCore.QObject.connect(self.constrButton,QtCore.SIGNAL("toggled(bool)"),self.toggleConstrMode) QtCore.QObject.connect(self.autoGroupButton,QtCore.SIGNAL("pressed()"),self.runAutoGroup) + # OBSOLETE - replaced by style button + #QtCore.QObject.connect(self.colorButton,QtCore.SIGNAL("pressed()"),self.getcol) + #QtCore.QObject.connect(self.facecolorButton,QtCore.SIGNAL("pressed()"),self.getfacecol) + #QtCore.QObject.connect(self.widthButton,QtCore.SIGNAL("valueChanged(int)"),self.setwidth) + #QtCore.QObject.connect(self.fontsizeButton,QtCore.SIGNAL("valueChanged(double)"),self.setfontsize) + #QtCore.QObject.connect(self.applyButton,QtCore.SIGNAL("pressed()"),self.apply) + QtCore.QTimer.singleShot(2000,self.retranslateTray) # delay so translations get a chance to load def setupStyle(self): @@ -622,12 +636,15 @@ class DraftToolBar: self.continueCmd.setText(translate("draft", "Continue")+" ("+inCommandShortcuts["Continue"][0]+")") self.occOffset.setToolTip(translate("draft", "If checked, an OCC-style offset will be performed instead of the classic offset")) self.occOffset.setText(translate("draft", "&OCC-style offset")) + + # OBSOLETE # self.addButton.setToolTip(translate("draft", "Add points to the current object")) # self.delButton.setToolTip(translate("draft", "Remove points from the current object")) # self.sharpButton.setToolTip(translate("draft", "Make Bezier node sharp")) # self.tangentButton.setToolTip(translate("draft", "Make Bezier node tangent")) # self.symmetricButton.setToolTip(translate("draft", "Make Bezier node symmetric")) # self.arc3PtButton.setToolTip(translate("draft", "Toggle radius and angles arc editing")) + self.undoButton.setText(translate("draft", "&Undo (CTRL+Z)")) self.undoButton.setToolTip(translate("draft", "Undo the last segment")) self.closeButton.setText(translate("draft", "Close")+" ("+inCommandShortcuts["Close"][0]+")") @@ -677,13 +694,17 @@ class DraftToolBar: def retranslateTray(self,widget=None): self.wplabel.setToolTip(translate("draft", "Current working plane")+":"+self.wplabel.text()) + self.styleButton.setToolTip(translate("draft", "Change default style for new objects")) self.constrButton.setToolTip(translate("draft", "Toggle construction mode")) - self.colorButton.setToolTip(translate("draft", "Current line color")) - self.facecolorButton.setToolTip(translate("draft", "Current face color")) - self.widthButton.setToolTip(translate("draft", "Current line width")) - self.fontsizeButton.setToolTip(translate("draft", "Current font size")) - self.applyButton.setToolTip(translate("draft", "Apply to selected objects")) self.autoGroupButton.setToolTip(translate("draft", "Autogroup off")) + + # OBSOLETE - replaced by style button + #self.colorButton.setToolTip(translate("draft", "Current line color")) + #self.facecolorButton.setToolTip(translate("draft", "Current face color")) + #self.widthButton.setToolTip(translate("draft", "Current line width")) + #self.fontsizeButton.setToolTip(translate("draft", "Current font size")) + #self.applyButton.setToolTip(translate("draft", "Apply to selected objects")) + #--------------------------------------------------------------------------- # Interface modes @@ -913,12 +934,15 @@ class DraftToolBar: self.isRelative.hide() self.hasFill.hide() self.finishButton.hide() + + # OBSOLETE # self.addButton.hide() # self.delButton.hide() # self.sharpButton.hide() # self.tangentButton.hide() # self.symmetricButton.hide() # self.arc3PtButton.hide() + self.undoButton.hide() self.closeButton.hide() self.wipeButton.hide() @@ -1176,6 +1200,8 @@ class DraftToolBar: def getcol(self): """opens a color picker dialog""" + print("draft: warning: getcol() is obsolete") + return oldColor = self.color self.color=QtGui.QColorDialog.getColor(self.color) if not QtGui.QColor.isValid(self.color): #user canceled @@ -1200,6 +1226,8 @@ class DraftToolBar: def getfacecol(self): """opens a color picker dialog""" + print("draft: warning: getfacecol() is obsolete") + return oldColor = self.facecolor self.facecolor=QtGui.QColorDialog.getColor(self.facecolor) if not QtGui.QColor.isValid(self.facecolor): #user canceled @@ -1218,6 +1246,8 @@ class DraftToolBar: i.ViewObject.ShapeColor = col def setwidth(self,val): + print("draft: warning: setwidth() is obsolete") + return self.linewidth = float(val) if Draft.getParam("saveonexit",False): Draft.setParam("linewidth",int(val)) @@ -1226,6 +1256,8 @@ class DraftToolBar: i.ViewObject.LineWidth = float(val) def setfontsize(self,val): + print("draft: warning: setfontsize() is obsolete") + return self.fontsize = float(val) if Draft.getParam("saveonexit",False): Draft.setParam("textheight",float(val)) @@ -1240,6 +1272,8 @@ class DraftToolBar: self.fillmode = bool(val) def apply(self): + print("draft: warning: apply() is obsolete") + return for i in FreeCADGui.Selection.getSelection(): Draft.formatObject(i) @@ -1652,9 +1686,20 @@ class DraftToolBar: g = ((color>>16)&0xFF)/255 b = ((color>>8)&0xFF)/255 elif type == "ui": + print("draft: deprecation warning: Do not use getDefaultColor(\"ui\") anymore - use getDefaultColor(\"line\") instead.") r = float(self.color.red()/255.0) g = float(self.color.green()/255.0) b = float(self.color.blue()/255.0) + elif type == "line": + color = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeLineColor",255) + r = ((color>>24)&0xFF)/255 + g = ((color>>16)&0xFF)/255 + b = ((color>>8)&0xFF)/255 + elif type == "text": + color = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetUnsigned("DefaultTextColor",255) + r = ((color>>24)&0xFF)/255 + g = ((color>>16)&0xFF)/255 + b = ((color>>8)&0xFF)/255 elif type == "face": color = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeColor",4294967295) r = ((color>>24)&0xFF)/255 @@ -1720,6 +1765,31 @@ class DraftToolBar: def selectplane(self): FreeCADGui.runCommand("Draft_SelectPlane") + def setstyle(self): + FreeCADGui.runCommand("Draft_SetStyle") + + def setStyleButton(self): + "sets icon and text on the style button" + linecolor = QtGui.QColor(Draft.getParam("color",255)>>8) + facecolor = QtGui.QColor(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeColor",4294967295)>>8) + im = QtGui.QImage(32,32,QtGui.QImage.Format_ARGB32) + im.fill(QtCore.Qt.transparent) + pt = QtGui.QPainter(im) + pt.setPen(QtGui.QPen(QtCore.Qt.black, 1, QtCore.Qt.SolidLine, QtCore.Qt.FlatCap)) + pt.setBrush(QtGui.QBrush(linecolor, QtCore.Qt.SolidPattern)) + pts = [QtCore.QPointF(4.0,4.0),QtCore.QPointF(4.0,26.0),QtCore.QPointF(26.0,4.0)] + pt.drawPolygon(pts,QtCore.Qt.OddEvenFill) + pt.setBrush(QtGui.QBrush(facecolor, QtCore.Qt.SolidPattern)) + pts = [QtCore.QPointF(28.0,28.0),QtCore.QPointF(8.0,28.0),QtCore.QPointF(28.0,8.0)] + pt.drawPolygon(pts,QtCore.Qt.OddEvenFill) + pt.end() + icon = QtGui.QIcon(QtGui.QPixmap.fromImage(im)) + linewidth = Draft.getParam("linewidth",2) + fontsize = Draft.getParam("textheight",0.20) + txt = str(linewidth)+"px | "+FreeCAD.Units.Quantity(fontsize,FreeCAD.Units.Length).UserString + self.styleButton.setIcon(icon) + self.styleButton.setText(txt) + def popupMenu(self,llist,ilist=None,pos=None): """pops up a menu filled with the given list""" self.groupmenu = QtGui.QMenu() diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py index 05a5cdfd30..f7ec8bdc1e 100644 --- a/src/Mod/Draft/DraftTools.py +++ b/src/Mod/Draft/DraftTools.py @@ -76,6 +76,7 @@ if not hasattr(FreeCAD, "DraftWorkingPlane"): # --------------------------------------------------------------------------- import draftguitools.gui_edit import draftguitools.gui_selectplane +import draftguitools.gui_setstyle import draftguitools.gui_planeproxy from draftguitools.gui_lineops import FinishLine from draftguitools.gui_lineops import CloseLine diff --git a/src/Mod/Draft/Resources/Draft.qrc b/src/Mod/Draft/Resources/Draft.qrc index 86c265d758..f914187b7f 100644 --- a/src/Mod/Draft/Resources/Draft.qrc +++ b/src/Mod/Draft/Resources/Draft.qrc @@ -181,5 +181,6 @@ ui/TaskSelectPlane.ui ui/TaskShapeString.ui ui/dialog_AnnotationStyleEditor.ui + ui/TaskPanel_SetStyle.ui diff --git a/src/Mod/Draft/Resources/ui/TaskPanel_SetStyle.ui b/src/Mod/Draft/Resources/ui/TaskPanel_SetStyle.ui new file mode 100644 index 0000000000..99cfb93ea7 --- /dev/null +++ b/src/Mod/Draft/Resources/ui/TaskPanel_SetStyle.ui @@ -0,0 +1,315 @@ + + + Form + + + + 0 + 0 + 251 + 461 + + + + Style settings + + + + + + + + Text color + + + + + + + Shape color + + + + + + + Line width + + + + + + + The color of faces + + + + + + + The type of dimension arrows + + + + Dot + + + + + Circle + + + + + Arrow + + + + + Tick + + + + + Tick-2 + + + + + + + + The color of texts and dimension texts + + + + + + + The size of texts and dimension texts + + + + + + + + + + Show unit + + + + + + + Line color + + + + + + + The size of dimension arrows + + + + + + + + + + + 0 + 0 + + + + The font to use for texts and dimensions + + + + + + + The line style + + + + Solid + + + + + Dashed + + + + + Dotted + + + + + DashDot + + + + + + + + Text size + + + + + + + Unit override + + + + + + + If the unit siffix is shown on dimension texts or not + + + Qt::RightToLeft + + + + + + + + + + The unit to use for dimensions. Leave blank to use current FreeCAD unit + + + + + + + The transparency of faces + + + % + + + 100 + + + + + + + Transparency + + + + + + + Display mode + + + + + + + Text font + + + + + + + Arrow size + + + + + + + The display mode for faces + + + + Flat Lines + + + + + Wireframe + + + + + Shaded + + + + + Points + + + + + + + + Draw style + + + + + + + The color of lines + + + + + + + Arrow style + + + + + + + px + + + + + + + + + Apply to selected objects + + + + + + + + Gui::InputField + QLineEdit +
Gui/InputField.h
+
+ + Gui::ColorButton + QPushButton +
Gui/Widgets.h
+
+
+ + +
diff --git a/src/Mod/Draft/draftguitools/gui_setstyle.py b/src/Mod/Draft/draftguitools/gui_setstyle.py new file mode 100644 index 0000000000..23c8a999c5 --- /dev/null +++ b/src/Mod/Draft/draftguitools/gui_setstyle.py @@ -0,0 +1,117 @@ +# *************************************************************************** +# * Copyright (c) 2020 Yorik van Havre * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +"""Provides GUI tools to set up default styles.""" +## @package gui_setstyle +# \ingroup draftguitools +# \brief Provides GUI tools to set Draft styles such as color or line width + +## \addtogroup draftguitools +# @{ + +import FreeCAD +if FreeCAD.GuiUp: + import FreeCADGui + import Draft_rc +def QT_TRANSLATE_NOOP(ctx,txt): + return txt + +__title__ = "FreeCAD Draft Workbench GUI Tools - Styling tools" +__author__ = ("Yorik van Havre") +__url__ = "https://www.freecadweb.org" + + +class Draft_SetStyle: + """The Draft_SetStyle FreeCAD command definition.""" + + def GetResources(self): + + d = {'Pixmap': 'Draft_Apply', + 'Accel': "S, S", + 'MenuText': QT_TRANSLATE_NOOP("Draft_SetStyle", "Set style"), + 'ToolTip': QT_TRANSLATE_NOOP("Draft_SetStyle", "Sets default styles")} + return d + + def Activated(self): + + FreeCADGui.Control.showDialog(Draft_SetStyle_TaskPanel()) + + + +class Draft_SetStyle_TaskPanel: + """The task panel for the Draft_SetStyle command""" + + def __init__(self): + + from PySide import QtCore,QtGui + self.p = "User parameter:BaseApp/Preferences/" + self.form = FreeCADGui.PySideUic.loadUi(":/ui/TaskPanel_SetStyle.ui") + self.form.setWindowIcon(QtGui.QIcon(":/icons/Draft_Apply.svg")) + self.form.applyButton.setIcon(QtGui.QIcon(":/icons/Draft_Apply.svg")) + self.form.LineColor.setProperty("color",self.getPrefColor("View","DefaultShapeLineColor",255)) + self.form.LineWidth.setValue(FreeCAD.ParamGet(self.p+"View").GetInt("DefaultShapeLineWidth",2)) + self.form.DrawStyle.setCurrentIndex(FreeCAD.ParamGet(self.p+"Mod/Draft").GetInt("DefaultDrawStyle",0)) + self.form.DisplayMode.setCurrentIndex(FreeCAD.ParamGet(self.p+"Mod/Draft").GetInt("DefaultDisplayMode",0)) + self.form.ShapeColor.setProperty("color",self.getPrefColor("View","DefaultShapeColor",4294967295)) + self.form.Transparency.setValue(FreeCAD.ParamGet(self.p+"Mod/Draft").GetInt("DefaultTransparency",0)) + self.form.TextFont.setCurrentFont(QtGui.QFont(FreeCAD.ParamGet(self.p+"Mod/Draft").GetString("textfont","Sans"))) + self.form.TextSize.setText(FreeCAD.Units.Quantity(FreeCAD.ParamGet(self.p+"Mod/Draft").GetFloat("textheight",10),FreeCAD.Units.Length).UserString) + self.form.TextColor.setProperty("color",self.getPrefColor("Mod/Draft","DefaultTextColor",255)) + self.form.ArrowStyle.setCurrentIndex(FreeCAD.ParamGet(self.p+"Mod/Draft").GetInt("dimsymbol",0)) + self.form.ArrowSize.setText(FreeCAD.Units.Quantity(FreeCAD.ParamGet(self.p+"/Mod/Draft").GetFloat("arrowsize",5),FreeCAD.Units.Length).UserString) + self.form.ShowUnit.setChecked(FreeCAD.ParamGet(self.p+"Mod/Draft").GetBool("showUnit",True)) + self.form.UnitOverride.setText(FreeCAD.ParamGet(self.p+"Mod/Draft").GetString("overrideUnit","")) + + def getPrefColor(self,group,prop,default): + + c = FreeCAD.ParamGet(self.p+group).GetUnsigned(prop,default) + r = ((c>>24)&0xFF)/255.0 + g = ((c>>16)&0xFF)/255.0 + b = ((c>>8)&0xFF)/255.0 + from PySide import QtGui + return QtGui.QColor.fromRgbF(r,g,b) + + def reject(self): + + FreeCADGui.Control.closeDialog() + + def accept(self): + + FreeCAD.ParamGet(self.p+"View").SetUnsigned("DefaultShapeLineColor",self.form.LineColor.property("color").rgb()<<8) + FreeCAD.ParamGet(self.p+"View").SetInt("DefaultShapeLineWidth",self.form.LineWidth.value()) + FreeCAD.ParamGet(self.p+"Mod/Draft").SetInt("DefaultDrawStyle",self.form.DrawStyle.currentIndex()) + FreeCAD.ParamGet(self.p+"Mod/Draft").SetInt("DefaultDisplayMode",self.form.DisplayMode.currentIndex()) + FreeCAD.ParamGet(self.p+"View").SetUnsigned("DefaultShapeColor",self.form.ShapeColor.property("color").rgb()<<8) + FreeCAD.ParamGet(self.p+"Mod/Draft").SetInt("DefaultTransparency",self.form.Transparency.value()) + FreeCAD.ParamGet(self.p+"Mod/Draft").SetString("textfont",self.form.TextFont.currentFont().family()) + FreeCAD.ParamGet(self.p+"Mod/Draft").SetFloat("textheight",FreeCAD.Units.Quantity(self.form.TextSize.text()).Value) + FreeCAD.ParamGet(self.p+"Mod/Draft").SetUnsigned("DefaultTextColor",self.form.TextColor.property("color").rgb()<<8) + FreeCAD.ParamGet(self.p+"Mod/Draft").SetInt("dimsymbol",self.form.ArrowStyle.currentIndex()) + FreeCAD.ParamGet(self.p+"/Mod/Draft").SetFloat("arrowsize",FreeCAD.Units.Quantity(self.form.ArrowSize.text()).Value) + FreeCAD.ParamGet(self.p+"Mod/Draft").SetBool("showUnit",self.form.ShowUnit.isChecked()) + FreeCAD.ParamGet(self.p+"Mod/Draft").SetString("overrideUnit",self.form.UnitOverride.text()) + if hasattr(FreeCADGui,"draftToolBar"): + FreeCADGui.draftToolBar.setStyleButton() + self.reject() + +FreeCADGui.addCommand('Draft_SetStyle', Draft_SetStyle()) + +## @} diff --git a/src/Mod/Draft/draftguitools/gui_snapper.py b/src/Mod/Draft/draftguitools/gui_snapper.py index c3abe8ac61..a6005ceb59 100644 --- a/src/Mod/Draft/draftguitools/gui_snapper.py +++ b/src/Mod/Draft/draftguitools/gui_snapper.py @@ -75,7 +75,7 @@ class Snapper: meant to be used directly, they are all called when necessary by the general snap() function. - The Snapper lives inside FreeCADGui once the Draft module has been + The Snapper lives inside Gui once the Draft module has been loaded. """ @@ -333,6 +333,7 @@ class Snapper: fp = self.cstr(lastpoint, constrain, point) if self.trackLine and lastpoint and (not noTracker): self.trackLine.p2(fp) + self.trackLine.color.rgb = Gui.draftToolBar.getDefaultColor("line") self.trackLine.on() # Set the arch point tracking if lastpoint: @@ -475,6 +476,7 @@ class Snapper: self.running = False if self.trackLine and lastpoint: self.trackLine.p2(self.spoint) + self.trackLine.color.rgb = Gui.draftToolBar.getDefaultColor("line") self.trackLine.on() return self.spoint @@ -512,6 +514,7 @@ class Snapper: fp = self.cstr(lastpoint, constrain, winner[2]) if self.trackLine and lastpoint: self.trackLine.p2(fp) + self.trackLine.color.rgb = Gui.draftToolBar.getDefaultColor("line") self.trackLine.on() # set the cursor self.setCursor(winner[1]) @@ -573,6 +576,7 @@ class Snapper: if self.extLine: self.extLine.p1(tsnap[0]) self.extLine.p2(tsnap[2]) + self.extLine.color.rgb = Gui.draftToolBar.getDefaultColor("line") self.extLine.on() self.setCursor(tsnap[1]) return tsnap[2], eline @@ -586,6 +590,7 @@ class Snapper: self.tracker.on() if self.extLine: self.extLine.p2(tsnap[2]) + self.extLine.color.rgb = Gui.draftToolBar.getDefaultColor("line") self.extLine.on() self.setCursor(tsnap[1]) return tsnap[2], eline @@ -599,6 +604,7 @@ class Snapper: self.tracker.on() if self.extLine: self.extLine.p2(tsnap[2]) + self.extLine.color.rgb = Gui.draftToolBar.getDefaultColor("line") self.extLine.on() self.setCursor(tsnap[1]) return tsnap[2], eline @@ -640,6 +646,7 @@ class Snapper: else: self.extLine.p1(p0) self.extLine.p2(np) + self.extLine.color.rgb = Gui.draftToolBar.getDefaultColor("line") self.extLine.on() self.setCursor('extension') ne = Part.LineSegment(p0,np).toShape() @@ -699,6 +706,7 @@ class Snapper: self.extLine2.p1(p0) self.extLine2.p2(p) self.extLine.p2(p) + self.extLine.color.rgb = Gui.draftToolBar.getDefaultColor("line") self.extLine2.on() return p return None @@ -1705,6 +1713,7 @@ class Snapper: if self.spoint and self.spoint not in self.holdPoints: if self.holdTracker: self.holdTracker.addCoords(self.spoint) + self.holdTracker.color.rgb = Gui.draftToolBar.getDefaultColor("line") self.holdTracker.on() self.holdPoints.append(self.spoint) diff --git a/src/Mod/Draft/draftguitools/gui_trackers.py b/src/Mod/Draft/draftguitools/gui_trackers.py index 636b987225..de286a8d45 100644 --- a/src/Mod/Draft/draftguitools/gui_trackers.py +++ b/src/Mod/Draft/draftguitools/gui_trackers.py @@ -60,8 +60,8 @@ class Tracker: global Part, DraftGeomUtils import Part, DraftGeomUtils self.ontop = ontop - color = coin.SoBaseColor() - color.rgb = scolor or FreeCADGui.draftToolBar.getDefaultColor("ui") + self.color = coin.SoBaseColor() + self.color.rgb = scolor or FreeCADGui.draftToolBar.getDefaultColor("line") drawstyle = coin.SoDrawStyle() if swidth: drawstyle.lineWidth = swidth @@ -70,7 +70,7 @@ class Tracker: drawstyle.lineWeight = 3 drawstyle.linePattern = 0x0f0f # 0xaa node = coin.SoSeparator() - for c in [drawstyle, color] + children: + for c in [drawstyle, self.color] + children: node.addChild(c) self.switch = coin.SoSwitch() # this is the on/off switch if name: diff --git a/src/Mod/Draft/draftmake/make_point.py b/src/Mod/Draft/draftmake/make_point.py index 2324a36b75..a690e5920b 100644 --- a/src/Mod/Draft/draftmake/make_point.py +++ b/src/Mod/Draft/draftmake/make_point.py @@ -84,7 +84,7 @@ def make_point(X=0, Y=0, Z=0, color=None, name = "Point", point_size= 5): if App.GuiUp: ViewProviderPoint(obj.ViewObject) if hasattr(Gui,"draftToolBar") and (not color): - color = Gui.draftToolBar.getDefaultColor('ui') + color = Gui.draftToolBar.getDefaultColor('line') obj.ViewObject.PointColor = (float(color[0]), float(color[1]), float(color[2])) obj.ViewObject.PointSize = point_size obj.ViewObject.Visibility = True diff --git a/src/Mod/Draft/draftutils/gui_utils.py b/src/Mod/Draft/draftutils/gui_utils.py index 1e5fdfbfef..5d010c956f 100644 --- a/src/Mod/Draft/draftutils/gui_utils.py +++ b/src/Mod/Draft/draftutils/gui_utils.py @@ -350,7 +350,9 @@ def format_object(target, origin=None): if ui: doc = App.ActiveDocument if ui.isConstructionMode(): - col = fcol = ui.getDefaultColor("constr") + lcol = fcol = ui.getDefaultColor("constr") + tcol = lcol + fcol = lcol grp = doc.getObject("Draft_Construction") if not grp: grp = doc.addObject("App::DocumentObjectGroup", "Draft_Construction") @@ -359,25 +361,27 @@ def format_object(target, origin=None): if hasattr(obrep, "Transparency"): obrep.Transparency = 80 else: - col = ui.getDefaultColor("ui") + lcol = ui.getDefaultColor("line") + tcol = ui.getDefaultColor("text") fcol = ui.getDefaultColor("face") - col = (float(col[0]), float(col[1]), float(col[2]), 0.0) + lcol = (float(lcol[0]), float(lcol[1]), float(lcol[2]), 0.0) + tcol = (float(tcol[0]), float(tcol[1]), float(tcol[2]), 0.0) fcol = (float(fcol[0]), float(fcol[1]), float(fcol[2]), 0.0) - lw = ui.linewidth - fs = ui.fontsize + lw = utils.getParam("linewidth",2) + fs = utils.getParam("textheight",0.20) if not origin or not hasattr(origin, 'ViewObject'): if "FontSize" in obrep.PropertiesList: obrep.FontSize = fs if "TextSize" in obrep.PropertiesList: obrep.TextSize = fs if "TextColor" in obrep.PropertiesList: - obrep.TextColor = col + obrep.TextColor = tcol if "LineWidth" in obrep.PropertiesList: obrep.LineWidth = lw if "PointColor" in obrep.PropertiesList: - obrep.PointColor = col + obrep.PointColor = lcol if "LineColor" in obrep.PropertiesList: - obrep.LineColor = col + obrep.LineColor = lcol if "ShapeColor" in obrep.PropertiesList: obrep.ShapeColor = fcol else: diff --git a/src/Mod/Draft/draftutils/init_tools.py b/src/Mod/Draft/draftutils/init_tools.py index 12b24b28a5..6a9afe8d7f 100644 --- a/src/Mod/Draft/draftutils/init_tools.py +++ b/src/Mod/Draft/draftutils/init_tools.py @@ -97,7 +97,8 @@ def get_draft_context_commands(): return ["Draft_ApplyStyle", "Draft_ToggleDisplayMode", "Draft_AddToGroup", "Draft_SelectGroup", "Draft_SelectPlane", "Draft_ShowSnapBar", - "Draft_ToggleGrid", "Draft_AutoGroup"] + "Draft_ToggleGrid", "Draft_AutoGroup", + "Draft_SetStyle"] def get_draft_line_commands():