mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-09-28 07:21:31 +12:00
Changing text type should work. Sort of.
This commit is contained in:
parent
e3ceedabd2
commit
546eb4d819
2 changed files with 34 additions and 20 deletions
|
@ -94,8 +94,13 @@ class outlineModel(QAbstractItemModel):
|
||||||
#self.dataChanged.emit(index.sibling(index.row(), 0),
|
#self.dataChanged.emit(index.sibling(index.row(), 0),
|
||||||
#index.sibling(index.row(), max([i.value for i in Outline])))
|
#index.sibling(index.row(), max([i.value for i in Outline])))
|
||||||
#print("Model emit", index.row(), index.column())
|
#print("Model emit", index.row(), index.column())
|
||||||
self.dataChanged.emit(index.sibling(index.row(), index.column()),
|
self.dataChanged.emit(index, index)
|
||||||
index.sibling(index.row(), index.column()))
|
|
||||||
|
if index.column() == Outline.type.value:
|
||||||
|
# If type changed, then the icon of title changed.
|
||||||
|
# Some views might be glad to know it.
|
||||||
|
self.dataChanged.emit(index.sibling(index.row(), Outline.title.value),
|
||||||
|
index.sibling(index.row(), Outline.title.value))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -434,6 +439,15 @@ class outlineItem():
|
||||||
updateWordCount = False
|
updateWordCount = False
|
||||||
if column in [Outline.wordCount.value, Outline.goal.value, Outline.setGoal.value]:
|
if column in [Outline.wordCount.value, Outline.goal.value, Outline.setGoal.value]:
|
||||||
updateWordCount = not Outline(column) in self._data or self._data[Outline(column)] != data
|
updateWordCount = not Outline(column) in self._data or self._data[Outline(column)] != data
|
||||||
|
|
||||||
|
# Stuff to do before
|
||||||
|
if column == Outline.type.value:
|
||||||
|
oldType = self._data[Outline.type]
|
||||||
|
if oldType == "html" and data in ["txt", "t2t"]:
|
||||||
|
# Resource inneficient way to convert HTML to plain text
|
||||||
|
e = QTextEdit()
|
||||||
|
e.setHtml(self._data[Outline.text])
|
||||||
|
self._data[Outline.text] = e.toPlainText()
|
||||||
|
|
||||||
# Setting data
|
# Setting data
|
||||||
self._data[Outline(column)] = data
|
self._data[Outline(column)] = data
|
||||||
|
@ -442,14 +456,6 @@ class outlineItem():
|
||||||
if column == Outline.text.value:
|
if column == Outline.text.value:
|
||||||
wc = wordCount(data)
|
wc = wordCount(data)
|
||||||
self.setData(Outline.wordCount.value, wc)
|
self.setData(Outline.wordCount.value, wc)
|
||||||
|
|
||||||
if column == Outline.type.value:
|
|
||||||
oldType = self._data[Outline.type]
|
|
||||||
if oldType == "html" and data in ["txt", "t2t"]:
|
|
||||||
# Resource inneficient way to convert HTML to plain text
|
|
||||||
e = QTextEdit()
|
|
||||||
e.setHtml(self._data[Outline.text])
|
|
||||||
self._data[Outline.text] = e.toPlainText()
|
|
||||||
|
|
||||||
if updateWordCount:
|
if updateWordCount:
|
||||||
self.updateWordCount()
|
self.updateWordCount()
|
||||||
|
|
|
@ -137,6 +137,12 @@ class textEditView(QTextEdit):
|
||||||
else:
|
else:
|
||||||
self._textFormat = "text"
|
self._textFormat = "text"
|
||||||
|
|
||||||
|
# Accept richtext maybe
|
||||||
|
if self._textFormat == "html":
|
||||||
|
self.setAcceptRichText(True)
|
||||||
|
else:
|
||||||
|
self.setAcceptRichText(False)
|
||||||
|
|
||||||
# Setting highlighter
|
# Setting highlighter
|
||||||
if self._highlighting:
|
if self._highlighting:
|
||||||
item = index.internalPointer()
|
item = index.internalPointer()
|
||||||
|
@ -147,12 +153,6 @@ class textEditView(QTextEdit):
|
||||||
|
|
||||||
self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
|
self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
|
||||||
|
|
||||||
# Accept richtext maybe
|
|
||||||
if self._textFormat == "html":
|
|
||||||
self.setAcceptRichText(True)
|
|
||||||
else:
|
|
||||||
self.setAcceptRichText
|
|
||||||
|
|
||||||
def setCurrentModelIndexes(self, indexes):
|
def setCurrentModelIndexes(self, indexes):
|
||||||
self._index = None
|
self._index = None
|
||||||
self._indexes = []
|
self._indexes = []
|
||||||
|
@ -175,15 +175,22 @@ class textEditView(QTextEdit):
|
||||||
if topLeft.parent() != self._index.parent():
|
if topLeft.parent() != self._index.parent():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
#print("Model changed: ({}:{}), ({}:{}/{}), ({}:{}) for {} of {}".format(
|
||||||
|
#topLeft.row(), topLeft.column(),
|
||||||
|
#self._index.row(), self._index.row(), self._column,
|
||||||
|
#bottomRight.row(), bottomRight.column(),
|
||||||
|
#self.objectName(), self.parent().objectName()))
|
||||||
|
|
||||||
if topLeft.row() <= self._index.row() <= bottomRight.row():
|
if topLeft.row() <= self._index.row() <= bottomRight.row():
|
||||||
if topLeft.column() <= Outline.type.value <= bottomRight.column():
|
if self._column == Outline.text.value and \
|
||||||
# If item type change, we reset the index to set the proper
|
topLeft.column() <= Outline.type.value <= bottomRight.column():
|
||||||
|
# If item type change, and we display the main text,
|
||||||
|
# we reset the index to set the proper
|
||||||
# highlighter and other defaults
|
# highlighter and other defaults
|
||||||
self.setupEditorForIndex(self._index)
|
self.setupEditorForIndex(self._index)
|
||||||
self.updateText()
|
self.updateText()
|
||||||
|
|
||||||
elif topLeft.column() <= self._column <= bottomRight.column():
|
elif topLeft.column() <= self._column <= bottomRight.column():
|
||||||
print(topLeft.column(), self._column, bottomRight.column())
|
|
||||||
self.updateText()
|
self.updateText()
|
||||||
|
|
||||||
elif self._indexes:
|
elif self._indexes:
|
||||||
|
@ -399,4 +406,5 @@ class textEditView(QTextEdit):
|
||||||
|
|
||||||
def applyFormat(self, _format):
|
def applyFormat(self, _format):
|
||||||
#FIXME
|
#FIXME
|
||||||
print(_format)
|
print(_format)
|
||||||
|
|
Loading…
Reference in a new issue