mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-10-01 01:36:27 +13:00
Purging types from textEditView
This commit is contained in:
parent
8a90f3213f
commit
a5b0b6cd95
1 changed files with 27 additions and 128 deletions
|
@ -13,9 +13,6 @@ from manuskript.functions import toString
|
||||||
from manuskript.models.outlineModel import outlineModel
|
from manuskript.models.outlineModel import outlineModel
|
||||||
from manuskript.ui.editors.MMDHighlighter import MMDHighlighter
|
from manuskript.ui.editors.MMDHighlighter import MMDHighlighter
|
||||||
from manuskript.ui.editors.basicHighlighter import basicHighlighter
|
from manuskript.ui.editors.basicHighlighter import basicHighlighter
|
||||||
from manuskript.ui.editors.t2tFunctions import t2tClearFormat
|
|
||||||
from manuskript.ui.editors.t2tFunctions import t2tFormatSelection
|
|
||||||
from manuskript.ui.editors.t2tHighlighter import t2tHighlighter
|
|
||||||
from manuskript.ui.editors.textFormat import textFormat
|
from manuskript.ui.editors.textFormat import textFormat
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -151,40 +148,25 @@ class textEditView(QTextEdit):
|
||||||
self.updateText()
|
self.updateText()
|
||||||
|
|
||||||
def setupEditorForIndex(self, index):
|
def setupEditorForIndex(self, index):
|
||||||
# what type of text are we editing?
|
# In which model are we editing?
|
||||||
if type(index.model()) != outlineModel:
|
if type(index.model()) != outlineModel:
|
||||||
self._textFormat = "text"
|
self._textFormat = "text"
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# what type of text are we editing?
|
||||||
if self._column not in [Outline.text.value, Outline.notes.value]:
|
if self._column not in [Outline.text.value, Outline.notes.value]:
|
||||||
self._textFormat = "text"
|
self._textFormat = "text"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
item = index.internalPointer()
|
|
||||||
if item.isHTML():
|
|
||||||
self._textFormat = "html"
|
|
||||||
elif item.isT2T():
|
|
||||||
self._textFormat = "t2t"
|
|
||||||
elif item.isMD():
|
|
||||||
self._textFormat = "md"
|
self._textFormat = "md"
|
||||||
else:
|
|
||||||
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()
|
||||||
if self._column == Outline.text.value and not (item.isT2T() or item.isMD()):
|
if self._column in [Outline.text.value, Outline.notes.value]:
|
||||||
self.highlighter = basicHighlighter(self)
|
|
||||||
elif item.isT2T():
|
|
||||||
self.highlighter = t2tHighlighter(self)
|
|
||||||
elif item.isMD():
|
|
||||||
self.highlighter = MMDHighlighter(self)
|
self.highlighter = MMDHighlighter(self)
|
||||||
|
else:
|
||||||
|
self.highlighter = basicHighlighter(self)
|
||||||
|
|
||||||
self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
|
self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
|
||||||
|
|
||||||
|
@ -244,15 +226,7 @@ class textEditView(QTextEdit):
|
||||||
# self.objectName(), self.parent().objectName()))
|
# self.objectName(), self.parent().objectName()))
|
||||||
|
|
||||||
if topLeft.row() <= self._index.row() <= bottomRight.row():
|
if topLeft.row() <= self._index.row() <= bottomRight.row():
|
||||||
if self._column == Outline.text.value and \
|
if topLeft.column() <= self._column <= bottomRight.column():
|
||||||
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
|
|
||||||
self.setupEditorForIndex(self._index)
|
|
||||||
self.updateText()
|
|
||||||
|
|
||||||
elif topLeft.column() <= self._column <= bottomRight.column():
|
|
||||||
self.updateText()
|
self.updateText()
|
||||||
|
|
||||||
elif self._indexes:
|
elif self._indexes:
|
||||||
|
@ -288,12 +262,6 @@ class textEditView(QTextEdit):
|
||||||
self._updating = True
|
self._updating = True
|
||||||
if self._index:
|
if self._index:
|
||||||
self.disconnectDocument()
|
self.disconnectDocument()
|
||||||
if self._textFormat == "html":
|
|
||||||
if self.toHtml() != toString(self._model.data(self._index)):
|
|
||||||
# print(" Updating html")
|
|
||||||
html = self._model.data(self._index)
|
|
||||||
self.document().setHtml(toString(html))
|
|
||||||
else:
|
|
||||||
if self.toPlainText() != toString(self._model.data(self._index)):
|
if self.toPlainText() != toString(self._model.data(self._index)):
|
||||||
# print(" Updating plaintext")
|
# print(" Updating plaintext")
|
||||||
self.document().setPlainText(toString(self._model.data(self._index)))
|
self.document().setPlainText(toString(self._model.data(self._index)))
|
||||||
|
@ -313,7 +281,6 @@ class textEditView(QTextEdit):
|
||||||
break
|
break
|
||||||
|
|
||||||
if same:
|
if same:
|
||||||
# Assuming that we don't use HTML with multiple items
|
|
||||||
self.document().setPlainText(t[0])
|
self.document().setPlainText(t[0])
|
||||||
else:
|
else:
|
||||||
self.document().setPlainText("")
|
self.document().setPlainText("")
|
||||||
|
@ -332,21 +299,6 @@ class textEditView(QTextEdit):
|
||||||
# print("Submitting", self.objectName())
|
# print("Submitting", self.objectName())
|
||||||
if self._index:
|
if self._index:
|
||||||
# item = self._index.internalPointer()
|
# item = self._index.internalPointer()
|
||||||
if self._textFormat == "html":
|
|
||||||
if self.toHtml() != self._model.data(self._index):
|
|
||||||
# print(" Submitting html")
|
|
||||||
self._updating = True
|
|
||||||
html = self.toHtml()
|
|
||||||
# We don't store paragraph and font settings
|
|
||||||
html = re.sub(r"font-family:.*?;\s*", "", html)
|
|
||||||
html = re.sub(r"font-size:.*?;\s*", "", html)
|
|
||||||
html = re.sub(r"margin-.*?;\s*", "", html)
|
|
||||||
html = re.sub(r"text-indent:.*?;\s*", "", html)
|
|
||||||
html = re.sub(r"line-height:.*?;\s*", "", html)
|
|
||||||
# print("Submitting:", html)
|
|
||||||
self._model.setData(self._index, html)
|
|
||||||
self._updating = False
|
|
||||||
else:
|
|
||||||
if self.toPlainText() != self._model.data(self._index):
|
if self.toPlainText() != self._model.data(self._index):
|
||||||
# print(" Submitting plain text")
|
# print(" Submitting plain text")
|
||||||
self._updating = True
|
self._updating = True
|
||||||
|
@ -503,70 +455,17 @@ class textEditView(QTextEdit):
|
||||||
|
|
||||||
def applyFormat(self, _format):
|
def applyFormat(self, _format):
|
||||||
|
|
||||||
if self._textFormat == "html":
|
if self._textFormat == "md":
|
||||||
|
|
||||||
if _format == "Clear":
|
|
||||||
|
|
||||||
cursor = self.textCursor()
|
|
||||||
|
|
||||||
if _format == "Clear":
|
|
||||||
fmt = self._defaultCharFormat
|
|
||||||
cursor.setCharFormat(fmt)
|
|
||||||
bf = self._defaultBlockFormat
|
|
||||||
cursor.setBlockFormat(bf)
|
|
||||||
|
|
||||||
elif _format in ["Bold", "Italic", "Underline"]:
|
|
||||||
|
|
||||||
cursor = self.textCursor()
|
|
||||||
|
|
||||||
# If no selection, selects the word in which the cursor is now
|
|
||||||
if not cursor.hasSelection():
|
|
||||||
cursor.movePosition(QTextCursor.StartOfWord,
|
|
||||||
QTextCursor.MoveAnchor)
|
|
||||||
cursor.movePosition(QTextCursor.EndOfWord,
|
|
||||||
QTextCursor.KeepAnchor)
|
|
||||||
|
|
||||||
fmt = cursor.charFormat()
|
|
||||||
|
|
||||||
if _format == "Bold":
|
|
||||||
fmt.setFontWeight(QFont.Bold if fmt.fontWeight() != QFont.Bold else QFont.Normal)
|
|
||||||
elif _format == "Italic":
|
|
||||||
fmt.setFontItalic(not fmt.fontItalic())
|
|
||||||
elif _format == "Underline":
|
|
||||||
fmt.setFontUnderline(not fmt.fontUnderline())
|
|
||||||
|
|
||||||
fmt2 = self._defaultCharFormat
|
|
||||||
fmt2.setFontWeight(fmt.fontWeight())
|
|
||||||
fmt2.setFontItalic(fmt.fontItalic())
|
|
||||||
fmt2.setFontUnderline(fmt.fontUnderline())
|
|
||||||
|
|
||||||
cursor.mergeCharFormat(fmt2)
|
|
||||||
|
|
||||||
elif _format in ["Left", "Center", "Right", "Justify"]:
|
|
||||||
|
|
||||||
cursor = self.textCursor()
|
|
||||||
|
|
||||||
# bf = cursor.blockFormat()
|
|
||||||
bf = QTextBlockFormat()
|
|
||||||
bf.setAlignment(
|
|
||||||
Qt.AlignLeft if _format == "Left" else
|
|
||||||
Qt.AlignHCenter if _format == "Center" else
|
|
||||||
Qt.AlignRight if _format == "Right" else
|
|
||||||
Qt.AlignJustify)
|
|
||||||
|
|
||||||
cursor.setBlockFormat(bf)
|
|
||||||
self.setTextCursor(cursor)
|
|
||||||
|
|
||||||
elif self._textFormat == "t2t":
|
|
||||||
if _format == "Bold":
|
|
||||||
t2tFormatSelection(self, 0)
|
|
||||||
elif _format == "Italic":
|
|
||||||
t2tFormatSelection(self, 1)
|
|
||||||
elif _format == "Underline":
|
|
||||||
t2tFormatSelection(self, 2)
|
|
||||||
elif _format == "Clear":
|
|
||||||
t2tClearFormat(self)
|
|
||||||
|
|
||||||
elif self._textFormat == "md":
|
|
||||||
# FIXME
|
# FIXME
|
||||||
print("Not implemented yet.")
|
print("Not implemented yet.")
|
||||||
|
|
||||||
|
# Model: from t2tFunctions
|
||||||
|
# if self._textFormat == "t2t":
|
||||||
|
# if _format == "Bold":
|
||||||
|
# t2tFormatSelection(self, 0)
|
||||||
|
# elif _format == "Italic":
|
||||||
|
# t2tFormatSelection(self, 1)
|
||||||
|
# elif _format == "Underline":
|
||||||
|
# t2tFormatSelection(self, 2)
|
||||||
|
# elif _format == "Clear":
|
||||||
|
# t2tClearFormat(self)
|
||||||
|
|
Loading…
Reference in a new issue