- enhancement: Correctly handle high-precision mouse wheel / touchpad in editors.

This commit is contained in:
Roy Qu 2023-02-17 16:16:57 +08:00
parent fcd086ebb5
commit 9f036d0d70
5 changed files with 50 additions and 59 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -347,6 +347,7 @@ private:
QTimer mAutoBackupTimer;
QTimer mTooltipTimer;
int mHoverModifiedLine;
int mWheelAccumulatedDelta;
static QHash<ParserLanguage,std::weak_ptr<CppParser>> mSharedParsers;

View File

@ -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)

View File

@ -743,8 +743,8 @@ private:
BufferCoord mDragSelBeginSave;
BufferCoord mDragSelEndSave;
bool mDropped;
qint64 mLastWheelEventTime;
int mWheelEventTimes;
int mWheelAccumlatedDeltaX;
int mWheelAccumlatedDeltaY;
friend class QSynEditPainter;