Adds: new flash card style

This commit is contained in:
Olivier Keshavjee 2017-10-14 17:11:17 +02:00
parent db8ef59c2f
commit e11e9f81b5
6 changed files with 477 additions and 161 deletions

View file

@ -133,13 +133,19 @@ def outlineItemColors(item):
# POV
colors["POV"] = QColor(Qt.transparent)
POV = item.data(Outline.POV.value)
for i in range(mw.mdlCharacter.rowCount()):
if mw.mdlCharacter.ID(i) == POV:
colors["POV"] = iconColor(mw.mdlCharacter.icon(i))
if POV == "":
col = QColor(Qt.transparent)
else:
for i in range(mw.mdlCharacter.rowCount()):
if mw.mdlCharacter.ID(i) == POV:
colors["POV"] = iconColor(mw.mdlCharacter.icon(i))
# Label
lbl = item.data(Outline.label.value)
col = iconColor(mw.mdlLabels.item(toInt(lbl)).icon())
if lbl == "":
col = QColor(Qt.transparent)
else:
col = iconColor(mw.mdlLabels.item(toInt(lbl)).icon())
# if col == Qt.black:
# # Don't know why, but transparent is rendered as black
# col = QColor(Qt.transparent)

View file

@ -52,6 +52,7 @@ corkBackground = {
"color": "#926239",
"image": "writingdesk"
}
corkStyle = "new"
defaultTextType = "md"
fullScreenTheme = "spacedreams"
@ -93,7 +94,7 @@ def save(filename=None, protocol=None):
global spellcheck, dict, corkSliderFactor, viewSettings, corkSizeFactor, folderView, lastTab, openIndexes, \
autoSave, autoSaveDelay, saveOnQuit, autoSaveNoChanges, autoSaveNoChangesDelay, outlineViewColumns, \
corkBackground, fullScreenTheme, defaultTextType, textEditor, revisions, frequencyAnalyzer, viewMode, \
corkBackground, corkStyle, fullScreenTheme, defaultTextType, textEditor, revisions, frequencyAnalyzer, viewMode, \
saveToZip
allSettings = {
@ -111,6 +112,7 @@ def save(filename=None, protocol=None):
"autoSaveNoChangesDelay":autoSaveNoChangesDelay,
"outlineViewColumns":outlineViewColumns,
"corkBackground":corkBackground,
"corkStyle": corkStyle,
"fullScreenTheme":fullScreenTheme,
"defaultTextType":defaultTextType,
"textEditor":textEditor,
@ -216,6 +218,10 @@ def load(string, fromString=False, protocol=None):
global corkBackground
corkBackground = allSettings["corkBackground"]
if "corkStyle" in allSettings:
global corkStyle
corkStyle = allSettings["corkStyle"]
if "fullScreenTheme" in allSettings:
global fullScreenTheme
fullScreenTheme = allSettings["fullScreenTheme"]

View file

@ -126,7 +126,12 @@ class settingsWindow(QWidget, Ui_Settings):
]:
item.setChecked(settings.viewSettings["Tree"][what] == value)
item.toggled.connect(self.treeViewSettignsChanged)
self.rdoCorkOldStyle.setChecked(settings.corkStyle == "old")
self.rdoCorkNewStyle.setChecked(settings.corkStyle == "new")
self.rdoCorkNewStyle.toggled.connect(self.setCorkStyle)
self.rdoCorkOldStyle.toggled.connect(self.setCorkStyle)
self.populatesCmbBackgrounds(self.cmbCorkImage)
self.setCorkImageDefault()
self.updateCorkColor()
@ -339,6 +344,10 @@ class settingsWindow(QWidget, Ui_Settings):
self.updateCorkColor()
# Update Cork view
self.mw.mainEditor.updateCorkBackground()
def setCorkStyle(self):
settings.corkStyle = "new" if self.rdoCorkNewStyle.isChecked() else "old"
self.mw.mainEditor.updateCorkView()
def updateCorkColor(self):
self.btnCorkColor.setStyleSheet("background:{};".format(settings.corkBackground["color"]))

View file

@ -2,7 +2,8 @@
# Form implementation generated from reading ui file 'manuskript/ui/settings_ui.ui'
#
# Created by: PyQt5 UI code generator 5.4.2
# Created: Sat Oct 14 16:47:16 2017
# by: PyQt5 UI code generator 5.2.1
#
# WARNING! All changes made in this file will be lost!
@ -748,8 +749,73 @@ class Ui_Settings(object):
self.tabViews.addTab(self.tab_2, "")
self.tab_3 = QtWidgets.QWidget()
self.tab_3.setObjectName("tab_3")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.tab_3)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.gridLayout_3 = QtWidgets.QGridLayout(self.tab_3)
self.gridLayout_3.setObjectName("gridLayout_3")
self.groupBox_7 = QtWidgets.QGroupBox(self.tab_3)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.groupBox_7.setFont(font)
self.groupBox_7.setObjectName("groupBox_7")
self.verticalLayout_8 = QtWidgets.QVBoxLayout(self.groupBox_7)
self.verticalLayout_8.setObjectName("verticalLayout_8")
self.label_15 = QtWidgets.QLabel(self.groupBox_7)
font = QtGui.QFont()
font.setBold(False)
font.setWeight(50)
self.label_15.setFont(font)
self.label_15.setObjectName("label_15")
self.verticalLayout_8.addWidget(self.label_15)
self.btnCorkColor = QtWidgets.QPushButton(self.groupBox_7)
self.btnCorkColor.setMaximumSize(QtCore.QSize(16777215, 32))
font = QtGui.QFont()
font.setBold(False)
font.setWeight(50)
self.btnCorkColor.setFont(font)
self.btnCorkColor.setText("")
self.btnCorkColor.setIconSize(QtCore.QSize(64, 64))
self.btnCorkColor.setObjectName("btnCorkColor")
self.verticalLayout_8.addWidget(self.btnCorkColor)
self.label_16 = QtWidgets.QLabel(self.groupBox_7)
font = QtGui.QFont()
font.setBold(False)
font.setWeight(50)
self.label_16.setFont(font)
self.label_16.setObjectName("label_16")
self.verticalLayout_8.addWidget(self.label_16)
self.cmbCorkImage = QtWidgets.QComboBox(self.groupBox_7)
font = QtGui.QFont()
font.setBold(False)
font.setWeight(50)
self.cmbCorkImage.setFont(font)
self.cmbCorkImage.setObjectName("cmbCorkImage")
self.verticalLayout_8.addWidget(self.cmbCorkImage)
spacerItem7 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_8.addItem(spacerItem7)
self.gridLayout_3.addWidget(self.groupBox_7, 1, 1, 1, 1)
self.groupBox_11 = QtWidgets.QGroupBox(self.tab_3)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.groupBox_11.setFont(font)
self.groupBox_11.setObjectName("groupBox_11")
self.verticalLayout_19 = QtWidgets.QVBoxLayout(self.groupBox_11)
self.verticalLayout_19.setObjectName("verticalLayout_19")
self.rdoCorkOldStyle = QtWidgets.QRadioButton(self.groupBox_11)
font = QtGui.QFont()
font.setBold(False)
font.setWeight(50)
self.rdoCorkOldStyle.setFont(font)
self.rdoCorkOldStyle.setObjectName("rdoCorkOldStyle")
self.verticalLayout_19.addWidget(self.rdoCorkOldStyle)
self.rdoCorkNewStyle = QtWidgets.QRadioButton(self.groupBox_11)
font = QtGui.QFont()
font.setBold(False)
font.setWeight(50)
self.rdoCorkNewStyle.setFont(font)
self.rdoCorkNewStyle.setObjectName("rdoCorkNewStyle")
self.verticalLayout_19.addWidget(self.rdoCorkNewStyle)
self.gridLayout_3.addWidget(self.groupBox_11, 0, 1, 1, 1)
self.groupBox_5 = QtWidgets.QGroupBox(self.tab_3)
font = QtGui.QFont()
font.setBold(True)
@ -854,49 +920,7 @@ class Ui_Settings(object):
self.cmbCorkCorner.addItem("")
self.cmbCorkCorner.addItem("")
self.formLayout_2.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.cmbCorkCorner)
self.horizontalLayout_4.addWidget(self.groupBox_5)
self.groupBox_7 = QtWidgets.QGroupBox(self.tab_3)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.groupBox_7.setFont(font)
self.groupBox_7.setObjectName("groupBox_7")
self.verticalLayout_8 = QtWidgets.QVBoxLayout(self.groupBox_7)
self.verticalLayout_8.setObjectName("verticalLayout_8")
self.label_15 = QtWidgets.QLabel(self.groupBox_7)
font = QtGui.QFont()
font.setBold(False)
font.setWeight(50)
self.label_15.setFont(font)
self.label_15.setObjectName("label_15")
self.verticalLayout_8.addWidget(self.label_15)
self.btnCorkColor = QtWidgets.QPushButton(self.groupBox_7)
self.btnCorkColor.setMaximumSize(QtCore.QSize(16777215, 32))
font = QtGui.QFont()
font.setBold(False)
font.setWeight(50)
self.btnCorkColor.setFont(font)
self.btnCorkColor.setText("")
self.btnCorkColor.setIconSize(QtCore.QSize(64, 64))
self.btnCorkColor.setObjectName("btnCorkColor")
self.verticalLayout_8.addWidget(self.btnCorkColor)
self.label_16 = QtWidgets.QLabel(self.groupBox_7)
font = QtGui.QFont()
font.setBold(False)
font.setWeight(50)
self.label_16.setFont(font)
self.label_16.setObjectName("label_16")
self.verticalLayout_8.addWidget(self.label_16)
self.cmbCorkImage = QtWidgets.QComboBox(self.groupBox_7)
font = QtGui.QFont()
font.setBold(False)
font.setWeight(50)
self.cmbCorkImage.setFont(font)
self.cmbCorkImage.setObjectName("cmbCorkImage")
self.verticalLayout_8.addWidget(self.cmbCorkImage)
spacerItem7 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_8.addItem(spacerItem7)
self.horizontalLayout_4.addWidget(self.groupBox_7)
self.gridLayout_3.addWidget(self.groupBox_5, 0, 0, 2, 1)
self.tabViews.addTab(self.tab_3, "")
self.tab_4 = QtWidgets.QWidget()
self.tab_4.setObjectName("tab_4")
@ -1329,6 +1353,7 @@ class Ui_Settings(object):
self.layoutWidget = QtWidgets.QWidget(self.splitter)
self.layoutWidget.setObjectName("layoutWidget")
self.verticalLayout_14 = QtWidgets.QVBoxLayout(self.layoutWidget)
self.verticalLayout_14.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_14.setObjectName("verticalLayout_14")
self.cmbThemeEdit = QtWidgets.QComboBox(self.layoutWidget)
self.cmbThemeEdit.setObjectName("cmbThemeEdit")
@ -1608,7 +1633,7 @@ class Ui_Settings(object):
self.horizontalLayout_8.addWidget(self.stack)
self.retranslateUi(Settings)
self.stack.setCurrentIndex(0)
self.stack.setCurrentIndex(2)
self.tabViews.setCurrentIndex(0)
self.themeStack.setCurrentIndex(1)
self.themeEditStack.setCurrentIndex(0)
@ -1721,6 +1746,13 @@ class Ui_Settings(object):
self.chkOutlinePOV.setText(_translate("Settings", "POV"))
self.chkOutlineTitle.setText(_translate("Settings", "Title"))
self.tabViews.setTabText(self.tabViews.indexOf(self.tab_2), _translate("Settings", "Outline"))
self.groupBox_7.setTitle(_translate("Settings", "Background"))
self.label_15.setText(_translate("Settings", "Color:"))
self.btnCorkColor.setShortcut(_translate("Settings", "Ctrl+S"))
self.label_16.setText(_translate("Settings", "Image:"))
self.groupBox_11.setTitle(_translate("Settings", "Style"))
self.rdoCorkOldStyle.setText(_translate("Settings", "Old style"))
self.rdoCorkNewStyle.setText(_translate("Settings", "New style"))
self.groupBox_5.setTitle(_translate("Settings", "Item colors"))
self.label_9.setText(_translate("Settings", "Icon color:"))
self.cmbCorkIcon.setItemText(0, _translate("Settings", "Nothing"))
@ -1752,10 +1784,6 @@ class Ui_Settings(object):
self.cmbCorkCorner.setItemText(2, _translate("Settings", "Label"))
self.cmbCorkCorner.setItemText(3, _translate("Settings", "Progress"))
self.cmbCorkCorner.setItemText(4, _translate("Settings", "Compile"))
self.groupBox_7.setTitle(_translate("Settings", "Background"))
self.label_15.setText(_translate("Settings", "Color:"))
self.btnCorkColor.setShortcut(_translate("Settings", "Ctrl+S"))
self.label_16.setText(_translate("Settings", "Image:"))
self.tabViews.setTabText(self.tabViews.indexOf(self.tab_3), _translate("Settings", "Index cards"))
self.groupBox_12.setTitle(_translate("Settings", "Font"))
self.label_37.setText(_translate("Settings", "Color:"))

View file

@ -51,7 +51,7 @@
<item>
<widget class="QStackedWidget" name="stack">
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="stackedWidgetPage1">
<layout class="QVBoxLayout" name="verticalLayout_7">
@ -1514,8 +1514,141 @@ text-align:center;</string>
<attribute name="title">
<string>Index cards</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="1">
<widget class="QGroupBox" name="groupBox_7">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="title">
<string>Background</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QLabel" name="label_15">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Color:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnCorkColor">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>32</height>
</size>
</property>
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_16">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Image:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cmbCorkImage">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<widget class="QGroupBox" name="groupBox_11">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="title">
<string>Style</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_19">
<item>
<widget class="QRadioButton" name="rdoCorkOldStyle">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Old style</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rdoCorkNewStyle">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>New style</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0" rowspan="2">
<widget class="QGroupBox" name="groupBox_5">
<property name="font">
<font>
@ -1773,98 +1906,6 @@ text-align:center;</string>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_7">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="title">
<string>Background</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QLabel" name="label_15">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Color:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnCorkColor">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>32</height>
</size>
</property>
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_16">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Image:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cmbCorkImage">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_4">

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python
# --!-- coding: utf8 --!--
from PyQt5.QtCore import QSize, Qt, QRect, QPoint
from PyQt5.QtGui import QMouseEvent, QFont, QPalette, QRegion, QFontMetrics, QColor, QIcon
from PyQt5.QtCore import QSize, Qt, QRect, QPoint, QPointF
from PyQt5.QtGui import QMouseEvent, QFont, QPalette, QRegion, QFontMetrics, QColor, QIcon, QPolygonF
from PyQt5.QtWidgets import QStyledItemDelegate, QLineEdit, QPlainTextEdit, QFrame, qApp, QStyle
from manuskript import settings
@ -16,16 +16,22 @@ class corkDelegate(QStyledItemDelegate):
def __init__(self, parent=None):
QStyledItemDelegate.__init__(self, parent)
self.factor = settings.corkSizeFactor / 100.
self.defaultSize = QSize(300, 200)
self.lastPos = None
self.editing = None
self.margin = 5
def newStyle(self):
return settings.corkStyle == "new"
def setCorkSizeFactor(self, v):
self.factor = v / 100.
def sizeHint(self, option, index):
return self.defaultSize * self.factor
if self.newStyle():
defaultSize = QSize(300, 210)
else:
defaultSize = QSize(300, 200)
return defaultSize * self.factor
def editorEvent(self, event, model, option, index):
# We catch the mouse position in the widget to know which part to edit
@ -42,10 +48,13 @@ class corkDelegate(QStyledItemDelegate):
edt = QLineEdit(parent)
edt.setFocusPolicy(Qt.StrongFocus)
edt.setFrame(False)
edt.setAlignment(Qt.AlignCenter)
edt.setPlaceholderText(self.tr("One line summary"))
f = QFont(option.font)
f.setItalic(True)
if self.newStyle():
f.setBold(True)
else:
f.setItalic(True)
edt.setAlignment(Qt.AlignCenter)
edt.setPlaceholderText(self.tr("One line summary"))
edt.setFont(f)
return edt
@ -56,10 +65,12 @@ class corkDelegate(QStyledItemDelegate):
edt.setFocusPolicy(Qt.StrongFocus)
edt.setFrame(False)
f = QFont(option.font)
# f.setPointSize(f.pointSize() + 1)
if self.newStyle():
f.setPointSize(f.pointSize() + 4)
else:
edt.setAlignment(Qt.AlignCenter)
f.setBold(True)
edt.setFont(f)
edt.setAlignment(Qt.AlignCenter)
# edt.setGeometry(self.titleRect)
return edt
@ -120,6 +131,44 @@ class corkDelegate(QStyledItemDelegate):
model.setData(index.sibling(index.row(), Outline.summaryFull.value), editor.toPlainText())
def updateRects(self, option, index):
if self.newStyle():
self.updateRects_v2(option, index)
else:
self.updateRects_v1(option, index)
def updateRects_v2(self, option, index):
margin = self.margin * 2
iconSize = max(24 * self.factor, 18)
item = index.internalPointer()
fm = QFontMetrics(option.font)
h = fm.lineSpacing()
self.itemRect = option.rect.adjusted(margin, margin, -margin, -margin)
top = 15 * self.factor
self.topRect = QRect(self.itemRect)
self.topRect.setHeight(top)
self.cardRect = QRect(self.itemRect.topLeft() + QPoint(0, top),
self.itemRect.bottomRight())
self.iconRect = QRect(self.cardRect.topLeft() + QPoint(margin, margin),
QSize(iconSize, iconSize))
self.labelRect = QRect(self.cardRect.topRight() - QPoint(margin + self.factor * 18, 1),
self.cardRect.topRight() + QPoint(- margin - self.factor * 4, self.factor * 24))
self.titleRect = QRect(self.iconRect.topRight() + QPoint(margin, 0),
self.labelRect.bottomLeft() - QPoint(margin, margin))
self.titleRect.setBottom(self.iconRect.bottom())
self.mainRect = QRect(self.iconRect.bottomLeft() + QPoint(0, margin),
self.cardRect.bottomRight() - QPoint(margin, 2*margin))
self.mainRect.setLeft(self.titleRect.left())
self.mainLineRect = QRect(self.mainRect.topLeft(),
self.mainRect.topRight() + QPoint(0, h))
self.mainTextRect = QRect(self.mainLineRect.bottomLeft() + QPoint(0, margin),
self.mainRect.bottomRight())
if not item.data(Outline.summarySentence.value):
self.mainTextRect.setTopLeft(self.mainLineRect.topLeft())
def updateRects_v1(self, option, index):
margin = self.margin
iconSize = max(16 * self.factor, 12)
item = index.internalPointer()
@ -143,6 +192,183 @@ class corkDelegate(QStyledItemDelegate):
self.titleRect.setBottomRight(self.labelRect.bottomRight() - QPoint(self.margin, self.margin))
def paint(self, p, option, index):
if self.newStyle():
self.paint_v2(p, option, index)
else:
self.paint_v1(p, option, index)
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):
p.translate(self.mainRect.center())
p.rotate(angle)
p.translate(-self.mainRect.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)
p.setBrush(col)
else:
p.setBrush(Qt.white)
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:
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() + 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.value)
fullSummary = item.data(Outline.summaryFull.value)
# 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
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(170))
_rotate(-35)
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)
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.setFont(option.font)
p.drawText(self.mainTextRect, Qt.TextWordWrap, fullSummary)
def paint_v1(self, p, option, index):
# QStyledItemDelegate.paint(self, p, option, index)
if not index.isValid():
return