| 421 | } |
| 422 | |
| 423 | void KeypadWidget::touchUpdate(const QList<QTouchEvent::TouchPoint> &points) { |
| 424 | for (uint8_t row = 0; row != sRows; ++row) { |
| 425 | for (uint8_t col = 0; col != sCols; ++col) { |
| 426 | if (Key *key = mKeys[row][col]) { |
| 427 | bool wasSelected = key->isSelected(); |
| 428 | for (const QTouchEvent::TouchPoint &point : points) { |
| 429 | if (point.state() & Qt::TouchPointStationary) { |
| 430 | continue; |
| 431 | } |
| 432 | QRectF ellipse; |
| 433 | #if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0) |
| 434 | ellipse.setSize(point.ellipseDiameters()); |
| 435 | #endif |
| 436 | ellipse.moveCenter(point.pos()); |
| 437 | ellipse = mInverseTransform.mapRect(ellipse); |
| 438 | if (ellipse.isEmpty()) { |
| 439 | ellipse += {4, 4, 4, 4}; |
| 440 | } |
| 441 | QPainterPath area; |
| 442 | area.addEllipse(ellipse); |
| 443 | #if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0) |
| 444 | if (point.rotation() != 0.0) { |
| 445 | area = area * QTransform::fromTranslate(ellipse.center().x(), |
| 446 | ellipse.center().y()). |
| 447 | rotate(point.rotation()). |
| 448 | translate(-ellipse.center().x(), -ellipse.center().y()); |
| 449 | } |
| 450 | #endif |
| 451 | if ((point.state() & (Qt::TouchPointMoved | Qt::TouchPointPressed)) && key->isUnder(area)) { |
| 452 | if (!mTouched.contains(key->keycode())) { |
| 453 | mTouched.insert(key->keycode()); |
| 454 | key->press(); |
| 455 | } |
| 456 | } else if (mTouched.remove(key->keycode())) { |
| 457 | key->release(); |
| 458 | } |
| 459 | } |
| 460 | updateKey(key, wasSelected); |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | void KeypadWidget::touchEnd() { |
| 467 | for (KeyCode code : mTouched) { |