From 21e5aac024a3fa7ba65271276ed76eeff4d799fa Mon Sep 17 00:00:00 2001 From: Le Tan Date: Thu, 19 Jul 2018 20:53:09 +0800 Subject: [PATCH] VTextEdit: force to update() to show cursor while dragging text This is a work-around. --- src/vtextdocumentlayout.cpp | 10 ---------- src/vtextdocumentlayout.h | 10 ++++++++++ src/vtextedit.cpp | 11 +++++++++++ src/vtextedit.h | 2 ++ 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/vtextdocumentlayout.cpp b/src/vtextdocumentlayout.cpp index 182c9aec..bc090eaf 100644 --- a/src/vtextdocumentlayout.cpp +++ b/src/vtextdocumentlayout.cpp @@ -793,16 +793,6 @@ void VTextDocumentLayout::updateDocumentSize() } } -void VTextDocumentLayout::setCursorWidth(int p_width) -{ - m_cursorWidth = p_width; -} - -int VTextDocumentLayout::cursorWidth() const -{ - return m_cursorWidth; -} - QRectF VTextDocumentLayout::blockRectFromTextLayout(const QTextBlock &p_block, ImagePaintInfo *p_image) { diff --git a/src/vtextdocumentlayout.h b/src/vtextdocumentlayout.h index da9ab57b..408eee13 100644 --- a/src/vtextdocumentlayout.h +++ b/src/vtextdocumentlayout.h @@ -385,4 +385,14 @@ inline void VTextDocumentLayout::setCursorLineBlockNumber(int p_blockNumber) } } } + +inline void VTextDocumentLayout::setCursorWidth(int p_width) +{ + m_cursorWidth = p_width; +} + +inline int VTextDocumentLayout::cursorWidth() const +{ + return m_cursorWidth; +} #endif // VTEXTDOCUMENTLAYOUT_H diff --git a/src/vtextedit.cpp b/src/vtextedit.cpp index 4fad8650..8362e845 100644 --- a/src/vtextedit.cpp +++ b/src/vtextedit.cpp @@ -447,3 +447,14 @@ void VTextEdit::updateLineNumberAreaWidth(const QFontMetrics &p_metrics) { m_lineNumberArea->setDigitWidth(p_metrics.width(QLatin1Char('8'))); } + +void VTextEdit::dragMoveEvent(QDragMoveEvent *p_event) +{ + QTextEdit::dragMoveEvent(p_event); + + // We need to update the cursor rect to show the cursor while dragging text. + // This is a work-around. We do not know why VTextEdit won't update the cursor + // rect to show the cursor. + // TODO: find out the rect of current cursor to update that rect only. + update(); +} diff --git a/src/vtextedit.h b/src/vtextedit.h index 0506a3dd..4cb5a64f 100644 --- a/src/vtextedit.h +++ b/src/vtextedit.h @@ -83,6 +83,8 @@ protected: void updateLineNumberAreaWidth(const QFontMetrics &p_metrics); + void dragMoveEvent(QDragMoveEvent *p_event) Q_DECL_OVERRIDE; + private slots: // Update viewport margin to hold the line number area. void updateLineNumberAreaMargin();