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.
This commit is contained in:
Eberhard Graether
2014-07-17 13:41:51 +02:00
parent efe3316ae3
commit 75e1cb7229
3 changed files with 13 additions and 10 deletions
+1 -1
View File
@@ -5,6 +5,6 @@
<FontName>Courier</FontName>
<FontSize>12</FontSize>
<LinkColor>222 222 222 100</LinkColor>
<ActiveLinkColor>210 240 70 50</ActiveLinkColor>
<ActiveLinkColor>210 240 70 100</ActiveLinkColor>
</code>
</config>
+10 -8
View File
@@ -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);
+2 -1
View File
@@ -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);