2015-06-04 12:04:47 +12:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#--!-- coding: utf8 --!--
|
|
|
|
|
|
|
|
from qt import *
|
|
|
|
from enums import *
|
2015-06-05 21:37:01 +12:00
|
|
|
from functions import *
|
2015-06-16 09:15:10 +12:00
|
|
|
import settings
|
2015-06-04 12:04:47 +12:00
|
|
|
|
2015-06-18 03:15:13 +12:00
|
|
|
class outlineTitleDelegate(QStyledItemDelegate):
|
|
|
|
def __init__(self, parent=None):
|
2015-06-16 09:15:10 +12:00
|
|
|
QStyledItemDelegate.__init__(self, parent)
|
2015-06-18 03:15:13 +12:00
|
|
|
self._view = None
|
|
|
|
|
|
|
|
def setView(self, view):
|
|
|
|
self._view = view
|
2015-06-16 09:15:10 +12:00
|
|
|
|
|
|
|
def paint(self, painter, option, index):
|
|
|
|
|
|
|
|
item = index.internalPointer()
|
|
|
|
colors = outlineItemColors(item)
|
|
|
|
|
2015-06-18 03:15:13 +12:00
|
|
|
style = qApp.style()
|
2015-06-16 09:15:10 +12:00
|
|
|
|
2015-06-18 03:15:13 +12:00
|
|
|
opt = QStyleOptionViewItem(option)
|
|
|
|
self.initStyleOption(opt, index)
|
2015-06-16 09:15:10 +12:00
|
|
|
|
2015-06-18 03:15:13 +12:00
|
|
|
iconRect = style.subElementRect(style.SE_ItemViewItemDecoration, opt)
|
|
|
|
textRect = style.subElementRect(style.SE_ItemViewItemText, opt)
|
2015-06-16 09:15:10 +12:00
|
|
|
|
2015-06-18 03:15:13 +12:00
|
|
|
# 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()
|
|
|
|
|
|
|
|
#QStyledItemDelegate.paint(self, painter, option, index)
|
2015-06-10 00:03:22 +12:00
|
|
|
|
2015-06-18 03:15:13 +12:00
|
|
|
class outlinePersoDelegate(QStyledItemDelegate):
|
2015-06-04 12:04:47 +12:00
|
|
|
|
|
|
|
def __init__(self, mdlPersos, parent=None):
|
|
|
|
QStyledItemDelegate.__init__(self, parent)
|
|
|
|
self.mdlPersos = mdlPersos
|
2015-06-04 12:51:37 +12:00
|
|
|
|
|
|
|
def sizeHint(self, option, index):
|
2015-06-21 21:54:52 +12:00
|
|
|
#s = QStyledItemDelegate.sizeHint(self, option, index)
|
|
|
|
|
|
|
|
item = QModelIndex()
|
|
|
|
for i in range(self.mdlPersos.rowCount()):
|
|
|
|
if self.mdlPersos.item(i, Perso.ID.value).text() == index.data(Perso.name.value):
|
|
|
|
item = self.mdlPersos.index(i, Perso.name.value)
|
|
|
|
|
|
|
|
opt = QStyleOptionViewItem(option)
|
|
|
|
self.initStyleOption(opt, item)
|
|
|
|
s = QStyledItemDelegate.sizeHint(self, opt, item)
|
|
|
|
|
2015-06-06 11:13:27 +12:00
|
|
|
if s.width() > 200:
|
|
|
|
s.setWidth(200)
|
|
|
|
elif s.width() < 100:
|
|
|
|
s.setWidth(100)
|
2015-06-04 12:51:37 +12:00
|
|
|
return s + QSize(18, 0)
|
2015-06-04 12:04:47 +12:00
|
|
|
|
|
|
|
def createEditor(self, parent, option, index):
|
|
|
|
item = index.internalPointer()
|
2015-06-10 06:27:42 +12:00
|
|
|
#if item.isFolder(): # No POV for folders
|
|
|
|
#return
|
2015-06-04 12:04:47 +12:00
|
|
|
|
|
|
|
editor = QComboBox(parent)
|
|
|
|
editor.setAutoFillBackground(True)
|
2015-06-04 12:51:37 +12:00
|
|
|
editor.setFrame(False)
|
2015-06-04 12:04:47 +12:00
|
|
|
return editor
|
|
|
|
|
|
|
|
def setEditorData(self, editor, index):
|
2015-06-16 01:35:48 +12:00
|
|
|
#editor.addItem("")
|
|
|
|
editor.addItem(QIcon.fromTheme("edit-delete"), self.tr("None"))
|
|
|
|
#for i in range(self.mdlPersos.rowCount()):
|
|
|
|
#editor.addItem(self.mdlPersos.item(i, Perso.name.value).text(), self.mdlPersos.item(i, Perso.ID.value).text())
|
|
|
|
#editor.setItemData(i+1, self.mdlPersos.item(i, Perso.name.value).text(), Qt.ToolTipRole)
|
|
|
|
|
|
|
|
l = [self.tr("Main"), self.tr("Secondary"), self.tr("Minor")]
|
|
|
|
for importance in range(3):
|
|
|
|
editor.addItem(l[importance])
|
|
|
|
editor.setItemData(editor.count()-1, QBrush(Qt.darkBlue), Qt.ForegroundRole)
|
|
|
|
editor.setItemData(editor.count()-1, QBrush(QColor(Qt.blue).lighter(190)), Qt.BackgroundRole)
|
|
|
|
item = editor.model().item(editor.count()-1)
|
|
|
|
item.setFlags(Qt.ItemIsEnabled)
|
|
|
|
for i in range(self.mdlPersos.rowCount()):
|
|
|
|
imp = self.mdlPersos.item(i, Perso.importance.value)
|
|
|
|
if imp:
|
|
|
|
imp = toInt(imp.text())
|
|
|
|
else:
|
|
|
|
imp = 0
|
|
|
|
if not 2-imp == importance: continue
|
|
|
|
|
|
|
|
try:
|
2015-06-21 21:54:52 +12:00
|
|
|
editor.addItem(self.mdlPersos.item(i, Perso.name.value).icon(), self.mdlPersos.item(i, Perso.name.value).text(), self.mdlPersos.item(i, Perso.ID.value).text())
|
2015-06-16 01:35:48 +12:00
|
|
|
editor.setItemData(i+1, self.mdlPersos.item(i, Perso.name.value).text(), Qt.ToolTipRole)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2015-06-04 12:04:47 +12:00
|
|
|
editor.setCurrentIndex(editor.findData(index.data()))
|
2015-06-10 00:03:22 +12:00
|
|
|
editor.showPopup()
|
2015-06-04 12:04:47 +12:00
|
|
|
|
|
|
|
def setModelData(self, editor, model, index):
|
|
|
|
val = editor.currentData()
|
|
|
|
model.setData(index, val)
|
|
|
|
|
2015-06-21 21:54:52 +12:00
|
|
|
#def displayText(self, value, locale):
|
|
|
|
#for i in range(self.mdlPersos.rowCount()):
|
|
|
|
#if self.mdlPersos.item(i, Perso.ID.value).text() == value:
|
|
|
|
#return self.mdlPersos.item(i, Perso.name.value).text()
|
|
|
|
#return ""
|
2015-06-04 12:04:47 +12:00
|
|
|
|
2015-06-11 05:45:42 +12:00
|
|
|
def paint(self, painter, option, index):
|
2015-06-21 21:54:52 +12:00
|
|
|
##option.rect.setWidth(option.rect.width() - 18)
|
|
|
|
#QStyledItemDelegate.paint(self, painter, option, index)
|
|
|
|
##option.rect.setWidth(option.rect.width() + 18)
|
|
|
|
|
|
|
|
item = QModelIndex()
|
|
|
|
for i in range(self.mdlPersos.rowCount()):
|
|
|
|
if self.mdlPersos.item(i, Perso.ID.value).text() == index.data(Perso.name.value):
|
|
|
|
item = self.mdlPersos.index(i, Perso.name.value)
|
|
|
|
|
|
|
|
opt = QStyleOptionViewItem(option)
|
|
|
|
self.initStyleOption(opt, item)
|
|
|
|
|
|
|
|
qApp.style().drawControl(QStyle.CE_ItemViewItem, opt, painter)
|
2015-06-11 05:45:42 +12:00
|
|
|
|
|
|
|
if index.isValid() and index.internalPointer().data(Outline.POV.value) not in ["", None]:
|
|
|
|
opt = QStyleOptionComboBox()
|
|
|
|
opt.rect = option.rect
|
|
|
|
r = qApp.style().subControlRect(QStyle.CC_ComboBox, opt, QStyle.SC_ComboBoxArrow)
|
|
|
|
option.rect = r
|
|
|
|
qApp.style().drawPrimitive(QStyle.PE_IndicatorArrowDown, option, painter)
|
|
|
|
|
2015-06-10 00:03:22 +12:00
|
|
|
|
2015-06-18 03:15:13 +12:00
|
|
|
class outlineCompileDelegate(QStyledItemDelegate):
|
2015-06-04 12:04:47 +12:00
|
|
|
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
QStyledItemDelegate.__init__(self, parent)
|
|
|
|
|
2015-06-05 21:37:01 +12:00
|
|
|
def displayText(self, value, locale):
|
|
|
|
return ""
|
|
|
|
|
2015-06-10 00:03:22 +12:00
|
|
|
|
2015-06-18 03:15:13 +12:00
|
|
|
class outlineGoalPercentageDelegate(QStyledItemDelegate):
|
2015-06-09 22:32:43 +12:00
|
|
|
def __init__(self, rootIndex=None, parent=None):
|
2015-06-05 21:37:01 +12:00
|
|
|
QStyledItemDelegate.__init__(self, parent)
|
2015-06-09 22:32:43 +12:00
|
|
|
self.rootIndex = rootIndex
|
|
|
|
|
|
|
|
def sizeHint(self, option, index):
|
|
|
|
sh = QStyledItemDelegate.sizeHint(self, option, index)
|
|
|
|
#if sh.width() > 50:
|
|
|
|
sh.setWidth(100)
|
|
|
|
return sh
|
2015-06-05 21:37:01 +12:00
|
|
|
|
|
|
|
def paint(self, painter, option, index):
|
|
|
|
if not index.isValid():
|
|
|
|
return QStyledItemDelegate.paint(self, painter, option, index)
|
|
|
|
|
|
|
|
QStyledItemDelegate.paint(self, painter, option, index)
|
|
|
|
|
|
|
|
item = index.internalPointer()
|
|
|
|
|
|
|
|
if not item.data(Outline.goal.value):
|
|
|
|
return
|
|
|
|
|
|
|
|
p = toFloat(item.data(Outline.goalPercentage.value))
|
|
|
|
|
|
|
|
typ = item.data(Outline.type.value)
|
|
|
|
|
|
|
|
level = item.level()
|
2015-06-11 05:45:42 +12:00
|
|
|
if self.rootIndex and self.rootIndex.isValid():
|
2015-06-09 22:32:43 +12:00
|
|
|
level -= self.rootIndex.internalPointer().level() + 1
|
2015-06-05 21:37:01 +12:00
|
|
|
|
2015-06-07 01:44:04 +12:00
|
|
|
margin = 5
|
|
|
|
height = max(min(option.rect.height() - 2*margin, 12) - 2 * level, 6)
|
|
|
|
|
2015-06-05 21:37:01 +12:00
|
|
|
painter.save()
|
|
|
|
|
|
|
|
rect = option.rect.adjusted(margin, margin, -margin, -margin)
|
2015-06-06 11:13:27 +12:00
|
|
|
|
|
|
|
# Move
|
|
|
|
rect.translate(level * rect.width() / 10, 0)
|
|
|
|
rect.setWidth(rect.width() - level * rect.width() / 10)
|
|
|
|
|
2015-06-05 21:37:01 +12:00
|
|
|
rect.setHeight(height)
|
|
|
|
rect.setTop(option.rect.top() + (option.rect.height() - height) / 2)
|
2015-06-06 11:13:27 +12:00
|
|
|
|
2015-06-07 06:29:02 +12:00
|
|
|
drawProgress(painter, rect, p) # from functions
|
|
|
|
|
2015-06-05 21:37:01 +12:00
|
|
|
painter.restore()
|
|
|
|
|
|
|
|
def displayText(self, value, locale):
|
|
|
|
return ""
|
2015-06-04 12:51:37 +12:00
|
|
|
|
2015-06-10 00:03:22 +12:00
|
|
|
|
2015-06-18 03:15:13 +12:00
|
|
|
class outlineStatusDelegate(QStyledItemDelegate):
|
2015-06-04 12:51:37 +12:00
|
|
|
|
2015-06-11 01:57:44 +12:00
|
|
|
def __init__(self, mdlStatus, parent=None):
|
2015-06-04 12:51:37 +12:00
|
|
|
QStyledItemDelegate.__init__(self, parent)
|
2015-06-11 01:57:44 +12:00
|
|
|
self.mdlStatus = mdlStatus
|
2015-06-04 12:51:37 +12:00
|
|
|
|
|
|
|
def sizeHint(self, option, index):
|
|
|
|
s = QStyledItemDelegate.sizeHint(self, option, index)
|
2015-06-11 01:57:44 +12:00
|
|
|
if s.width() > 150:
|
|
|
|
s.setWidth(150)
|
|
|
|
elif s.width() < 50:
|
|
|
|
s.setWidth(50)
|
2015-06-04 12:51:37 +12:00
|
|
|
return s + QSize(18, 0)
|
|
|
|
|
|
|
|
def createEditor(self, parent, option, index):
|
|
|
|
editor = QComboBox(parent)
|
|
|
|
editor.setAutoFillBackground(True)
|
|
|
|
editor.setFrame(False)
|
|
|
|
return editor
|
|
|
|
|
|
|
|
def setEditorData(self, editor, index):
|
2015-06-11 01:57:44 +12:00
|
|
|
for i in range(self.mdlStatus.rowCount()):
|
|
|
|
editor.addItem(self.mdlStatus.item(i, 0).text())
|
|
|
|
|
|
|
|
val = index.internalPointer().data(Outline.status.value)
|
|
|
|
if not val: val = 0
|
|
|
|
editor.setCurrentIndex(int(val))
|
2015-06-10 00:03:22 +12:00
|
|
|
editor.showPopup()
|
2015-06-04 12:51:37 +12:00
|
|
|
|
|
|
|
def setModelData(self, editor, model, index):
|
2015-06-11 01:57:44 +12:00
|
|
|
val = editor.currentIndex()
|
2015-06-10 00:03:22 +12:00
|
|
|
model.setData(index, val)
|
|
|
|
|
2015-06-11 01:57:44 +12:00
|
|
|
def displayText(self, value, locale):
|
|
|
|
try:
|
|
|
|
return self.mdlStatus.item(int(value), 0).text()
|
|
|
|
except:
|
|
|
|
return ""
|
|
|
|
|
2015-06-11 05:45:42 +12:00
|
|
|
def paint(self, painter, option, index):
|
|
|
|
QStyledItemDelegate.paint(self, painter, option, index)
|
|
|
|
|
|
|
|
if index.isValid() and index.internalPointer().data(Outline.status.value) not in ["", None, "0"]:
|
|
|
|
opt = QStyleOptionComboBox()
|
|
|
|
opt.rect = option.rect
|
|
|
|
r = qApp.style().subControlRect(QStyle.CC_ComboBox, opt, QStyle.SC_ComboBoxArrow)
|
|
|
|
option.rect = r
|
|
|
|
qApp.style().drawPrimitive(QStyle.PE_IndicatorArrowDown, option, painter)
|
|
|
|
|
2015-06-10 00:03:22 +12:00
|
|
|
|
2015-06-18 03:15:13 +12:00
|
|
|
class outlineLabelDelegate(QStyledItemDelegate):
|
2015-06-10 00:03:22 +12:00
|
|
|
|
|
|
|
def __init__(self, mdlLabels, parent=None):
|
|
|
|
QStyledItemDelegate.__init__(self, parent)
|
|
|
|
self.mdlLabels = mdlLabels
|
|
|
|
|
2015-06-11 05:45:42 +12:00
|
|
|
def sizeHint(self, option, index):
|
|
|
|
d = index.internalPointer().data(index.column(), Qt.DisplayRole)
|
|
|
|
if not d:
|
|
|
|
d = 0
|
|
|
|
item = self.mdlLabels.item(int(d), 0)
|
|
|
|
idx = self.mdlLabels.indexFromItem(item)
|
|
|
|
opt = QStyleOptionViewItem(option)
|
|
|
|
self.initStyleOption(opt, idx)
|
|
|
|
s = qApp.style().sizeFromContents(QStyle.CT_ItemViewItem, opt, QSize())
|
|
|
|
if s.width() > 150:
|
|
|
|
s.setWidth(150)
|
|
|
|
elif s.width() < 50:
|
|
|
|
s.setWidth(50)
|
|
|
|
return s + QSize(18, 0)
|
2015-06-10 00:03:22 +12:00
|
|
|
|
|
|
|
def createEditor(self, parent, option, index):
|
|
|
|
item = index.internalPointer()
|
|
|
|
editor = QComboBox(parent)
|
2015-06-11 05:45:42 +12:00
|
|
|
#editor.setAutoFillBackground(True)
|
2015-06-10 00:03:22 +12:00
|
|
|
editor.setFrame(False)
|
|
|
|
return editor
|
|
|
|
|
|
|
|
def setEditorData(self, editor, index):
|
|
|
|
for i in range(self.mdlLabels.rowCount()):
|
|
|
|
editor.addItem(self.mdlLabels.item(i, 0).icon(),
|
|
|
|
self.mdlLabels.item(i, 0).text())
|
|
|
|
|
|
|
|
val = index.internalPointer().data(Outline.label.value)
|
|
|
|
if not val: val = 0
|
|
|
|
editor.setCurrentIndex(int(val))
|
|
|
|
editor.showPopup()
|
|
|
|
|
|
|
|
def setModelData(self, editor, model, index):
|
|
|
|
val = editor.currentIndex()
|
|
|
|
model.setData(index, val)
|
|
|
|
|
|
|
|
def paint(self, painter, option, index):
|
|
|
|
if not index.isValid():
|
|
|
|
return QStyledItemDelegate.paint(self, painter, option, index)
|
|
|
|
else:
|
|
|
|
item = index.internalPointer()
|
|
|
|
|
|
|
|
d = item.data(index.column(), Qt.DisplayRole)
|
|
|
|
if not d:
|
|
|
|
d = 0
|
|
|
|
|
|
|
|
lbl = self.mdlLabels.item(int(d), 0)
|
|
|
|
opt = QStyleOptionViewItem(option)
|
|
|
|
self.initStyleOption(opt, self.mdlLabels.indexFromItem(lbl))
|
|
|
|
|
|
|
|
qApp.style().drawControl(QStyle.CE_ItemViewItem, opt, painter)
|
2015-06-11 05:45:42 +12:00
|
|
|
|
|
|
|
# Drop down indicator
|
|
|
|
if index.isValid() and index.internalPointer().data(Outline.label.value) not in ["", None, "0"]:
|
|
|
|
opt = QStyleOptionComboBox()
|
|
|
|
opt.rect = option.rect
|
|
|
|
r = qApp.style().subControlRect(QStyle.CC_ComboBox, opt, QStyle.SC_ComboBoxArrow)
|
|
|
|
option.rect = r
|
|
|
|
qApp.style().drawPrimitive(QStyle.PE_IndicatorArrowDown, option, painter)
|
2015-06-10 00:03:22 +12:00
|
|
|
|