summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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) {