summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2011-04-30 10:02:18 (GMT)
committerKevin Smith <git@kismith.co.uk>2011-04-30 10:02:18 (GMT)
commitff21fe854d4c6bf5a5fed8d7412c9b02609faeb6 (patch)
tree6d1bfe9ed4f7d5d9ef1b8f811ec67f1943c9b96a /Swift
parentc26753dc9785377da0d836ce6f4286af6e3b8790 (diff)
downloadswift-ff21fe854d4c6bf5a5fed8d7412c9b02609faeb6.zip
swift-ff21fe854d4c6bf5a5fed8d7412c9b02609faeb6.tar.bz2
Tidy up some correction quibbles
Diffstat (limited to 'Swift')
-rw-r--r--Swift/QtUI/QtChatWindow.cpp47
-rw-r--r--Swift/QtUI/QtChatWindow.h6
-rw-r--r--Swift/QtUI/QtTextEdit.cpp8
3 files changed, 44 insertions, 17 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index ab230c4..e7cfa2b 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2011 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -17,6 +17,7 @@
#include "SwifTools/TabComplete.h"
+#include <QLabel>
#include <QApplication>
#include <QBoxLayout>
#include <QCloseEvent>
@@ -70,9 +71,17 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt
labelsWidget_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
midBarLayout->addWidget(labelsWidget_,0);
+ QWidget* inputBar = new QWidget(this);
+ layout->addWidget(inputBar);
+ QHBoxLayout* inputBarLayout = new QHBoxLayout(inputBar);
+ inputBarLayout->setContentsMargins(0,0,0,0);
+ inputBarLayout->setSpacing(2);
input_ = new QtTextEdit(this);
input_->setAcceptRichText(false);
- layout->addWidget(input_);
+ inputBarLayout->addWidget(input_);
+ correctingLabel_ = new QLabel(tr("Correcting"), this);
+ inputBarLayout->addWidget(correctingLabel_);
+ correctingLabel_->hide();
inputClearing_ = false;
contactIsTyping_ = false;
@@ -100,7 +109,6 @@ void QtChatWindow::setTabComplete(TabComplete* completer) {
void QtChatWindow::handleKeyPressEvent(QKeyEvent* event) {
int key = event->key();
Qt::KeyboardModifiers modifiers = event->modifiers();
- QTextCursor cursor;
if (key == Qt::Key_W && modifiers == Qt::ControlModifier) {
close();
} else if (
@@ -121,21 +129,32 @@ void QtChatWindow::handleKeyPressEvent(QKeyEvent* event) {
} else if (key == Qt::Key_Tab) {
tabComplete();
} else if ((key == Qt::Key_Up) && input_->toPlainText().isEmpty() && !(lastSentMessage_.isEmpty())) {
- cursor = input_->textCursor();
- cursor.select(QTextCursor::Document);
- cursor.beginEditBlock();
- cursor.insertText(QString(lastSentMessage_));
- cursor.endEditBlock();
- isCorrection_ = true;
- } else if (key == Qt::Key_Down && isCorrection_ && (cursor = input_->textCursor()).atBlockEnd()) {
- cursor.select(QTextCursor::Document);
- cursor.removeSelectedText();
- isCorrection_ = false;
+ beginCorrection();
+ } else if (key == Qt::Key_Down && isCorrection_ && input_->textCursor().atBlockEnd()) {
+ cancelCorrection();
} else {
messageLog_->handleKeyPressEvent(event);
}
}
+void QtChatWindow::beginCorrection() {
+ QTextCursor cursor = input_->textCursor();
+ cursor.select(QTextCursor::Document);
+ cursor.beginEditBlock();
+ cursor.insertText(QString(lastSentMessage_));
+ cursor.endEditBlock();
+ isCorrection_ = true;
+ correctingLabel_->show();
+}
+
+void QtChatWindow::cancelCorrection() {
+ QTextCursor cursor = input_->textCursor();
+ cursor.select(QTextCursor::Document);
+ cursor.removeSelectedText();
+ isCorrection_ = false;
+ correctingLabel_->hide();
+}
+
void QtChatWindow::tabComplete() {
if (!completer_) {
return;
@@ -396,9 +415,9 @@ void QtChatWindow::returnPressed() {
messageLog_->scrollToBottom();
lastSentMessage_ = QString(input_->toPlainText());
onSendMessageRequest(Q2PSTRING(input_->toPlainText()), isCorrection_);
- isCorrection_ = false;
inputClearing_ = true;
input_->clear();
+ cancelCorrection();
inputClearing_ = false;
}
diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h
index fd6b315..a95041e 100644
--- a/Swift/QtUI/QtChatWindow.h
+++ b/Swift/QtUI/QtChatWindow.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2011 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -17,6 +17,7 @@
class QTextEdit;
class QLineEdit;
class QComboBox;
+class QLabel;
namespace Swift {
class QtChatView;
@@ -77,6 +78,8 @@ namespace Swift {
private:
void updateTitleWithUnreadCount();
void tabComplete();
+ void beginCorrection();
+ void cancelCorrection();
std::string addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const QString& style, const boost::posix_time::ptime& time);
int unreadCount_;
@@ -89,6 +92,7 @@ namespace Swift {
QtTextEdit* input_;
QComboBox* labelsWidget_;
QtTreeWidget* treeWidget_;
+ QLabel* correctingLabel_;
TabComplete* completer_;
std::vector<SecurityLabelsCatalog::Item> availableLabels_;
bool isCorrection_;
diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp
index f7ac1ef..3a62325 100644
--- a/Swift/QtUI/QtTextEdit.cpp
+++ b/Swift/QtUI/QtTextEdit.cpp
@@ -31,11 +31,15 @@ void QtTextEdit::keyPressEvent(QKeyEvent* event) {
|| (key == Qt::Key_Tab && modifiers == Qt::ControlModifier)
|| (key == Qt::Key_A && modifiers == Qt::AltModifier)
|| (key == Qt::Key_Tab)
- || (key == Qt::Key_Up)
- || (key == Qt::Key_Down)
) {
emit unhandledKeyPressEvent(event);
}
+ else if ((key == Qt::Key_Up)
+ || (key == Qt::Key_Down)
+ ){
+ emit unhandledKeyPressEvent(event);
+ QTextEdit::keyPressEvent(event);
+ }
else {
QTextEdit::keyPressEvent(event);
}