manuskript/manuskript/ui/views/outlineView.py

96 lines
4.3 KiB
Python
Raw Normal View History

2015-06-09 22:32:43 +12:00
#!/usr/bin/env python
2016-02-07 00:34:22 +13:00
# --!-- coding: utf8 --!--
from PyQt5.QtCore import Qt
2016-02-07 00:34:22 +13:00
from PyQt5.QtWidgets import QTreeView, QHeaderView
2015-06-09 22:32:43 +12:00
2016-02-07 00:34:22 +13:00
from manuskript import settings
from manuskript.enums import Outline
from manuskript.ui.views.dndView import dndView
from manuskript.ui.views.outlineBasics import outlineBasics
from manuskript.ui.views.outlineDelegates import outlineTitleDelegate, outlineCharacterDelegate, outlineCompileDelegate, \
2016-02-07 00:34:22 +13:00
outlineStatusDelegate, outlineGoalPercentageDelegate, outlineLabelDelegate
2015-06-09 22:32:43 +12:00
class outlineView(QTreeView, dndView, outlineBasics):
def __init__(self, parent=None, modelCharacters=None, modelLabels=None, modelStatus=None):
2015-06-09 22:32:43 +12:00
QTreeView.__init__(self, parent)
dndView.__init__(self)
outlineBasics.__init__(self, parent)
2016-02-07 00:34:22 +13:00
self.modelCharacters = modelCharacters
2015-06-10 00:03:22 +12:00
self.modelLabels = modelLabels
2015-06-11 01:57:44 +12:00
self.modelStatus = modelStatus
2016-02-07 00:34:22 +13:00
2015-06-09 22:32:43 +12:00
self.header().setStretchLastSection(False)
2016-02-07 00:34:22 +13:00
def setModelCharacters(self, model):
# This is used by outlineCharacterDelegate to select character
self.modelCharacters = model
2016-02-07 00:34:22 +13:00
2015-06-10 00:03:22 +12:00
def setModelLabels(self, model):
2015-06-18 03:15:13 +12:00
# This is used by outlineLabelDelegate to display labels
2015-06-10 00:03:22 +12:00
self.modelLabels = model
2016-02-07 00:34:22 +13:00
2015-06-11 01:57:44 +12:00
def setModelStatus(self, model):
2015-06-18 03:15:13 +12:00
# This is used by outlineStatusDelegate to display statuses
2015-06-11 01:57:44 +12:00
self.modelStatus = model
2016-02-07 00:34:22 +13:00
2015-06-09 22:32:43 +12:00
def setModel(self, model):
QTreeView.setModel(self, model)
2016-02-07 00:34:22 +13:00
2015-06-09 22:32:43 +12:00
# Setting delegates
2015-06-22 23:11:45 +12:00
self.outlineTitleDelegate = outlineTitleDelegate(self)
2016-02-07 00:34:22 +13:00
# self.outlineTitleDelegate.setView(self)
2017-11-16 08:58:12 +13:00
self.setItemDelegateForColumn(Outline.title, self.outlineTitleDelegate)
2016-03-06 20:47:51 +13:00
self.outlineCharacterDelegate = outlineCharacterDelegate(self.modelCharacters)
2017-11-16 08:58:12 +13:00
self.setItemDelegateForColumn(Outline.POV, self.outlineCharacterDelegate)
2015-06-18 03:15:13 +12:00
self.outlineCompileDelegate = outlineCompileDelegate()
2017-11-16 08:58:12 +13:00
self.setItemDelegateForColumn(Outline.compile, self.outlineCompileDelegate)
2015-06-18 03:15:13 +12:00
self.outlineStatusDelegate = outlineStatusDelegate(self.modelStatus)
2017-11-16 08:58:12 +13:00
self.setItemDelegateForColumn(Outline.status, self.outlineStatusDelegate)
2015-06-18 03:15:13 +12:00
self.outlineGoalPercentageDelegate = outlineGoalPercentageDelegate()
2017-11-16 08:58:12 +13:00
self.setItemDelegateForColumn(Outline.goalPercentage, self.outlineGoalPercentageDelegate)
2015-06-18 03:15:13 +12:00
self.outlineLabelDelegate = outlineLabelDelegate(self.modelLabels)
2017-11-16 08:58:12 +13:00
self.setItemDelegateForColumn(Outline.label, self.outlineLabelDelegate)
2016-02-07 00:34:22 +13:00
2015-06-09 22:32:43 +12:00
# Hiding columns
2015-06-18 04:40:55 +12:00
self.hideColumns()
2016-02-07 00:34:22 +13:00
2017-11-16 08:58:12 +13:00
self.header().setSectionResizeMode(Outline.title, QHeaderView.Stretch)
self.header().setSectionResizeMode(Outline.POV, QHeaderView.ResizeToContents)
self.header().setSectionResizeMode(Outline.status, QHeaderView.ResizeToContents)
self.header().setSectionResizeMode(Outline.label, QHeaderView.ResizeToContents)
self.header().setSectionResizeMode(Outline.compile, QHeaderView.ResizeToContents)
self.header().setSectionResizeMode(Outline.wordCount, QHeaderView.ResizeToContents)
self.header().setSectionResizeMode(Outline.goal, QHeaderView.ResizeToContents)
self.header().setSectionResizeMode(Outline.goalPercentage, QHeaderView.ResizeToContents)
2016-02-07 00:34:22 +13:00
2015-06-18 04:40:55 +12:00
def hideColumns(self):
2016-03-25 01:42:47 +13:00
if not self.model():
# outlineView is probably not initialized, because editorWidgets shows index cards or text.
return
2015-06-18 04:40:55 +12:00
for c in range(self.model().columnCount()):
self.hideColumn(c)
for c in settings.outlineViewColumns:
self.showColumn(c)
2016-02-07 00:34:22 +13:00
2015-06-09 22:32:43 +12:00
def setRootIndex(self, index):
QTreeView.setRootIndex(self, index)
2015-06-18 03:15:13 +12:00
self.outlineGoalPercentageDelegate = outlineGoalPercentageDelegate(index)
2017-11-16 08:58:12 +13:00
self.setItemDelegateForColumn(Outline.goalPercentage, self.outlineGoalPercentageDelegate)
2016-02-07 00:34:22 +13:00
2015-06-09 22:32:43 +12:00
def dragMoveEvent(self, event):
dndView.dragMoveEvent(self, event)
QTreeView.dragMoveEvent(self, event)
2016-02-07 00:34:22 +13:00
def mousePressEvent(self, event):
# Prevent selecting item while right-clicking for popup menu!
if event.button() != Qt.RightButton:
QTreeView.mousePressEvent(self, event)
outlineBasics.mousePressEvent(self, event)
def mouseReleaseEvent(self, event):
QTreeView.mouseReleaseEvent(self, event)
outlineBasics.mouseReleaseEvent(self, event)