fix: left/top pos after font size changed

This commit is contained in:
Roy Qu 2024-03-29 00:54:33 +08:00
parent dc4f252b41
commit 4f312b8de4
3 changed files with 14 additions and 10 deletions

View File

@ -1013,7 +1013,6 @@ QList<int> Document::calcGlyphPositionList(const QString &lineText, const QList<
right += gWidth; right += gWidth;
} }
return glyphPostionList; return glyphPostionList;
} }
int Document::xposToGlyphIndex(int line, int xpos) int Document::xposToGlyphIndex(int line, int xpos)

View File

@ -155,9 +155,9 @@ QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent),
hideCaret(); hideCaret();
connect(horizontalScrollBar(),&QScrollBar::valueChanged, connect(horizontalScrollBar(),&QScrollBar::valueChanged,
this, &QSynEdit::onScrolled); this, &QSynEdit::onHScrolled);
connect(verticalScrollBar(),&QScrollBar::valueChanged, connect(verticalScrollBar(),&QScrollBar::valueChanged,
this, &QSynEdit::onScrolled); this, &QSynEdit::onVScrolled);
connect(verticalScrollBar(), &QAbstractSlider::sliderReleased, connect(verticalScrollBar(), &QAbstractSlider::sliderReleased,
this, &QSynEdit::ensureLineAlignedWithTop); this, &QSynEdit::ensureLineAlignedWithTop);
//enable input method //enable input method
@ -286,6 +286,8 @@ bool QSynEdit::canRedo() const
int QSynEdit::maxScrollWidth() const int QSynEdit::maxScrollWidth() const
{ {
int maxWidth = mDocument->maxLineWidth(); int maxWidth = mDocument->maxLineWidth();
if (maxWidth <= 0)
return INT_MAX; //all inlines invalid. Next paintEvent() will update it.
if (useCodeFolding()) if (useCodeFolding())
maxWidth += stringWidth(syntaxer()->foldString(""),maxWidth); maxWidth += stringWidth(syntaxer()->foldString(""),maxWidth);
if (mOptions.testFlag(eoScrollPastEol)) if (mOptions.testFlag(eoScrollPastEol))
@ -3074,7 +3076,6 @@ void QSynEdit::doOnStatusChange(StatusChanges)
void QSynEdit::updateHScrollbar() void QSynEdit::updateHScrollbar()
{ {
int nMaxScroll;
int nMin,nMax,nPage,nPos; int nMin,nMax,nPage,nPos;
if (mPaintLock!=0) { if (mPaintLock!=0) {
mStateFlags.setFlag(StateFlag::sfHScrollbarChanged); mStateFlags.setFlag(StateFlag::sfHScrollbarChanged);
@ -3087,9 +3088,8 @@ void QSynEdit::updateHScrollbar()
setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOn); setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOn);
} }
if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssHorizontal) { if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssHorizontal) {
nMaxScroll = maxScrollWidth();
nMin = 0; nMin = 0;
nMax = nMaxScroll; nMax = maxScrollWidth();
nPage = viewWidth(); nPage = viewWidth();
nPos = mLeftPos; nPos = mLeftPos;
horizontalScrollBar()->setMinimum(nMin); horizontalScrollBar()->setMinimum(nMin);
@ -3735,15 +3735,19 @@ void QSynEdit::onChanged()
emit changed(); emit changed();
} }
void QSynEdit::onScrolled(int) void QSynEdit::onHScrolled(int)
{ {
incPaintLock();
mLeftPos = horizontalScrollBar()->value(); mLeftPos = horizontalScrollBar()->value();
invalidate();
}
void QSynEdit::onVScrolled(int)
{
mTopPos = verticalScrollBar()->value(); mTopPos = verticalScrollBar()->value();
invalidate(); invalidate();
decPaintLock();
} }
const PFormatter &QSynEdit::formatter() const const PFormatter &QSynEdit::formatter() const
{ {
return mFormatter; return mFormatter;

View File

@ -664,7 +664,8 @@ private slots:
void onUndoAdded(); void onUndoAdded();
void onSizeOrFontChanged(); void onSizeOrFontChanged();
void onChanged(); void onChanged();
void onScrolled(int value); void onHScrolled(int value);
void onVScrolled(int value);
private: private:
std::shared_ptr<QImage> mContentImage; std::shared_ptr<QImage> mContentImage;