From 7940cdb3365e22fcde576c56f15d16d49736baa4 Mon Sep 17 00:00:00 2001 From: Olivier Keshavjee Date: Sat, 25 Nov 2017 14:17:49 +0100 Subject: [PATCH] Adds better fullscreen theme color integration --- manuskript/ui/editors/themes.py | 11 ++++--- .../ui/highlighters/basicHighlighter.py | 33 +++++++++++++------ .../ui/highlighters/markdownHighlighter.py | 29 +++++++++------- manuskript/ui/views/textEditView.py | 1 + 4 files changed, 48 insertions(+), 26 deletions(-) diff --git a/manuskript/ui/editors/themes.py b/manuskript/ui/editors/themes.py index 47f96f32..29903b09 100644 --- a/manuskript/ui/editors/themes.py +++ b/manuskript/ui/editors/themes.py @@ -89,13 +89,13 @@ def themeTextRect(themeDatas, screenRect): def createThemePreview(theme, screenRect, size=QSize(200, 120)): """ Generates a QPixmap preview for given theme. - + Theme can be either a string containing the filename of the ini file with the theme settings, or it can be a dict with the settings. - + If theme is a filename, the result is cached. """ - + # Checking whether theme is a string or dict if type(theme) == str and os.path.exists(theme): # Theme is the path to an ini file @@ -126,7 +126,7 @@ def createThemePreview(theme, screenRect, size=QSize(200, 120)): painter.setPen(Qt.white) painter.drawRect(QRect(w, h, w * 4, h * 5)) painter.end() - + # If theme is a themefile, we keep it in cache if fromFile: _thumbCache[theme] = [themeDatas, px] @@ -265,7 +265,8 @@ def setThemeEditorDatas(editor, themeDatas, pixmap, screenRect): ) editor._fromTheme = True - + editor._themeData = themeDatas + editor.highlighter.updateColorScheme() def addThemePreviewText(pixmap, themeDatas, screenRect): # Text diff --git a/manuskript/ui/highlighters/basicHighlighter.py b/manuskript/ui/highlighters/basicHighlighter.py index c4830414..18c1dfc0 100644 --- a/manuskript/ui/highlighters/basicHighlighter.py +++ b/manuskript/ui/highlighters/basicHighlighter.py @@ -47,16 +47,29 @@ class BasicHighlighter(QSyntaxHighlighter): # Reading user settings opt = settings.textEditor - self.defaultTextColor = QColor(opt["fontColor"]) - self.backgroundColor = (QColor(opt["background"]) - if not opt["backgroundTransparent"] - else QColor(S.window)) - self.markupColor = F.mixColors(self.defaultTextColor, - self.backgroundColor, - .3) - self.linkColor = QColor(S.link) - self.spellingErrorColor = QColor(opt["misspelled"]) - self._defaultCharFormat.setForeground(QBrush(self.defaultTextColor)) + if not self.editor._fromTheme or not self.editor._themeData: + + self.defaultTextColor = QColor(opt["fontColor"]) + self.backgroundColor = (QColor(opt["background"]) + if not opt["backgroundTransparent"] + else QColor(S.window)) + self.markupColor = F.mixColors(self.defaultTextColor, + self.backgroundColor, + .3) + self.linkColor = QColor(S.link) + self.spellingErrorColor = QColor(opt["misspelled"]) + self._defaultCharFormat.setForeground(QBrush(self.defaultTextColor)) + + # FullscreenEditor probably + else: + opt = self.editor._themeData + self.defaultTextColor = QColor(opt["Text/Color"]) + self.backgroundColor = QColor(opt["Background/Color"]) + self.markupColor = F.mixColors(self.defaultTextColor, + self.backgroundColor, + .3) + self.linkColor = QColor(S.link) + self.spellingErrorColor = QColor(opt["Text/Misspelled"]) if rehighlight: self.rehighlight() diff --git a/manuskript/ui/highlighters/markdownHighlighter.py b/manuskript/ui/highlighters/markdownHighlighter.py index 3b9939c2..cb38e46f 100644 --- a/manuskript/ui/highlighters/markdownHighlighter.py +++ b/manuskript/ui/highlighters/markdownHighlighter.py @@ -174,22 +174,33 @@ class MarkdownHighlighter(BasicHighlighter): def defaultTheme(self): - # Colors + # Base Colors background = self.backgroundColor text = self.defaultTextColor - light = F.mixColors(text, background, .75) - markup = F.mixColors(text, background, .5) - veryLight = F.mixColors(text, background, .25) - highlightedText = QColor(S.highlightedText) highlightedTextDark = QColor(S.highlightedTextDark) highlightedTextLight = QColor(S.highlightedTextLight) highlight = QColor(S.highlight) - listToken = F.mixColors(highlight, background, .4) - link = self.linkColor linkVisited = QColor(S.linkVisited) + # titleColor = highlight + titleColor = QColor(S.highlightedTextDark) + + # FullscreenEditor probably + if self.editor._fromTheme and self.editor._themeData: + text = QColor(self.editor._themeData["Text/Color"]) + background = QColor(self.editor._themeData["Background/Color"]) + titleColor = text + + # Compositions + light = F.mixColors(text, background, .75) + markup = F.mixColors(text, background, .5) + veryLight = F.mixColors(text, background, .25) + listToken = F.mixColors(highlight, background, .4) + titleMarkupColor = F.mixColors(titleColor, background, .3) + + theme = { "markup": markup} @@ -211,10 +222,6 @@ class MarkdownHighlighter(BasicHighlighter): #"super":True, #"sub":True - titleColor = QColor(S.highlightedTextDark) - # titleColor = highlight - titleMarkupColor = F.mixColors(titleColor, background, .3) - for i in MTT.TITLES: theme[i] = { "formatMarkup":True, diff --git a/manuskript/ui/views/textEditView.py b/manuskript/ui/views/textEditView.py index ee589267..493ef6db 100644 --- a/manuskript/ui/views/textEditView.py +++ b/manuskript/ui/views/textEditView.py @@ -38,6 +38,7 @@ class textEditView(QTextEdit): self.setAcceptRichText(False) # When setting up a theme, this becomes true. self._fromTheme = False + self._themeData = None self.spellcheck = spellcheck self.currentDict = dict if dict else settings.dict