From 7598014eecec4a71305278ec0efd477eaa442de9 Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Wed, 4 Nov 2015 13:09:46 +0100
Subject: Improve QtTextEdit::sizeHint() for symmetric vertical padding

Test-Information:

Verified UI under OS X 10.10.5 and Debian 8.2.

Change-Id: Ifaf063eed06f51c94d4103c5397187e62035fb90

diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp
index 79a9474..a0188d9 100644
--- a/Swift/QtUI/QtTextEdit.cpp
+++ b/Swift/QtUI/QtTextEdit.cpp
@@ -11,10 +11,10 @@
 #include <boost/tuple/tuple.hpp>
 
 #include <QApplication>
-#include <QFontMetrics>
 #include <QKeyEvent>
 #include <QMenu>
 #include <QTime>
+#include <QTextDocument>
 
 #include <Swiften/Base/foreach.h>
 
@@ -36,6 +36,9 @@ QtTextEdit::QtTextEdit(SettingsProvider* settings, QWidget* parent) : QTextEdit(
 	setUpSpellChecker();
 #endif
 	handleTextChanged();
+	QTextOption textOption = document()->defaultTextOption();
+	textOption.setWrapMode(QTextOption::WordWrap);
+	document()->setDefaultTextOption(textOption);
 }
 
 QtTextEdit::~QtTextEdit() {
@@ -113,16 +116,9 @@ PositionPair QtTextEdit::getWordFromCursor(int cursorPosition) {
 }
 
 QSize QtTextEdit::sizeHint() const {
-	QFontMetrics inputMetrics(currentFont());
-	QRect horizontalBounds = contentsRect().adjusted(0,0,0,9999);
-	QRect boundingRect = inputMetrics.boundingRect(horizontalBounds, Qt::TextWordWrap, toPlainText() + "A");
-	int left, top, right, bottom;
-	getContentsMargins(&left, &top, &right, &bottom);
-	int height = boundingRect.height() + top + bottom + inputMetrics.height();
-	return QSize(width(), height);
-	//int numberOfLines = 1;
-	//int lineHeight = inputMetrics.lineSpacing();
-	//return QSize(QTextEdit::sizeHint().width(), lineHeight * numberOfLines);
+	QSize hint = document()->size().toSize();
+	QMargins margins = contentsMargins();
+	return hint + QSize(margins.left() + margins.right(), margins.top() + margins.bottom());
 }
 
 void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) {
-- 
cgit v0.10.2-6-g49f6