Draft: Condensed the Draft toolbar style buttons into one with more options

This commit is contained in:
Yorik van Havre
2020-11-10 14:14:18 +01:00
parent 485b0b58a0
commit 88f5fc20b1
11 changed files with 562 additions and 43 deletions

View File

@@ -0,0 +1,117 @@
# ***************************************************************************
# * Copyright (c) 2020 Yorik van Havre <yorik@uncreated.net> *
# * *
# * 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())
## @}

View File

@@ -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)

View File

@@ -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: