mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-29 17:19:50 +12:00
Using stylesheets for QTextEdit default formatting is lot less of a headache
This commit is contained in:
parent
ff7bf96108
commit
6744d2350a
|
@ -497,7 +497,7 @@ class outlineItem():
|
||||||
e = QTextEdit()
|
e = QTextEdit()
|
||||||
e.setHtml(self._data[Outline.text])
|
e.setHtml(self._data[Outline.text])
|
||||||
self._data[Outline.text] = e.toPlainText()
|
self._data[Outline.text] = e.toPlainText()
|
||||||
elif oldType in ["txt", "t2t"] and data == "html":
|
elif oldType in ["txt", "t2t"] and data == "html" and Outline.text in self._data:
|
||||||
self._data[Outline.text] = self._data[Outline.text].replace("\n", "<br>")
|
self._data[Outline.text] = self._data[Outline.text].replace("\n", "<br>")
|
||||||
|
|
||||||
# Setting data
|
# Setting data
|
||||||
|
|
|
@ -334,7 +334,6 @@ class settingsWindow(QWidget, Ui_Settings):
|
||||||
|
|
||||||
# Update font and defaultBlockFormat to all textEditView. Drastically.
|
# Update font and defaultBlockFormat to all textEditView. Drastically.
|
||||||
for w in mainWindow().findChildren(textEditView, QRegExp(".*")):
|
for w in mainWindow().findChildren(textEditView, QRegExp(".*")):
|
||||||
print(w.objectName(), w.parent().objectName())
|
|
||||||
w.loadFontSettings()
|
w.loadFontSettings()
|
||||||
|
|
||||||
def choseEditorFontColor(self):
|
def choseEditorFontColor(self):
|
||||||
|
@ -344,6 +343,7 @@ class settingsWindow(QWidget, Ui_Settings):
|
||||||
if color.isValid():
|
if color.isValid():
|
||||||
settings.textEditor["fontColor"] = color.name()
|
settings.textEditor["fontColor"] = color.name()
|
||||||
self.setButtonColor(self.btnEditorFontColor, color.name())
|
self.setButtonColor(self.btnEditorFontColor, color.name())
|
||||||
|
self.updateEditorSettings()
|
||||||
|
|
||||||
def choseEditorMisspelledColor(self):
|
def choseEditorMisspelledColor(self):
|
||||||
color = settings.textEditor["misspelled"]
|
color = settings.textEditor["misspelled"]
|
||||||
|
@ -352,6 +352,7 @@ class settingsWindow(QWidget, Ui_Settings):
|
||||||
if color.isValid():
|
if color.isValid():
|
||||||
settings.textEditor["misspelled"] = color.name()
|
settings.textEditor["misspelled"] = color.name()
|
||||||
self.setButtonColor(self.btnEditorMisspelledColor, color.name())
|
self.setButtonColor(self.btnEditorMisspelledColor, color.name())
|
||||||
|
self.updateEditorSettings()
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
# STATUS #
|
# STATUS #
|
||||||
|
|
|
@ -43,7 +43,7 @@ class basicHighlighter(QSyntaxHighlighter):
|
||||||
bf.setAlignment(QTextCursor(self.currentBlock()).blockFormat().alignment())
|
bf.setAlignment(QTextCursor(self.currentBlock()).blockFormat().alignment())
|
||||||
QTextCursor(self.currentBlock()).setBlockFormat(bf)
|
QTextCursor(self.currentBlock()).setBlockFormat(bf)
|
||||||
|
|
||||||
self.setFormat(0, len(text), self._defaultCharFormat)
|
#self.setFormat(0, len(text), self._defaultCharFormat)
|
||||||
|
|
||||||
def highlightBlockAfter(self, text):
|
def highlightBlockAfter(self, text):
|
||||||
"""Highlighting to do after everything else.
|
"""Highlighting to do after everything else.
|
||||||
|
|
|
@ -32,7 +32,6 @@ class fullScreenEditor(QWidget):
|
||||||
self.editor.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
self.editor.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||||
self.editor.installEventFilter(self)
|
self.editor.installEventFilter(self)
|
||||||
self.editor.setMouseTracking(True)
|
self.editor.setMouseTracking(True)
|
||||||
|
|
||||||
self.editor.setVerticalScrollBar(myScrollBar())
|
self.editor.setVerticalScrollBar(myScrollBar())
|
||||||
self.scrollBar = self.editor.verticalScrollBar()
|
self.scrollBar = self.editor.verticalScrollBar()
|
||||||
self.scrollBar.setParent(self)
|
self.scrollBar.setParent(self)
|
||||||
|
|
|
@ -185,13 +185,13 @@ def setThemeEditorDatas(editor, themeDatas, pixmap, screenRect):
|
||||||
x, y, width, height = themeEditorGeometry(themeDatas, textRect)
|
x, y, width, height = themeEditorGeometry(themeDatas, textRect)
|
||||||
editor.setGeometry(x, y, width, height)
|
editor.setGeometry(x, y, width, height)
|
||||||
|
|
||||||
p = editor.palette()
|
#p = editor.palette()
|
||||||
#p.setBrush(QPalette.Base, QBrush(pixmap.copy(x, y, width, height)))
|
##p.setBrush(QPalette.Base, QBrush(pixmap.copy(x, y, width, height)))
|
||||||
p.setBrush(QPalette.Base, QColor(Qt.transparent))
|
#p.setBrush(QPalette.Base, QColor(Qt.transparent))
|
||||||
p.setColor(QPalette.Text, QColor(themeDatas["Text/Color"]))
|
#p.setColor(QPalette.Text, QColor(themeDatas["Text/Color"]))
|
||||||
p.setColor(QPalette.Highlight, QColor(themeDatas["Text/Color"]))
|
#p.setColor(QPalette.Highlight, QColor(themeDatas["Text/Color"]))
|
||||||
p.setColor(QPalette.HighlightedText, Qt.black if qGray(QColor(themeDatas["Text/Color"]).rgb()) > 127 else Qt.white)
|
#p.setColor(QPalette.HighlightedText, Qt.black if qGray(QColor(themeDatas["Text/Color"]).rgb()) > 127 else Qt.white)
|
||||||
editor.setPalette(p)
|
#editor.setPalette(p)
|
||||||
|
|
||||||
editor.setAttribute(Qt.WA_NoSystemBackground, True)
|
editor.setAttribute(Qt.WA_NoSystemBackground, True)
|
||||||
|
|
||||||
|
@ -215,13 +215,30 @@ def setThemeEditorDatas(editor, themeDatas, pixmap, screenRect):
|
||||||
editor.highlighter.setMisspelledColor(QColor(themeDatas["Text/Misspelled"]))
|
editor.highlighter.setMisspelledColor(QColor(themeDatas["Text/Misspelled"]))
|
||||||
|
|
||||||
cf = QTextCharFormat()
|
cf = QTextCharFormat()
|
||||||
f = QFont()
|
|
||||||
f.fromString(themeDatas["Text/Font"])
|
|
||||||
cf.setFont(f)
|
|
||||||
editor.highlighter.setDefaultCharFormat(cf)
|
|
||||||
#f = QFont()
|
#f = QFont()
|
||||||
#f.fromString(themeDatas["Text/Font"])
|
#f.fromString(themeDatas["Text/Font"])
|
||||||
editor.setFont(f)
|
#cf.setFont(f)
|
||||||
|
editor.highlighter.setDefaultCharFormat(cf)
|
||||||
|
f = QFont()
|
||||||
|
f.fromString(themeDatas["Text/Font"])
|
||||||
|
#editor.setFont(f)
|
||||||
|
|
||||||
|
editor.setStyleSheet("""
|
||||||
|
background: transparent;
|
||||||
|
color: {foreground};
|
||||||
|
font-family: {ff};
|
||||||
|
font-size: {fs};
|
||||||
|
selection-color: {sc};
|
||||||
|
selection-background-color: {sbc};
|
||||||
|
""".format(
|
||||||
|
foreground=themeDatas["Text/Color"],
|
||||||
|
ff=f.family(),
|
||||||
|
fs="{}pt".format(str(f.pointSize())),
|
||||||
|
sc="black" if qGray(QColor(themeDatas["Text/Color"]).rgb()) > 127 else "white",
|
||||||
|
sbc=themeDatas["Text/Color"],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
editor._fromTheme = True
|
editor._fromTheme = True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -170,12 +170,19 @@ class textEditView(QTextEdit):
|
||||||
opt = settings.textEditor
|
opt = settings.textEditor
|
||||||
f = QFont()
|
f = QFont()
|
||||||
f.fromString(opt["font"])
|
f.fromString(opt["font"])
|
||||||
self.setFont(f)
|
#self.setFont(f)
|
||||||
|
self.setStyleSheet("""
|
||||||
|
color: {foreground};
|
||||||
|
font-family: {ff};
|
||||||
|
font-size: {fs};
|
||||||
|
""".format(
|
||||||
|
foreground=opt["fontColor"],
|
||||||
|
ff=f.family(),
|
||||||
|
fs="{}pt".format(str(f.pointSize()))))
|
||||||
|
|
||||||
cf = QTextCharFormat()
|
cf = QTextCharFormat()
|
||||||
cf.setFont(f)
|
#cf.setFont(f)
|
||||||
cf.setForeground(QColor(opt["fontColor"]))
|
#cf.setForeground(QColor(opt["fontColor"]))
|
||||||
|
|
||||||
bf = QTextBlockFormat()
|
bf = QTextBlockFormat()
|
||||||
bf.setLineHeight(opt["lineSpacing"], bf.ProportionalHeight)
|
bf.setLineHeight(opt["lineSpacing"], bf.ProportionalHeight)
|
||||||
|
@ -306,6 +313,7 @@ class textEditView(QTextEdit):
|
||||||
# We don't store font settings
|
# We don't store font settings
|
||||||
html = re.sub(r"font-family:.*?;", "", html)
|
html = re.sub(r"font-family:.*?;", "", html)
|
||||||
html = re.sub(r"font-size:.*?;", "", html)
|
html = re.sub(r"font-size:.*?;", "", html)
|
||||||
|
#print("Submitting:", html)
|
||||||
self._model.setData(self._index, html)
|
self._model.setData(self._index, html)
|
||||||
self._updating = False
|
self._updating = False
|
||||||
else:
|
else:
|
||||||
|
@ -464,6 +472,8 @@ class textEditView(QTextEdit):
|
||||||
|
|
||||||
def applyFormat(self, _format):
|
def applyFormat(self, _format):
|
||||||
|
|
||||||
|
print(_format)
|
||||||
|
|
||||||
if self._textFormat == "html":
|
if self._textFormat == "html":
|
||||||
|
|
||||||
if _format == "Clear":
|
if _format == "Clear":
|
||||||
|
|
Loading…
Reference in a new issue