summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2015-11-04 12:09:46 (GMT)
committerKevin Smith <kevin.smith@isode.com>2015-11-09 16:50:40 (GMT)
commit7598014eecec4a71305278ec0efd477eaa442de9 (patch)
treec73943cd1cecb7e5f63a26a5477e22bfc3fb776d /Swift/QtUI
parent526bbaf268851f8295a72f4ca8e6a97bcf43e37a (diff)
downloadswift-7598014eecec4a71305278ec0efd477eaa442de9.zip
swift-7598014eecec4a71305278ec0efd477eaa442de9.tar.bz2
Improve QtTextEdit::sizeHint() for symmetric vertical padding
Test-Information: Verified UI under OS X 10.10.5 and Debian 8.2. Change-Id: Ifaf063eed06f51c94d4103c5397187e62035fb90
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/QtTextEdit.cpp18
1 files changed, 7 insertions, 11 deletions
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) {