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-04 12:04:47 +12:00
|
|
|
|
2015-06-10 00:03:22 +12:00
|
|
|
|
2015-06-04 12:04:47 +12:00
|
|
|
class treeOutlinePersoDelegate(QStyledItemDelegate):
|
|
|
|
|
|
|
|
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):
|
|
|
|
s = QStyledItemDelegate.sizeHint(self, option, index)
|
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-06 11:13:27 +12:00
|
|
|
editor.addItem("")
|
2015-06-04 12:04:47 +12:00
|
|
|
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())
|
2015-06-06 11:13:27 +12:00
|
|
|
editor.setItemData(i+1, self.mdlPersos.item(i, Perso.name.value).text(), Qt.ToolTipRole)
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
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-11 05:45:42 +12:00
|
|
|
def paint(self, painter, option, index):
|
|
|
|
#option.rect.setWidth(option.rect.width() - 18)
|
|
|
|
QStyledItemDelegate.paint(self, painter, option, index)
|
|
|
|
#option.rect.setWidth(option.rect.width() + 18)
|
|
|
|
|
|
|
|
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-04 12:04:47 +12:00
|
|
|
class treeOutlineCompileDelegate(QStyledItemDelegate):
|
|
|
|
|
|
|
|
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-05 21:37:01 +12:00
|
|
|
class treeOutlineGoalPercentageDelegate(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-04 12:51:37 +12:00
|
|
|
class treeOutlineStatusDelegate(QStyledItemDelegate):
|
|
|
|
|
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
|
|
|
|
|
|
|
class treeOutlineLabelDelegate(QStyledItemDelegate):
|
|
|
|
|
|
|
|
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
|
|
|
|