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
parent52b06bd89d91e2f5e0c1ae439cd1e5c3e4b9bf2e (diff)
downloadswift-9c79d93c3a98b9507f42c2f564916e0ef975c525.zip
swift-9c79d93c3a98b9507f42c2f564916e0ef975c525.tar.bz2
Allow multi-line inputs, and grow accordingly.
-rw-r--r--Swift/QtUI/QtAboutWidget.cpp2
-rw-r--r--Swift/QtUI/QtAboutWidget.h2
-rw-r--r--Swift/QtUI/QtChatWindow.cpp9
-rw-r--r--Swift/QtUI/QtChatWindow.h3
-rw-r--r--Swift/QtUI/QtTextEdit.cpp40
-rw-r--r--Swift/QtUI/QtTextEdit.h17
-rw-r--r--Swift/QtUI/SConscript1
7 files changed, 68 insertions, 6 deletions
diff --git a/Swift/QtUI/QtAboutWidget.cpp b/Swift/QtUI/QtAboutWidget.cpp
index bc3fb4b..7e5cda1 100644
--- a/Swift/QtUI/QtAboutWidget.cpp
+++ b/Swift/QtUI/QtAboutWidget.cpp
@@ -42,4 +42,4 @@ QtAboutWidget::QtAboutWidget() : QWidget() {
}
QtAboutWidget* QtAboutWidget::instance_ = NULL;
-} \ No newline at end of file
+}
diff --git a/Swift/QtUI/QtAboutWidget.h b/Swift/QtUI/QtAboutWidget.h
index 8e6f027..0a1fc3f 100644
--- a/Swift/QtUI/QtAboutWidget.h
+++ b/Swift/QtUI/QtAboutWidget.h
@@ -12,4 +12,4 @@ namespace Swift {
QtAboutWidget();
static QtAboutWidget* instance_;
};
-} \ No newline at end of file
+}
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index 2e08adb..b7987b9 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -5,6 +5,7 @@
#include "QtChatView.h"
#include "MessageSnippet.h"
#include "SystemMessageSnippet.h"
+#include "QtTextEdit.h"
#include <QApplication>
#include <QBoxLayout>
@@ -50,9 +51,10 @@ QtChatWindow::QtChatWindow(const QString &contact, QtTreeWidgetFactory *treeWidg
labelsWidget_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
midBarLayout->addWidget(labelsWidget_,0);
- input_ = new QLineEdit(this);
+ input_ = new QtTextEdit(this);
+ input_->setAcceptRichText(false);
layout->addWidget(input_);
-
+
connect(input_, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
setFocusProxy(input_);
connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(qAppFocusChanged(QWidget*, QWidget*)));
@@ -106,6 +108,7 @@ void QtChatWindow::convertToMUC() {
void QtChatWindow::qAppFocusChanged(QWidget *old, QWidget *now) {
Q_UNUSED(old);
+ Q_UNUSED(now);
if (isWidgetSelected()) {
onAllMessagesRead();
}
@@ -182,7 +185,7 @@ void QtChatWindow::addSystemMessage(const String& message) {
}
void QtChatWindow::returnPressed() {
- onSendMessageRequest(Q2PSTRING(input_->text()));
+ onSendMessageRequest(Q2PSTRING(input_->toPlainText()));
messageLog_->scrollToBottom();
input_->clear();
}
diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h
index 6e45d34..ea4983f 100644
--- a/Swift/QtUI/QtChatWindow.h
+++ b/Swift/QtUI/QtChatWindow.h
@@ -14,6 +14,7 @@ namespace Swift {
class QtTreeWidget;
class QtTreeWidgetFactory;
class TreeWidget;
+ class QtTextEdit;
class QtChatWindow : public QtTabbable, public ChatWindow {
Q_OBJECT
public:
@@ -46,7 +47,7 @@ namespace Swift {
int unreadCount_;
QString contact_;
QtChatView *messageLog_;
- QLineEdit* input_;
+ QtTextEdit* input_;
QComboBox *labelsWidget_;
QtTreeWidget *treeWidget_;
std::vector<SecurityLabel> availableLabels_;
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);
+}
+
+}
+
+
+
diff --git a/Swift/QtUI/QtTextEdit.h b/Swift/QtUI/QtTextEdit.h
new file mode 100644
index 0000000..0663377
--- /dev/null
+++ b/Swift/QtUI/QtTextEdit.h
@@ -0,0 +1,17 @@
+#pragma once
+#include <QTextEdit>
+
+namespace Swift {
+ class QtTextEdit : public QTextEdit {
+ Q_OBJECT
+ public:
+ QtTextEdit(QWidget* parent = 0);
+ virtual QSize sizeHint() const;
+ signals:
+ void returnPressed();
+ protected:
+ virtual void keyPressEvent(QKeyEvent* event);
+ private slots:
+ void handleTextChanged();
+ };
+}
diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript
index 679b3c0..b818af9 100644
--- a/Swift/QtUI/SConscript
+++ b/Swift/QtUI/SConscript
@@ -64,6 +64,7 @@ sources = [
"QtSoundPlayer.cpp",
"QtSystemTray.cpp",
"QtTabbable.cpp",
+ "QtTextEdit.cpp",
"ChatSnippet.cpp",
"MessageSnippet.cpp",
"SystemMessageSnippet.cpp",