QTfrontend/model/playerslistmodel.cpp
author unc0rr
Mon, 08 Oct 2012 23:57:17 +0400
changeset 7731 262228c64f15
parent 7728 664738870325
child 7732 fad3408fdcc1
permissions -rw-r--r--
Room players list
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     1
#include <QModelIndexList>
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     2
#include <QModelIndex>
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     3
#include <QPainter>
7727
bd252cacabe8 Bring icons back
unc0rr
parents: 7725
diff changeset
     4
#include <QDebug>
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     5
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
     6
#include "playerslistmodel.h"
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
     7
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
     8
PlayersListModel::PlayersListModel(QObject *parent) :
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     9
    QAbstractListModel(parent)
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    10
{
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    11
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    12
}
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    13
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    14
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    15
int PlayersListModel::rowCount(const QModelIndex &parent) const
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    16
{
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    17
    if(parent.isValid())
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    18
        return 0;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    19
    else
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    20
        return m_data.size();
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    21
}
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    22
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    23
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    24
QVariant PlayersListModel::data(const QModelIndex &index, int role) const
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    25
{
7727
bd252cacabe8 Bring icons back
unc0rr
parents: 7725
diff changeset
    26
    if(!index.isValid() || index.row() < 0 || index.row() >= rowCount() || index.column() != 0)
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    27
        return QVariant(QVariant::Invalid);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    28
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    29
    return m_data.at(index.row()).value(role);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    30
}
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    31
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    32
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    33
bool PlayersListModel::setData(const QModelIndex &index, const QVariant &value, int role)
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    34
{
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    35
    if(!index.isValid() || index.row() < 0 || index.row() >= rowCount() || index.column() != 0)
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    36
        return false;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    37
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    38
    m_data[index.row()].insert(role, value);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    39
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    40
    emit dataChanged(index, index);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    41
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    42
    return true;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    43
}
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    44
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    45
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    46
bool PlayersListModel::insertRow(int row, const QModelIndex &parent)
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    47
{
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    48
    return insertRows(row, 1, parent);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    49
}
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    50
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    51
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    52
bool PlayersListModel::insertRows(int row, int count, const QModelIndex &parent)
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    53
{
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    54
    if(parent.isValid() || row > rowCount() || row < 0 || count < 1)
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    55
        return false;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    56
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    57
    beginInsertRows(parent, row, row + count - 1);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    58
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    59
    for(int i = 0; i < count; ++i)
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    60
        m_data.insert(row, DataEntry());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    61
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    62
    endInsertRows();
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    63
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    64
    return true;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    65
}
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    66
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    67
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    68
bool PlayersListModel::removeRows(int row, int count, const QModelIndex &parent)
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    69
{
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    70
    if(parent.isValid() || row + count > rowCount() || row < 0 || count < 1)
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    71
        return false;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    72
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    73
    beginRemoveRows(parent, row, row + count - 1);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    74
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    75
    for(int i = 0; i < count; ++i)
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    76
        m_data.removeAt(row);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    77
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    78
    endRemoveRows();
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    79
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    80
    return true;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    81
}
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    82
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    83
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    84
void PlayersListModel::addPlayer(const QString & nickname)
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    85
{
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    86
    insertRow(rowCount());
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    87
7728
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
    88
    QModelIndex mi = index(rowCount() - 1);
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
    89
    setData(mi, nickname);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    90
7728
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
    91
    updateSortData(mi);
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
    92
    updateIcon(mi);
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    93
}
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    94
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    95
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    96
void PlayersListModel::removePlayer(const QString & nickname)
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    97
{
7727
bd252cacabe8 Bring icons back
unc0rr
parents: 7725
diff changeset
    98
    QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    99
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   100
    if(mil.size())
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   101
        removeRow(mil[0].row());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   102
}
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   103
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   104
7731
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   105
void PlayersListModel::playerJoinedRoom(const QString & nickname)
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   106
{
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   107
    QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname);
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   108
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   109
    if(mil.size())
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   110
        setData(mil[0], "1", RoomFilterRole);
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   111
}
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   112
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   113
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   114
void PlayersListModel::playerLeftRoom(const QString & nickname)
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   115
{
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   116
    QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname);
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   117
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   118
    if(mil.size())
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   119
        setData(mil[0], "0", RoomFilterRole);
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   120
}
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   121
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   122
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   123
void PlayersListModel::setFlag(const QString &nickname, StateFlag flagType, bool isSet)
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   124
{
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   125
    QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   126
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   127
    if(mil.size())
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   128
    {
7727
bd252cacabe8 Bring icons back
unc0rr
parents: 7725
diff changeset
   129
        setData(mil[0], isSet, flagType);
7728
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   130
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   131
        if(flagType == Friend || flagType == ServerAdmin
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   132
                || flagType == Ignore || flagType == RoomAdmin)
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   133
            updateSortData(mil[0]);
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   134
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   135
        updateIcon(mil[0]);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   136
    }
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   137
}
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   138
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   139
7731
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   140
void PlayersListModel::resetRoomFlags()
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   141
{
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   142
    for(int i = rowCount() - 1; i >= 0; --i)
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   143
    {
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   144
        QModelIndex mi = index(i);
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   145
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   146
        if(mi.data(RoomFilterRole).toString() == "1")
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   147
        {
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   148
            setData(mi, "0", RoomFilterRole);
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   149
            setData(mi, false, RoomAdmin);
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   150
            setData(mi, false, Ready);
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   151
        }
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   152
    }
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   153
}
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
   154
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   155
void PlayersListModel::updateIcon(const QModelIndex & index)
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   156
{
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   157
    quint32 iconNum = 0;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   158
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   159
    QList<bool> flags;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   160
    flags
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   161
        << index.data(Ready).toBool()
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   162
        << index.data(ServerAdmin).toBool()
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   163
        << index.data(RoomAdmin).toBool()
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   164
        << index.data(Registered).toBool()
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   165
        << index.data(Friend).toBool()
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   166
        << index.data(Ignore).toBool()
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   167
        ;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   168
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   169
    for(int i = flags.size() - 1; i >= 0; --i)
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   170
        if(flags[i])
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   171
            iconNum |= 1 << i;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   172
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   173
    if(m_icons().contains(iconNum))
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   174
    {
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   175
        setData(index, m_icons().value(iconNum), Qt::DecorationRole);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   176
    }
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   177
    else
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   178
    {
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   179
        QPixmap result(24, 16);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   180
        result.fill(Qt::transparent);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   181
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   182
        QPainter painter(&result);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   183
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   184
        if(index.data(Ready).toBool())
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   185
            painter.drawPixmap(0, 0, 16, 16, QPixmap(":/res/chat/lamp.png"));
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   186
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   187
        QString mainIconName(":/res/chat/");
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   188
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   189
        if(index.data(RoomAdmin).toBool())
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   190
            mainIconName += "roomadmin";
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   191
        else if(index.data(ServerAdmin).toBool())
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   192
            mainIconName += "serveradmin";
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   193
        else
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   194
            mainIconName += "hedgehog";
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   195
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   196
        if(!index.data(Registered).toBool())
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   197
            mainIconName += "_gray";
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   198
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   199
        painter.drawPixmap(8, 0, 16, 16, QPixmap(mainIconName + ".png"));
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   200
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   201
        if(index.data(Ignore).toBool())
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   202
            painter.drawPixmap(8, 0, 16, 16, QPixmap(":/res/chat/ignore.png"));
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   203
        else
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   204
        if(index.data(Friend).toBool())
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   205
            painter.drawPixmap(8, 0, 16, 16, QPixmap(":/res/chat/friend.png"));
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   206
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   207
        painter.end();
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   208
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   209
        QIcon icon(result);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   210
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   211
        setData(index, icon, Qt::DecorationRole);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   212
        m_icons().insert(iconNum, icon);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   213
    }
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   214
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   215
    if(index.data(Ignore).toBool())
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   216
        setData(index, Qt::gray, Qt::ForegroundRole);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   217
    else
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   218
    if(index.data(Friend).toBool())
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   219
        setData(index, Qt::green, Qt::ForegroundRole);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   220
    else
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   221
        setData(index, QBrush(QColor(0xff, 0xcc, 0x00)), Qt::ForegroundRole);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   222
}
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   223
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   224
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   225
QHash<quint32, QIcon> & PlayersListModel::m_icons()
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   226
{
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   227
    static QHash<quint32, QIcon> iconsCache;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   228
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   229
    return iconsCache;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
   230
}
7728
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   231
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   232
void PlayersListModel::updateSortData(const QModelIndex & index)
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   233
{
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   234
    QString result = QString("%1%2%3%4%5")
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   235
            .arg(1 - index.data(RoomAdmin).toInt())
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   236
            .arg(1 - index.data(ServerAdmin).toInt())
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   237
            .arg(1 - index.data(Friend).toInt())
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   238
            .arg(index.data(Ignore).toInt())
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   239
            .arg(index.data(Qt::DisplayRole).toString().toLower())
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   240
            ;
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   241
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   242
    setData(index, result, SortRole);
664738870325 Bring back sorting
unc0rr
parents: 7727
diff changeset
   243
}