Browse Source

VTextEdit: force to update() to show cursor while dragging text

This is a work-around.
Le Tan 7 years ago
parent
commit
21e5aac024
4 changed files with 23 additions and 10 deletions
  1. 0 10
      src/vtextdocumentlayout.cpp
  2. 10 0
      src/vtextdocumentlayout.h
  3. 11 0
      src/vtextedit.cpp
  4. 2 0
      src/vtextedit.h

+ 0 - 10
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)
 {

+ 10 - 0
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

+ 11 - 0
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();
+}

+ 2 - 0
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();