From b7225938de274d1054cba69d227d4527a055f47b Mon Sep 17 00:00:00 2001 From: Olivier Keshavjee Date: Tue, 9 Jun 2015 22:05:03 +0200 Subject: [PATCH] Delegates shows label color --- src/functions.py | 6 +++++- src/ui/views/corkDelegate.py | 32 ++++++++++++++++++++++++-------- test_project/outline.xml | 34 +++++++++++++++++----------------- 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/src/functions.py b/src/functions.py index 07d36c26..ed168374 100644 --- a/src/functions.py +++ b/src/functions.py @@ -48,4 +48,8 @@ def mainWindow(): for i in qApp.topLevelWidgets(): if i.objectName() == "MainWindow": return i - return None \ No newline at end of file + return None + +def iconColor(icon): + "Returns a QRgb from a QIcon, assuming its all the same color" + return QColor(QImage(icon.pixmap(5, 5)).pixel(2, 2)) \ No newline at end of file diff --git a/src/ui/views/corkDelegate.py b/src/ui/views/corkDelegate.py index 933fec93..8e81b1dd 100644 --- a/src/ui/views/corkDelegate.py +++ b/src/ui/views/corkDelegate.py @@ -120,11 +120,12 @@ class corkDelegate(QStyledItemDelegate): item = index.internalPointer() self.itemRect = option.rect.adjusted(margin, margin, -margin, -margin) self.iconRect = QRect(self.itemRect.topLeft() + QPoint(margin, margin), QSize(iconSize, iconSize)) - self.titleRect = QRect(self.iconRect.topRight().x() + margin, self.iconRect.top(), - self.itemRect.topRight().x() - self.iconRect.right() - 2 * margin, - self.iconRect.height()) - self.bottomRect = QRect(QPoint(self.itemRect.x(), self.iconRect.bottom() + margin), - QPoint(self.itemRect.right(), self.itemRect.bottom())) + self.labelRect = QRect(self.itemRect.topRight() - QPoint(iconSize + margin, 0), + self.itemRect.topRight() + QPoint(0, iconSize + 2 * margin)) + self.titleRect = QRect(self.iconRect.topRight() + QPoint(margin, 0), + self.labelRect.bottomLeft() - QPoint(margin, margin)) + self.bottomRect = QRect(QPoint(self.itemRect.x(), self.iconRect.bottom() + margin), + QPoint(self.itemRect.right(), self.itemRect.bottom())) self.topRect = QRect(self.itemRect.topLeft(), self.bottomRect.topRight()) self.mainRect = self.bottomRect.adjusted(margin, margin, -margin, -margin) self.mainLineRect = QRect(self.mainRect.topLeft(), @@ -133,7 +134,8 @@ class corkDelegate(QStyledItemDelegate): self.mainRect.bottomRight()) if not item.data(Outline.summarySentance.value) : self.mainTextRect.setTopLeft(self.mainLineRect.topLeft()) - + if item.data(Outline.label.value) in ["", "0"]: + self.titleRect.setBottomRight(self.labelRect.bottomRight() - QPoint(self.margin, self.margin)) def paint(self, p, option, index): #QStyledItemDelegate.paint(self, p, option, index) @@ -166,10 +168,10 @@ class corkDelegate(QStyledItemDelegate): # Stack if item.isFolder() and item.childCount() > 0: p.save() - angle = [-3, 5, 3] p.setBrush(Qt.white) for i in reversed(range(3)): - p.drawRoundedRect(self.itemRect.translated(3*i, 3*i), 10, 10) + p.drawRoundedRect(self.itemRect.adjusted(2*i, 2*i, -2*i, 2*i), 10, 10) + p.restore() # Background @@ -196,6 +198,20 @@ class corkDelegate(QStyledItemDelegate): #p.drawRect(topRect) p.restore() + # Label color + lbl = item.data(Outline.label.value) + if lbl and lbl != "0": + it = mainWindow().mdlLabels.item(int(lbl), 0) + if it != None: + p.save() + color = iconColor(it.icon()) + p.setPen(Qt.NoPen) + p.setBrush(QBrush(color)) + p.setClipRegion(QRegion(self.labelRect)) + p.drawRoundedRect(itemRect, 10, 10) + #p.drawRect(topRect) + p.restore() + # One line summary background lineSummary = item.data(Outline.summarySentance.value) fullSummary = item.data(Outline.summaryFull.value) diff --git a/test_project/outline.xml b/test_project/outline.xml index b1e6e827..6d2ce9dc 100644 --- a/test_project/outline.xml +++ b/test_project/outline.xml @@ -3,7 +3,7 @@ - + @@ -13,7 +13,7 @@ - + @@ -37,22 +37,22 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + - - + +