fix: turn on "auto hide scroller" will crash app.

This commit is contained in:
Roy Qu 2024-03-29 23:50:59 +08:00
parent 92d7916288
commit bae50693b9
2 changed files with 13 additions and 1 deletions

View File

@ -41,6 +41,8 @@
#include <QTextEdit> #include <QTextEdit>
#include <QMimeData> #include <QMimeData>
#define MAX_LINE_WIDTH_CHANGED_EVENT ((QEvent::Type)(QEvent::User+1))
namespace QSynedit { namespace QSynedit {
QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent), QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent),
mEditingCount{0}, mEditingCount{0},
@ -70,7 +72,7 @@ QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent),
connect(mDocument.get(), &Document::inserted, this, &QSynEdit::onLinesInserted); connect(mDocument.get(), &Document::inserted, this, &QSynEdit::onLinesInserted);
connect(mDocument.get(), &Document::putted, this, &QSynEdit::onLinesPutted); connect(mDocument.get(), &Document::putted, this, &QSynEdit::onLinesPutted);
connect(mDocument.get(), &Document::maxLineWidthChanged, connect(mDocument.get(), &Document::maxLineWidthChanged,
this, &QSynEdit::updateHScrollbar); this, &QSynEdit::onMaxLineWidthChanged);
connect(mDocument.get(), &Document::cleared, this, &QSynEdit::updateVScrollbar); connect(mDocument.get(), &Document::cleared, this, &QSynEdit::updateVScrollbar);
connect(mDocument.get(), &Document::deleted, this, &QSynEdit::updateVScrollbar); connect(mDocument.get(), &Document::deleted, this, &QSynEdit::updateVScrollbar);
connect(mDocument.get(), &Document::inserted, this, &QSynEdit::updateVScrollbar); connect(mDocument.get(), &Document::inserted, this, &QSynEdit::updateVScrollbar);
@ -1743,6 +1745,12 @@ QString QSynEdit::getDisplayStringAtLine(int line) const
return s; return s;
} }
void QSynEdit::onMaxLineWidthChanged()
{
QEvent * event = new QEvent(MAX_LINE_WIDTH_CHANGED_EVENT);
qApp->postEvent(this,event);
}
void QSynEdit::doDeleteLastChar() void QSynEdit::doDeleteLastChar()
{ {
if (mReadOnly) if (mReadOnly)
@ -5952,6 +5960,9 @@ void QSynEdit::timerEvent(QTimerEvent *event)
bool QSynEdit::event(QEvent *event) bool QSynEdit::event(QEvent *event)
{ {
switch(event->type()) { switch(event->type()) {
case MAX_LINE_WIDTH_CHANGED_EVENT:
updateHScrollbar();
break;
case QEvent::KeyPress:{ case QEvent::KeyPress:{
QKeyEvent* keyEvent = static_cast<QKeyEvent *>(event); QKeyEvent* keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Backtab) if(keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Backtab)

View File

@ -650,6 +650,7 @@ private:
private slots: private slots:
void onMaxLineWidthChanged();
void onBookMarkOptionsChanged(); void onBookMarkOptionsChanged();
void onGutterChanged(); void onGutterChanged();
void onLinesChanged(); void onLinesChanged();