Don't update line width in background.
This commit is contained in:
parent
89e2c330e3
commit
e29b7c0148
|
@ -92,22 +92,6 @@ int Document::lineWidth(int line)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void Document::updateLineWidth(int line)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if (line>=0 && line < mLines.size()) {
|
||||
if (mLines[line]->mWidth<0) {
|
||||
int width;
|
||||
QList<int> glyphPositions = mGlyphCalculator.calcLineWidth(
|
||||
mLines[line]->lineText(),
|
||||
mLines[line]->glyphStartCharList(),
|
||||
width);
|
||||
setLineWidth(line, width,glyphPositions);
|
||||
mLines[line]->mIsTempWidth = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int Document::lineWidth(int line, const QString &newText)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
|
@ -1268,12 +1252,6 @@ void Document::invalidateAllLineWidth()
|
|||
line->invalidateWidth();
|
||||
}
|
||||
mIndexOfLongestLine = -1;
|
||||
FindMaxLineWidthThread *thread = new FindMaxLineWidthThread(mLines, mGlyphCalculator);
|
||||
connect(thread, &FindMaxLineWidthThread::maxWidthLineFound,
|
||||
this, &Document::maxWidthLineFound);
|
||||
connect(thread, &QThread::finished,
|
||||
thread, &QThread::deleteLater);
|
||||
thread->start();
|
||||
}
|
||||
|
||||
void Document::invalidateAllNonTempLineWidth()
|
||||
|
@ -1778,29 +1756,4 @@ void GlyphCalculator::setFont(const QFont &newFont)
|
|||
mSpaceWidth = mFontMetrics.horizontalAdvance(" ");
|
||||
}
|
||||
|
||||
FindMaxLineWidthThread::FindMaxLineWidthThread(const DocumentLines &lines, const GlyphCalculator &glyphCalculator, QObject *parent):
|
||||
QThread(parent),
|
||||
mLines{lines},
|
||||
mGlyphCalculator{glyphCalculator}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FindMaxLineWidthThread::run()
|
||||
{
|
||||
int maxWidth = 0;
|
||||
int maxWidthLine = -1;
|
||||
for (int i=0;i<mLines.size();i++) {
|
||||
int width = mLines[i]->mWidth;
|
||||
if ( width < 0 )
|
||||
width = mGlyphCalculator.stringWidth(mLines[i]->lineText(),0);
|
||||
if (width > maxWidth) {
|
||||
maxWidth = width;
|
||||
maxWidthLine = i;
|
||||
}
|
||||
}
|
||||
if (maxWidthLine >= 0)
|
||||
emit maxWidthLineFound(maxWidthLine);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ QList<int> calcGlyphStartCharList(const QString &text);
|
|||
void expandGlyphStartCharList(const QString& strAdded, int oldStrLen, QList<int> &glyphStartCharList);
|
||||
|
||||
class Document;
|
||||
class FindMaxLineWidthThread;
|
||||
|
||||
using SearchConfirmAroundProc = std::function<bool ()>;
|
||||
/**
|
||||
|
@ -180,7 +179,6 @@ private:
|
|||
bool mIsTempWidth;
|
||||
UpdateWidthFunc mUpdateWidthFunc;
|
||||
friend class Document;
|
||||
friend class FindMaxLineWidthThread;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<DocumentLine> PDocumentLine;
|
||||
|
@ -275,26 +273,6 @@ private:
|
|||
bool mForceMonospace;
|
||||
};
|
||||
|
||||
class FindMaxLineWidthThread: public QThread {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FindMaxLineWidthThread(
|
||||
const DocumentLines &lines,
|
||||
const GlyphCalculator& glyphCalculator,
|
||||
QObject* parent=nullptr);
|
||||
FindMaxLineWidthThread(const FindMaxLineWidthThread&) = delete;
|
||||
signals:
|
||||
void maxWidthLineFound(int line);
|
||||
private:
|
||||
DocumentLines mLines;
|
||||
GlyphCalculator mGlyphCalculator;
|
||||
|
||||
// QThread interface
|
||||
protected:
|
||||
void run() override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief The Document class
|
||||
*
|
||||
|
@ -349,8 +327,6 @@ public:
|
|||
*/
|
||||
int lineWidth(int line);
|
||||
|
||||
void updateLineWidth(int line);
|
||||
|
||||
/**
|
||||
* @brief get width of the specified text / line
|
||||
*
|
||||
|
@ -646,7 +622,6 @@ signals:
|
|||
void inserted(int startLine, int count);
|
||||
void putted(int line);
|
||||
void maxLineWidthChanged();
|
||||
void lineWidthUpdateNeeded(int line);
|
||||
protected:
|
||||
QString getTextStr() const;
|
||||
void setUpdateState(bool Updating);
|
||||
|
@ -654,9 +629,6 @@ protected:
|
|||
void addItem(const QString& s);
|
||||
void putTextStr(const QString& text);
|
||||
void internalClear();
|
||||
void maxWidthLineFound(int line) {
|
||||
emit lineWidthUpdateNeeded(line);
|
||||
}
|
||||
private:
|
||||
void invalidateAllLineWidth();
|
||||
bool lineWidthValid(int line);
|
||||
|
|
|
@ -44,20 +44,6 @@
|
|||
|
||||
#define UPDATE_HORIZONTAL_SCROLLBAR_EVENT ((QEvent::Type)(QEvent::User+1))
|
||||
#define UPDATE_VERTICAL_SCROLLBAR_EVENT ((QEvent::Type)(QEvent::User+2))
|
||||
#define UPDATE_LINE_WIDTH_EVENT ((QEvent::Type)(QEvent::User+3))
|
||||
|
||||
class UpdateLineWidthEvent: public QEvent{
|
||||
public:
|
||||
explicit UpdateLineWidthEvent(int line):
|
||||
QEvent{UPDATE_LINE_WIDTH_EVENT},
|
||||
mLine{line}
|
||||
{
|
||||
|
||||
}
|
||||
int line() const { return mLine; }
|
||||
private:
|
||||
int mLine;
|
||||
};
|
||||
|
||||
namespace QSynedit {
|
||||
QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent),
|
||||
|
@ -91,7 +77,6 @@ QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent),
|
|||
connect(mDocument.get(), &Document::cleared, this, &QSynEdit::updateVScrollbar);
|
||||
connect(mDocument.get(), &Document::deleted, this, &QSynEdit::updateVScrollbar);
|
||||
connect(mDocument.get(), &Document::inserted, this, &QSynEdit::updateVScrollbar);
|
||||
connect(mDocument.get(), &Document::lineWidthUpdateNeeded, this, &QSynEdit::onLineWidthUpdateNeeded);
|
||||
|
||||
mGutterWidth = 0;
|
||||
|
||||
|
@ -1770,12 +1755,6 @@ void QSynEdit::onMaxLineWidthChanged()
|
|||
updateHScrollBarLater();
|
||||
}
|
||||
|
||||
void QSynEdit::onLineWidthUpdateNeeded(int line)
|
||||
{
|
||||
UpdateLineWidthEvent * event = new UpdateLineWidthEvent(line);
|
||||
qApp->postEvent(this,event);
|
||||
}
|
||||
|
||||
void QSynEdit::updateHScrollBarLater()
|
||||
{
|
||||
QEvent * event = new QEvent(UPDATE_HORIZONTAL_SCROLLBAR_EVENT);
|
||||
|
@ -3164,12 +3143,6 @@ void QSynEdit::doUpdateVScrollbar()
|
|||
verticalScrollBar()->setSingleStep(mTextHeight);
|
||||
}
|
||||
|
||||
void QSynEdit::doUpdateLineWidth(int line)
|
||||
{
|
||||
mDocument->updateLineWidth(line);
|
||||
}
|
||||
|
||||
|
||||
void QSynEdit::updateCaret()
|
||||
{
|
||||
if (mDocument->maxLineWidth()<0)
|
||||
|
@ -6008,12 +5981,6 @@ bool QSynEdit::event(QEvent *event)
|
|||
event->setAccepted(true);
|
||||
doUpdateHScrollbar();
|
||||
break;
|
||||
case UPDATE_LINE_WIDTH_EVENT: {
|
||||
event->setAccepted(true);
|
||||
UpdateLineWidthEvent* updateEvent = dynamic_cast<UpdateLineWidthEvent *>(event);
|
||||
doUpdateLineWidth(updateEvent->line());
|
||||
}
|
||||
break;
|
||||
case QEvent::KeyPress:{
|
||||
QKeyEvent* keyEvent = dynamic_cast<QKeyEvent *>(event);
|
||||
if(keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Backtab)
|
||||
|
|
|
@ -525,7 +525,6 @@ private:
|
|||
void doUpdateHScrollbar();
|
||||
void updateVScrollbar();
|
||||
void doUpdateVScrollbar();
|
||||
void doUpdateLineWidth(int line);
|
||||
void updateCaret();
|
||||
void recalcCharExtent();
|
||||
QString expandAtWideGlyphs(const QString& S);
|
||||
|
@ -646,7 +645,6 @@ private:
|
|||
|
||||
private slots:
|
||||
void onMaxLineWidthChanged();
|
||||
void onLineWidthUpdateNeeded(int line);
|
||||
void updateHScrollBarLater();
|
||||
void onBookMarkOptionsChanged();
|
||||
void onGutterChanged();
|
||||
|
|
Loading…
Reference in New Issue