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();
}
Exemple #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();
}
Exemple #3
0
void IrcClient::onUserActivated(const QModelIndex& index)
{
    IrcUser* user = index.data(Irc::UserRole).value<IrcUser*>();

    if (user) {
        IrcBuffer* buffer = bufferModel->add(user->name());

        // activate the new query
        int idx = bufferModel->buffers().indexOf(buffer);
        if (idx != -1)
            bufferList->setCurrentIndex(bufferModel->index(idx));
    }
}
Exemple #4
0
void IrcChannelPrivate::addUser(const QString& name)
{
    Q_Q(IrcChannel);
    const QStringList prefixes = q->network()->prefixes();

    IrcUser* user = new IrcUser(q);
    IrcUserPrivate* priv = IrcUserPrivate::get(user);
    priv->channel = q;
    priv->setName(userName(name, prefixes));
    priv->setPrefix(getPrefix(name, prefixes));
    priv->setMode(getMode(q->network(), user->prefix()));
    activeUsers.prepend(user);
    userList.append(user);
    userMap.insert(user->name(), user);
    names = userMap.keys();

    foreach (IrcUserModel* model, userModels)
        IrcUserModelPrivate::get(model)->addUser(user);
}