1 /*
2 remoteviewinterface.cpp
3
4 This file is part of GammaRay, the Qt application inspection and
5 manipulation tool.
6
7 Copyright (C) 2015-2021 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
8 Author: Volker Krause <volker.krause@kdab.com>
9
10 Licensees holding valid commercial KDAB GammaRay licenses may use this file in
11 accordance with GammaRay Commercial License Agreement provided with the Software.
12
13 Contact info@kdab.com if any conditions of this licensing are not clear to you.
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 2 of the License, or
18 (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 */
28
29 #include "remoteviewinterface.h"
30 #include "streamoperators.h"
31
32 #include <common/objectbroker.h>
33 #include <common/remoteviewframe.h>
34
35 using namespace GammaRay;
36 QT_BEGIN_NAMESPACE
37 GAMMARAY_ENUM_STREAM_OPERATORS(RemoteViewInterface::RequestMode)
38
39 QDataStream &operator<<(QDataStream &s, Qt::TouchPointStates states)
40 {
41 return s << (int)states;
42 }
43
operator >>(QDataStream & s,Qt::TouchPointStates & states)44 QDataStream &operator>>(QDataStream &s, Qt::TouchPointStates &states)
45 {
46 int st;
47 s >> st;
48 states = Qt::TouchPointStates(st);
49 return s;
50 }
51
operator <<(QDataStream & s,QTouchEvent::TouchPoint::InfoFlags flags)52 QDataStream &operator<<(QDataStream &s, QTouchEvent::TouchPoint::InfoFlags flags)
53 {
54 return s << (int)flags;
55 }
56
operator >>(QDataStream & s,QTouchEvent::TouchPoint::InfoFlags & flags)57 QDataStream &operator>>(QDataStream &s, QTouchEvent::TouchPoint::InfoFlags &flags)
58 {
59 int f;
60 s >> f;
61 flags = QTouchEvent::TouchPoint::InfoFlags(f);
62 return s;
63 }
64
operator <<(QDataStream & s,const QList<QTouchEvent::TouchPoint> & points)65 QDataStream &operator<<(QDataStream &s, const QList<QTouchEvent::TouchPoint> &points)
66 {
67 s << points.count();
68 for (const auto &p : points) {
69 s << p.id();
70 s << p.state();
71 s << p.rect() << p.sceneRect() << p.screenRect();
72 s << p.normalizedPos();
73 s << p.startPos() << p.startScenePos() << p.startScreenPos() << p.startNormalizedPos();
74 s << p.lastPos() << p.lastScenePos() << p.lastScreenPos() << p.lastNormalizedPos();
75 s << p.pressure();
76 s << p.velocity();
77 s << p.flags();
78 s << p.rawScreenPositions();
79 }
80 return s;
81 }
82
83 template<class T>
setPointValue(QDataStream & s,QTouchEvent::TouchPoint & p,void (QTouchEvent::TouchPoint::* func)(T))84 void setPointValue(QDataStream &s, QTouchEvent::TouchPoint &p, void (QTouchEvent::TouchPoint::*func)(T))
85 {
86 typename std::decay<T>::type value;
87 s >> value;
88 (p.*func)(value);
89 }
90
operator >>(QDataStream & s,QList<QTouchEvent::TouchPoint> & points)91 QDataStream &operator>>(QDataStream &s, QList<QTouchEvent::TouchPoint> &points)
92 {
93 int count;
94 s >> count;
95 points.reserve(count);
96 for (int i = 0; i < count; ++i) {
97 QTouchEvent::TouchPoint p;
98
99 setPointValue(s, p, &QTouchEvent::TouchPoint::setId);
100 setPointValue(s, p, &QTouchEvent::TouchPoint::setState);
101
102 setPointValue(s, p, &QTouchEvent::TouchPoint::setRect);
103 setPointValue(s, p, &QTouchEvent::TouchPoint::setSceneRect);
104 setPointValue(s, p, &QTouchEvent::TouchPoint::setScreenRect);
105
106 setPointValue(s, p, &QTouchEvent::TouchPoint::setNormalizedPos);
107
108 setPointValue(s, p, &QTouchEvent::TouchPoint::setStartPos);
109 setPointValue(s, p, &QTouchEvent::TouchPoint::setStartScenePos);
110 setPointValue(s, p, &QTouchEvent::TouchPoint::setStartScreenPos);
111 setPointValue(s, p, &QTouchEvent::TouchPoint::setStartNormalizedPos);
112
113 setPointValue(s, p, &QTouchEvent::TouchPoint::setLastPos);
114 setPointValue(s, p, &QTouchEvent::TouchPoint::setLastScenePos);
115 setPointValue(s, p, &QTouchEvent::TouchPoint::setLastScreenPos);
116 setPointValue(s, p, &QTouchEvent::TouchPoint::setLastNormalizedPos);
117
118 setPointValue(s, p, &QTouchEvent::TouchPoint::setPressure);
119 setPointValue(s, p, &QTouchEvent::TouchPoint::setVelocity);
120
121 setPointValue(s, p, &QTouchEvent::TouchPoint::setFlags);
122 setPointValue(s, p, &QTouchEvent::TouchPoint::setRawScreenPositions);
123
124 points.append(p);
125 }
126 return s;
127 }
128
129 QT_END_NAMESPACE
130
131
RemoteViewInterface(const QString & name,QObject * parent)132 RemoteViewInterface::RemoteViewInterface(const QString &name, QObject *parent)
133 : QObject(parent)
134 , m_name(name)
135 {
136 ObjectBroker::registerObject(name, this);
137
138 qRegisterMetaType<QTouchEvent::TouchPoint>();
139 qRegisterMetaType<QList<QTouchEvent::TouchPoint >>();
140
141 qRegisterMetaType<RequestMode>();
142 qRegisterMetaTypeStreamOperators<RequestMode>();
143 qRegisterMetaTypeStreamOperators<GammaRay::RemoteViewFrame>();
144 qRegisterMetaTypeStreamOperators<Qt::TouchPointStates>();
145 qRegisterMetaTypeStreamOperators<QList<QTouchEvent::TouchPoint>>();
146 qRegisterMetaTypeStreamOperators<QTouchEvent::TouchPoint::InfoFlags>();
147 }
148
name() const149 QString RemoteViewInterface::name() const
150 {
151 return m_name;
152 }
153