From 9fb40bfc3c9a5b1877fdfdf65b307c690ea860d9 Mon Sep 17 00:00:00 2001 From: q5sys Date: Wed, 14 Jun 2017 14:29:25 -0400 Subject: fix font size bug for line sizes --- .../desktop-utils/lumina-textedit/PlainTextEditor.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp') diff --git a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp index a1b77732..865798e2 100644 --- a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp @@ -134,8 +134,10 @@ int PlainTextEditor::LNWWidth(){ int lines = this->blockCount(); if(lines<1){ lines = 1; } int chars = 1; + qDebug() << "point 1" << this->document()->defaultFont(); while(lines>=10){ chars++; lines/=10; } - return (this->fontMetrics().width("9")*chars); //make sure to add a tiny bit of padding + QFontMetrics metrics(this->document()->defaultFont()); + return (metrics.width("9")*chars); //make sure to add a tiny bit of padding } void PlainTextEditor::paintLNW(QPaintEvent *ev){ @@ -146,12 +148,20 @@ void PlainTextEditor::paintLNW(QPaintEvent *ev){ QTextBlock block = this->firstVisibleBlock(); int bTop = blockBoundingGeometry(block).translated(contentOffset()).top(); int bBottom; +// QFont font = P.font(); +// font.setPointSize(this->document()->defaultFont().pointSize()); + P.setFont(this->document()->defaultFont()); //Now loop over the blocks (lines) and write in the numbers + QFontMetrics metrics(this->document()->defaultFont()); + qDebug() << "point 2" << this->document()->defaultFont(); P.setPen(Qt::black); //setup the font color while(block.isValid() && bTop<=ev->rect().bottom()){ //ensure block below top of viewport bBottom = bTop+blockBoundingRect(block).height(); if(block.isVisible() && bBottom >= ev->rect().top()){ //ensure block above bottom of viewport - P.drawText(0,bTop, LNW->width(), this->fontMetrics().height(), Qt::AlignRight, QString::number(block.blockNumber()+1) ); + P.drawText(0,bTop, LNW->width(), metrics.height(), Qt::AlignRight, QString::number(block.blockNumber()+1) ); + qDebug() << "bTop" << bTop; + qDebug() << "LNW->width()" << LNW->width(); + qDebug() << "metrics.height()" << metrics.height(); } //Go to the next block block = block.next(); @@ -333,3 +343,7 @@ void PlainTextEditor::resizeEvent(QResizeEvent *ev){ QRect cGeom = this->contentsRect(); LNW->setGeometry( QRect(cGeom.left(), cGeom.top(), LNWWidth(), cGeom.height()) ); } + +void PlainTextEditor::updateLNW(){ + LNW_updateWidth(); +} -- cgit From a9036a594d4985764d2c4813b18caf0e12e6a35a Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 14 Jun 2017 15:01:20 -0400 Subject: Fix the sync of the line wrap with the current tab/file. --- src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp') diff --git a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp index 865798e2..57bc35a6 100644 --- a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp @@ -134,13 +134,16 @@ int PlainTextEditor::LNWWidth(){ int lines = this->blockCount(); if(lines<1){ lines = 1; } int chars = 1; - qDebug() << "point 1" << this->document()->defaultFont(); + //qDebug() << "point 1" << this->document()->defaultFont(); while(lines>=10){ chars++; lines/=10; } QFontMetrics metrics(this->document()->defaultFont()); return (metrics.width("9")*chars); //make sure to add a tiny bit of padding } void PlainTextEditor::paintLNW(QPaintEvent *ev){ + //qDebug() << "Paint LNW Event:" << ev->rect() << LNW->geometry(); + //if(ev->rect().height() < (QFontMetrics(this->document()->defaultFont()).height() *1.5) ){ return; } + //qDebug() << " -- paint line numbers"; QPainter P(LNW); //First set the background color P.fillRect(ev->rect(), QColor("lightgrey")); @@ -153,15 +156,15 @@ void PlainTextEditor::paintLNW(QPaintEvent *ev){ P.setFont(this->document()->defaultFont()); //Now loop over the blocks (lines) and write in the numbers QFontMetrics metrics(this->document()->defaultFont()); - qDebug() << "point 2" << this->document()->defaultFont(); + //qDebug() << "point 2" << this->document()->defaultFont(); P.setPen(Qt::black); //setup the font color while(block.isValid() && bTop<=ev->rect().bottom()){ //ensure block below top of viewport bBottom = bTop+blockBoundingRect(block).height(); if(block.isVisible() && bBottom >= ev->rect().top()){ //ensure block above bottom of viewport P.drawText(0,bTop, LNW->width(), metrics.height(), Qt::AlignRight, QString::number(block.blockNumber()+1) ); - qDebug() << "bTop" << bTop; - qDebug() << "LNW->width()" << LNW->width(); - qDebug() << "metrics.height()" << metrics.height(); + //qDebug() << "bTop" << bTop; + //qDebug() << "LNW->width()" << LNW->width(); + //qDebug() << "metrics.height()" << metrics.height(); } //Go to the next block block = block.next(); -- cgit From 065462b14aee9e689538791c9212e7bab9e720d1 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Mon, 19 Jun 2017 10:46:56 -0400 Subject: Commit some minor updates to whitespace and the python syntax file name. --- .../lumina-textedit/PlainTextEditor.cpp | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp') diff --git a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp index 57bc35a6..653bd0e8 100644 --- a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp @@ -43,7 +43,7 @@ PlainTextEditor::PlainTextEditor(QSettings *set, QWidget *parent) : QPlainTextEd } PlainTextEditor::~PlainTextEditor(){ - + } void PlainTextEditor::showLineNumbers(bool show){ @@ -60,13 +60,14 @@ void PlainTextEditor::LoadSyntaxRule(QString type){ SYNTAX->loadRules(files[i]); break; } + if(i==files.length()-1){ SyntaxFile dummy; SYNTAX->loadRules(dummy); } } SYNTAX->rehighlight(); } void PlainTextEditor::updateSyntaxColors(){ SYNTAX->reloadRules(); - SYNTAX->rehighlight(); + SYNTAX->rehighlight(); } //File loading/setting options @@ -77,7 +78,7 @@ void PlainTextEditor::LoadFile(QString filepath){ this->clear(); QList files = SyntaxFile::availableFiles(settings); for(int i=0; iloadRules(files[i]); break; @@ -125,7 +126,7 @@ QString PlainTextEditor::currentFile(){ } bool PlainTextEditor::hasChange(){ - return hasChanges; + return hasChanges; } //Functions for managing the line number widget @@ -171,7 +172,7 @@ void PlainTextEditor::paintLNW(QPaintEvent *ev){ bTop = bBottom; } } - + //============== // PRIVATE //============== @@ -190,7 +191,7 @@ void PlainTextEditor::clearMatchData(){ void PlainTextEditor::highlightMatch(QChar ch, bool forward, int fromPos, QChar startch){ if(forward){ matchleft = fromPos; } else{ matchright = fromPos; } - + int nested = 1; //always start within the first nest (the primary nest) int tmpFromPos = fromPos; //if(!forward){ tmpFromPos++; } //need to include the initial location @@ -205,7 +206,7 @@ void PlainTextEditor::highlightMatch(QChar ch, bool forward, int fromPos, QChar }else{ break; } }else{ QTextCursor cur = this->document()->find(ch, tmpFromPos, QTextDocument::FindBackward); - if(!cur.isNull()){ + if(!cur.isNull()){ QString mid = doc.mid(cur.position()-1, tmpFromPos-cur.position()+1); //qDebug() << "Found backwards match:" << nested << startch << ch << mid; //qDebug() << doc.mid(cur.position(),1) << doc.mid(tmpFromPos,1); @@ -215,10 +216,10 @@ void PlainTextEditor::highlightMatch(QChar ch, bool forward, int fromPos, QChar }else{ break; } } } - + //Now highlight the two characters - QList sels = this->extraSelections(); - if(matchleft>=0){ + QList sels = this->extraSelections(); + if(matchleft>=0){ QTextEdit::ExtraSelection sel; if(matchright>=0){ sel.format.setBackground( QColor(settings->value("colors/bracket-found").toString()) ); } else{ sel.format.setBackground( QColor(settings->value("colors/bracket-missing").toString()) ); } @@ -238,7 +239,7 @@ void PlainTextEditor::highlightMatch(QChar ch, bool forward, int fromPos, QChar if(!forward){ cur.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); } else{ cur.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor); } sel.cursor = cur; - sels << sel; + sels << sel; } this->setExtraSelections(sels); } @@ -327,7 +328,7 @@ void PlainTextEditor::fileChanged(){ text.append("\n"); text.append( tr("(Note: You will lose all currently-unsaved changes)") ); text.append("\n\n%1"); - + if(!update){ update = (QMessageBox::Yes == QMessageBox::question(this, tr("File Modified"),text.arg(currentFile()) , QMessageBox::Yes | QMessageBox::No, QMessageBox::No) ); } -- cgit