def updateColorScheme(self, rehighlight=True): """ Generates a base set of colors that will take account of user preferences, and use system style. """ # Reading user settings opt = settings.textEditor 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 = F.mixColors( QColor(opt["Foreground/Color"]), QColor(opt["Background/Color"]), int(opt["Foreground/Opacity"])/100.) self.markupColor = F.mixColors(self.defaultTextColor, self.backgroundColor, .3) self.linkColor = QColor(S.link) self.spellingErrorColor = QColor(opt["Text/Misspelled"]) if rehighlight: self.rehighlight()
def test_several(): from PyQt5.QtGui import QPainter, QPixmap, QIcon, QColor from PyQt5.QtCore import QRect # drawProgress px = QPixmap(10, 10) F.drawProgress(QPainter(px), QRect(0, 0, 100, 100), 0.5) # colorFromProgress a = F.colorFromProgress(0.1) b = F.colorFromProgress(0.5) c = F.colorFromProgress(1.0) d = F.colorFromProgress(1.5) assert a != b != c != d # iconColor & iconFromColor & iconFromColorString icon = F.iconFromColorString("#ff0000") assert F.iconColor(icon).name().lower() == "#ff0000" # themeIcon assert F.themeIcon("text") != None assert F.themeIcon("nonexistingname") != None # randomColor c1 = F.randomColor() c2 = F.randomColor(c1) assert c1.name() != c2.name() # mixColors c1 = QColor("#FFF") c2 = QColor("#000") assert F.mixColors(c1, c2).name() == "#7f7f7f" # colorifyPixmap assert F.colorifyPixmap(px, c1) != None
def test_several(): from PyQt5.QtGui import QPainter, QPixmap, QIcon, QColor from PyQt5.QtCore import QRect # drawProgress px = QPixmap(10, 10) F.drawProgress(QPainter(px), QRect(0, 0, 100, 100), 0.5) # colorFromProgress a = F.colorFromProgress(0.1) b = F.colorFromProgress(0.5) c = F.colorFromProgress(1.0) d = F.colorFromProgress(1.5) assert a != b != c != d # iconColor & iconFromColor & iconFromColorString icon = F.iconFromColorString("#ff0000") assert F.iconColor(icon).name().lower() == "#ff0000" # themeIcon assert F.themeIcon("text") is not None assert F.themeIcon("nonexistingname") is not None # randomColor c1 = F.randomColor() c2 = F.randomColor(c1) assert c1.name() != c2.name() # mixColors c1 = QColor("#FFF") c2 = QColor("#000") assert F.mixColors(c1, c2).name() == "#7f7f7f" # colorifyPixmap assert F.colorifyPixmap(px, c1) != None
def paint(self, p, option, index): # QStyledItemDelegate.paint(self, p, option, index) if not index.isValid(): return item = index.internalPointer() self.updateRects(option, index) colors = outlineItemColors(item) style = qApp.style() def _rotate(angle): p.translate(self.mainRect.center()) p.rotate(angle) p.translate(-self.mainRect.center()) # Draw background cg = QPalette.ColorGroup(QPalette.Normal if option.state & QStyle.State_Enabled else QPalette.Disabled) if cg == QPalette.Normal and not option.state & QStyle.State_Active: cg = QPalette.Inactive # Selection if option.state & QStyle.State_Selected: p.save() p.setBrush(option.palette.brush(cg, QPalette.Highlight)) p.setPen(Qt.NoPen) p.drawRoundedRect(option.rect, 12, 12) p.restore() # Stack if item.isFolder() and item.childCount() > 0: p.save() p.setBrush(Qt.white) for i in reversed(range(3)): p.drawRoundedRect(self.itemRect.adjusted(2 * i, 2 * i, -2 * i, 2 * i), 10, 10) p.restore() # Background itemRect = self.itemRect p.save() if settings.viewSettings["Cork"]["Background"] != "Nothing": c = colors[settings.viewSettings["Cork"]["Background"]] col = mixColors(c, QColor(Qt.white), .2) p.setBrush(col) else: p.setBrush(Qt.white) pen = p.pen() pen.setWidth(2) p.setPen(pen) p.drawRoundedRect(itemRect, 10, 10) p.restore() # Title bar topRect = self.topRect p.save() if item.isFolder(): color = QColor(Qt.darkGreen) else: color = QColor(Qt.blue).lighter(175) p.setPen(Qt.NoPen) p.setBrush(color) p.setClipRegion(QRegion(topRect)) p.drawRoundedRect(itemRect, 10, 10) # p.drawRect(topRect) p.restore() # Label color if settings.viewSettings["Cork"]["Corner"] != "Nothing": p.save() color = colors[settings.viewSettings["Cork"]["Corner"]] p.setPen(Qt.NoPen) p.setBrush(color) p.setClipRegion(QRegion(self.labelRect)) p.drawRoundedRect(itemRect, 10, 10) # p.drawRect(topRect) p.restore() p.drawLine(self.labelRect.topLeft(), self.labelRect.bottomLeft()) # One line summary background lineSummary = item.data(Outline.summarySentance.value) fullSummary = item.data(Outline.summaryFull.value) if lineSummary or not fullSummary: m = self.margin r = self.mainLineRect.adjusted(-m, -m, m, m / 2) p.save() p.setPen(Qt.NoPen) p.setBrush(QColor("#EEE")) p.drawRect(r) p.restore() # Border p.save() p.setBrush(Qt.NoBrush) pen = p.pen() pen.setWidth(2) if settings.viewSettings["Cork"]["Border"] != "Nothing": col = colors[settings.viewSettings["Cork"]["Border"]] if col == Qt.transparent: col = Qt.black pen.setColor(col) p.setPen(pen) p.drawRoundedRect(itemRect, 10, 10) p.restore() # Draw the icon iconRect = self.iconRect mode = QIcon.Normal if not option.state & style.State_Enabled: mode = QIcon.Disabled elif option.state & style.State_Selected: mode = QIcon.Selected # index.data(Qt.DecorationRole).paint(p, iconRect, option.decorationAlignment, mode) icon = index.data(Qt.DecorationRole).pixmap(iconRect.size()) if settings.viewSettings["Cork"]["Icon"] != "Nothing": color = colors[settings.viewSettings["Cork"]["Icon"]] colorifyPixmap(icon, color) QIcon(icon).paint(p, iconRect, option.decorationAlignment, mode) # Draw title p.save() text = index.data() titleRect = self.titleRect if text: if settings.viewSettings["Cork"]["Text"] != "Nothing": col = colors[settings.viewSettings["Cork"]["Text"]] if col == Qt.transparent: col = Qt.black p.setPen(col) f = QFont(option.font) # f.setPointSize(f.pointSize() + 1) f.setBold(True) p.setFont(f) fm = QFontMetrics(f) elidedText = fm.elidedText(text, Qt.ElideRight, titleRect.width()) p.drawText(titleRect, Qt.AlignCenter, elidedText) p.restore() # Draw the line bottomRect = self.bottomRect p.save() # p.drawLine(itemRect.x(), iconRect.bottom() + margin, # itemRect.right(), iconRect.bottom() + margin) p.drawLine(bottomRect.topLeft(), bottomRect.topRight()) p.restore() # Lines if True: p.save() p.setPen(QColor("#EEE")) fm = QFontMetrics(option.font) h = fm.lineSpacing() l = self.mainTextRect.topLeft() + QPoint(0, h) while self.mainTextRect.contains(l): p.drawLine(l, QPoint(self.mainTextRect.right(), l.y())) l.setY(l.y() + h) p.restore() # Draw status mainRect = self.mainRect status = item.data(Outline.status.value) if status: it = mainWindow().mdlStatus.item(int(status), 0) if it != None: p.save() p.setClipRegion(QRegion(mainRect)) f = p.font() f.setPointSize(f.pointSize() + 12) f.setBold(True) p.setFont(f) p.setPen(QColor(Qt.red).lighter(175)) _rotate(-35) p.drawText(mainRect, Qt.AlignCenter, it.text()) p.restore() # Draw Summary # One line if lineSummary: p.save() f = QFont(option.font) f.setItalic(True) p.setFont(f) fm = QFontMetrics(f) elidedText = fm.elidedText(lineSummary, Qt.ElideRight, self.mainLineRect.width()) p.drawText(self.mainLineRect, Qt.AlignCenter, elidedText) p.restore() # Full summary if fullSummary: p.setFont(option.font) p.drawText(self.mainTextRect, Qt.TextWordWrap, fullSummary)
base = p.color(QPalette.Base).name() # Other background alternateBase = p.color(QPalette.AlternateBase).name() # Other background text = p.color(QPalette.Text).name() # Base Text brightText = p.color(QPalette.BrightText).name() # Contrast Text button = p.color(QPalette.Button).name() # Button background buttonText = p.color(QPalette.ButtonText).name() # Button Text highlight = p.color(QPalette.Highlight).name() # Other background 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 highlightLight = F.mixColors(highlight, window, .3) highlightedTextDark = F.mixColors(highlight, text, .3) highlightedTextLight = F.mixColors(highlight, highlightedText) midlighter = F.mixColors(mid, window, .4) textLight = F.mixColors(window, text) #from manuskript.ui import style as S #QColor(S.highlightedTextDark) #QColor(S.highlightLight) def mainWindowSS(): return """ QMenuBar#menubar{{border:none;}} QToolButton{{
def paint(self, p, option, index): # QStyledItemDelegate.paint(self, p, option, index) if not index.isValid(): return item = index.internalPointer() self.updateRects(option, index) colors = outlineItemColors(item) style = qApp.style() def _rotate(angle): p.translate(self.mainRect.center()) p.rotate(angle) p.translate(-self.mainRect.center()) # Draw background cg = QPalette.ColorGroup(QPalette.Normal if option.state & QStyle.State_Enabled else QPalette.Disabled) if cg == QPalette.Normal and not option.state & QStyle.State_Active: cg = QPalette.Inactive # Selection if option.state & QStyle.State_Selected: p.save() p.setBrush(option.palette.brush(cg, QPalette.Highlight)) p.setPen(Qt.NoPen) p.drawRoundedRect(option.rect, 12, 12) p.restore() # Stack if item.isFolder() and item.childCount() > 0: p.save() p.setBrush(Qt.white) for i in reversed(range(3)): p.drawRoundedRect( self.itemRect.adjusted(2 * i, 2 * i, -2 * i, 2 * i), 10, 10) p.restore() # Background itemRect = self.itemRect p.save() if settings.viewSettings["Cork"]["Background"] != "Nothing": c = colors[settings.viewSettings["Cork"]["Background"]] col = mixColors(c, QColor(Qt.white), .2) p.setBrush(col) else: p.setBrush(Qt.white) pen = p.pen() pen.setWidth(2) p.setPen(pen) p.drawRoundedRect(itemRect, 10, 10) p.restore() # Title bar topRect = self.topRect p.save() if item.isFolder(): color = QColor(Qt.darkGreen) else: color = QColor(Qt.blue).lighter(175) p.setPen(Qt.NoPen) p.setBrush(color) p.setClipRegion(QRegion(topRect)) p.drawRoundedRect(itemRect, 10, 10) # p.drawRect(topRect) p.restore() # Label color if settings.viewSettings["Cork"]["Corner"] != "Nothing": p.save() color = colors[settings.viewSettings["Cork"]["Corner"]] p.setPen(Qt.NoPen) p.setBrush(color) p.setClipRegion(QRegion(self.labelRect)) p.drawRoundedRect(itemRect, 10, 10) # p.drawRect(topRect) p.restore() if color != Qt.transparent: p.drawLine(self.labelRect.topLeft(), self.labelRect.bottomLeft()) # One line summary background lineSummary = item.data(Outline.summarySentence.value) fullSummary = item.data(Outline.summaryFull.value) if lineSummary or not fullSummary: m = self.margin r = self.mainLineRect.adjusted(-m, -m, m, m / 2) p.save() p.setPen(Qt.NoPen) p.setBrush(QColor("#EEE")) p.drawRect(r) p.restore() # Border p.save() p.setBrush(Qt.NoBrush) pen = p.pen() pen.setWidth(2) if settings.viewSettings["Cork"]["Border"] != "Nothing": col = colors[settings.viewSettings["Cork"]["Border"]] if col == Qt.transparent: col = Qt.black pen.setColor(col) p.setPen(pen) p.drawRoundedRect(itemRect, 10, 10) p.restore() # Draw the icon iconRect = self.iconRect mode = QIcon.Normal if not option.state & style.State_Enabled: mode = QIcon.Disabled elif option.state & style.State_Selected: mode = QIcon.Selected # index.data(Qt.DecorationRole).paint(p, iconRect, option.decorationAlignment, mode) icon = index.data(Qt.DecorationRole).pixmap(iconRect.size()) if settings.viewSettings["Cork"]["Icon"] != "Nothing": color = colors[settings.viewSettings["Cork"]["Icon"]] colorifyPixmap(icon, color) QIcon(icon).paint(p, iconRect, option.decorationAlignment, mode) # Draw title p.save() text = index.data() titleRect = self.titleRect if text: if settings.viewSettings["Cork"]["Text"] != "Nothing": col = colors[settings.viewSettings["Cork"]["Text"]] if col == Qt.transparent: col = Qt.black p.setPen(col) f = QFont(option.font) # f.setPointSize(f.pointSize() + 1) f.setBold(True) p.setFont(f) fm = QFontMetrics(f) elidedText = fm.elidedText(text, Qt.ElideRight, titleRect.width()) p.drawText(titleRect, Qt.AlignCenter, elidedText) p.restore() # Draw the line bottomRect = self.bottomRect p.save() # p.drawLine(itemRect.x(), iconRect.bottom() + margin, # itemRect.right(), iconRect.bottom() + margin) p.drawLine(bottomRect.topLeft(), bottomRect.topRight()) p.restore() # Lines if True: p.save() p.setPen(QColor("#EEE")) fm = QFontMetrics(option.font) h = fm.lineSpacing() l = self.mainTextRect.topLeft() + QPoint(0, h) while self.mainTextRect.contains(l): p.drawLine(l, QPoint(self.mainTextRect.right(), l.y())) l.setY(l.y() + h) p.restore() # Draw status mainRect = self.mainRect status = item.data(Outline.status.value) if status: it = mainWindow().mdlStatus.item(int(status), 0) if it != None: p.save() p.setClipRegion(QRegion(mainRect)) f = p.font() f.setPointSize(f.pointSize() + 12) f.setBold(True) p.setFont(f) p.setPen(QColor(Qt.red).lighter(175)) _rotate(-35) p.drawText(mainRect, Qt.AlignCenter, it.text()) p.restore() # Draw Summary # One line if lineSummary: p.save() f = QFont(option.font) f.setItalic(True) p.setFont(f) fm = QFontMetrics(f) elidedText = fm.elidedText(lineSummary, Qt.ElideRight, self.mainLineRect.width()) p.drawText(self.mainLineRect, Qt.AlignCenter, elidedText) p.restore() # Full summary if fullSummary: p.setFont(option.font) p.drawText(self.mainTextRect, Qt.TextWordWrap, fullSummary)
from manuskript.functions import mainWindow, mixColors from manuskript.ui import style as S RegEx = r"{(\w):(\d+):?.*?}" # A non-capturing regex used to identify references RegExNonCapturing = r"{\w:\d+:?.*?}" # The basic format of the references EmptyRef = "{{{}:{}:{}}}" EmptyRefSearchable = "{{{}:{}:" CharacterLetter = "C" TextLetter = "T" PlotLetter = "P" WorldLetter = "W" # Colors TextHighlightColor = QColor(mixColors(QColor(Qt.blue).name(), S.window, .3)) CharacterHighlightColor = QColor( mixColors(QColor(Qt.yellow).name(), S.window, .3)) PlotHighlightColor = QColor(mixColors(QColor(Qt.red).name(), S.window, .3)) WorldHighlightColor = QColor(mixColors(QColor(Qt.green).name(), S.window, .3)) def plotReference(ID, searchable=False): """Takes the ID of a plot and returns a reference for that plot. @searchable: returns a stripped version that allows simple text search.""" if not searchable: return EmptyRef.format(PlotLetter, ID, "") else: return EmptyRefSearchable.format(PlotLetter, ID, "")
from manuskript.ui import style as S RegEx = r"{(\w):(\d+):?.*?}" # A non-capturing regex used to identify references RegExNonCapturing = r"{\w:\d+:?.*?}" # The basic format of the references EmptyRef = "{{{}:{}:{}}}" EmptyRefSearchable = "{{{}:{}:" CharacterLetter = "C" TextLetter = "T" PlotLetter = "P" WorldLetter = "W" # Colors TextHighlightColor = QColor(mixColors(QColor(Qt.blue).name(), S.window, .3)) CharacterHighlightColor = QColor(mixColors(QColor(Qt.yellow).name(), S.window, .3)) PlotHighlightColor = QColor(mixColors(QColor(Qt.red).name(), S.window, .3)) WorldHighlightColor = QColor(mixColors(QColor(Qt.green).name(), S.window, .3)) def plotReference(ID, searchable=False): """Takes the ID of a plot and returns a reference for that plot. @searchable: returns a stripped version that allows simple text search.""" if not searchable: return EmptyRef.format(PlotLetter, ID, "") else: return EmptyRefSearchable.format(PlotLetter, ID, "") def characterReference(ID, searchable=False):
def paint_v2(self, p, option, index): # QStyledItemDelegate.paint(self, p, option, index) if not index.isValid(): return item = index.internalPointer() self.updateRects(option, index) colors = outlineItemColors(item) style = qApp.style() def _rotate(angle, rect=self.mainRect): p.translate(rect.center()) p.rotate(angle) p.translate(-rect.center()) def drawRect(r): p.save() p.setBrush(Qt.gray) p.drawRect(r) p.restore() # Draw background cg = QPalette.ColorGroup(QPalette.Normal if option.state & QStyle.State_Enabled else QPalette.Disabled) if cg == QPalette.Normal and not option.state & QStyle.State_Active: cg = QPalette.Inactive # Selection if option.state & QStyle.State_Selected: p.save() p.setBrush(option.palette.brush(cg, QPalette.Highlight)) p.setPen(Qt.NoPen) #p.drawRoundedRect(option.rect, 12, 12) p.drawRect(option.rect) p.restore() # Background p.save() if settings.viewSettings["Cork"]["Background"] != "Nothing": c = colors[settings.viewSettings["Cork"]["Background"]] if c == QColor(Qt.transparent): c = QColor(Qt.white) col = mixColors(c, QColor(Qt.white), .2) backgroundColor = col p.setBrush(col) else: p.setBrush(Qt.white) backgroundColor = QColor(Qt.white) # Cache background color self.bgColors[index] = backgroundColor.name() p.setPen(Qt.NoPen) p.drawRect(self.cardRect) if item.isFolder(): itemPoly = QPolygonF([ self.topRect.topLeft(), self.topRect.topLeft() + QPoint(self.topRect.width() * .35, 0), self.cardRect.topLeft() + QPoint(self.topRect.width() * .45, 0), self.cardRect.topRight(), self.cardRect.bottomRight(), self.cardRect.bottomLeft() ]) p.drawPolygon(itemPoly) p.restore() # Label color if settings.viewSettings["Cork"]["Corner"] != "Nothing": p.save() color = colors[settings.viewSettings["Cork"]["Corner"]] p.setPen(Qt.NoPen) p.setBrush(color) p.drawRect(self.labelRect) w = self.labelRect.width() poly = QPolygonF([ self.labelRect.bottomLeft() + QPointF(0, 1), self.labelRect.bottomLeft() + QPointF(0, w / 2), self.labelRect.bottomLeft() + QPointF(w / 2, 1), self.labelRect.bottomRight() + QPointF(1, w / 2), self.labelRect.bottomRight() + QPointF(1, 1), ]) p.drawPolygon(poly) p.restore() if settings.viewSettings["Cork"]["Corner"] == "Nothing" or \ color == Qt.transparent: # No corner, so title can be full width self.titleRect.setRight(self.mainRect.right()) # Draw the icon iconRect = self.iconRect mode = QIcon.Normal if not option.state & style.State_Enabled: mode = QIcon.Disabled elif option.state & style.State_Selected: mode = QIcon.Selected # index.data(Qt.DecorationRole).paint(p, iconRect, option.decorationAlignment, mode) icon = index.data(Qt.DecorationRole).pixmap(iconRect.size()) if settings.viewSettings["Cork"]["Icon"] != "Nothing": color = colors[settings.viewSettings["Cork"]["Icon"]] colorifyPixmap(icon, color) QIcon(icon).paint(p, iconRect, option.decorationAlignment, mode) # Draw title p.save() text = index.data() if text: p.setPen(Qt.black) textColor = QColor(Qt.black) if settings.viewSettings["Cork"]["Text"] != "Nothing": col = colors[settings.viewSettings["Cork"]["Text"]] if col == Qt.transparent: col = Qt.black # If title setting is compile, we have to hack the color # Or we won't see anything in some themes if settings.viewSettings["Cork"]["Text"] == "Compile": if item.compile() in [0, "0"]: col = mixColors(QColor(Qt.black), backgroundColor) else: col = Qt.black textColor = col p.setPen(col) f = QFont(option.font) f.setPointSize(f.pointSize() + 4) f.setBold(True) p.setFont(f) fm = QFontMetrics(f) elidedText = fm.elidedText(text, Qt.ElideRight, self.titleRect.width()) p.drawText(self.titleRect, Qt.AlignLeft | Qt.AlignVCenter, elidedText) p.restore() # One line summary background lineSummary = item.data(Outline.summarySentence) fullSummary = item.data(Outline.summaryFull) # Border if settings.viewSettings["Cork"]["Border"] != "Nothing": p.save() p.setBrush(Qt.NoBrush) pen = p.pen() pen.setWidth(2) col = colors[settings.viewSettings["Cork"]["Border"]] pen.setColor(col) p.setPen(pen) if item.isFolder(): p.drawPolygon(itemPoly) else: p.drawRect(self.cardRect) p.restore() # Draw status status = item.data(Outline.status) if status: it = mainWindow().mdlStatus.item(int(status), 0) if it != None: p.save() p.setClipRegion(QRegion(self.cardRect)) f = p.font() f.setPointSize(f.pointSize() + 12) f.setBold(True) p.setFont(f) p.setPen(QColor(Qt.red).lighter(170)) _rotate(-35, rect=self.cardRect) p.drawText(self.cardRect, Qt.AlignCenter, it.text()) p.restore() # Draw Summary # One line if lineSummary: p.save() f = QFont(option.font) f.setBold(True) p.setFont(f) p.setPen(textColor) fm = QFontMetrics(f) elidedText = fm.elidedText(lineSummary, Qt.ElideRight, self.mainLineRect.width()) p.drawText(self.mainLineRect, Qt.AlignLeft | Qt.AlignVCenter, elidedText) p.restore() # Full summary if fullSummary: p.save() p.setFont(option.font) p.setPen(textColor) p.drawText(self.mainTextRect, Qt.TextWordWrap, fullSummary) p.restore()
def paint(self, painter, option, index): item = index.internalPointer() colors = outlineItemColors(item) style = qApp.style() opt = QStyleOptionViewItem(option) self.initStyleOption(opt, index) iconRect = style.subElementRect(style.SE_ItemViewItemDecoration, opt) textRect = style.subElementRect(style.SE_ItemViewItemText, opt) # Background style.drawPrimitive(style.PE_PanelItemViewItem, opt, painter) if settings.viewSettings["Outline"][ "Background"] != "Nothing" and not opt.state & QStyle.State_Selected: col = colors[settings.viewSettings["Outline"]["Background"]] if col != QColor(Qt.transparent): col2 = QColor(S.base) if opt.state & QStyle.State_Selected: col2 = opt.palette.brush(QPalette.Normal, QPalette.Highlight).color() col = mixColors(col, col2, .2) painter.save() painter.setBrush(col) painter.setPen(Qt.NoPen) rect = opt.rect if self._view: r2 = self._view.visualRect(index) rect = self._view.viewport().rect() rect.setLeft(r2.left()) rect.setTop(r2.top()) rect.setBottom(r2.bottom()) painter.drawRoundedRect(rect, 5, 5) painter.restore() # Icon mode = QIcon.Normal if not opt.state & QStyle.State_Enabled: mode = QIcon.Disabled elif opt.state & QStyle.State_Selected: mode = QIcon.Selected state = QIcon.On if opt.state & QStyle.State_Open else QIcon.Off icon = opt.icon.pixmap(iconRect.size(), mode=mode, state=state) if opt.icon and settings.viewSettings["Outline"]["Icon"] != "Nothing": color = colors[settings.viewSettings["Outline"]["Icon"]] colorifyPixmap(icon, color) opt.icon = QIcon(icon) opt.icon.paint(painter, iconRect, opt.decorationAlignment, mode, state) # Text if opt.text: painter.save() textColor = QColor(S.text) if option.state & QStyle.State_Selected: col = QColor(S.highlightedText) textColor = col painter.setPen(col) if settings.viewSettings["Outline"]["Text"] != "Nothing": col = colors[settings.viewSettings["Outline"]["Text"]] if col == Qt.transparent: col = textColor # If text color is Compile and item is selected, we have # to change the color if settings.viewSettings["Outline"]["Text"] == "Compile" and \ item.compile() in [0, "0"]: col = mixColors(textColor, QColor(S.window)) painter.setPen(col) f = QFont(opt.font) painter.setFont(f) fm = QFontMetrics(f) elidedText = fm.elidedText(opt.text, Qt.ElideRight, textRect.width()) painter.drawText(textRect, Qt.AlignLeft, elidedText) painter.restore()
def paint(self, painter, option, index): item = index.internalPointer() colors = outlineItemColors(item) style = qApp.style() opt = QStyleOptionViewItem(option) self.initStyleOption(opt, index) iconRect = style.subElementRect(style.SE_ItemViewItemDecoration, opt, None) textRect = style.subElementRect(style.SE_ItemViewItemText, opt, None) # Background style.drawPrimitive(style.PE_PanelItemViewItem, opt, painter) if settings.viewSettings["Tree"][ "Background"] != "Nothing" and not opt.state & QStyle.State_Selected: col = colors[settings.viewSettings["Tree"]["Background"]] if col != QColor(Qt.transparent): col2 = QColor(S.window) if opt.state & QStyle.State_Selected: col2 = opt.palette.brush(QPalette.Normal, QPalette.Highlight).color() col = mixColors(col, col2, .2) painter.save() painter.setBrush(col) painter.setPen(Qt.NoPen) rect = opt.rect if self._view: r2 = self._view.visualRect(index) rect = self._view.viewport().rect() rect.setLeft(r2.left()) rect.setTop(r2.top()) rect.setBottom(r2.bottom()) painter.drawRoundedRect(rect, 5, 5) painter.restore() # Icon mode = QIcon.Normal if not opt.state & QStyle.State_Enabled: mode = QIcon.Disabled elif opt.state & QStyle.State_Selected: mode = QIcon.Selected state = QIcon.On if opt.state & QStyle.State_Open else QIcon.Off icon = opt.icon.pixmap(iconRect.size(), mode=mode, state=state) if opt.icon and settings.viewSettings["Tree"]["Icon"] != "Nothing": color = colors[settings.viewSettings["Tree"]["Icon"]] colorifyPixmap(icon, color) opt.icon = QIcon(icon) opt.icon.paint(painter, iconRect, opt.decorationAlignment, mode, state) # Text if opt.text: painter.save() textColor = QColor(S.text) if option.state & QStyle.State_Selected: col = QColor(S.highlightedText) textColor = col painter.setPen(col) if settings.viewSettings["Tree"]["Text"] != "Nothing": col = colors[settings.viewSettings["Tree"]["Text"]] if col == Qt.transparent: col = textColor # If text color is Compile and item is selected, we have # to change the color if settings.viewSettings["Outline"]["Text"] == "Compile" and \ not item.compile(): col = mixColors(textColor, QColor(S.window)) painter.setPen(col) f = QFont(opt.font) painter.setFont(f) fm = QFontMetrics(f) elidedText = fm.elidedText(opt.text, Qt.ElideRight, textRect.width()) painter.drawText(textRect, Qt.AlignLeft | Qt.AlignVCenter, elidedText) extraText = "" if item.isFolder( ) and settings.viewSettings["Tree"]["InfoFolder"] != "Nothing": if settings.viewSettings["Tree"]["InfoFolder"] == "Count": extraText = item.childCount() extraText = " [{}]".format(extraText) elif settings.viewSettings["Tree"]["InfoFolder"] == "WC": extraText = item.wordCount() extraText = " ({})".format(extraText) elif settings.viewSettings["Tree"]["InfoFolder"] == "CC": extraText = item.charCount() extraText = " ({})".format(extraText) elif settings.viewSettings["Tree"]["InfoFolder"] == "Progress": extraText = int( toFloat(item.data(Outline.goalPercentage)) * 100) if extraText: extraText = " ({}%)".format(extraText) elif settings.viewSettings["Tree"]["InfoFolder"] == "Summary": extraText = item.data(Outline.summarySentence) if extraText: extraText = " - {}".format(extraText) if item.isText( ) and settings.viewSettings["Tree"]["InfoText"] != "Nothing": if settings.viewSettings["Tree"]["InfoText"] == "WC": extraText = item.wordCount() extraText = " ({})".format(extraText) elif settings.viewSettings["Tree"]["InfoText"] == "CC": extraText = item.charCount() extraText = " ({})".format(extraText) elif settings.viewSettings["Tree"]["InfoText"] == "Progress": extraText = int( toFloat(item.data(Outline.goalPercentage)) * 100) if extraText: extraText = " ({}%)".format(extraText) elif settings.viewSettings["Tree"]["InfoText"] == "Summary": extraText = item.data(Outline.summarySentence) if extraText: extraText = " - {}".format(extraText) if extraText: r = QRect(textRect) r.setLeft(r.left() + fm.width(opt.text + " ")) painter.save() f = painter.font() f.setWeight(QFont.Normal) painter.setFont(f) if option.state & QStyle.State_Selected: col = QColor(S.highlightedTextLight) else: col = QColor(S.textLight) painter.setPen(col) painter.drawText(r, Qt.AlignLeft | Qt.AlignVCenter, extraText) painter.restore() painter.restore()
def defaultTheme(self): # Base Colors background = self.backgroundColor text = self.defaultTextColor highlightedText = QColor(S.highlightedText) highlightedTextDark = QColor(S.highlightedTextDark) highlightedTextLight = QColor(S.highlightedTextLight) highlight = QColor(S.highlight) 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} #Example: #"color": Qt.red, #"deltaSize": 10, #"background": Qt.yellow, #"monospace": True, #"bold": True, #"italic": True, #"underline": True, #"overline": True, #"strike": True, #"formatMarkup": True, #"markupBold": True, #"markupColor": Qt.blue, #"markupBackground": Qt.green, #"markupMonospace": True, #"super":True, #"sub":True for i in MTT.TITLES: theme[i] = { "formatMarkup": True, "bold": True, # "monospace": True, "markupColor": titleMarkupColor } theme[MTT.TokenAtxHeading1]["color"] = titleColor theme[MTT.TokenAtxHeading2]["color"] = F.mixColors( titleColor, background, .9) theme[MTT.TokenAtxHeading3]["color"] = F.mixColors( titleColor, background, .8) theme[MTT.TokenAtxHeading4]["color"] = F.mixColors( titleColor, background, .7) theme[MTT.TokenAtxHeading5]["color"] = F.mixColors( titleColor, background, .6) theme[MTT.TokenAtxHeading6]["color"] = F.mixColors( titleColor, background, .5) theme[MTT.TokenSetextHeading1Line1]["color"] = titleColor theme[MTT.TokenSetextHeading2Line1]["color"] = F.mixColors( titleColor, background, .9) for i in [MTT.TokenSetextHeading1Line1, MTT.TokenSetextHeading2Line1]: theme[i]["monospace"] = True for i in [MTT.TokenSetextHeading1Line2, MTT.TokenSetextHeading2Line2]: theme[i] = {"color": titleMarkupColor, "monospace": True} # Beautifiers theme[MTT.TokenEmphasis] = {"italic": True} theme[MTT.TokenStrong] = {"bold": True} theme[MTT.TokenStrikethrough] = {"strike": True} theme[MTT.TokenVerbatim] = { "monospace": True, "background": veryLight, "formatMarkup": True, "markupColor": markup, "deltaSize": -1 } theme[MTT.TokenSuperScript] = {"super": True, "formatMarkup": True} theme[MTT.TokenSubScript] = {"sub": True, "formatMarkup": True} theme[MTT.TokenHtmlTag] = {"color": linkVisited} theme[MTT.TokenHtmlEntity] = { # "color": linkVisited } theme[MTT.TokenAutomaticLink] = {"color": link} theme[MTT.TokenInlineLink] = {"color": link} theme[MTT.TokenReferenceLink] = {"color": link} theme[MTT.TokenReferenceDefinition] = {"color": link} theme[MTT.TokenImage] = {"color": highlightedTextDark} theme[MTT.TokenHtmlComment] = {"color": markup} theme[MTT.TokenNumberedList] = { "markupColor": listToken, "markupBold": True, "markupMonospace": True, } theme[MTT.TokenBulletPointList] = { "markupColor": listToken, "markupBold": True, "markupMonospace": True, } theme[MTT.TokenHorizontalRule] = { "overline": True, "underline": True, "monospace": True, "color": markup } theme[MTT.TokenLineBreak] = {"background": markup} theme[MTT.TokenBlockquote] = { "color": light, "markupColor": veryLight, "markupBackground": veryLight } theme[MTT.TokenCodeBlock] = { "color": light, "markupBackground": veryLight, "formatMarkup": True, "monospace": True, "deltaSize": -1 } theme[MTT.TokenGithubCodeFence] = {"color": markup} theme[MTT.TokenPandocCodeFence] = {"color": markup} theme[MTT.TokenCodeFenceEnd] = {"color": markup} theme[MTT.TokenMention] = {} # FIXME theme[MTT.TokenTableHeader] = {"color": light, "monospace": True} theme[MTT.TokenTableDivider] = {"color": markup, "monospace": True} theme[MTT.TokenTablePipe] = {"color": markup, "monospace": True} # CriticMarkup theme[MTT.TokenCMAddition] = { "color": QColor("#00bb00"), "markupColor": QColor(F.mixColors("#00bb00", background, .4)), "markupMonospace": True, } theme[MTT.TokenCMDeletion] = { "color": QColor("#dd0000"), "markupColor": QColor(F.mixColors("#dd0000", background, .4)), "markupMonospace": True, "strike": True } theme[MTT.TokenCMSubstitution] = { "color": QColor("#ff8600"), "markupColor": QColor(F.mixColors("#ff8600", background, .4)), "markupMonospace": True, } theme[MTT.TokenCMComment] = { "color": QColor("#0000bb"), "markupColor": QColor(F.mixColors("#0000bb", background, .4)), "markupMonospace": True, } theme[MTT.TokenCMHighlight] = { "color": QColor("#aa53a9"), "background": QColor(F.mixColors("#aa53a9", background, .1)), "markupBackground": QColor(F.mixColors("#aa53a9", background, .1)), "markupColor": QColor(F.mixColors("#aa53a9", background, .5)), "markupMonospace": True, } return theme
def paint(self, painter, option, index): item = index.internalPointer() colors = outlineItemColors(item) style = qApp.style() opt = QStyleOptionViewItem(option) self.initStyleOption(opt, index) iconRect = style.subElementRect(style.SE_ItemViewItemDecoration, opt) textRect = style.subElementRect(style.SE_ItemViewItemText, opt) # Background style.drawPrimitive(style.PE_PanelItemViewItem, opt, painter) if settings.viewSettings["Tree"]["Background"] != "Nothing" and not opt.state & QStyle.State_Selected: col = colors[settings.viewSettings["Tree"]["Background"]] if col != QColor(Qt.transparent): col2 = QColor(Qt.white) if opt.state & QStyle.State_Selected: col2 = opt.palette.brush(QPalette.Normal, QPalette.Highlight).color() col = mixColors(col, col2, .2) painter.save() painter.setBrush(col) painter.setPen(Qt.NoPen) rect = opt.rect if self._view: r2 = self._view.visualRect(index) rect = self._view.viewport().rect() rect.setLeft(r2.left()) rect.setTop(r2.top()) rect.setBottom(r2.bottom()) painter.drawRoundedRect(rect, 5, 5) painter.restore() # Icon mode = QIcon.Normal if not opt.state & QStyle.State_Enabled: mode = QIcon.Disabled elif opt.state & QStyle.State_Selected: mode = QIcon.Selected state = QIcon.On if opt.state & QStyle.State_Open else QIcon.Off icon = opt.icon.pixmap(iconRect.size(), mode=mode, state=state) if opt.icon and settings.viewSettings["Tree"]["Icon"] != "Nothing": color = colors[settings.viewSettings["Tree"]["Icon"]] colorifyPixmap(icon, color) opt.icon = QIcon(icon) opt.icon.paint(painter, iconRect, opt.decorationAlignment, mode, state) # Text if opt.text: painter.save() if settings.viewSettings["Tree"]["Text"] != "Nothing": col = colors[settings.viewSettings["Tree"]["Text"]] if col == Qt.transparent: col = Qt.black painter.setPen(col) f = QFont(opt.font) painter.setFont(f) fm = QFontMetrics(f) elidedText = fm.elidedText(opt.text, Qt.ElideRight, textRect.width()) painter.drawText(textRect, Qt.AlignLeft, elidedText) extraText = "" if item.isFolder() and settings.viewSettings["Tree"]["InfoFolder"] != "Nothing": if settings.viewSettings["Tree"]["InfoFolder"] == "Count": extraText = item.childCount() extraText = " [{}]".format(extraText) elif settings.viewSettings["Tree"]["InfoFolder"] == "WC": extraText = item.data(Outline.wordCount.value) extraText = " ({})".format(extraText) elif settings.viewSettings["Tree"]["InfoFolder"] == "Progress": extraText = int(toFloat(item.data(Outline.goalPercentage.value)) * 100) if extraText: extraText = " ({}%)".format(extraText) elif settings.viewSettings["Tree"]["InfoFolder"] == "Summary": extraText = item.data(Outline.summarySentance.value) if extraText: extraText = " - {}".format(extraText) if item.isText() and settings.viewSettings["Tree"]["InfoText"] != "Nothing": if settings.viewSettings["Tree"]["InfoText"] == "WC": extraText = item.data(Outline.wordCount.value) extraText = " ({})".format(extraText) elif settings.viewSettings["Tree"]["InfoText"] == "Progress": extraText = int(toFloat(item.data(Outline.goalPercentage.value)) * 100) if extraText: extraText = " ({}%)".format(extraText) elif settings.viewSettings["Tree"]["InfoText"] == "Summary": extraText = item.data(Outline.summarySentance.value) if extraText: extraText = " - {}".format(extraText) if extraText: r = QRect(textRect) r.setLeft(r.left() + fm.width(opt.text + " ")) painter.save() f = painter.font() f.setWeight(QFont.Normal) painter.setFont(f) painter.setPen(Qt.darkGray) painter.drawText(r, Qt.AlignLeft | Qt.AlignBottom, extraText) painter.restore() painter.restore()
text = p.color(QPalette.Text).name() # Base Text brightText = p.color(QPalette.BrightText).name() # Contrast Text button = p.color(QPalette.Button).name() # Button background buttonText = p.color(QPalette.ButtonText).name() # Button Text highlight = p.color(QPalette.Highlight).name() # Other background highlightedText = p.color(QPalette.HighlightedText).name() # Base Text link = p.color(QPalette.Link).name() # Link linkVisited = p.color(QPalette.LinkVisited).name() # Link visited light = p.color(QPalette.Light).name() # Lighter than Button color midlight = p.color(QPalette.Midlight).name() # Between Button and Light mid = p.color(QPalette.Mid).name() # Between Button and Dark dark = p.color(QPalette.Dark).name() # Darker than Button shadow = p.color(QPalette.Shadow).name() # A very dark color highlightLight = F.mixColors(highlight, window, .3) highlightedTextDark = F.mixColors(highlight, text, .3) highlightedTextLight = F.mixColors(highlight, highlightedText) midlighter = F.mixColors(mid, window, .4) textLight = F.mixColors(window, text) textLighter = F.mixColors(window, text, .85) #from manuskript.ui import style as S #QColor(S.highlightedTextDark) #QColor(S.highlightLight) def mainWindowSS(): return """ QMenuBar#menubar{{border:none;}}
def paint(self, painter, option, index): item = index.internalPointer() colors = outlineItemColors(item) style = qApp.style() opt = QStyleOptionViewItem(option) self.initStyleOption(opt, index) iconRect = style.subElementRect(style.SE_ItemViewItemDecoration, opt) textRect = style.subElementRect(style.SE_ItemViewItemText, opt) # Background style.drawPrimitive(style.PE_PanelItemViewItem, opt, painter) if settings.viewSettings["Outline"]["Background"] != "Nothing" and not opt.state & QStyle.State_Selected: col = colors[settings.viewSettings["Outline"]["Background"]] if col != QColor(Qt.transparent): col2 = QColor(Qt.white) if opt.state & QStyle.State_Selected: col2 = opt.palette.brush(QPalette.Normal, QPalette.Highlight).color() col = mixColors(col, col2, .2) painter.save() painter.setBrush(col) painter.setPen(Qt.NoPen) rect = opt.rect if self._view: r2 = self._view.visualRect(index) rect = self._view.viewport().rect() rect.setLeft(r2.left()) rect.setTop(r2.top()) rect.setBottom(r2.bottom()) painter.drawRoundedRect(rect, 5, 5) painter.restore() # Icon mode = QIcon.Normal if not opt.state & QStyle.State_Enabled: mode = QIcon.Disabled elif opt.state & QStyle.State_Selected: mode = QIcon.Selected state = QIcon.On if opt.state & QStyle.State_Open else QIcon.Off icon = opt.icon.pixmap(iconRect.size(), mode=mode, state=state) if opt.icon and settings.viewSettings["Outline"]["Icon"] != "Nothing": color = colors[settings.viewSettings["Outline"]["Icon"]] colorifyPixmap(icon, color) opt.icon = QIcon(icon) opt.icon.paint(painter, iconRect, opt.decorationAlignment, mode, state) # Text if opt.text: painter.save() if settings.viewSettings["Outline"]["Text"] != "Nothing": col = colors[settings.viewSettings["Outline"]["Text"]] if col == Qt.transparent: col = Qt.black painter.setPen(col) f = QFont(opt.font) painter.setFont(f) fm = QFontMetrics(f) elidedText = fm.elidedText(opt.text, Qt.ElideRight, textRect.width()) painter.drawText(textRect, Qt.AlignLeft, elidedText) painter.restore()