author | Wuzzy <Wuzzy@disroot.org> |
Thu, 22 Jun 2023 09:13:50 +0200 | |
changeset 15961 | 4ad8dd66d9d5 |
parent 15047 | 773beead236f |
permissions | -rw-r--r-- |
7723 | 1 |
#ifndef PLAYERSLISTMODEL_H |
2 |
#define PLAYERSLISTMODEL_H |
|
3 |
||
7725 | 4 |
#include <QAbstractListModel> |
15047
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
5 |
#include <QFont> |
7725 | 6 |
#include <QHash> |
7 |
#include <QIcon> |
|
8 |
#include <QModelIndex> |
|
7732 | 9 |
#include <QSet> |
7723 | 10 |
|
15047
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
11 |
class PlayersListModel : public QAbstractListModel { |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
12 |
Q_OBJECT |
7725 | 13 |
|
15047
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
14 |
public: |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
15 |
enum StateFlag { |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
16 |
Ready = Qt::UserRole, |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
17 |
ServerAdmin = Qt::UserRole + 1, |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
18 |
RoomAdmin = Qt::UserRole + 2, |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
19 |
Registered = Qt::UserRole + 3, |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
20 |
Friend = Qt::UserRole + 4, |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
21 |
Ignore = Qt::UserRole + 5, |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
22 |
InGame = Qt::UserRole + 6, |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
23 |
InRoom = Qt::UserRole + 7, |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
24 |
Contributor = Qt::UserRole + 8 |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
25 |
// if you add a role that will affect the player icon, |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
26 |
// then also add it to the flags Qlist in updateIcon()! |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
27 |
}; |
7725 | 28 |
|
15047
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
29 |
enum SpecialRoles { |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
30 |
SortRole = Qt::UserRole + 100, |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
31 |
RoomFilterRole = Qt::UserRole + 101 |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
32 |
}; |
7728 | 33 |
|
15047
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
34 |
explicit PlayersListModel(QObject *parent = 0); |
7723 | 35 |
|
15047
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
36 |
int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
7725 | 37 |
|
15047
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
38 |
QVariant data(const QModelIndex &index, int role) const override; |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
39 |
bool setData(const QModelIndex &index, const QVariant &value, |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
40 |
int role = Qt::DisplayRole) override; |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
41 |
|
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
42 |
void setFlag(const QString &nickname, StateFlag flagType, bool isSet); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
43 |
bool isFlagSet(const QString &nickname, StateFlag flagType); |
7725 | 44 |
|
15047
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
45 |
bool insertRows(int row, int count, |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
46 |
const QModelIndex &parent = QModelIndex()) override; |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
47 |
bool removeRows(int row, int count, |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
48 |
const QModelIndex &parent = QModelIndex()) override; |
7725 | 49 |
|
15047
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
50 |
QModelIndex nicknameIndex(const QString &nickname); |
9727 | 51 |
|
15047
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
52 |
public slots: |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
53 |
void addPlayer(const QString &nickname, bool notify); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
54 |
void removePlayer(const QString &nickname, const QString &msg = QString()); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
55 |
void playerJoinedRoom(const QString &nickname, bool notify); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
56 |
void playerLeftRoom(const QString &nickname); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
57 |
void resetRoomFlags(); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
58 |
void setNickname(const QString &nickname); |
7725 | 59 |
|
15047
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
60 |
signals: |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
61 |
void nickAdded(const QString &nick, bool notifyNick); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
62 |
void nickRemoved(const QString &nick); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
63 |
void nickAddedLobby(const QString &nick, bool notifyNick); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
64 |
void nickRemovedLobby(const QString &nick, const QString &message); |
8891
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
65 |
|
15047
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
66 |
private: |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
67 |
QHash<quint32, QIcon> &m_icons(); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
68 |
using DataEntry = QHash<int, QVariant>; |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
69 |
QList<DataEntry> m_data; |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
70 |
QSet<QString> m_friendsSet, m_ignoredSet; |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
71 |
QString m_nickname; |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
72 |
QFont m_fontInRoom; |
7732 | 73 |
|
15047
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
74 |
void updateIcon(const QModelIndex &index); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
75 |
void updateSortData(const QModelIndex &index); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
76 |
void loadSet(QSet<QString> &set, const QString &fileName); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
77 |
void saveSet(const QSet<QString> &set, const QString &fileName); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
78 |
void checkFriendIgnore(const QModelIndex &mi); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
79 |
bool isFriend(const QString &nickname); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
80 |
bool isIgnored(const QString &nickname); |
7723 | 81 |
}; |
82 |
||
15047
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
10753
diff
changeset
|
83 |
#endif // PLAYERSLISTMODEL_H |