summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2009-08-29 10:25:14 (GMT)
committerKevin Smith <git@kismith.co.uk>2009-08-29 10:25:14 (GMT)
commit9c79d93c3a98b9507f42c2f564916e0ef975c525 (patch)
treea14f4abb4f8c2adec4e11603f21b484853bc7bd2 /Swift/QtUI/QtTextEdit.cpp
parent52b06bd89d91e2f5e0c1ae439cd1e5c3e4b9bf2e (diff)
downloadswift-9c79d93c3a98b9507f42c2f564916e0ef975c525.zip
swift-9c79d93c3a98b9507f42c2f564916e0ef975c525.tar.bz2
Allow multi-line inputs, and grow accordingly.
Diffstat (limited to 'Swift/QtUI/QtTextEdit.cpp')
-rw-r--r--Swift/QtUI/QtTextEdit.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp
new file mode 100644
index 0000000..a116ede
--- /dev/null
+++ b/Swift/QtUI/QtTextEdit.cpp
@@ -0,0 +1,40 @@
+#include "QtTextEdit.h"
+
+#include <QFontMetrics>
+#include <QKeyEvent>
+
+namespace Swift {
+
+QtTextEdit::QtTextEdit(QWidget* parent) : QTextEdit(parent){
+ connect(this, SIGNAL(textChanged()), this, SLOT(handleTextChanged()));
+ handleTextChanged();
+};
+
+void QtTextEdit::keyPressEvent(QKeyEvent* event) {
+ if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return)
+ && event->modifiers() == Qt::NoModifier) {
+ emit returnPressed();
+ } else {
+ QTextEdit::keyPressEvent(event);
+ }
+}
+
+void QtTextEdit::handleTextChanged() {
+ setMaximumSize(QSize(maximumWidth(), sizeHint().height()));
+ updateGeometry();
+}
+
+QSize QtTextEdit::sizeHint() const {
+ QFontMetrics inputMetrics(currentFont());
+ QRect boundingRect = inputMetrics.boundingRect(geometry(), Qt::TextWordWrap, toPlainText());
+ int height = boundingRect.height() + inputMetrics.height();
+ return QSize(width(), height);
+ //int numberOfLines = 1;
+ //int lineHeight = inputMetrics.lineSpacing();
+ //return QSize(QTextEdit::sizeHint().width(), lineHeight * numberOfLines);
+}
+
+}
+
+
+