From 75e1cb7229f163506282876aa8b10ca0e64cc2fb Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Thu, 17 Jul 2014 13:41:51 +0200 Subject: [PATCH] ui: fixed fontMetrics lineheight working with wrong font in QtCodeSnippet FontMetric specific settings are now applied in the showEvent method, which is executed right before showing the Widget where the font setting from the stylesheet is already present. --- bin/app/data/ApplicationSettings.xml | 2 +- src/app/qt/element/QtCodeSnippet.cpp | 18 ++++++++++-------- src/app/qt/element/QtCodeSnippet.h | 3 ++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/bin/app/data/ApplicationSettings.xml b/bin/app/data/ApplicationSettings.xml index 775796ee..e6b93f98 100644 --- a/bin/app/data/ApplicationSettings.xml +++ b/bin/app/data/ApplicationSettings.xml @@ -5,6 +5,6 @@ Courier 12 222 222 222 100 - 210 240 70 50 + 210 240 70 100 diff --git a/src/app/qt/element/QtCodeSnippet.cpp b/src/app/qt/element/QtCodeSnippet.cpp index fd91f41c..ec15e793 100644 --- a/src/app/qt/element/QtCodeSnippet.cpp +++ b/src/app/qt/element/QtCodeSnippet.cpp @@ -46,7 +46,6 @@ QtCodeSnippet::QtCodeSnippet( , m_activeTokenId(activeTokenId) , m_digits(0) { - minimumSizeHint(); // force font loading setObjectName("code_snippet"); m_lineNumberArea = new LineNumberArea(this); @@ -56,9 +55,6 @@ QtCodeSnippet::QtCodeSnippet( setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setLineWrapMode(QPlainTextEdit::NoWrap); - int tabWidth = ApplicationSettings::getInstance()->getCodeTabWidth(); - setTabStopWidth(tabWidth * fontMetrics().width('9')); - m_highlighter = new QtHighlighter(document()); std::string displayCode = code; @@ -75,8 +71,6 @@ QtCodeSnippet::QtCodeSnippet( connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(clickTokenLocation())); connect(this, SIGNAL(selectionChanged()), this, SLOT(clearSelection())); - setMaximumHeight(sizeHint().height()); - m_digits = lineNumberDigits(); updateLineNumberAreaWidth(0); } @@ -87,8 +81,8 @@ QtCodeSnippet::~QtCodeSnippet() QSize QtCodeSnippet::sizeHint() const { - int width = lineNumberAreaWidth() + document()->size().width(); - int height = (document()->size().height() + 1) * fontMetrics().lineSpacing() * 1.1f; + int width = lineNumberAreaWidth(); + int height = (document()->size().height() + 0.7f) * fontMetrics().lineSpacing(); return QSize(width, height); } @@ -209,6 +203,14 @@ void QtCodeSnippet::resizeEvent(QResizeEvent *e) m_lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height())); } +void QtCodeSnippet::showEvent(QShowEvent* event) +{ + int tabWidth = ApplicationSettings::getInstance()->getCodeTabWidth(); + setTabStopWidth(tabWidth * fontMetrics().width('9')); + + setMaximumHeight(sizeHint().height()); +} + void QtCodeSnippet::updateLineNumberAreaWidth(int /* newBlockCount */) { setViewportMargins(lineNumberAreaWidth(), 0, 0, 0); diff --git a/src/app/qt/element/QtCodeSnippet.h b/src/app/qt/element/QtCodeSnippet.h index b50d9ea2..4d8346c9 100644 --- a/src/app/qt/element/QtCodeSnippet.h +++ b/src/app/qt/element/QtCodeSnippet.h @@ -55,7 +55,8 @@ public: void annotateText(const TokenLocationFile& locationFile); protected: - void resizeEvent(QResizeEvent *event); + virtual void resizeEvent(QResizeEvent *event); + virtual void showEvent(QShowEvent* event); private slots: void updateLineNumberAreaWidth(int newBlockCount);