diff --git a/NEWS.md b/NEWS.md index dca00ab9..7e7acab0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -34,8 +34,8 @@ Red Panda C++ Version 2.12 - enhancement: Delay for tooltips. - enhancement: "Tool tips delay" option in Options/editor/Tooltips - change: Remove "Compile & Run" menu item. It's replaced by "Run". - - enhancement: Limit max speed for mouse scroll (and touch pad?) - enhancement: Show "..." instead of "...}" when folding #if/#endif + - enhancement: Correctly handle high-precision mouse wheel / touchpad in editors. Red Panda C++ Version 2.11 diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 7da92182..ffe07922 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -66,25 +66,22 @@ Editor::Editor(QWidget *parent, const QString& filename, const QByteArray& encoding, Project* pProject, bool isNew, QTabWidget* parentPageControl): - QSynEdit(parent), - mInited(false), - mEncodingOption(encoding), - mFilename(filename), - mParentPageControl(parentPageControl), - mProject(pProject), - mIsNew(isNew), - mSyntaxIssues(), - mSyntaxErrorColor(Qt::red), - mSyntaxWarningColor("orange"), - mLineCount(0), - mActiveBreakpointLine(-1), - mLastIdCharPressed(0), - mCurrentWord(), - mCurrentTipType(TipType::None), - mOldHighlightedWord(), - mCurrentHighlightedWord(), - mSaving(false), - mHoverModifiedLine(-1) + QSynEdit{parent}, + mInited{false}, + mEncodingOption{encoding}, + mFilename{filename}, + mParentPageControl{parentPageControl}, + mProject{pProject}, + mIsNew{isNew}, + mSyntaxErrorColor{Qt::red}, + mSyntaxWarningColor{"orange"}, + mLineCount{0}, + mActiveBreakpointLine{-1}, + mLastIdCharPressed{0}, + mCurrentTipType{TipType::None}, + mSaving{false}, + mHoverModifiedLine{-1}, + mWheelAccumulatedDelta{0} { mInited=false; mBackupFile=nullptr; @@ -622,21 +619,23 @@ void Editor::undoSymbolCompletion(int pos) void Editor::wheelEvent(QWheelEvent *event) { if ( (event->modifiers() & Qt::ControlModifier)!=0) { int size = pSettings->editor().fontSize(); - if (event->angleDelta().y()>0) { + int oldSize = size; + mWheelAccumulatedDelta+=event->angleDelta().y(); + while (mWheelAccumulatedDelta>=120) { + mWheelAccumulatedDelta-=120; size = std::min(99,size+1); - pSettings->editor().setFontSize(size); - pSettings->editor().save(); - pMainWindow->updateEditorSettings(); - event->accept(); - return; - } else if (event->angleDelta().y()<0) { - size = std::max(2,size-1); - pSettings->editor().setFontSize(size); - pSettings->editor().save(); - pMainWindow->updateEditorSettings(); - event->accept(); - return; } + while (mWheelAccumulatedDelta<=-120) { + mWheelAccumulatedDelta+=120; + size = std::max(2,size-1); + } + if (size!=oldSize) { + pSettings->editor().setFontSize(size); + pSettings->editor().save(); + pMainWindow->updateEditorSettings(); + } + event->accept(); + return; } QSynEdit::wheelEvent(event); } diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index 67d93a07..d416ebc6 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -347,6 +347,7 @@ private: QTimer mAutoBackupTimer; QTimer mTooltipTimer; int mHoverModifiedLine; + int mWheelAccumulatedDelta; static QHash> mSharedParsers; diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index eb685eb2..18ec91ae 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -44,8 +44,8 @@ namespace QSynedit { QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent), mDropped{false}, - mLastWheelEventTime{QDateTime::currentMSecsSinceEpoch()}, - mWheelEventTimes{0} + mWheelAccumlatedDeltaX{0}, + mWheelAccumlatedDeltaY{0} { mCharWidth=1; mTextHeight = 1; @@ -6330,37 +6330,28 @@ void QSynEdit::leaveEvent(QEvent *) void QSynEdit::wheelEvent(QWheelEvent *event) { - qint64 current=QDateTime::currentMSecsSinceEpoch(); - if (current-mLastWheelEventTime<=1000) { - mWheelEventTimes+=1; - if (mWheelEventTimes>30) - return; - } else { - mWheelEventTimes=0; - mLastWheelEventTime=current; - } if (event->modifiers() == Qt::ShiftModifier) { - if (event->angleDelta().y()>0) { + mWheelAccumlatedDeltaX+=event->angleDelta().y(); + while (mWheelAccumlatedDeltaX>=120) { + mWheelAccumlatedDeltaX-=120; horizontalScrollBar()->setValue(horizontalScrollBar()->value()-mMouseWheelScrollSpeed); - event->accept(); - return; - } else if (event->angleDelta().y()<0) { + } + while (mWheelAccumlatedDeltaX<=-120) { + mWheelAccumlatedDeltaX+=120; horizontalScrollBar()->setValue(horizontalScrollBar()->value()+mMouseWheelScrollSpeed); - event->accept(); - return; } } else { - if (event->angleDelta().y()>0) { + mWheelAccumlatedDeltaY+=event->angleDelta().y(); + while (mWheelAccumlatedDeltaY>=120) { + mWheelAccumlatedDeltaY-=120; verticalScrollBar()->setValue(verticalScrollBar()->value()-mMouseWheelScrollSpeed); - event->accept(); - return; - } else if (event->angleDelta().y()<0) { + } + while (mWheelAccumlatedDeltaY<=-120) { + mWheelAccumlatedDeltaY+=120; verticalScrollBar()->setValue(verticalScrollBar()->value()+mMouseWheelScrollSpeed); - event->accept(); - return; } } - QAbstractScrollArea::wheelEvent(event); + event->accept(); } bool QSynEdit::viewportEvent(QEvent * event) diff --git a/libs/qsynedit/qsynedit/qsynedit.h b/libs/qsynedit/qsynedit/qsynedit.h index 67774530..ea799675 100644 --- a/libs/qsynedit/qsynedit/qsynedit.h +++ b/libs/qsynedit/qsynedit/qsynedit.h @@ -743,8 +743,8 @@ private: BufferCoord mDragSelBeginSave; BufferCoord mDragSelEndSave; bool mDropped; - qint64 mLastWheelEventTime; - int mWheelEventTimes; + int mWheelAccumlatedDeltaX; + int mWheelAccumlatedDeltaY; friend class QSynEditPainter;