Adds: transparent text editor

This commit is contained in:
Olivier Keshavjee 2017-11-14 11:23:18 +01:00
parent b0af99eddc
commit 58bdf35953
2 changed files with 91 additions and 39 deletions

View file

@ -18,11 +18,18 @@ windowText = p.color(QPalette.WindowText).name() # General foregroung
base = p.color(QPalette.Base).name() # Other background base = p.color(QPalette.Base).name() # Other background
text = p.color(QPalette.Text).name() # Base Text text = p.color(QPalette.Text).name() # Base Text
brightText = p.color(QPalette.BrightText).name() # Contrast Text brightText = p.color(QPalette.BrightText).name() # Contrast Text
button = p.color(QPalette.Window).name() # Button background button = p.color(QPalette.Button).name() # Button background
buttonText = p.color(QPalette.Window).name() # Button Text buttonText = p.color(QPalette.ButtonText).name() # Button Text
highlight = p.color(QPalette.Highlight).name() # Other background highlight = p.color(QPalette.Highlight).name() # Other background
highlightedText = p.color(QPalette.HighlightedText).name() # Base Text highlightedText = p.color(QPalette.HighlightedText).name() # Base Text
light = p.color(QPalette.Light).name() # Lighter than Button color
midlight = p.color(QPalette.Midlight).name() # Between Button and Light
dark = p.color(QPalette.Dark).name() # Darker than Button
mid = p.color(QPalette.Mid).name() # Between Button and Dark
shadow = p.color(QPalette.Shadow).name() # A very dark color
bgHover = "#ccc" bgHover = "#ccc"
bgChecked = "#bbb" bgChecked = "#bbb"
borderColor = "darkGray" borderColor = "darkGray"
@ -119,43 +126,85 @@ def collapsibleGroupBoxButton():
def mainEditorTabSS(): def mainEditorTabSS():
return """ if not settings.textEditor["backgroundTransparent"]:
QTabWidget::pane{{ SS = """
margin-top: -1px; QTabWidget::pane{{
border: 1px solid #999; margin-top: -1px;
}} border: 1px solid {borderColor};
QTabWidget::tab-bar{{ }}
left:50px; QTabWidget::tab-bar{{
}} left:50px;
QTabBar{{ }}
background: transparent; QTabBar{{
border-radius: 0; background: transparent;
border: 0px; border-radius: 0;
}} border: 0px;
QTabBar::tab{{ }}
margin: 3px 0 -3px 0; QTabBar::tab{{
padding: 2px 9px; padding: 2px 9px;
border: 1px solid #999; border: 1px solid {borderColor};
border-bottom: 0px; border-bottom: 0px;
}} }}
QTabBar::tab:selected{{ QTabBar::tab:selected{{
border: 1px solid #999; border: 1px solid {borderColor};
background: {bgColor}; background: {bgColor};
border-bottom: 0px; border-bottom: 0px;
margin-top: 0px; color: {foreground};
color: {foreground}; }}
}} QTabBar::tab:!selected:hover{{
QTabBar::tab:!selected:hover{{ background:{highlight};
background:#ddd; color: {highlightedText};
}} }}
""".format(
bgColor=settings.textEditor["background"],
foreground=settings.textEditor["fontColor"],
borderColor=mid,
highlight=highlight,
highlightedText=highlightedText,
)
else:
# Transparent text view
SS = """
QTabWidget::pane{{
margin-top: -1px;
border: none;
}}
QTabWidget::tab-bar{{
left:50px;
}}
QTabBar{{
background: transparent;
border: 0px;
}}
QTabBar::tab{{
padding: 2px 9px;
border: 1px solid {borderColor};
}}
QTabBar::tab:selected{{
border: 1px solid {borderColor};
background: {highlight};
color: {text};
}}
QTabBar::tab:!selected:hover{{
background:{highlight};
color: {highlightedText};
}}
""".format(
highlight=highlight,
highlightedText=highlightedText,
text=text,
borderColor=mid,
)
# Add scrollbar
SS += """
QScrollBar:vertical {{ QScrollBar:vertical {{
border: none; border: none;
background: transparent; background: transparent;
width: 10px; width: 10px;
}} }}
QScrollBar::handle {{ QScrollBar::handle {{
background: rgba(180, 180, 180, 40%); background: {scrollBG};
}} }}
QScrollBar::add-line:vertical {{ QScrollBar::add-line:vertical {{
width:0; width:0;
@ -170,10 +219,10 @@ def mainEditorTabSS():
border: none; border: none;
background: none; background: none;
}} }}
""".format( """.format(scrollBG=button)
bgColor=settings.textEditor["background"],
foreground=settings.textEditor["fontColor"] return SS
)
def toolBarSS(): def toolBarSS():
return """ return """

View file

@ -15,6 +15,7 @@ from manuskript.ui.editors.MDFunctions import MDFormatSelection
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.textFormat import textFormat from manuskript.ui.editors.textFormat import textFormat
from manuskript.ui import style as S
try: try:
import enchant import enchant
@ -205,6 +206,8 @@ class textEditView(QTextEdit):
opt = settings.textEditor opt = settings.textEditor
f = QFont() f = QFont()
f.fromString(opt["font"]) f.fromString(opt["font"])
background = opt["background"] if not opt["backgroundTransparent"] else "transparent"
foreground = opt["fontColor"] if not opt["backgroundTransparent"] else S.text
# self.setFont(f) # self.setFont(f)
self.setStyleSheet("""QTextEdit{{ self.setStyleSheet("""QTextEdit{{
background: {bg}; background: {bg};
@ -215,8 +218,8 @@ class textEditView(QTextEdit):
{maxWidth} {maxWidth}
}} }}
""".format( """.format(
bg=opt["background"], bg=background,
foreground=opt["fontColor"], foreground=foreground,
ff=f.family(), ff=f.family(),
fs="{}pt".format(str(f.pointSize())), fs="{}pt".format(str(f.pointSize())),
mTB = opt["marginsTB"], mTB = opt["marginsTB"],
@ -237,7 +240,7 @@ class textEditView(QTextEdit):
# We style by name, otherwise all heriting widgets get the same # We style by name, otherwise all heriting widgets get the same
# colored background, for example context menu. # colored background, for example context menu.
name=self.parent().objectName(), name=self.parent().objectName(),
bg=opt["background"], bg=background,
)) ))
cf = QTextCharFormat() cf = QTextCharFormat()