示例#1
0
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();
}
示例#2
0
/*!
    Returns the data for specified \a role referred to by the \a index.

    \sa Irc::DataRole, roleNames()
 */
QVariant IrcUserModel::data(const QModelIndex& index, int role) const
{
    Q_D(const IrcUserModel);
    if (!d->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 data(index, d->role);
    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();
}