diff options
author | q5sys <jt@obs-sec.com> | 2017-06-14 14:29:25 -0400 |
---|---|---|
committer | q5sys <jt@obs-sec.com> | 2017-06-14 14:29:25 -0400 |
commit | 9fb40bfc3c9a5b1877fdfdf65b307c690ea860d9 (patch) | |
tree | b537499f575194ed4525bec104297ea06d3bd401 /src-qt5/desktop-utils/lumina-textedit | |
parent | Merge branch 'master' of http://github.com/trueos/lumina (diff) | |
download | lumina-9fb40bfc3c9a5b1877fdfdf65b307c690ea860d9.tar.gz lumina-9fb40bfc3c9a5b1877fdfdf65b307c690ea860d9.tar.bz2 lumina-9fb40bfc3c9a5b1877fdfdf65b307c690ea860d9.zip |
fix font size bug for line sizes
Diffstat (limited to 'src-qt5/desktop-utils/lumina-textedit')
-rw-r--r-- | src-qt5/desktop-utils/lumina-textedit/MainUI.cpp | 2 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp | 18 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.h | 5 |
3 files changed, 22 insertions, 3 deletions
diff --git a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp index 145c7c7e..41fc6788 100644 --- a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp @@ -18,6 +18,7 @@ #include <QTimer> #include <QMessageBox> #include <QActionGroup> +#include "PlainTextEditor.h" MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->setupUi(this); @@ -255,6 +256,7 @@ void MainUI::changeFontSize(int newFontSize){ QFont currentFont = currentEditor()->document()->defaultFont(); currentFont.setPointSize(newFontSize); currentEditor()->document()->setDefaultFont(currentFont); + currentEditor()->updateLNW(); } void MainUI::changeTabsLocation(QAction *act){ 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(); +} diff --git a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.h b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.h index 64ff256b..0c83b7ce 100644 --- a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.h +++ b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.h @@ -37,6 +37,9 @@ public: //Functions for managing the line number widget (internal - do not need to run directly) int LNWWidth(); //replacing the LNW size hint detection void paintLNW(QPaintEvent *ev); //forwarded from the LNW paint event + void updateLNW(); + + QFontMetrics *metrics; private: QWidget *LNW; //Line Number Widget @@ -65,7 +68,7 @@ private slots: void textChanged(); void cursorMoved(); //Function for prompting the user if the file changed externally - void fileChanged(); + void fileChanged(); protected: void resizeEvent(QResizeEvent *ev); |