Skip to content

Commit

Permalink
Draft: Use proper multi-line text editor for Draft Text tool
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Jan 29, 2020
1 parent e43ec37 commit 1350da3
Showing 1 changed file with 21 additions and 40 deletions.
61 changes: 21 additions & 40 deletions src/Mod/Draft/DraftGui.py
Expand Up @@ -427,7 +427,14 @@ def setupToolBar(self,task=False):

# text

self.textValue = self._lineedit("textValue", self.layout)
self.textValue = QtGui.QTextEdit(self.baseWidget)
self.textValue.setObjectName("textValue")
self.textValue.setTabChangesFocus(True)
self.layout.addWidget(self.textValue)
self.textValue.hide()
tl = QtGui.QHBoxLayout()
self.layout.addLayout(tl)
self.textOkButton = self._pushbutton("textButton", tl, icon="button_valid")

# additional line controls

Expand Down Expand Up @@ -528,11 +535,8 @@ def setupToolBar(self,task=False):
QtCore.QObject.connect(self.pointButton,QtCore.SIGNAL("clicked()"),self.validatePoint)
QtCore.QObject.connect(self.radiusValue,QtCore.SIGNAL("returnPressed()"),self.validatePoint)
QtCore.QObject.connect(self.angleValue,QtCore.SIGNAL("returnPressed()"),self.validatePoint)
QtCore.QObject.connect(self.textValue,QtCore.SIGNAL("textChanged(QString)"),self.storeCurrentText)
QtCore.QObject.connect(self.textValue,QtCore.SIGNAL("returnPressed()"),self.sendText)
#QtCore.QObject.connect(self.textValue,QtCore.SIGNAL("escaped()"),self.escape)
QtCore.QObject.connect(self.textValue,QtCore.SIGNAL("down()"),self.sendText)
QtCore.QObject.connect(self.textValue,QtCore.SIGNAL("up()"),self.lineUp)
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)
QtCore.QObject.connect(self.addButton,QtCore.SIGNAL("toggled(bool)"),self.setAddMode)
QtCore.QObject.connect(self.delButton,QtCore.SIGNAL("toggled(bool)"),self.setDelMode)
Expand Down Expand Up @@ -697,6 +701,8 @@ def retranslateUi(self, widget=None):
self.labelSTrack.setText(translate("draft", "Tracking"))
self.labelFFile.setText(translate("draft", "Full path to font file:"))
self.chooserButton.setToolTip(translate("draft", "Open a FileChooser for font file"))
self.textOkButton.setText(translate("draft", "Create text"))
self.textOkButton.setToolTip(translate("draft", "Press this button to create the text object, or finish your text with two blank lines"))
self.retranslateTray(widget)

# Update the maximum width of the push buttons
Expand Down Expand Up @@ -963,6 +969,7 @@ def offUi(self):
self.radiusValue.hide()
self.isCopy.hide()
self.textValue.hide()
self.textOkButton.hide()
self.continueCmd.hide()
self.occOffset.hide()
self.labelSString.hide()
Expand Down Expand Up @@ -998,6 +1005,7 @@ def radiusUi(self):
def textUi(self):
self.hideXYZ()
self.textValue.show()
self.textOkButton.show()
self.textValue.setText('')
todo.delay(self.textValue.setFocus,None)
self.textbuffer=[]
Expand Down Expand Up @@ -1582,45 +1590,18 @@ def updateSnapper(self):
delta = FreeCAD.DraftWorkingPlane.getGlobalCoords(FreeCAD.Vector(self.x,self.y,self.z))
FreeCADGui.Snapper.trackLine.p2(last.add(delta))

def storeCurrentText(self,qstr):
self.currEditText = self.textValue.text()

def setCurrentText(self,tstr):
if (not self.taskmode) or (self.taskmode and self.isTaskOn):
self.textValue.setText(tstr)
def checkEnterText(self):
"""this function checks if the entered text ends with two blank lines"""
t = self.textValue.toPlainText()
if t.endswith("\n\n"):
self.sendText()

def sendText(self):
"""this function sends the entered text to the active draft command
if enter has been pressed twice. Otherwise it blanks the line.
"""
if self.textline == len(self.textbuffer):
if self.textline:
if not self.currEditText:
self.sourceCmd.text=self.textbuffer
self.sourceCmd.createObject()
self.textbuffer.append(self.currEditText)
self.textline += 1
self.setCurrentText('')
elif self.textline < len(self.textbuffer):
self.textbuffer[self.textline] = self.currEditText
self.textline += 1
if self.textline < len(self.textbuffer):
self.setCurrentText(self.textbuffer[self.textline])
else:
self.setCurrentText('')

def lineUp(self):
"""displays previous line in text editor"""
if self.textline:
if self.textline == len(self.textbuffer):
self.textbuffer.append(self.textValue.text())
self.textline -= 1
if self.textValue.text():
self.textValue.setText(self.textbuffer[self.textline])
elif self.textline < len(self.textbuffer):
self.textbuffer[self.textline] = self.textValue.text()
self.textline -= 1
self.textValue.setText(self.textbuffer[self.textline])
self.sourceCmd.text = self.textValue.toPlainText().split()
self.sourceCmd.createObject()

def displayPoint(self, point=None, last=None, plane=None, mask=None):
"""this function displays the passed coords in the x, y, and z widgets"""
Expand Down

0 comments on commit 1350da3

Please sign in to comment.