Commit 1cf0eaba authored by Nicolas Fella's avatar Nicolas Fella
Browse files

[sendreplydialog] Submit on enter, enter newline on shift+enter

This enables better keyboard navigation and is consistent with virtually all messaging apps

CCBUG: 441742
(cherry picked from commit 695e3675)
parent f6b81d4b
......@@ -11,6 +11,7 @@
#include <QLineEdit>
#include <QBoxLayout>
#include <QStandardPaths>
#include <QKeyEvent>
#include <KLocalizedString>
......@@ -27,6 +28,9 @@ SendReplyDialog::SendReplyDialog(const QString& originalMessage, const QString&
auto button = m_ui->buttonBox->button(QDialogButtonBox::Ok);
button->setText(i18n("Send"));
auto textEdit = m_ui->replyEdit;
connect(textEdit, &SendReplyTextEdit::send, this, &SendReplyDialog::sendButtonClicked);
connect(this, &QDialog::accepted, this, &SendReplyDialog::sendButtonClicked);
setWindowTitle(topicName);
setWindowIcon(QIcon::fromTheme(QStringLiteral("kdeconnect")));
......@@ -46,3 +50,22 @@ QSize SendReplyDialog::sizeHint() const
{
return QSize(512, 64);
}
SendReplyTextEdit::SendReplyTextEdit(QWidget *parent)
: QTextEdit(parent)
{
}
void SendReplyTextEdit::keyPressEvent(QKeyEvent* event)
{
// Send reply on enter, except when shift + enter is pressed, then insert newline
const int key = event->key();
if (key == Qt::Key_Return || key == Qt::Key_Enter) {
if ((key == Qt::Key_Enter && (event->modifiers() == Qt::KeypadModifier)) || !event->modifiers()) {
Q_EMIT send();
event->accept();
return;
}
}
QTextEdit::keyPressEvent(event);
}
......@@ -9,6 +9,7 @@
#include <QDialog>
#include <QSize>
#include <QTextEdit>
namespace Ui { class SendReplyDialog; }
......@@ -33,4 +34,15 @@ private:
const QScopedPointer<Ui::SendReplyDialog> m_ui;
};
class SendReplyTextEdit : public QTextEdit
{
Q_OBJECT
public:
SendReplyTextEdit(QWidget* parent);
void keyPressEvent(QKeyEvent* event) override;
Q_SIGNAL void send();
};
#endif
......@@ -25,7 +25,7 @@
</widget>
</item>
<item>
<widget class="QTextEdit" name="replyEdit"/>
<widget class="SendReplyTextEdit" name="replyEdit"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
......@@ -71,4 +71,11 @@
</hints>
</connection>
</connections>
<customwidgets>
<customwidget>
<class>SendReplyTextEdit</class>
<extends>QTextEdit</extends>
<header>sendreplydialog.h</header>
</customwidget>
</customwidgets>
</ui>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment