author | nemo |
Sat, 03 Jan 2015 17:27:33 -0500 | |
branch | 0.9.21 |
changeset 10739 | d886f319e7b3 |
parent 9727 | e89ed65f62da |
child 10753 | e56db5d988ef |
permissions | -rw-r--r-- |
7723 | 1 |
#ifndef PLAYERSLISTMODEL_H |
2 |
#define PLAYERSLISTMODEL_H |
|
3 |
||
7725 | 4 |
#include <QAbstractListModel> |
5 |
#include <QHash> |
|
6 |
#include <QIcon> |
|
7 |
#include <QModelIndex> |
|
7732 | 8 |
#include <QSet> |
9503 | 9 |
#include <QFont> |
7723 | 10 |
|
7725 | 11 |
class PlayersListModel : public QAbstractListModel |
7723 | 12 |
{ |
13 |
Q_OBJECT |
|
7725 | 14 |
|
7723 | 15 |
public: |
7725 | 16 |
enum StateFlag { |
17 |
Ready = Qt::UserRole, |
|
18 |
ServerAdmin = Qt::UserRole + 1, |
|
19 |
RoomAdmin = Qt::UserRole + 2, |
|
20 |
Registered = Qt::UserRole + 3, |
|
21 |
Friend = Qt::UserRole + 4, |
|
7765
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7737
diff
changeset
|
22 |
Ignore = Qt::UserRole + 5, |
9503 | 23 |
InGame = Qt::UserRole + 6, |
24 |
InRoom = Qt::UserRole + 7, |
|
25 |
Contributor = Qt::UserRole + 8 |
|
7725 | 26 |
}; |
27 |
||
7728 | 28 |
enum SpecialRoles { |
7731 | 29 |
SortRole = Qt::UserRole + 100, |
30 |
RoomFilterRole = Qt::UserRole + 101 |
|
7728 | 31 |
}; |
32 |
||
7723 | 33 |
explicit PlayersListModel(QObject *parent = 0); |
34 |
||
7725 | 35 |
int rowCount(const QModelIndex &parent = QModelIndex()) const; |
36 |
||
37 |
QVariant data(const QModelIndex &index, int role) const; |
|
38 |
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole); |
|
7737 | 39 |
void setFlag(const QString & nickname, StateFlag flagType, bool isSet); |
40 |
bool isFlagSet(const QString & nickname, StateFlag flagType); |
|
7725 | 41 |
|
42 |
bool insertRow(int row, const QModelIndex &parent = QModelIndex()); |
|
43 |
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()); |
|
44 |
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); |
|
45 |
||
9727 | 46 |
QModelIndex nicknameIndex(const QString & nickname); |
47 |
||
7723 | 48 |
public slots: |
8891
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
49 |
void addPlayer(const QString & nickname, bool notify); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
50 |
void removePlayer(const QString & nickname, const QString & msg = QString()); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
51 |
void playerJoinedRoom(const QString & nickname, bool notify); |
7731 | 52 |
void playerLeftRoom(const QString & nickname); |
53 |
void resetRoomFlags(); |
|
7732 | 54 |
void setNickname(const QString & nickname); |
7725 | 55 |
|
8891
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
56 |
signals: |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
57 |
void nickAdded(const QString& nick, bool notifyNick); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
58 |
void nickRemoved(const QString& nick); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
59 |
void nickAddedLobby(const QString& nick, bool notifyNick); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
60 |
void nickRemovedLobby(const QString& nick); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
61 |
void nickRemovedLobby(const QString& nick, const QString& message); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
62 |
|
7725 | 63 |
private: |
64 |
QHash<quint32, QIcon> & m_icons(); |
|
65 |
typedef QHash<int, QVariant> DataEntry; |
|
66 |
QList<DataEntry> m_data; |
|
7732 | 67 |
QSet<QString> m_friendsSet, m_ignoredSet; |
68 |
QString m_nickname; |
|
9503 | 69 |
QFont m_fontInRoom; |
7732 | 70 |
|
7725 | 71 |
void updateIcon(const QModelIndex & index); |
7728 | 72 |
void updateSortData(const QModelIndex & index); |
7732 | 73 |
void loadSet(QSet<QString> & set, const QString & suffix); |
74 |
void saveSet(const QSet<QString> & set, const QString & suffix); |
|
75 |
void checkFriendIgnore(const QModelIndex & mi); |
|
9725
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
76 |
bool isFriend(const QString & nickname); |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
77 |
bool isIgnored(const QString & nickname); |
7723 | 78 |
}; |
79 |
||
80 |
#endif // PLAYERSLISTMODEL_H |