def data(self, index, role=Qt.DisplayRole): """score table""" # pylint: disable=R0912,R0914 # pylint too many branches result = QVariant() if role == Qt.TextAlignmentRole: if index.column() == 0: result = QVariant(int(Qt.AlignHCenter | Qt.AlignVCenter)) else: result = QVariant(int(Qt.AlignLeft | Qt.AlignVCenter)) if index.isValid() and (0 <= index.row() < len(self.tables)): table = self.tables[index.row()] if role == Qt.DisplayRole and index.column() in (0, 1): result = QVariant(table.tableid) elif role == Qt.DisplayRole and index.column() == 2: players = [] zipped = zip(table.playerNames, table.playersOnline) for idx, pair in enumerate(zipped): name, online = pair[0], pair[1] if idx < len(zipped) - 1: name += ', ' palette = KApplication.palette() if online: color = palette.color(QPalette.Active, QPalette.WindowText).name() style = 'font-weight:normal;font-style:normal;color:%s' % color else: color = palette.color(QPalette.Disabled, QPalette.WindowText).name() style = 'font-weight:100;font-style:italic;color:%s' % color players.append('<nobr style="%s">' % style + name + '</nobr>') names = ''.join(players) result = QVariant(names) elif role == Qt.DisplayRole and index.column() == 3: status = table.status() if table.suspendedAt: dateVal = ' ' + datetime.datetime.strptime( table.suspendedAt, '%Y-%m-%dT%H:%M:%S').strftime('%c').decode('utf-8') status = 'Suspended' else: dateVal = '' result = QVariant(m18nc('table status', status) + dateVal) elif index.column() == 4: if role == Qt.DisplayRole: result = QVariant( m18n((table.myRuleset if table.myRuleset else table.ruleset).name)) elif role == Qt.ForegroundRole: palette = KApplication.palette() color = palette.windowText() if table.myRuleset else 'red' result = QVariant(QColor(color)) return result
def data(self, index, role=Qt.DisplayRole): """score table""" # pylint: disable=R0912,R0914 # pylint too many branches result = QVariant() if role == Qt.TextAlignmentRole: if index.column() == 0: result = QVariant(int(Qt.AlignHCenter|Qt.AlignVCenter)) else: result = QVariant(int(Qt.AlignLeft|Qt.AlignVCenter)) if index.isValid() and (0 <= index.row() < len(self.tables)): table = self.tables[index.row()] if role == Qt.DisplayRole and index.column() == 1: result = QVariant(table.tableid) elif role == Qt.DisplayRole and index.column() == 0: if not table.status.startswith('Suspended'): result = QVariant(table.tableid) elif role == Qt.DisplayRole and index.column() == 2: players = [] zipped = zip(table.playerNames, table.playersOnline) for idx, pair in enumerate(zipped): name, online = pair[0], pair[1] if idx < len(zipped) - 1: name += ', ' palette = KApplication.palette() if online: color = palette.color(QPalette.Active, QPalette.WindowText).name() style = 'font-weight:normal;font-style:normal;color:%s' % color else: color = palette.color(QPalette.Disabled, QPalette.WindowText).name() style = 'font-weight:100;font-style:italic;color:%s' % color players.append('<nobr style="%s">' % style + name + '</nobr>') names = ''.join(players) result = QVariant(names) elif role == Qt.DisplayRole and index.column() == 3: status = table.status if status.startswith('Suspended'): dateVal = ' ' + datetime.datetime.strptime(status.replace('Suspended', ''), '%Y-%m-%dT%H:%M:%S').strftime('%c').decode('utf-8') status = 'Suspended' else: dateVal = '' result = QVariant(m18nc('table status', status) + dateVal) elif index.column() == 4: if role == Qt.DisplayRole: result = QVariant(m18n(table.ruleset.name)) elif role == Qt.ForegroundRole: palette = KApplication.palette() color = palette.windowText() if table.myRuleset else 'red' result = QVariant(QColor(color)) return result
def data(self, index, role=Qt.DisplayRole): """score table""" result = toQVariant() if role == Qt.TextAlignmentRole: if index.column() == 1: return toQVariant(int(Qt.AlignRight)) else: return toQVariant(int(Qt.AlignLeft)) if index.isValid() and (0 <= index.row() < len(self.chatLines)): chatLine = self.chatLines[index.row()] if role == Qt.DisplayRole and index.column() == 0: local = chatLine.localtimestamp() result = toQVariant('%02d:%02d:%02d' % ( local.hour, local.minute, local.second)) elif role == Qt.DisplayRole and index.column() == 1: result = toQVariant(chatLine.fromUser) elif role == Qt.DisplayRole and index.column() == 2: result = toQVariant(m18n(chatLine.message)) elif role == Qt.ForegroundRole and index.column() == 2: palette = KApplication.palette() # pylint: disable=no-member color = 'blue' if chatLine.isStatusMessage else palette.windowText( ) result = toQVariant(QColor(color)) return result
class ScoreItemDelegate(QStyledItemDelegate): """since setting delegates for a row does not work as wanted with a tree view, we set the same delegate on ALL items.""" # try to use colors that look good with all color schemes. Bright # contrast colors are not optimal as long as our lines have a width of # only one pixel: antialiasing is not sufficient colors = [ KApplication.palette().color(x) for x in [QPalette.Text, QPalette.Link, QPalette.LinkVisited] ] colors.append(QColor('orange')) def __init__(self, parent=None): QStyledItemDelegate.__init__(self, parent) def paint(self, painter, option, index): """where the real work is done...""" item = index.internalPointer() if isinstance(item, ScorePlayerItem) and item.parent.row( ) == 3 and index.column() != 0: for idx, playerItem in enumerate( index.parent().internalPointer().children): chart = index.model().chart(option.rect, index, playerItem) if chart: with Painter(painter): painter.translate(option.rect.topLeft()) painter.setPen(self.colors[idx]) painter.setRenderHint(QPainter.Antialiasing) # if we want to use a pen width > 1, we can no longer directly drawPolyline # separately per cell beause the lines spread vertically over two rows: We would # have to draw the lines into one big pixmap and copy # from the into the cells painter.drawPolyline(*chart) return return QStyledItemDelegate.paint(self, painter, option, index)
def data(self, index, role=Qt.DisplayRole): """score table""" result = QVariant() if role == Qt.TextAlignmentRole: if index.column() == 1: return QVariant(int(Qt.AlignRight)) else: return QVariant(int(Qt.AlignLeft)) if index.isValid() and (0 <= index.row() < len(self.chatLines)): chatLine = self.chatLines[index.row()] if role == Qt.DisplayRole and index.column() == 0: local = chatLine.localtimestamp() result = QVariant('%02d:%02d:%02d' % (local.hour, local.minute, local.second)) elif role == Qt.DisplayRole and index.column() == 1: result = QVariant(chatLine.fromUser) elif role == Qt.DisplayRole and index.column() == 2: result = QVariant(m18n(chatLine.message)) elif role == Qt.ForegroundRole and index.column() == 2: palette = KApplication.palette() color = 'blue' if chatLine.isStatusMessage else palette.windowText( ) result = QVariant(QColor(color)) return result
def data(self, index, role=Qt.DisplayRole): """score table""" # pylint: disable=too-many-branches,too-many-locals,redefined-variable-type result = toQVariant() if role == Qt.TextAlignmentRole: if index.column() == 0: result = toQVariant(int(Qt.AlignHCenter | Qt.AlignVCenter)) else: result = toQVariant(int(Qt.AlignLeft | Qt.AlignVCenter)) if index.isValid() and (0 <= index.row() < len(self.tables)): table = self.tables[index.row()] if role == Qt.DisplayRole and index.column() in (0, 1): result = toQVariant(table.tableid) elif role == Qt.DisplayRole and index.column() == 2: players = [] zipped = list(zip(table.playerNames, table.playersOnline)) for idx, pair in enumerate(zipped): name, online = pair[0], pair[1] if idx < len(zipped) - 1: name += ', ' palette = KApplication.palette() if online: color = palette.color( QPalette.Active, QPalette.WindowText).name() style = ('font-weight:normal;' 'font-style:normal;color:%s' % color) else: color = palette.color( QPalette.Disabled, QPalette.WindowText).name() style = ('font-weight:100;font-style:italic;color:%s' % color) players.append( '<nobr style="%s">' % style + name + '</nobr>') names = ''.join(players) result = toQVariant(names) elif role == Qt.DisplayRole and index.column() == 3: status = table.status() if table.suspendedAt: dateVal = u' ' + unicodeString(datetime.datetime.strptime( table.suspendedAt, '%Y-%m-%dT%H:%M:%S').strftime('%c')) status = u'Suspended' else: dateVal = u'' result = toQVariant(m18nc('table status', status) + dateVal) elif index.column() == 4: if role == Qt.DisplayRole: result = toQVariant( m18n(( table.myRuleset if table.myRuleset else table.ruleset).name)) elif role == Qt.ForegroundRole: palette = KApplication.palette() color = palette.windowText() if table.myRuleset else 'red' result = toQVariant(QColor(color)) return result