def _paintSpacer(self, painter, option, index): st = index.data(ServerViewRoles.spacertype) if st != Qt.CustomDashLine: painter.setPen(st) painter.drawLine(option.rect.x(), option.rect.y() + option.rect.height() / 2, option.rect.x() + option.rect.width(), option.rect.y() + option.rect.height() / 2) else: align = index.data(ServerViewRoles.spaceralignment) ctext = index.data(ServerViewRoles.spacercustomtext) if align != Qt.AlignJustify: painter.drawText(option.rect.x(), option.rect.y(), option.rect.width(), option.rect.height(), align, ctext) else: fm = QFontMetrics(QApplication.font()) w = l = fm.width(ctext) txt = ctext while l < option.rect.width(): txt += ctext l += w painter.drawText(option.rect.x(), option.rect.y(), option.rect.width(), option.rect.height(), Qt.AlignLeft, txt)
def paint(self, painter, option, index): if option.state & QStyle.State_Selected: painter.fillRect(option.rect, option.palette.highlight()) if not index.isValid(): super().paint(painter, option, index) return if index.data(ServerViewRoles.isspacer): painter.save() self._paintSpacer(painter, option, index) painter.restore() return icon = index.data(Qt.DecorationRole) statusicons = index.data(ServerViewRoles.statusicons) font = index.data(Qt.FontRole) or QApplication.font() brush = index.data(Qt.ForegroundRole) or Qt.black if icon: iconsize = icon.actualSize(option.decorationSize) icon.paint(painter, option.rect, Qt.AlignLeft) else: iconsize = option.decorationSize headerRect = option.rect headerRect.setLeft(headerRect.left() + iconsize.width() + 5) painter.save() pen = painter.pen() pen.setBrush(brush) painter.setPen(pen) painter.setFont(font) painter.drawText(headerRect, Qt.AlignLeft, index.data()) nextx = 18 if statusicons: for ico in reversed(statusicons): ico.paint(painter, option.rect.right() - nextx, option.rect.y(), iconsize.width(), iconsize.height()) nextx += 18 painter.restore()
def data(self, index, role): obj = self._indexObject(index) if role == Qt.DisplayRole: if type(obj) is Client: if obj.isRecording: return "*** %s *** [RECORDING]" % obj.displayName else: return obj.displayName return obj.name elif role == ServerViewRoles.isspacer: return type(obj) is Channel and obj.isSpacer elif type(obj) is Channel and role == ServerViewRoles.spacertype: return obj.spacerType elif type(obj) is Channel and role == ServerViewRoles.spacercustomtext: return obj.spacerCustomtext elif type(obj) is Channel and role == ServerViewRoles.spaceralignment: return obj.spacerAlignment elif role == Qt.DecorationRole: if not (type(obj) is Channel and obj.isSpacer): return QIcon(self.iconpack.icon(obj.iconVariable())) elif role == ServerViewRoles.statusicons: ret = [] if type(obj) is Channel: if obj.isDefault: ret.append(QIcon(self.iconpack.icon("DEFAULT"))) if obj.codec == ts3defines.CodecType.CODEC_OPUS_MUSIC: ret.append(QIcon(self.iconpack.icon("MUSIC"))) if obj.neededTalkPower > 0: ret.append(QIcon(self.iconpack.icon("MODERATED"))) if obj.iconID != 0: ret.append(QIcon(self.icons.icon(obj.iconID))) elif type(obj) is Client: # badges # priority speaker if obj.isPrioritySpeaker: ret.append(QIcon(self.iconpack.icon("CAPTURE"))) # istalker if obj.isTalker: ret.append(QIcon(self.iconpack.icon("IS_TALKER"))) elif obj.talkPower < obj.parentNode.neededTalkPower: ret.append(QIcon(self.iconpack.icon("INPUT_MUTED"))) # channelgroup if obj.channelGroup in self.cgicons: ret.append(QIcon(self.icons.icon( self.cgicons[obj.channelGroup]))) # servergroups for sg in obj.serverGroups: if sg in self.sgicons: ret.append(QIcon(self.icons.icon(self.sgicons[sg]))) # clienticon if obj.iconID != 0: ret.append(QIcon(self.icons.icon(obj.iconID))) # talkrequest if obj.isRequestingTalkPower: ret.append(QIcon(self.iconpack.icon("REQUEST_TALK_POWER"))) # flag if obj.country != "": ret.append(QIcon(self.countries.flag(obj.country))) else: assert type(obj) is Server if obj.iconID != 0: ret.append(QIcon(self.icons.icon(obj.iconID))) return ret elif role == Qt.FontRole: if type(obj) is Client and obj.isme: font = QApplication.font() font.setBold(True) return font elif role == Qt.ForegroundRole: if type(obj) is Client and obj.isRecording: return QColor(Qt.darkRed) return None
def data(self, index, role): obj = self._indexObject(index) if role == Qt.DisplayRole: if type(obj) is Client: if obj.isRecording: return "*** %s *** [RECORDING]" % obj.displayName else: return obj.displayName return obj.name elif role == ServerViewRoles.isspacer: return type(obj) is Channel and obj.isSpacer elif type(obj) is Channel and role == ServerViewRoles.spacertype: return obj.spacerType elif type(obj) is Channel and role == ServerViewRoles.spacercustomtext: return obj.spacerCustomtext elif type(obj) is Channel and role == ServerViewRoles.spaceralignment: return obj.spacerAlignment elif role == Qt.DecorationRole: if not (type(obj) is Channel and obj.isSpacer): return QIcon(self.iconpack.icon(obj.iconVariable())) elif role == ServerViewRoles.statusicons: ret = [] if type(obj) is Channel: if obj.isDefault: ret.append(QIcon(self.iconpack.icon("DEFAULT"))) if obj.codec == ts3defines.CodecType.CODEC_OPUS_MUSIC: ret.append(QIcon(self.iconpack.icon("MUSIC"))) if obj.neededTalkPower > 0: ret.append(QIcon(self.iconpack.icon("MODERATED"))) if obj.iconID != 0: ret.append(QIcon(self.icons.icon(obj.iconID))) elif type(obj) is Client: # badges # priority speaker if obj.isPrioritySpeaker: ret.append(QIcon(self.iconpack.icon("CAPTURE"))) # istalker if obj.isTalker: ret.append(QIcon(self.iconpack.icon("IS_TALKER"))) elif obj.talkPower < obj.parentNode.neededTalkPower: ret.append(QIcon(self.iconpack.icon("INPUT_MUTED"))) # channelgroup if obj.channelGroup in self.cgicons: ret.append( QIcon(self.icons.icon(self.cgicons[obj.channelGroup]))) # servergroups for sg in obj.serverGroups: if sg in self.sgicons: ret.append(QIcon(self.icons.icon(self.sgicons[sg]))) # clienticon if obj.iconID != 0: ret.append(QIcon(self.icons.icon(obj.iconID))) # talkrequest if obj.isRequestingTalkPower: ret.append(QIcon(self.iconpack.icon("REQUEST_TALK_POWER"))) # flag if obj.country != "": ret.append(QIcon(self.countries.flag(obj.country))) else: assert type(obj) is Server if obj.iconID != 0: ret.append(QIcon(self.icons.icon(obj.iconID))) return ret elif role == Qt.FontRole: if type(obj) is Client and obj.isme: font = QApplication.font() font.setBold(True) return font elif role == Qt.ForegroundRole: if type(obj) is Client and obj.isRecording: return QColor(Qt.darkRed) return None