1 /* 2 Drawpile - a collaborative drawing program. 3 4 Copyright (C) 2015 Calle Laakkonen 5 6 Drawpile is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 Drawpile is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with Drawpile. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef USERCURSORMODEL_H 21 #define USERCURSORMODEL_H 22 23 #include <QAbstractListModel> 24 #include <QColor> 25 #include <QPointF> 26 #include <QVector> 27 #include <QPixmap> 28 29 namespace canvas { 30 31 class LayerListModel; 32 33 struct UserCursor { 34 int id; 35 bool visible; 36 qint64 lastMoved; 37 int layerId; 38 39 QPoint pos; 40 QString name; 41 QString layer; 42 QColor color; 43 QPixmap avatar; 44 }; 45 46 class UserCursorModel : public QAbstractListModel 47 { 48 Q_OBJECT 49 public: 50 enum UserCursorRoles { 51 // DisplayRole is used to get the name 52 // DecorationRole is used to get the avatar 53 IdRole = Qt::UserRole + 10, 54 PositionRole, 55 LayerRole, 56 ColorRole, 57 VisibleRole 58 }; 59 60 explicit UserCursorModel(QObject *parent=nullptr); 61 62 /** 63 * @brief Set the layer list model. 64 * 65 * Layer names are read from here 66 */ setLayerList(LayerListModel * layers)67 void setLayerList(LayerListModel *layers) { m_layerlist = layers; } 68 69 int rowCount(const QModelIndex &parent=QModelIndex()) const; 70 QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const; 71 72 QHash<int, QByteArray> roleNames() const; 73 74 QModelIndex indexForId(int id) const; 75 76 public slots: 77 void setCursorName(int id, const QString &name); 78 void setCursorColor(int id, const QColor &color); 79 void setCursorPosition(int id, int layerId, const QPoint &pos); 80 void setCursorAvatar(int id, const QPixmap &avatar); 81 void hideCursor(int id); 82 void removeCursor(int id); 83 84 void clear(); 85 86 protected: 87 void timerEvent(QTimerEvent *e); 88 89 private: 90 UserCursor *getOrCreate(int id, QModelIndex &index); 91 92 QVector<UserCursor> m_cursors; 93 LayerListModel *m_layerlist; 94 int m_timerId; 95 }; 96 97 } 98 99 #endif // USERCURSORMODEL_H 100