#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
def __init__(self, parent = None):
super(bubbleDelegate, self).__init__(parent)
self.
errorColor = QColor(settings.
value("bubble/errorColor",
QColor(Qt.
red)))
def minimumSizeHint(self,option, index):
def sizeHint(self, option, index):
text = index.data(Qt.UserRole +1).toString().split('\n')
textH = 0
for i in text:
textH = textH + option.fontMetrics.boundingRect(0,0,option.rect.width()/2-4,0, Qt.TextWordWrap, i).height()
#text = option.fontMetrics.boundingRect(option.rect.x(), option.rect.y(), option.rect.width()/2, 100, Qt.TextWrapAnywhere, index.data(Qt.UserRole + 1).toString())
font.setPointSize(6)
hour = fontM.boundingRect(option.rect.x(), option.rect.y(), option.rect.width()/2, 100, Qt.TextWrapAnywhere, index.data(Qt.UserRole + 2).toString())
return QSize(option.
rect.
width(),textH
+hour.
height()+2)
def paint(self, painter, option, index):
hourFont.setPointSize(6)
hour = hourFontM.boundingRect(option.rect.x(), option.rect.y(), option.rect.width()/2, 100, Qt.TextWrapAnywhere, index.data(Qt.UserRole + 2).toString())
painter.
setRenderHint(QPainter.
Antialiasing,
True) painter.setPen(Qt.black)
text = index.data(Qt.UserRole +1).toString().split('\n')
h = 0
textH=0
if index.data(Qt.UserRole + 3).toBool() == True:
painter.
setBrush(QColor(index.
data(Qt.
UserRole + 4))) painter.drawRoundedRect(option.rect.x(), option.rect.y(), option.rect.width()/2 -1 ,option.rect.height(),5,5)
painter.setFont(textFont)
for i in text:
textH = textH + option.fontMetrics.boundingRect(0,0,option.rect.width()/2-4,0, Qt.TextWordWrap, i).height()
painter.drawText(option.rect.x()+2, option.rect.y()+2+h, option.rect.width()/2 -1, option.rect.height(),Qt.TextWordWrap,i)
h += textH
y = option.rect.y() +option.rect.height() - hour.height()-1
painter.setFont(hourFont)
painter.drawText(option.rect.x()+2, y, option.rect.width()/2 -1, option.rect.height(),Qt.TextWrapAnywhere,index.data(Qt.UserRole + 2).toString())
else:
painter.
setBrush(QColor(index.
data(Qt.
UserRole + 4))) painter.drawRoundedRect(option.rect.width()/2+1, option.rect.y(), option.rect.width()/2 -1 ,option.rect.height(),5,5)
painter.setFont(textFont)
h = 0
textH = 0
for i in text:
textH = textH + option.fontMetrics.boundingRect(0,0,option.rect.width()/2-4,0, Qt.TextWordWrap, i).height()
#painter.drawText(option.rect.x()+2, option.rect.y()+2+h, option.rect.width()/2 -1, option.rect.height(),Qt.TextWordWrap,i)
painter.drawText(option.rect.width()/2+2, option.rect.y()+2+h, option.rect.width()/2 -1, option.rect.height(),Qt.TextWordWrap,i)
h += textH
#painter.drawText(option.rect.width()/2+2, option.rect.y()+2, option.rect.width()/2 -1, option.rect.height(),Qt.TextWrapAnywhere,index.data(Qt.UserRole + 1).toString())
y = option.rect.y() +option.rect.height() - hour.height()-1
painter.setFont(hourFont)
painter.drawText(option.rect.width() - hour.width() - 2, y, option.rect.width()/2 -1, option.rect.height(),Qt.TextWrapAnywhere,index.data(Qt.UserRole + 2).toString())
status = index.data(Qt.UserRole + 5)
if (status == 1):
painter.setBrush(Qt.green)
painter.setPen(Qt.green)
polygon.translate(option.rect.width()/2+4, y)
painter.drawPolygon(polygon)
def updateColors(self,received, sended):
self.received = received
self.sended = sended
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
from PyQt4.QtCore import Qt, QSize, QSettings, QPointF
from PyQt4.QtGui import QItemDelegate, QPainter, QStyle, QFont, QFontMetrics, QColor, QPolygonF
class bubbleDelegate(QItemDelegate):
def __init__(self, parent = None):
super(bubbleDelegate, self).__init__(parent)
settings = QSettings()
self.errorColor = QColor(settings.value("bubble/errorColor", QColor(Qt.red)))
def minimumSizeHint(self,option, index):
return QSize(10,10)
def sizeHint(self, option, index):
text = index.data(Qt.UserRole +1).toString().split('\n')
textH = 0
for i in text:
textH = textH + option.fontMetrics.boundingRect(0,0,option.rect.width()/2-4,0, Qt.TextWordWrap, i).height()
#text = option.fontMetrics.boundingRect(option.rect.x(), option.rect.y(), option.rect.width()/2, 100, Qt.TextWrapAnywhere, index.data(Qt.UserRole + 1).toString())
font = QFont()
font.setPointSize(6)
fontM = QFontMetrics(font)
hour = fontM.boundingRect(option.rect.x(), option.rect.y(), option.rect.width()/2, 100, Qt.TextWrapAnywhere, index.data(Qt.UserRole + 2).toString())
return QSize(option.rect.width(),textH+hour.height()+2)
def paint(self, painter, option, index):
hourFont = QFont()
hourFont.setPointSize(6)
hourFontM = QFontMetrics(hourFont)
hour = hourFontM.boundingRect(option.rect.x(), option.rect.y(), option.rect.width()/2, 100, Qt.TextWrapAnywhere, index.data(Qt.UserRole + 2).toString())
textFont = QFont()
painter.setRenderHint(QPainter.Antialiasing, True)
painter.setPen(Qt.black)
text = index.data(Qt.UserRole +1).toString().split('\n')
h = 0
textH=0
if index.data(Qt.UserRole + 3).toBool() == True:
painter.setBrush(QColor(index.data(Qt.UserRole + 4)))
painter.drawRoundedRect(option.rect.x(), option.rect.y(), option.rect.width()/2 -1 ,option.rect.height(),5,5)
painter.setFont(textFont)
for i in text:
textH = textH + option.fontMetrics.boundingRect(0,0,option.rect.width()/2-4,0, Qt.TextWordWrap, i).height()
painter.drawText(option.rect.x()+2, option.rect.y()+2+h, option.rect.width()/2 -1, option.rect.height(),Qt.TextWordWrap,i)
h += textH
y = option.rect.y() +option.rect.height() - hour.height()-1
painter.setFont(hourFont)
painter.drawText(option.rect.x()+2, y, option.rect.width()/2 -1, option.rect.height(),Qt.TextWrapAnywhere,index.data(Qt.UserRole + 2).toString())
else:
painter.setBrush(QColor(index.data(Qt.UserRole + 4)))
painter.drawRoundedRect(option.rect.width()/2+1, option.rect.y(), option.rect.width()/2 -1 ,option.rect.height(),5,5)
painter.setFont(textFont)
h = 0
textH = 0
for i in text:
textH = textH + option.fontMetrics.boundingRect(0,0,option.rect.width()/2-4,0, Qt.TextWordWrap, i).height()
#painter.drawText(option.rect.x()+2, option.rect.y()+2+h, option.rect.width()/2 -1, option.rect.height(),Qt.TextWordWrap,i)
painter.drawText(option.rect.width()/2+2, option.rect.y()+2+h, option.rect.width()/2 -1, option.rect.height(),Qt.TextWordWrap,i)
h += textH
#painter.drawText(option.rect.width()/2+2, option.rect.y()+2, option.rect.width()/2 -1, option.rect.height(),Qt.TextWrapAnywhere,index.data(Qt.UserRole + 1).toString())
y = option.rect.y() +option.rect.height() - hour.height()-1
painter.setFont(hourFont)
painter.drawText(option.rect.width() - hour.width() - 2, y, option.rect.width()/2 -1, option.rect.height(),Qt.TextWrapAnywhere,index.data(Qt.UserRole + 2).toString())
status = index.data(Qt.UserRole + 5)
if (status == 1):
painter.setBrush(Qt.green)
painter.setPen(Qt.green)
polygon = QPolygonF()
polygon.append(QPointF(0.0,3.0))
polygon.append(QPointF(5.0,8.0))
polygon.append(QPointF(10.0,0.0))
polygon.append(QPointF(5.0,5.0))
polygon.append(QPointF(0.0,3.0))
polygon.translate(option.rect.width()/2+4, y)
painter.drawPolygon(polygon)
def updateColors(self,received, sended):
self.received = received
self.sended = sended
To copy to clipboard, switch view to plain text mode
I know, that this is poor code. I will write it better.
Bookmarks