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 LASERTRAILMODEL_H
21 #define LASERTRAILMODEL_H
22 
23 #include <QAbstractListModel>
24 #include <QColor>
25 #include <QPointF>
26 
27 namespace canvas {
28 
29 struct LaserTrail {
30 	int ctxid;
31 	int internalId;
32 	QColor color;
33 	QVector<QPointF> points;
34 	bool open;
35 	bool visible;
36 
37 	int persistence;
38 	qint64 expiration;
39 };
40 
41 class LaserTrailModel : public QAbstractListModel
42 {
43 	Q_OBJECT
44 public:
45 	enum LaserRolesRoles {
46 		ColorRole = Qt::UserRole + 1,
47 		ContextRole,
48 		PointsRole,
49 		VisibleRole,
50 		InternalIdRole
51 	};
52 
53 	explicit LaserTrailModel(QObject *parent=nullptr);
54 
55 	int rowCount(const QModelIndex &parent=QModelIndex()) const;
56 	QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const;
57 
58 	QHash<int, QByteArray> roleNames() const;
59 
60 public slots:
61 	void startTrail(int ctxId, const QColor &color, int persistence);
62 	void addPoint(int ctxId, const QPointF &point);
63 	void endTrail(int ctxId);
64 
65 protected:
66 	void timerEvent(QTimerEvent *e);
67 
68 private:
69 	bool isOpenTrail(int ctxId);
70 	QList<LaserTrail> m_lasers;
71 	int m_timerId;
72 	int m_lastId;
73 };
74 
75 }
76 
77 #endif // LASERTRAILMODEL_H
78