|
19 | 19 |
|
20 | 20 | #include <QtCore/QBuffer> |
21 | 21 | #include <QtCore/QDebug> |
| 22 | +#include <QtCore/QTimer> |
22 | 23 | #include <QtGui/QGuiApplication> |
23 | 24 | #include <QtQml/QQmlExpression> |
24 | 25 | #include <QtQml/QQmlEngine> |
| 26 | +#include <QtGui/QStyleHints> |
25 | 27 |
|
26 | 28 | #include "third_party/pugixml/pugixml.hpp" |
27 | 29 |
|
@@ -826,11 +828,23 @@ void Quick2ViewCmdExecutor::GetPlayerState(const ElementId &element, PlayerState |
826 | 828 | if (NULL == pItem) |
827 | 829 | return; |
828 | 830 |
|
829 | | - |
830 | 831 | base::Value* playbackState = NULL; |
831 | | - GetAttribute(element, "playbackState", &playbackState, error); |
| 832 | + QVariant propertyValue = pItem->property("playbackState"); |
832 | 833 |
|
833 | | - if( error != NULL && *error != NULL && (*error)->code() != kSuccess){ |
| 834 | + if (propertyValue.isValid()) { |
| 835 | + // convert QVariant to base::Value |
| 836 | + switch (propertyValue.type()) { |
| 837 | + case QVariant::Int: |
| 838 | + playbackState = Value::CreateIntegerValue(propertyValue.toInt()); |
| 839 | + break; |
| 840 | + default: |
| 841 | + session_->logger().Log(kWarningLogLevel, "wrong property type"); |
| 842 | + *error = new Error(kInvalidElementState); |
| 843 | + return; |
| 844 | + } |
| 845 | + } else { |
| 846 | + session_->logger().Log(kWarningLogLevel, "property not found."); |
| 847 | + *error = new Error(kInvalidElementState); |
834 | 848 | return; |
835 | 849 | } |
836 | 850 |
|
@@ -1027,6 +1041,269 @@ void Quick2ViewCmdExecutor::GetPlaybackSpeed(const ElementId &element, double *s |
1027 | 1041 | positionValue->GetAsDouble(speed); |
1028 | 1042 | } |
1029 | 1043 |
|
| 1044 | +void Quick2ViewCmdExecutor::TouchClick(const ElementId& element, Error **error) |
| 1045 | +{ |
| 1046 | + QQuickView* view = getView(view_id_, error); |
| 1047 | + if (NULL == view) |
| 1048 | + return; |
| 1049 | + |
| 1050 | + Point location(0,0); |
| 1051 | + |
| 1052 | + // calculate the half of the element size and translate by it. |
| 1053 | + Size size; |
| 1054 | + GetElementSize(element, &size, error); |
| 1055 | + if (*error) |
| 1056 | + return; |
| 1057 | + |
| 1058 | + location.Offset(size.width() / 2, size.height() / 2); |
| 1059 | + |
| 1060 | + QPointF point = ConvertPointToQPoint(location); |
| 1061 | + |
| 1062 | + QQuickItem* pItem = getElement(element, error); |
| 1063 | + if (*error) |
| 1064 | + return; |
| 1065 | + |
| 1066 | + point = pItem->mapToScene(point); |
| 1067 | + |
| 1068 | + QTouchEvent *touchBeginEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, point); |
| 1069 | + QTouchEvent *touchEndEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, point); |
| 1070 | + |
| 1071 | + QGuiApplication::postEvent(view, touchBeginEvent); |
| 1072 | + QGuiApplication::postEvent(view, touchEndEvent); |
| 1073 | + |
| 1074 | + QGuiApplication::processEvents(); |
| 1075 | +} |
| 1076 | + |
| 1077 | +void Quick2ViewCmdExecutor::TouchDoubleClick(const ElementId& element, Error **error) |
| 1078 | +{ |
| 1079 | + QQuickView* view = getView(view_id_, error); |
| 1080 | + if (NULL == view) |
| 1081 | + return; |
| 1082 | + |
| 1083 | + Point location(0,0); |
| 1084 | + |
| 1085 | + // calculate the half of the element size and translate by it. |
| 1086 | + Size size; |
| 1087 | + GetElementSize(element, &size, error); |
| 1088 | + if (*error) |
| 1089 | + return; |
| 1090 | + |
| 1091 | + location.Offset(size.width() / 2, size.height() / 2); |
| 1092 | + |
| 1093 | + QPointF point = ConvertPointToQPoint(location); |
| 1094 | + |
| 1095 | + QQuickItem* pItem = getElement(element, error); |
| 1096 | + if (*error) |
| 1097 | + return; |
| 1098 | + |
| 1099 | + point = pItem->mapToScene(point); |
| 1100 | + |
| 1101 | + QTouchEvent *touchBeginEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, point); |
| 1102 | + QTouchEvent *touchEndEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, point); |
| 1103 | + QTouchEvent *touchBeginEvent2 = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, point); |
| 1104 | + QTouchEvent *touchEndEvent2 = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, point); |
| 1105 | + |
| 1106 | + QGuiApplication::postEvent(view, touchBeginEvent); |
| 1107 | + QGuiApplication::postEvent(view, touchEndEvent); |
| 1108 | + QGuiApplication::postEvent(view, touchBeginEvent2); |
| 1109 | + QGuiApplication::postEvent(view, touchEndEvent2); |
| 1110 | + |
| 1111 | + |
| 1112 | + QGuiApplication::processEvents(); |
| 1113 | +} |
| 1114 | + |
| 1115 | +void Quick2ViewCmdExecutor::TouchDown(const int &x, const int &y, Error **error) |
| 1116 | +{ |
| 1117 | + QQuickView* view = getView(view_id_, error); |
| 1118 | + if (NULL == view) |
| 1119 | + return; |
| 1120 | + |
| 1121 | + QPointF point = ConvertPointToQPoint(Point(x, y)); |
| 1122 | + |
| 1123 | + QTouchEvent *touchBeginEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, point); |
| 1124 | + |
| 1125 | + QGuiApplication::postEvent(view, touchBeginEvent); |
| 1126 | + |
| 1127 | + QGuiApplication::processEvents(); |
| 1128 | +} |
| 1129 | + |
| 1130 | +void Quick2ViewCmdExecutor::TouchUp(const int &x, const int &y, Error **error) |
| 1131 | +{ |
| 1132 | + QQuickView* view = getView(view_id_, error); |
| 1133 | + if (NULL == view) |
| 1134 | + return; |
| 1135 | + |
| 1136 | + QPointF point = ConvertPointToQPoint(Point(x, y)); |
| 1137 | + |
| 1138 | + QTouchEvent *touchEndEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, point); |
| 1139 | + |
| 1140 | + QGuiApplication::postEvent(view, touchEndEvent); |
| 1141 | + |
| 1142 | + QGuiApplication::processEvents(); |
| 1143 | +} |
| 1144 | + |
| 1145 | +void Quick2ViewCmdExecutor::TouchMove(const int &x, const int &y, Error **error) |
| 1146 | +{ |
| 1147 | + QQuickView* view = getView(view_id_, error); |
| 1148 | + if (NULL == view) |
| 1149 | + return; |
| 1150 | + |
| 1151 | + QPointF point = ConvertPointToQPoint(Point(x, y)); |
| 1152 | + |
| 1153 | + QTouchEvent *touchMoveEvent = createSimpleTouchEvent(QEvent::TouchUpdate, Qt::TouchPointMoved, point); |
| 1154 | + |
| 1155 | + QGuiApplication::postEvent(view, touchMoveEvent); |
| 1156 | + |
| 1157 | + QGuiApplication::processEvents(); |
| 1158 | +} |
| 1159 | + |
| 1160 | +void Quick2ViewCmdExecutor::TouchLongClick(const ElementId& element, Error **error) |
| 1161 | +{ |
| 1162 | + QQuickView* view = getView(view_id_, error); |
| 1163 | + if (NULL == view) |
| 1164 | + return; |
| 1165 | + |
| 1166 | + Point location(0,0); |
| 1167 | + |
| 1168 | + // calculate the half of the element size and translate by it. |
| 1169 | + Size size; |
| 1170 | + GetElementSize(element, &size, error); |
| 1171 | + if (*error) |
| 1172 | + return; |
| 1173 | + |
| 1174 | + location.Offset(size.width() / 2, size.height() / 2); |
| 1175 | + |
| 1176 | + QPointF point = ConvertPointToQPoint(location); |
| 1177 | + |
| 1178 | + QEventLoop loop; |
| 1179 | + QTimer::singleShot(1000, &loop, SLOT(quit())); |
| 1180 | + |
| 1181 | + QQuickItem* pItem = getElement(element, error); |
| 1182 | + if (*error) |
| 1183 | + return; |
| 1184 | + |
| 1185 | + point = pItem->mapToScene(point); |
| 1186 | + |
| 1187 | + QTouchEvent *touchBeginEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, point); |
| 1188 | + QGuiApplication::postEvent(view, touchBeginEvent); |
| 1189 | + |
| 1190 | + loop.exec(); |
| 1191 | + |
| 1192 | + QTouchEvent *touchEndEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, point); |
| 1193 | + QGuiApplication::postEvent(view, touchEndEvent); |
| 1194 | + |
| 1195 | + QGuiApplication::processEvents(); |
| 1196 | + |
| 1197 | +} |
| 1198 | + |
| 1199 | +void Quick2ViewCmdExecutor::TouchScroll(const ElementId &element, const int &xoffset, const int &yoffset, Error **error) |
| 1200 | +{ |
| 1201 | + QQuickView* view = getView(view_id_, error); |
| 1202 | + if (NULL == view) |
| 1203 | + return; |
| 1204 | + |
| 1205 | + Point location(0,0); |
| 1206 | + |
| 1207 | + // calculate the half of the element size and translate by it. |
| 1208 | + Size sizel; |
| 1209 | + GetElementSize(element, &sizel, error); |
| 1210 | + if (*error) |
| 1211 | + return; |
| 1212 | + |
| 1213 | + location.Offset(sizel.width() / 2, sizel.height() / 2); |
| 1214 | + |
| 1215 | + QPointF startPoint = ConvertPointToQPoint(location); |
| 1216 | + |
| 1217 | + QQuickItem* pItem = getElement(element, error); |
| 1218 | + if (*error) |
| 1219 | + return; |
| 1220 | + |
| 1221 | + startPoint = pItem->mapToScene(startPoint); |
| 1222 | + |
| 1223 | + Point offset(xoffset, yoffset); |
| 1224 | + QPointF offsetPoint = ConvertPointToQPoint(offset); |
| 1225 | + int stepCount = 20; |
| 1226 | + int timeBetweenEvent = 30; |
| 1227 | + QEventLoop loop; |
| 1228 | + |
| 1229 | + for (int i = 0; i <= stepCount; ++i) |
| 1230 | + { |
| 1231 | + QPointF touchPoint(startPoint.x()+offsetPoint.x()*i/stepCount, startPoint.y()+offsetPoint.y()*i/stepCount); |
| 1232 | + |
| 1233 | + QTouchEvent *touchEvent; |
| 1234 | + if (i == 0) |
| 1235 | + touchEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, touchPoint); |
| 1236 | + else if (i == stepCount) |
| 1237 | + touchEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, touchPoint); |
| 1238 | + else |
| 1239 | + touchEvent = createSimpleTouchEvent(QEvent::TouchUpdate, Qt::TouchPointMoved, touchPoint); |
| 1240 | + |
| 1241 | + |
| 1242 | + QGuiApplication::postEvent(view, touchEvent); |
| 1243 | + QTimer::singleShot(timeBetweenEvent, &loop, SLOT(quit())); |
| 1244 | + loop.exec(); |
| 1245 | + } |
| 1246 | + QGuiApplication::processEvents(); |
| 1247 | +} |
| 1248 | + |
| 1249 | +void Quick2ViewCmdExecutor::TouchFlick(const ElementId &element, const int &xoffset, const int &yoffset, const int &speed, Error **error) |
| 1250 | +{ |
| 1251 | + QQuickView* view = getView(view_id_, error); |
| 1252 | + if (NULL == view) |
| 1253 | + return; |
| 1254 | + |
| 1255 | + Point location(0,0); |
| 1256 | + |
| 1257 | + // calculate the half of the element size and translate by it. |
| 1258 | + Size size; |
| 1259 | + GetElementSize(element, &size, error); |
| 1260 | + if (*error) |
| 1261 | + return; |
| 1262 | + |
| 1263 | + location.Offset(size.width() / 2, size.height() / 2); |
| 1264 | + QPointF startPoint = ConvertPointToQPoint(location); |
| 1265 | + |
| 1266 | + QQuickItem* pItem = getElement(element, error); |
| 1267 | + if (*error) |
| 1268 | + return; |
| 1269 | + |
| 1270 | + startPoint = pItem->mapToScene(startPoint); |
| 1271 | + |
| 1272 | + QPointF offsetPoint = ConvertPointToQPoint(Point(xoffset, yoffset)); |
| 1273 | + |
| 1274 | + QEventLoop loop; |
| 1275 | + |
| 1276 | + //some magic numbers |
| 1277 | + int stepCount = 20; |
| 1278 | + int timeBetweenEvent = 30/(speed+1); |
| 1279 | + |
| 1280 | + QVector2D velocity(xoffset*1000/(stepCount*timeBetweenEvent), yoffset*1000/(stepCount*timeBetweenEvent)); |
| 1281 | + |
| 1282 | + for (int i = 0; i <= stepCount; ++i) |
| 1283 | + { |
| 1284 | + QPointF touchPoint(startPoint.x()+offsetPoint.x()*i/stepCount, startPoint.y()+offsetPoint.y()*i/stepCount); |
| 1285 | + |
| 1286 | + QTouchEvent *touchEvent; |
| 1287 | + if (i == 0) |
| 1288 | + touchEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, touchPoint, velocity); |
| 1289 | + else if (i == stepCount) |
| 1290 | + touchEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, touchPoint, velocity); |
| 1291 | + else |
| 1292 | + touchEvent = createSimpleTouchEvent(QEvent::TouchUpdate, Qt::TouchPointMoved, touchPoint, velocity); |
| 1293 | + |
| 1294 | + QGuiApplication::postEvent(view, touchEvent); |
| 1295 | + QTimer::singleShot(timeBetweenEvent, &loop, SLOT(quit())); |
| 1296 | + loop.exec(); |
| 1297 | + if (i == stepCount) |
| 1298 | + { |
| 1299 | + QPointF touchPoint(startPoint); |
| 1300 | + touchEvent = createSimpleTouchEvent(QEvent::TouchCancel, Qt::TouchPointPressed, touchPoint); |
| 1301 | + QGuiApplication::postEvent(view, touchEvent); |
| 1302 | + } |
| 1303 | + } |
| 1304 | + QGuiApplication::processEvents(); |
| 1305 | +} |
| 1306 | + |
1030 | 1307 | QQuickItem* Quick2ViewCmdExecutor::getFocusItem(QQuickView* view) { |
1031 | 1308 | QQuickItem* pFocusItem = view->activeFocusItem(); |
1032 | 1309 | if (NULL != pFocusItem) return pFocusItem; |
|
0 commit comments