QVariant IrcUserListModel::data( const QModelIndex& index, int role ) const { if ( !channel() || !hasIndex( index.row(), index.column(), index.parent() ) ) { return QVariant(); } IrcUser* user = static_cast<IrcUser*>( index.internalPointer() ); Q_ASSERT( user ); switch ( role ) { case Qt::DisplayRole: return user->name(); case Qt::DecorationRole: return modeToIcon( user->mode().left( 1 ) ); case Qt::ForegroundRole: if ( user->isServOp() ) { if ( user->isAway() ) { return QColor( "red" ); } else { return QColor( "#9A2A2A" ); } } else { if ( user->isAway() ) { return QColor( quazaaSettings.Chat.Colors[IrcColorType::Inactive] ); } else { return QColor( quazaaSettings.Chat.Colors[IrcColorType::Default] ); } } case Irc::UserRole: return QVariant::fromValue( user ); case Irc::NameRole: return user->name(); case Irc::PrefixRole: return user->prefix().left( 1 ); case Irc::ModeRole: return user->mode().left( 1 ); case Irc::TitleRole: return user->title(); } return QVariant(); }
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { IrcUser* user = index.data(Irc::UserRole).value<IrcUser*>(); if (user && user->isAway()) const_cast<QStyleOptionViewItem&>(option).state |= QStyle::State_Off; QStyledItemDelegate::paint(painter, option, index); }