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.cpp47
1 files changed, 33 insertions, 14 deletions
diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp
index fee401d6ae..28c0973e04 100644
--- a/src/widgets/widgets/qwidgetlinecontrol.cpp
+++ b/src/widgets/widgets/qwidgetlinecontrol.cpp
@@ -60,6 +60,28 @@
QT_BEGIN_NAMESPACE
/*!
+ \internal
+
+ Updates the internal text layout. Returns the ascent of the
+ created QTextLine.
+*/
+int QWidgetLineControl::redoTextLayout() const
+{
+ m_textLayout.clearLayout();
+
+ m_textLayout.beginLayout();
+ QTextLine l = m_textLayout.createLine();
+ m_textLayout.endLayout();
+
+#if defined(Q_WS_MAC)
+ if (m_threadChecks)
+ m_textLayoutThread = QThread::currentThread();
+#endif
+
+ return qRound(l.ascent());
+}
+
+/*!
\internal
Updates the display text based of the current edit text
@@ -92,15 +114,12 @@ void QWidgetLineControl::updateDisplayText(bool forceUpdate)
m_textLayout.setText(str);
- QTextOption option;
+ QTextOption option = m_textLayout.textOption();
option.setTextDirection(m_layoutDirection);
option.setFlags(QTextOption::IncludeTrailingSpaces);
m_textLayout.setTextOption(option);
- m_textLayout.beginLayout();
- QTextLine l = m_textLayout.createLine();
- m_textLayout.endLayout();
- m_ascent = qRound(l.ascent());
+ m_ascent = redoTextLayout();
if (str != orig || forceUpdate)
emit displayTextChanged(str);
@@ -196,7 +215,7 @@ void QWidgetLineControl::del()
if (hasSelectedText()) {
removeSelectedText();
} else {
- int n = m_textLayout.nextCursorPosition(m_cursor) - m_cursor;
+ int n = textLayout()->nextCursorPosition(m_cursor) - m_cursor;
while (n--)
internalDelete();
}
@@ -324,7 +343,7 @@ void QWidgetLineControl::updatePasswordEchoEditing(bool editing)
*/
int QWidgetLineControl::xToPos(int x, QTextLine::CursorPosition betweenOrOn) const
{
- return m_textLayout.lineAt(0).xToCursor(x, betweenOrOn);
+ return textLayout()->lineAt(0).xToCursor(x, betweenOrOn);
}
/*!
@@ -335,7 +354,7 @@ int QWidgetLineControl::xToPos(int x, QTextLine::CursorPosition betweenOrOn) con
*/
QRect QWidgetLineControl::cursorRect() const
{
- QTextLine l = m_textLayout.lineAt(0);
+ QTextLine l = textLayout()->lineAt(0);
int c = m_cursor;
if (m_preeditCursor != -1)
c += m_preeditCursor;
@@ -538,14 +557,14 @@ void QWidgetLineControl::draw(QPainter *painter, const QPoint &offset, const QRe
}
if (flags & DrawText)
- m_textLayout.draw(painter, offset, selections, clip);
+ textLayout()->draw(painter, offset, selections, clip);
if (flags & DrawCursor){
int cursor = m_cursor;
if (m_preeditCursor != -1)
cursor += m_preeditCursor;
if (!m_hideCursor && (!m_blinkPeriod || m_blinkStatus))
- m_textLayout.drawCursor(painter, offset, cursor, m_cursorWidth);
+ textLayout()->drawCursor(painter, offset, cursor, m_cursorWidth);
}
}
@@ -561,10 +580,10 @@ void QWidgetLineControl::selectWordAtPos(int cursor)
int next = cursor + 1;
if(next > end())
--next;
- int c = m_textLayout.previousCursorPosition(next, QTextLayout::SkipWords);
+ int c = textLayout()->previousCursorPosition(next, QTextLayout::SkipWords);
moveCursor(c, false);
// ## text layout should support end of words.
- int end = m_textLayout.nextCursorPosition(c, QTextLayout::SkipWords);
+ int end = textLayout()->nextCursorPosition(c, QTextLayout::SkipWords);
while (end > cursor && m_text[end-1].isSpace())
--end;
moveCursor(end, true);
@@ -1392,9 +1411,9 @@ bool QWidgetLineControl::processEvent(QEvent* ev)
case QEvent::GraphicsSceneMouseRelease:
case QEvent::GraphicsSceneMousePress:{
QGraphicsSceneMouseEvent *gvEv = static_cast<QGraphicsSceneMouseEvent*>(ev);
- QMouseEvent* mouse = new QMouseEvent(ev->type(),
+ QMouseEvent mouse(ev->type(),
gvEv->pos().toPoint(), gvEv->button(), gvEv->buttons(), gvEv->modifiers());
- processMouseEvent(mouse); break;
+ processMouseEvent(&mouse); break;
}
#endif
case QEvent::MouseButtonPress: