2017-05-31 14:33:21 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2015 Albert Vaca <albertvaka@gmail.com>
|
2017-05-31 14:33:21 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2017-05-31 14:33:21 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sendreplydialog.h"
|
|
|
|
|
|
|
|
#include <QBoxLayout>
|
2021-09-22 14:45:58 +01:00
|
|
|
#include <QKeyEvent>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QTextEdit>
|
2017-05-31 14:33:21 +01:00
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
|
2017-08-03 16:23:12 +01:00
|
|
|
#include "ui_sendreplydialog.h"
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
SendReplyDialog::SendReplyDialog(const QString &originalMessage, const QString &replyId, const QString &topicName, QWidget *parent)
|
2017-05-31 14:33:21 +01:00
|
|
|
: QDialog(parent)
|
2017-09-03 20:39:44 +01:00
|
|
|
, m_replyId(replyId)
|
2017-08-03 16:23:12 +01:00
|
|
|
, m_ui(new Ui::SendReplyDialog)
|
2017-05-31 14:33:21 +01:00
|
|
|
{
|
2017-08-03 16:23:12 +01:00
|
|
|
m_ui->setupUi(this);
|
2019-06-10 15:40:28 +01:00
|
|
|
m_ui->textView->setText(topicName + QStringLiteral(": \n") + originalMessage);
|
2017-05-31 14:33:21 +01:00
|
|
|
|
2017-08-03 16:23:12 +01:00
|
|
|
auto button = m_ui->buttonBox->button(QDialogButtonBox::Ok);
|
|
|
|
button->setText(i18n("Send"));
|
2017-05-31 14:33:21 +01:00
|
|
|
|
2021-09-22 14:45:58 +01:00
|
|
|
auto textEdit = m_ui->replyEdit;
|
|
|
|
connect(textEdit, &SendReplyTextEdit::send, this, &SendReplyDialog::sendButtonClicked);
|
|
|
|
|
2017-08-03 16:23:12 +01:00
|
|
|
connect(this, &QDialog::accepted, this, &SendReplyDialog::sendButtonClicked);
|
2017-05-31 14:33:21 +01:00
|
|
|
setWindowTitle(topicName);
|
2021-05-23 06:12:29 +01:00
|
|
|
setWindowIcon(QIcon::fromTheme(QStringLiteral("kdeconnect")));
|
2017-05-31 14:33:21 +01:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
2021-02-01 13:10:47 +00:00
|
|
|
m_ui->replyEdit->setFocus();
|
2017-05-31 14:33:21 +01:00
|
|
|
}
|
|
|
|
|
2017-08-03 16:23:12 +01:00
|
|
|
SendReplyDialog::~SendReplyDialog() = default;
|
2017-05-31 14:33:21 +01:00
|
|
|
|
|
|
|
void SendReplyDialog::sendButtonClicked()
|
|
|
|
{
|
2017-09-03 21:00:06 +01:00
|
|
|
Q_EMIT sendReply(m_replyId, m_ui->replyEdit->toPlainText());
|
2017-05-31 14:33:21 +01:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize SendReplyDialog::sizeHint() const
|
|
|
|
{
|
|
|
|
return QSize(512, 64);
|
|
|
|
}
|
2021-09-22 14:45:58 +01:00
|
|
|
|
|
|
|
SendReplyTextEdit::SendReplyTextEdit(QWidget *parent)
|
|
|
|
: QTextEdit(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
void SendReplyTextEdit::keyPressEvent(QKeyEvent *event)
|
2021-09-22 14:45:58 +01:00
|
|
|
{
|
|
|
|
// 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);
|
|
|
|
}
|