From 4f312b8de423ee06c5c39bbe79d7da80cb27a0db Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 29 Mar 2024 00:54:33 +0800 Subject: [PATCH] fix: left/top pos after font size changed --- libs/qsynedit/qsynedit/document.cpp | 1 - libs/qsynedit/qsynedit/qsynedit.cpp | 20 ++++++++++++-------- libs/qsynedit/qsynedit/qsynedit.h | 3 ++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/libs/qsynedit/qsynedit/document.cpp b/libs/qsynedit/qsynedit/document.cpp index e1409a79..c5f89ce5 100644 --- a/libs/qsynedit/qsynedit/document.cpp +++ b/libs/qsynedit/qsynedit/document.cpp @@ -1013,7 +1013,6 @@ QList Document::calcGlyphPositionList(const QString &lineText, const QList< right += gWidth; } return glyphPostionList; - } int Document::xposToGlyphIndex(int line, int xpos) diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index 2d5d1a56..e6b808c0 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -155,9 +155,9 @@ QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent), hideCaret(); connect(horizontalScrollBar(),&QScrollBar::valueChanged, - this, &QSynEdit::onScrolled); + this, &QSynEdit::onHScrolled); connect(verticalScrollBar(),&QScrollBar::valueChanged, - this, &QSynEdit::onScrolled); + this, &QSynEdit::onVScrolled); connect(verticalScrollBar(), &QAbstractSlider::sliderReleased, this, &QSynEdit::ensureLineAlignedWithTop); //enable input method @@ -286,6 +286,8 @@ bool QSynEdit::canRedo() const int QSynEdit::maxScrollWidth() const { int maxWidth = mDocument->maxLineWidth(); + if (maxWidth <= 0) + return INT_MAX; //all inlines invalid. Next paintEvent() will update it. if (useCodeFolding()) maxWidth += stringWidth(syntaxer()->foldString(""),maxWidth); if (mOptions.testFlag(eoScrollPastEol)) @@ -3074,7 +3076,6 @@ void QSynEdit::doOnStatusChange(StatusChanges) void QSynEdit::updateHScrollbar() { - int nMaxScroll; int nMin,nMax,nPage,nPos; if (mPaintLock!=0) { mStateFlags.setFlag(StateFlag::sfHScrollbarChanged); @@ -3087,9 +3088,8 @@ void QSynEdit::updateHScrollbar() setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOn); } if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssHorizontal) { - nMaxScroll = maxScrollWidth(); nMin = 0; - nMax = nMaxScroll; + nMax = maxScrollWidth(); nPage = viewWidth(); nPos = mLeftPos; horizontalScrollBar()->setMinimum(nMin); @@ -3735,15 +3735,19 @@ void QSynEdit::onChanged() emit changed(); } -void QSynEdit::onScrolled(int) +void QSynEdit::onHScrolled(int) { - incPaintLock(); mLeftPos = horizontalScrollBar()->value(); + invalidate(); +} + +void QSynEdit::onVScrolled(int) +{ mTopPos = verticalScrollBar()->value(); invalidate(); - decPaintLock(); } + const PFormatter &QSynEdit::formatter() const { return mFormatter; diff --git a/libs/qsynedit/qsynedit/qsynedit.h b/libs/qsynedit/qsynedit/qsynedit.h index c228901a..d5f59ea8 100644 --- a/libs/qsynedit/qsynedit/qsynedit.h +++ b/libs/qsynedit/qsynedit/qsynedit.h @@ -664,7 +664,8 @@ private slots: void onUndoAdded(); void onSizeOrFontChanged(); void onChanged(); - void onScrolled(int value); + void onHScrolled(int value); + void onVScrolled(int value); private: std::shared_ptr mContentImage;