Skip to content

Commit

Permalink
Draft: Condensed the Draft toolbar style buttons into one with more o…
Browse files Browse the repository at this point in the history
…ptions
  • Loading branch information
yorikvanhavre committed Nov 10, 2020
1 parent 485b0b5 commit 88f5fc2
Show file tree
Hide file tree
Showing 11 changed files with 562 additions and 43 deletions.
1 change: 1 addition & 0 deletions src/Mod/Draft/CMakeLists.txt
Expand Up @@ -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
Expand Down
128 changes: 99 additions & 29 deletions src/Mod/Draft/DraftGui.py
Expand Up @@ -167,11 +167,14 @@ def __init__(self):
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
Expand Down Expand Up @@ -489,13 +492,15 @@ def setupToolBar(self,task=False):
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)
# QtCore.QObject.connect(self.sharpButton,QtCore.SIGNAL("toggled(bool)"),self.setSharpMode)
# 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)
Expand Down Expand Up @@ -545,35 +550,44 @@ def setupTray(self):
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):
Expand Down Expand Up @@ -622,12 +636,15 @@ def retranslateUi(self, widget=None):
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]+")")
Expand Down Expand Up @@ -677,13 +694,17 @@ def retranslateUi(self, widget=None):
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
Expand Down Expand Up @@ -913,12 +934,15 @@ def offUi(self):
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()
Expand Down Expand Up @@ -1176,6 +1200,8 @@ def reject(self):

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
Expand All @@ -1200,6 +1226,8 @@ def getcol(self):

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
Expand All @@ -1218,6 +1246,8 @@ def getfacecol(self):
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))
Expand All @@ -1226,6 +1256,8 @@ def setwidth(self,val):
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))
Expand All @@ -1240,6 +1272,8 @@ def setFill(self,val):
self.fillmode = bool(val)

def apply(self):
print("draft: warning: apply() is obsolete")
return
for i in FreeCADGui.Selection.getSelection():
Draft.formatObject(i)

Expand Down Expand Up @@ -1652,9 +1686,20 @@ def getDefaultColor(self,type,rgb=False):
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
Expand Down Expand Up @@ -1720,6 +1765,31 @@ def changePage(self,index):
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()
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Draft/DraftTools.py
Expand Up @@ -76,6 +76,7 @@
# ---------------------------------------------------------------------------
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
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Draft/Resources/Draft.qrc
Expand Up @@ -181,5 +181,6 @@
<file>ui/TaskSelectPlane.ui</file>
<file>ui/TaskShapeString.ui</file>
<file>ui/dialog_AnnotationStyleEditor.ui</file>
<file>ui/TaskPanel_SetStyle.ui</file>
</qresource>
</RCC>

2 comments on commit 88f5fc2

@marioalexis84
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yorikvanhavre applyButton doesn't work.

@yorikvanhavre
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marioalexis84 good catch, thanks! Will fix

Please sign in to comment.