QLineEdit: add support for Qt::ImAnchorRectangle
Change-Id: I52e15aa40af5ff77306c43209af87a3e727d2bdb Reviewed-by: Jan Arve Sæther <jan-arve.saether@theqtcompany.com>bb10
parent
ab67a5b7b6
commit
5391f3c72f
|
|
@ -1758,6 +1758,8 @@ QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property, QVariant arg
|
|||
switch(property) {
|
||||
case Qt::ImCursorRectangle:
|
||||
return d->cursorRect();
|
||||
case Qt::ImAnchorRectangle:
|
||||
return d->adjustedControlRect(d->control->anchorRect());
|
||||
case Qt::ImFont:
|
||||
return font();
|
||||
case Qt::ImCursorPosition: {
|
||||
|
|
|
|||
|
|
@ -404,6 +404,23 @@ int QWidgetLineControl::xToPos(int x, QTextLine::CursorPosition betweenOrOn) con
|
|||
return textLayout()->lineAt(0).xToCursor(x, betweenOrOn);
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
|
||||
Returns the bounds of the given text position.
|
||||
*/
|
||||
QRect QWidgetLineControl::rectForPos(int pos) const
|
||||
{
|
||||
QTextLine l = textLayout()->lineAt(0);
|
||||
if (m_preeditCursor != -1)
|
||||
pos += m_preeditCursor;
|
||||
int cix = qRound(l.cursorToX(pos));
|
||||
int w = m_cursorWidth;
|
||||
int ch = l.height() + 1;
|
||||
|
||||
return QRect(cix-5, 0, w+9, ch);
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
|
||||
|
|
@ -412,15 +429,19 @@ int QWidgetLineControl::xToPos(int x, QTextLine::CursorPosition betweenOrOn) con
|
|||
*/
|
||||
QRect QWidgetLineControl::cursorRect() const
|
||||
{
|
||||
QTextLine l = textLayout()->lineAt(0);
|
||||
int c = m_cursor;
|
||||
if (m_preeditCursor != -1)
|
||||
c += m_preeditCursor;
|
||||
int cix = qRound(l.cursorToX(c));
|
||||
int w = m_cursorWidth;
|
||||
int ch = l.height() + 1;
|
||||
return rectForPos(m_cursor);
|
||||
}
|
||||
|
||||
return QRect(cix-5, 0, w+9, ch);
|
||||
/*!
|
||||
\internal
|
||||
|
||||
Returns the bounds of the current anchor
|
||||
*/
|
||||
QRect QWidgetLineControl::anchorRect() const
|
||||
{
|
||||
if (!hasSelectedText())
|
||||
return cursorRect();
|
||||
return rectForPos(m_selstart < m_selend ? m_selstart : m_selend);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -212,7 +212,9 @@ public:
|
|||
void end(bool mark) { moveCursor(text().length(), mark); }
|
||||
|
||||
int xToPos(int x, QTextLine::CursorPosition = QTextLine::CursorBetweenCharacters) const;
|
||||
QRect rectForPos(int pos) const;
|
||||
QRect cursorRect() const;
|
||||
QRect anchorRect() const;
|
||||
|
||||
qreal cursorToX(int cursor) const { return m_textLayout.lineAt(0).cursorToX(cursor); }
|
||||
qreal cursorToX() const
|
||||
|
|
|
|||
Loading…
Reference in New Issue