mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-14 18:02:23 +12:00
Custom colors for all views
This commit is contained in:
parent
02a81996a9
commit
61998e5516
|
@ -65,7 +65,7 @@ def iconColor(icon):
|
|||
if px.width() != 0:
|
||||
return QColor(QImage(px).pixel(2, 2))
|
||||
else:
|
||||
return Qt.transparent
|
||||
return QColor(Qt.transparent)
|
||||
|
||||
def iconFromColor(color):
|
||||
px = QPixmap(32, 32)
|
||||
|
@ -101,7 +101,7 @@ def outlineItemColors(item):
|
|||
mw = mainWindow()
|
||||
|
||||
# POV
|
||||
colors["POV"] = Qt.transparent
|
||||
colors["POV"] = QColor(Qt.transparent)
|
||||
POV = item.data(Outline.POV.value)
|
||||
for i in range(mw.mdlPersos.rowCount()):
|
||||
if mw.mdlPersos.item(i, Perso.ID.value).text() == POV:
|
||||
|
|
|
@ -711,4 +711,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
item, part, element = action.data().split(",")
|
||||
settings.viewSettings[item][part] = element
|
||||
if item == "Cork":
|
||||
self.redacEditor.redrawCorkItems()
|
||||
self.redacEditor.corkView.viewport().update()
|
||||
if item == "Outline":
|
||||
self.redacEditor.outlineView.viewport().update()
|
||||
self.treePlanOutline.viewport().update()
|
||||
if item == "Tree":
|
||||
self.treeRedacOutline.viewport().update()
|
|
@ -382,9 +382,9 @@ class outlineItem():
|
|||
elif self.isText():
|
||||
return QIcon.fromTheme("document-new")
|
||||
|
||||
elif role == Qt.ForegroundRole:
|
||||
if self.isCompile() in [0, "0"]:
|
||||
return QBrush(Qt.gray)
|
||||
#elif role == Qt.ForegroundRole:
|
||||
#if self.isCompile() in [0, "0"]:
|
||||
#return QBrush(Qt.gray)
|
||||
|
||||
elif role == Qt.CheckStateRole and column == Outline.compile.value:
|
||||
return self._data[Outline(column)]
|
||||
|
|
|
@ -1247,11 +1247,11 @@ class Ui_MainWindow(object):
|
|||
self.actViewOutline.setText(_translate("MainWindow", "Outline"))
|
||||
self.actSettings.setText(_translate("MainWindow", "Settings"))
|
||||
|
||||
from ui.editors.editorWidget import editorWidget
|
||||
from ui.views.basicItemView import basicItemView
|
||||
from ui.views.lineEditView import lineEditView
|
||||
from ui.views.treeView import treeView
|
||||
from ui.views.textEditView import textEditView
|
||||
from ui.views.outlineView import outlineView
|
||||
from ui.views.basicItemView import basicItemView
|
||||
from ui.views.textEditView import textEditView
|
||||
from ui.editors.editorWidget import editorWidget
|
||||
from ui.views.metadataView import metadataView
|
||||
from ui.sldImportance import sldImportance
|
||||
from ui.views.treeView import treeView
|
||||
|
|
|
@ -6,33 +6,88 @@ from enums import *
|
|||
from functions import *
|
||||
import settings
|
||||
|
||||
class treeOutlineTitleDelegate(QStyledItemDelegate):
|
||||
def __init__(self, mdlPersos, parent=None):
|
||||
class outlineTitleDelegate(QStyledItemDelegate):
|
||||
def __init__(self, parent=None):
|
||||
QStyledItemDelegate.__init__(self, parent)
|
||||
self._view = None
|
||||
|
||||
def setView(self, view):
|
||||
self._view = view
|
||||
|
||||
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
|
||||
#icon = option.icon.pixmap(option.rect.size())
|
||||
#if option.icon and settings.viewSettings["Tree"]["Icon"] != "Nothing":
|
||||
#color = colors[settings.viewSettings["Tree"]["Icon"]]
|
||||
#colorifyPixmap(icon, color)
|
||||
#option.icon = QIcon(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 settings.viewSettings["Tree"]["Text"] != "Nothing":
|
||||
#color = colors[settings.viewSettings["Tree"]["Text"]]
|
||||
#print(option.palette.color(QPalette.Text))
|
||||
#option.palette.setColor(QPalette.Text, color)
|
||||
#print(option.palette.color(QPalette.Text), color)
|
||||
# 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()
|
||||
|
||||
|
||||
QStyledItemDelegate.paint(self, painter, option, index)
|
||||
#QStyledItemDelegate.paint(self, painter, option, index)
|
||||
|
||||
class treeOutlinePersoDelegate(QStyledItemDelegate):
|
||||
class outlinePersoDelegate(QStyledItemDelegate):
|
||||
|
||||
def __init__(self, mdlPersos, parent=None):
|
||||
QStyledItemDelegate.__init__(self, parent)
|
||||
|
@ -110,7 +165,7 @@ class treeOutlinePersoDelegate(QStyledItemDelegate):
|
|||
qApp.style().drawPrimitive(QStyle.PE_IndicatorArrowDown, option, painter)
|
||||
|
||||
|
||||
class treeOutlineCompileDelegate(QStyledItemDelegate):
|
||||
class outlineCompileDelegate(QStyledItemDelegate):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
QStyledItemDelegate.__init__(self, parent)
|
||||
|
@ -119,7 +174,7 @@ class treeOutlineCompileDelegate(QStyledItemDelegate):
|
|||
return ""
|
||||
|
||||
|
||||
class treeOutlineGoalPercentageDelegate(QStyledItemDelegate):
|
||||
class outlineGoalPercentageDelegate(QStyledItemDelegate):
|
||||
def __init__(self, rootIndex=None, parent=None):
|
||||
QStyledItemDelegate.__init__(self, parent)
|
||||
self.rootIndex = rootIndex
|
||||
|
@ -171,7 +226,7 @@ class treeOutlineGoalPercentageDelegate(QStyledItemDelegate):
|
|||
return ""
|
||||
|
||||
|
||||
class treeOutlineStatusDelegate(QStyledItemDelegate):
|
||||
class outlineStatusDelegate(QStyledItemDelegate):
|
||||
|
||||
def __init__(self, mdlStatus, parent=None):
|
||||
QStyledItemDelegate.__init__(self, parent)
|
||||
|
@ -221,7 +276,7 @@ class treeOutlineStatusDelegate(QStyledItemDelegate):
|
|||
qApp.style().drawPrimitive(QStyle.PE_IndicatorArrowDown, option, painter)
|
||||
|
||||
|
||||
class treeOutlineLabelDelegate(QStyledItemDelegate):
|
||||
class outlineLabelDelegate(QStyledItemDelegate):
|
||||
|
||||
def __init__(self, mdlLabels, parent=None):
|
||||
QStyledItemDelegate.__init__(self, parent)
|
|
@ -7,7 +7,7 @@
|
|||
from qt import *
|
||||
from enums import *
|
||||
from functions import *
|
||||
from ui.views.treeOutlineDelegates import *
|
||||
from ui.views.outlineDelegates import *
|
||||
from ui.views.dndView import *
|
||||
from ui.views.outlineBasics import *
|
||||
|
||||
|
@ -25,33 +25,34 @@ class outlineView(QTreeView, dndView, outlineBasics):
|
|||
self.header().setStretchLastSection(False)
|
||||
|
||||
def setModelPersos(self, model):
|
||||
# This is used by treeOutlinePersoDelegate to select character
|
||||
# This is used by outlinePersoDelegate to select character
|
||||
self.modelPersos = model
|
||||
|
||||
def setModelLabels(self, model):
|
||||
# This is used by treeOutlineLabelDelegate to display labels
|
||||
# This is used by outlineLabelDelegate to display labels
|
||||
self.modelLabels = model
|
||||
|
||||
def setModelStatus(self, model):
|
||||
# This is used by treeOutlineStatusDelegate to display statuses
|
||||
# This is used by outlineStatusDelegate to display statuses
|
||||
self.modelStatus = model
|
||||
|
||||
def setModel(self, model):
|
||||
QTreeView.setModel(self, model)
|
||||
|
||||
# Setting delegates
|
||||
self.treePlanOutlineTitleDelegate = treeOutlineTitleDelegate(self.modelPersos)
|
||||
self.setItemDelegateForColumn(Outline.title.value, self.treePlanOutlineTitleDelegate)
|
||||
self.treePlanOutlinePersoDelegate = treeOutlinePersoDelegate(self.modelPersos)
|
||||
self.setItemDelegateForColumn(Outline.POV.value, self.treePlanOutlinePersoDelegate)
|
||||
self.treePlanOutlineCompileDelegate = treeOutlineCompileDelegate()
|
||||
self.setItemDelegateForColumn(Outline.compile.value, self.treePlanOutlineCompileDelegate)
|
||||
self.treePlanOutlineStatusDelegate = treeOutlineStatusDelegate(self.modelStatus)
|
||||
self.setItemDelegateForColumn(Outline.status.value, self.treePlanOutlineStatusDelegate)
|
||||
self.treePlanOutlineGoalPercentageDelegate = treeOutlineGoalPercentageDelegate()
|
||||
self.setItemDelegateForColumn(Outline.goalPercentage.value, self.treePlanOutlineGoalPercentageDelegate)
|
||||
self.treePlanOutlineLabelDelegate = treeOutlineLabelDelegate(self.modelLabels)
|
||||
self.setItemDelegateForColumn(Outline.label.value, self.treePlanOutlineLabelDelegate)
|
||||
self.outlineTitleDelegate = outlineTitleDelegate()
|
||||
self.outlineTitleDelegate.setView(self)
|
||||
self.setItemDelegateForColumn(Outline.title.value, self.outlineTitleDelegate)
|
||||
self.outlinePersoDelegate = outlinePersoDelegate(self.modelPersos)
|
||||
self.setItemDelegateForColumn(Outline.POV.value, self.outlinePersoDelegate)
|
||||
self.outlineCompileDelegate = outlineCompileDelegate()
|
||||
self.setItemDelegateForColumn(Outline.compile.value, self.outlineCompileDelegate)
|
||||
self.outlineStatusDelegate = outlineStatusDelegate(self.modelStatus)
|
||||
self.setItemDelegateForColumn(Outline.status.value, self.outlineStatusDelegate)
|
||||
self.outlineGoalPercentageDelegate = outlineGoalPercentageDelegate()
|
||||
self.setItemDelegateForColumn(Outline.goalPercentage.value, self.outlineGoalPercentageDelegate)
|
||||
self.outlineLabelDelegate = outlineLabelDelegate(self.modelLabels)
|
||||
self.setItemDelegateForColumn(Outline.label.value, self.outlineLabelDelegate)
|
||||
|
||||
# Hiding columns
|
||||
for c in range(1, self.model().columnCount()):
|
||||
|
@ -72,8 +73,8 @@ class outlineView(QTreeView, dndView, outlineBasics):
|
|||
|
||||
def setRootIndex(self, index):
|
||||
QTreeView.setRootIndex(self, index)
|
||||
self.treePlanOutlineGoalPercentageDelegate = treeOutlineGoalPercentageDelegate(index)
|
||||
self.setItemDelegateForColumn(Outline.goalPercentage.value, self.treePlanOutlineGoalPercentageDelegate)
|
||||
self.outlineGoalPercentageDelegate = outlineGoalPercentageDelegate(index)
|
||||
self.setItemDelegateForColumn(Outline.goalPercentage.value, self.outlineGoalPercentageDelegate)
|
||||
|
||||
def dragMoveEvent(self, event):
|
||||
dndView.dragMoveEvent(self, event)
|
||||
|
|
88
src/ui/views/treeDelegates.py
Normal file
88
src/ui/views/treeDelegates.py
Normal file
|
@ -0,0 +1,88 @@
|
|||
#!/usr/bin/env python
|
||||
#--!-- coding: utf8 --!--
|
||||
|
||||
from qt import *
|
||||
from enums import *
|
||||
from functions import *
|
||||
import settings
|
||||
|
||||
class treeTitleDelegate(QStyledItemDelegate):
|
||||
def __init__(self, parent=None):
|
||||
QStyledItemDelegate.__init__(self, parent)
|
||||
self._view = None
|
||||
|
||||
def setView(self, view):
|
||||
self._view = view
|
||||
|
||||
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)
|
||||
|
||||
painter.restore()
|
||||
|
||||
#QStyledItemDelegate.paint(self, painter, option, index)
|
|
@ -9,6 +9,7 @@ from enums import *
|
|||
from functions import *
|
||||
from ui.views.dndView import *
|
||||
from ui.views.outlineBasics import *
|
||||
from ui.views.treeDelegates import *
|
||||
|
||||
class treeView(QTreeView, dndView, outlineBasics):
|
||||
|
||||
|
@ -23,6 +24,10 @@ class treeView(QTreeView, dndView, outlineBasics):
|
|||
# Hiding columns
|
||||
for c in range(1, self.model().columnCount()):
|
||||
self.hideColumn(c)
|
||||
|
||||
# Setting delegate
|
||||
self.titleDelegate = treeTitleDelegate()
|
||||
self.setItemDelegateForColumn(Outline.title.value, self.titleDelegate)
|
||||
|
||||
def dragMoveEvent(self, event):
|
||||
dndView.dragMoveEvent(self, event)
|
||||
|
|
Loading…
Reference in a new issue