iOS: Use new QPlatformInputContext geometry API
This enables support for QT_SCALE_FACTOR on iOS. Fixes: QTBUG-74978 Change-Id: Ibcf0741c178e44802065e472e096a5f4c7d6f3cf Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
dafe9e2363
commit
b23f5621d7
@ -499,8 +499,9 @@ void QIOSInputContext::scrollToCursor()
|
||||
return;
|
||||
}
|
||||
|
||||
QWindow *focusWindow = qApp->focusWindow();
|
||||
QRect cursorRect = qApp->inputMethod()->cursorRectangle().translated(focusWindow->geometry().topLeft()).toRect();
|
||||
QPlatformWindow *focusWindow = qApp->focusWindow()->handle();
|
||||
QRect windowCurosorRect = QPlatformInputContext::cursorRectangle().toRect();
|
||||
QRect cursorRect = QRect(focusWindow->mapToGlobal(windowCurosorRect.topLeft()), windowCurosorRect.size());
|
||||
|
||||
// We explicitly ask for the geometry of the screen instead of the availableGeometry,
|
||||
// as we hide the status bar when scrolling the screen, so the available geometry will
|
||||
|
@ -146,8 +146,9 @@ static void executeBlockWithoutAnimation(Block block)
|
||||
if (visible) {
|
||||
// Note that the contents of the edit menu is decided by
|
||||
// first responder, which is normally QIOSTextResponder.
|
||||
QRectF cr = qApp->inputMethod()->cursorRectangle();
|
||||
QRectF ar = qApp->inputMethod()->anchorRectangle();
|
||||
QRectF cr = QPlatformInputContext::cursorRectangle();
|
||||
QRectF ar = QPlatformInputContext::anchorRectangle();
|
||||
|
||||
CGRect targetRect = cr.united(ar).toCGRect();
|
||||
UIView *focusView = reinterpret_cast<UIView *>(qApp->focusWindow()->winId());
|
||||
[[UIMenuController sharedMenuController] setTargetRect:targetRect inView:focusView];
|
||||
@ -627,13 +628,13 @@ static void executeBlockWithoutAnimation(Block block)
|
||||
|
||||
- (BOOL)acceptTouchesBegan:(QPointF)touchPoint
|
||||
{
|
||||
QRectF inputRect = QGuiApplication::inputMethod()->inputItemClipRectangle();
|
||||
QRectF inputRect = QPlatformInputContext::inputItemRectangle();
|
||||
return !hasSelection() && inputRect.contains(touchPoint);
|
||||
}
|
||||
|
||||
- (void)updateFocalPoint:(QPointF)touchPoint
|
||||
{
|
||||
platformInputContext()->setSelectionOnFocusObject(touchPoint, touchPoint);
|
||||
QPlatformInputContext::setSelectionOnFocusObject(touchPoint, touchPoint);
|
||||
self.focalPoint = touchPoint;
|
||||
}
|
||||
|
||||
@ -783,8 +784,8 @@ static void executeBlockWithoutAnimation(Block block)
|
||||
|
||||
// Accept the touch if it "overlaps" with any of the handles
|
||||
const int handleRadius = 50;
|
||||
QPointF cursorCenter = qApp->inputMethod()->cursorRectangle().center();
|
||||
QPointF anchorCenter = qApp->inputMethod()->anchorRectangle().center();
|
||||
QPointF cursorCenter = QPlatformInputContext::cursorRectangle().center();
|
||||
QPointF anchorCenter = QPlatformInputContext::anchorRectangle().center();
|
||||
QPointF cursorOffset = QPointF(cursorCenter.x() - touchPoint.x(), cursorCenter.y() - touchPoint.y());
|
||||
QPointF anchorOffset = QPointF(anchorCenter.x() - touchPoint.x(), anchorCenter.y() - touchPoint.y());
|
||||
double cursorDist = hypot(cursorOffset.x(), cursorOffset.y());
|
||||
@ -812,8 +813,7 @@ static void executeBlockWithoutAnimation(Block block)
|
||||
|
||||
// Get the text position under the touch
|
||||
SelectionPair selection = querySelection();
|
||||
const QTransform mapToLocal = QGuiApplication::inputMethod()->inputItemTransform().inverted();
|
||||
int touchTextPos = QInputMethod::queryFocusObject(Qt::ImCursorPosition, touchPoint * mapToLocal).toInt();
|
||||
int touchTextPos = QPlatformInputContext::queryFocusObject(Qt::ImCursorPosition, touchPoint).toInt();
|
||||
|
||||
// Ensure that the handels cannot be dragged past each other
|
||||
if (_dragOnCursor)
|
||||
@ -830,8 +830,8 @@ static void executeBlockWithoutAnimation(Block block)
|
||||
|
||||
// Move loupe to new position
|
||||
QRectF handleRect = _dragOnCursor ?
|
||||
qApp->inputMethod()->cursorRectangle() :
|
||||
qApp->inputMethod()->anchorRectangle();
|
||||
QPlatformInputContext::cursorRectangle() :
|
||||
QPlatformInputContext::anchorRectangle();
|
||||
self.focalPoint = QPointF(touchPoint.x(), handleRect.center().y());
|
||||
}
|
||||
|
||||
@ -858,9 +858,9 @@ static void executeBlockWithoutAnimation(Block block)
|
||||
}
|
||||
|
||||
// Adjust handles and input rect to match the new selection
|
||||
QRectF inputRect = QGuiApplication::inputMethod()->inputItemClipRectangle();
|
||||
CGRect cursorRect = QGuiApplication::inputMethod()->cursorRectangle().toCGRect();
|
||||
CGRect anchorRect = QGuiApplication::inputMethod()->anchorRectangle().toCGRect();
|
||||
QRectF inputRect = QPlatformInputContext::inputItemClipRectangle();
|
||||
CGRect cursorRect = QPlatformInputContext::cursorRectangle().toCGRect();
|
||||
CGRect anchorRect = QPlatformInputContext::anchorRectangle().toCGRect();
|
||||
|
||||
if (!_multiLine) {
|
||||
// Resize the layer a bit bigger to ensure that the handles are
|
||||
@ -924,7 +924,7 @@ static void executeBlockWithoutAnimation(Block block)
|
||||
{
|
||||
[super touchesBegan:touches withEvent:event];
|
||||
|
||||
QRectF inputRect = QGuiApplication::inputMethod()->inputItemClipRectangle();
|
||||
QRectF inputRect = QPlatformInputContext::inputItemClipRectangle();
|
||||
QPointF touchPos = QPointF::fromCGPoint([static_cast<UITouch *>([touches anyObject]) locationInView:_focusView]);
|
||||
const bool touchInsideInputArea = inputRect.contains(touchPos);
|
||||
|
||||
@ -969,8 +969,7 @@ static void executeBlockWithoutAnimation(Block block)
|
||||
_menuShouldBeVisible = false;
|
||||
} else {
|
||||
QPointF touchPos = QPointF::fromCGPoint([static_cast<UITouch *>([touches anyObject]) locationInView:_focusView]);
|
||||
const QTransform mapToLocal = QGuiApplication::inputMethod()->inputItemTransform().inverted();
|
||||
int cursorPosOnRelease = QInputMethod::queryFocusObject(Qt::ImCursorPosition, touchPos * mapToLocal).toInt();
|
||||
int cursorPosOnRelease = QPlatformInputContext::queryFocusObject(Qt::ImCursorPosition, touchPos).toInt();
|
||||
|
||||
if (cursorPosOnRelease == _cursorPosOnPress) {
|
||||
_menuShouldBeVisible = true;
|
||||
|
@ -832,7 +832,7 @@
|
||||
QInputMethodEvent e(m_markedText, attrs);
|
||||
[self sendEventToFocusObject:e];
|
||||
}
|
||||
QRectF startRect = qApp->inputMethod()->cursorRectangle();
|
||||
QRectF startRect = QPlatformInputContext::cursorRectangle();;
|
||||
|
||||
attrs = QList<QInputMethodEvent::Attribute>();
|
||||
attrs << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, r.location + r.length, 0, 0);
|
||||
@ -840,7 +840,7 @@
|
||||
QInputMethodEvent e(m_markedText, attrs);
|
||||
[self sendEventToFocusObject:e];
|
||||
}
|
||||
QRectF endRect = qApp->inputMethod()->cursorRectangle();
|
||||
QRectF endRect = QPlatformInputContext::cursorRectangle();;
|
||||
|
||||
if (cursorPos != int(r.location + r.length) || cursorPos != anchorPos) {
|
||||
attrs = QList<QInputMethodEvent::Attribute>();
|
||||
@ -866,8 +866,7 @@
|
||||
Q_UNUSED(position);
|
||||
// Assume for now that position is always the same as
|
||||
// cursor index until a better API is in place:
|
||||
QRectF cursorRect = qApp->inputMethod()->cursorRectangle();
|
||||
return cursorRect.toCGRect();
|
||||
return QPlatformInputContext::cursorRectangle().toCGRect();
|
||||
}
|
||||
|
||||
- (void)replaceRange:(UITextRange *)range withText:(NSString *)text
|
||||
@ -906,9 +905,7 @@
|
||||
|
||||
- (UITextPosition *)closestPositionToPoint:(CGPoint)point
|
||||
{
|
||||
QPointF p = QPointF::fromCGPoint(point);
|
||||
const QTransform mapToLocal = QGuiApplication::inputMethod()->inputItemTransform().inverted();
|
||||
int textPos = QInputMethod::queryFocusObject(Qt::ImCursorPosition, p * mapToLocal).toInt();
|
||||
int textPos = QPlatformInputContext::queryFocusObject(Qt::ImCursorPosition, QPointF::fromCGPoint(point)).toInt();
|
||||
return [QUITextPosition positionWithIndex:textPos];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user