author | unc0rr |
Tue, 08 Oct 2013 23:38:45 +0400 | |
changeset 9503 | 8f9b04138456 |
parent 8891 | bf67b4d7d7b4 |
child 9725 | 68b5d87cfdb0 |
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 |
||
7723 | 46 |
public slots: |
8891
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
47 |
void addPlayer(const QString & nickname, bool notify); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
48 |
void removePlayer(const QString & nickname, const QString & msg = QString()); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
49 |
void playerJoinedRoom(const QString & nickname, bool notify); |
7731 | 50 |
void playerLeftRoom(const QString & nickname); |
51 |
void resetRoomFlags(); |
|
7732 | 52 |
void setNickname(const QString & nickname); |
7725 | 53 |
|
8891
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
54 |
signals: |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
55 |
void nickAdded(const QString& nick, bool notifyNick); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
56 |
void nickRemoved(const QString& nick); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
57 |
void nickAddedLobby(const QString& nick, bool notifyNick); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
58 |
void nickRemovedLobby(const QString& nick); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
59 |
void nickRemovedLobby(const QString& nick, const QString& message); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
60 |
|
7725 | 61 |
private: |
62 |
QHash<quint32, QIcon> & m_icons(); |
|
63 |
typedef QHash<int, QVariant> DataEntry; |
|
64 |
QList<DataEntry> m_data; |
|
7732 | 65 |
QSet<QString> m_friendsSet, m_ignoredSet; |
66 |
QString m_nickname; |
|
9503 | 67 |
QFont m_fontInRoom; |
7732 | 68 |
|
7725 | 69 |
void updateIcon(const QModelIndex & index); |
7728 | 70 |
void updateSortData(const QModelIndex & index); |
7732 | 71 |
void loadSet(QSet<QString> & set, const QString & suffix); |
72 |
void saveSet(const QSet<QString> & set, const QString & suffix); |
|
73 |
void checkFriendIgnore(const QModelIndex & mi); |
|
7723 | 74 |
}; |
75 |
||
76 |
#endif // PLAYERSLISTMODEL_H |