1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

arrow up to paste previous message

This commit is contained in:
agilob 2015-01-26 00:25:45 +00:00
parent 7f01288eb4
commit fe8f6593c7
No known key found for this signature in database
GPG Key ID: 34568050DBCCB997
3 changed files with 31 additions and 3 deletions

View File

@ -143,6 +143,8 @@ void ChatForm::onSendTriggered()
rec = Core::getInstance()->sendMessage(f->getFriendID(), qt_msg);
registerReceipt(rec, id, ma);
msgEdit->setLastMessage(msg); //set last message only when sending it
}
msgEdit->clear();

View File

@ -16,6 +16,7 @@
#include "chattextedit.h"
#include <QKeyEvent>
#include <QDebug>
ChatTextEdit::ChatTextEdit(QWidget *parent) :
QTextEdit(parent)
@ -31,9 +32,31 @@ void ChatTextEdit::keyPressEvent(QKeyEvent * event)
emit enterPressed();
else if (key == Qt::Key_Tab)
emit tabPressed();
else if (key == Qt::Key_Up && this->toPlainText().isEmpty())
{
this->setText(lastMessage);
this->setFocus();
}
else if (key == Qt::Key_Up && !this->toPlainText().isEmpty())
{
currentMessage = this->toPlainText();
this->setText(lastMessage);
}
else if (key == Qt::Key_Down && !currentMessage.isEmpty())
{
this->setPlainText(currentMessage);
currentMessage.clear();
}
else if (key == Qt::Key_Down)
this->clear();
else
{
emit keyPressed();
QTextEdit::keyPressEvent(event);
}
}
void ChatTextEdit::setLastMessage(QString lm)
{
lastMessage = lm;
}

View File

@ -25,13 +25,16 @@ class ChatTextEdit : public QTextEdit
public:
explicit ChatTextEdit(QWidget *parent = 0);
virtual void keyPressEvent(QKeyEvent * event) override;
void setLastMessage(QString lm);
signals:
void enterPressed();
void tabPressed();
void keyPressed();
public slots:
private:
QString lastMessage,
currentMessage;
};