From 03ae21ebf6057772caf0db8961dddb97bf615738 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 26 Nov 2021 08:14:23 +0800 Subject: [PATCH] - enhancement: scroll while dragging text in the editor --- NEWS.md | 1 + RedPandaIDE/qsynedit/SynEdit.cpp | 46 +++++++++++++++++++++++--------- RedPandaIDE/qsynedit/SynEdit.h | 1 + RedPandaIDE/widgets/qconsole.cpp | 6 ++--- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/NEWS.md b/NEWS.md index 31e757f0..88b831da 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ Version 0.10.1 For Dev-C++ 7 Beta - fix: can't correctly expand watch expression that has spaces in it - fix: can't correctly display stl containers in watch - fix: the last line in the debug console is not correctly displayed + - enhancement: scroll while dragging text in the editor Version 0.10.0 For Dev-C++ 7 Beta - enhancement: use gdb/mi interface to communicate with gdb debug session diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 2420b0f5..b27f86c8 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -34,6 +34,7 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) mOrigLines = mLines; //fPlugins := TList.Create; mMouseMoved = false; + mDragging = false; mUndoing = false; mLines->connect(mLines.get(), &SynEditStringList::changed, this, &SynEdit::onLinesChanged); mLines->connect(mLines.get(), &SynEditStringList::changing, this, &SynEdit::onLinesChanging); @@ -2483,14 +2484,16 @@ void SynEdit::computeCaret(int X, int Y) void SynEdit::computeScroll(int X, int Y) { QRect iScrollBounds; // relative to the client area - // don't scroll if dragging text from other control -// if (not MouseCapture) and (not Dragging) then begin -// fScrollTimer.Enabled := False; -// Exit; -// end; + int dispX,dispY = 2; + if (mDragging) { + dispX = mCharWidth / 2 -1; + dispY = mTextHeight/ 2 -1; + } - iScrollBounds = QRect(mGutterWidth+this->frameWidth(), this->frameWidth(), mCharsInWindow * mCharWidth, - mLinesInWindow * mTextHeight); + iScrollBounds = QRect(mGutterWidth+frameWidth()+dispX, + frameWidth()+dispY, + mCharsInWindow * mCharWidth-2*dispX, + mLinesInWindow * mTextHeight-2*dispY); if (X < iScrollBounds.left()) mScrollDeltaX = (X - iScrollBounds.left()) / mCharWidth - 1; @@ -5948,7 +5951,7 @@ void SynEdit::mousePressEvent(QMouseEvent *event) // setBlockBegin(TmpBegin); // setBlockEnd(TmpEnd); - setMouseTracking(true); + //setMouseTracking(true); //if mousedown occurred in selected block begin drag operation mStateFlags.setFlag(SynStateFlag::sfWaitForDragging,false); if (bWasSel && mOptions.testFlag(eoDragDropEditing) && (X >= mGutterWidth + 2) @@ -5988,7 +5991,7 @@ void SynEdit::mouseReleaseEvent(QMouseEvent *event) mScrollTimer->stop(); // if ((button = ) and (Shift = [ssRight]) and Assigned(PopupMenu) then // exit; - setMouseTracking(false); + //setMouseTracking(false); if (mStateFlags.testFlag(SynStateFlag::sfWaitForDragging) && !mStateFlags.testFlag(SynStateFlag::sfDblClicked)) { @@ -6129,6 +6132,7 @@ QVariant SynEdit::inputMethodQuery(Qt::InputMethodQuery property) const void SynEdit::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasFormat("text/plain")) { + mDragging = true; event->acceptProposedAction(); mDragCaretSave = caretXY(); mDragSelBeginSave = blockBegin(); @@ -6158,6 +6162,7 @@ void SynEdit::dropEvent(QDropEvent *event) setCaretXY(coord); setSelText(event->mimeData()->text()); event->acceptProposedAction(); + mDragging = false; } void SynEdit::dragMoveEvent(QDragMoveEvent *event) @@ -6167,9 +6172,21 @@ void SynEdit::dragMoveEvent(QDragMoveEvent *event) } else { event->setDropAction(Qt::MoveAction); } + // should we begin scrolling? + computeScroll(event->pos().x(), + event->pos().y()); +// DisplayCoord P = pixelsToNearestRowColumn(X, Y); +// P.Row = minMax(P.Row, 1, displayLineCount()); +// if (mScrollDeltaX != 0) +// P.Column = displayX(); +// if (mScrollDeltaY != 0) +// P.Row = displayY(); +// internalSetCaretXY(displayToBufferPos(P)); +// setBlockEnd(caretXY()); + BufferCoord coord = displayToBufferPos(pixelsToNearestRowColumn(event->pos().x(), event->pos().y())); - setCaretXY(coord); + internalSetCaretXY(coord); setBlockBegin(mDragSelBeginSave); setBlockEnd(mDragSelEndSave); showCaret(); @@ -6181,6 +6198,8 @@ void SynEdit::dragLeaveEvent(QDragLeaveEvent *) setBlockBegin(mDragSelBeginSave); setBlockEnd(mDragSelEndSave); showCaret(); + mScrollTimer->stop(); + mDragging = false; } int SynEdit::maxScrollHeight() const @@ -6591,8 +6610,11 @@ void SynEdit::onScrollTimeout() internalSetCaretXY(vCaret); // if MouseCapture is True we're changing selection. otherwise we're dragging -// if (mouseCapture()) - setBlockEnd(caretXY()); + if (mDragging) { + setBlockBegin(mDragSelBeginSave); + setBlockEnd(mDragSelEndSave); + } else + setBlockEnd(caretXY()); } computeScroll(iMousePos.x(), iMousePos.y()); } diff --git a/RedPandaIDE/qsynedit/SynEdit.h b/RedPandaIDE/qsynedit/SynEdit.h index 596bdc63..d5fcc091 100644 --- a/RedPandaIDE/qsynedit/SynEdit.h +++ b/RedPandaIDE/qsynedit/SynEdit.h @@ -701,6 +701,7 @@ private: BufferCoord mDragCaretSave; BufferCoord mDragSelBeginSave; BufferCoord mDragSelEndSave; + bool mDragging; friend class SynEditTextPainter; diff --git a/RedPandaIDE/widgets/qconsole.cpp b/RedPandaIDE/widgets/qconsole.cpp index 97a0210a..2697f339 100644 --- a/RedPandaIDE/widgets/qconsole.cpp +++ b/RedPandaIDE/widgets/qconsole.cpp @@ -43,7 +43,7 @@ QConsole::QConsole(QWidget *parent): mBlinkStatus = 0; //enable input method setAttribute(Qt::WA_InputMethodEnabled); - setMouseTracking(false); +// setMouseTracking(false); recalcCharExtent(); mScrollTimer = new QTimer(this); mScrollTimer->setInterval(100); @@ -504,7 +504,7 @@ void QConsole::mousePressEvent(QMouseEvent *event) //fKbdHandler.ExecuteMouseDown(Self, Button, Shift, X, Y); if (button == Qt::LeftButton) { - setMouseTracking(true); +// setMouseTracking(true); RowColumn mousePosRC = pixelsToNearestRowColumn(X,Y); LineChar mousePos = mContents.rowColumnToLineChar(mousePosRC); //I couldn't track down why, but sometimes (and definitely not all the time) @@ -522,7 +522,7 @@ void QConsole::mouseReleaseEvent(QMouseEvent *event) { QAbstractScrollArea::mouseReleaseEvent(event); mScrollTimer->stop(); - setMouseTracking(false); +// setMouseTracking(false); }