summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qwidgetlinecontrol.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/widgets/qwidgetlinecontrol.cpp')
-rw-r--r--src/widgets/widgets/qwidgetlinecontrol.cpp33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp
index af8e5a8b42..24edca172b 100644
--- a/src/widgets/widgets/qwidgetlinecontrol.cpp
+++ b/src/widgets/widgets/qwidgetlinecontrol.cpp
@@ -407,16 +407,14 @@ int QWidgetLineControl::xToPos(int x, QTextLine::CursorPosition betweenOrOn) con
/*!
\internal
- Returns the bounds of the current cursor, as defined as a
- between characters cursor.
+ Returns the bounds of the given text position.
*/
-QRect QWidgetLineControl::cursorRect() const
+QRect QWidgetLineControl::rectForPos(int pos) const
{
QTextLine l = textLayout()->lineAt(0);
- int c = m_cursor;
if (m_preeditCursor != -1)
- c += m_preeditCursor;
- int cix = qRound(l.cursorToX(c));
+ pos += m_preeditCursor;
+ int cix = qRound(l.cursorToX(pos));
int w = m_cursorWidth;
int ch = l.height() + 1;
@@ -426,6 +424,29 @@ QRect QWidgetLineControl::cursorRect() const
/*!
\internal
+ Returns the bounds of the current cursor, as defined as a
+ between characters cursor.
+*/
+QRect QWidgetLineControl::cursorRect() const
+{
+ return rectForPos(m_cursor);
+}
+
+/*!
+ \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);
+}
+
+/*!
+ \internal
+
Fixes the current text so that it is valid given any set validators.
Returns \c true if the text was changed. Otherwise returns \c false.